bump product version to 4.1.6.2
[LibreOffice.git] / solenv / bin / modules / installer / profiles.pm
blobe873a85b96ed26429520a884bb0c01e3b1eac6f4
2 # This file is part of the LibreOffice project.
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 # This file incorporates work covered by the following license notice:
10 # Licensed to the Apache Software Foundation (ASF) under one or more
11 # contributor license agreements. See the NOTICE file distributed
12 # with this work for additional information regarding copyright
13 # ownership. The ASF licenses this file to you under the Apache
14 # License, Version 2.0 (the "License"); you may not use this file
15 # except in compliance with the License. You may obtain a copy of
16 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package installer::profiles;
21 use installer::converter;
22 use installer::files;
23 use installer::globals;
24 use installer::logger;
25 use installer::remover;
26 use installer::systemactions;
28 #############################
29 # Profiles
30 #############################
32 #######################################################
33 # Sorting the content of a profile
34 #######################################################
36 sub sorting_profile {
37 my ($profilesref) = @_;
39 my @sections;
40 my %section_content;
42 for ( my $i = 0; $i < @{$profilesref}; $i++ ) {
43 my $line = ${$profilesref}[$i];
45 # Skip unless this is a section (every second line)
46 next unless ( $line =~ /^\s*(\[.*\])\s*$/ );
48 my $section = $1;
49 my $next_line = ${$profilesref}[$i+1];
51 if ( ! exists $section_content{$section} ) {
52 push @sections, $section;
55 push @{ $section_content{$section} }, $next_line;
58 my @profile;
60 for my $section (@sections) {
61 push @profile, "$section\n";
62 push @profile, @{ $section_content{$section} };
65 return \@profile;
68 #####################################################################
69 # Adding the newly created profile into the file list
70 #####################################################################
72 sub add_profile_into_filelist
74 my ($filesarrayref, $oneprofile, $completeprofilename, $allvariables) = @_;
76 my %profile = ();
78 # Taking the base data from the "gid_File_Lib_Oox"
80 my $vclgid = "gid_File_Lib_Oox";
81 if ( $allvariables->{'GLOBALFILEGID'} ) { $vclgid = $allvariables->{'GLOBALFILEGID'}; }
82 my ($vclfile) = grep {$_->{gid} eq $vclgid} @{$filesarrayref};
83 if (! defined $vclfile) {
84 die "Could not find file $vclgid in list of files!";
87 # copying all base data
88 installer::converter::copy_item_object($vclfile, \%profile);
90 # and overriding all new values
92 $profile{'ismultilingual'} = 0;
93 $profile{'sourcepath'} = $completeprofilename;
94 $profile{'Name'} = $oneprofile->{'Name'};
95 $profile{'UnixRights'} = "644";
96 $profile{'gid'} = $oneprofile->{'gid'};
97 $profile{'Dir'} = $oneprofile->{'Dir'};
98 $profile{'destination'} = $oneprofile->{'destination'};
99 $profile{'Styles'} = "";
100 if ( $oneprofile->{'Styles'} ) { $profile{'Styles'} = $oneprofile->{'Styles'}; }
101 $profile{'modules'} = $oneprofile->{'ModuleID'}; # Profiles can only be added completely to a module
103 push(@{$filesarrayref}, \%profile);
106 ###################################################
107 # Including Windows line ends in ini files
108 # Profiles on Windows shall have \r\n line ends
109 ###################################################
111 sub include_windows_lineends
113 my ($onefile) = @_;
115 for ( my $i = 0; $i <= $#{$onefile}; $i++ )
117 ${$onefile}[$i] =~ s/\r?\n$/\r\n/;
121 ####################################
122 # Create profiles
123 ####################################
125 sub create_profiles
127 my ($profilesref, $profileitemsref, $filesarrayref, $languagestringref, $allvariables) = @_;
129 my $infoline;
131 my $profilesdir = installer::systemactions::create_directories("profiles", $languagestringref);
133 installer::logger::include_header_into_logfile("Creating profiles:");
135 # Attention: The module dependencies from ProfileItems have to be ignored, because
136 # the Profile has to be installed completely with all of its content and the correct name.
137 # Only complete profiles can belong to a specified module, but not ProfileItems!
139 # iterating over all files
141 for ( my $i = 0; $i <= $#{$profilesref}; $i++ )
143 my $oneprofile = ${$profilesref}[$i];
144 my $dir = $oneprofile->{'Dir'};
145 if ( $dir eq "PREDEFINED_CONFIGDIR" ) { next; } # ignoring the profile sversion file
147 my $profilegid = $oneprofile->{'gid'};
148 my $profilename = $oneprofile->{'Name'};
150 my $localprofilesdir = $profilesdir . $installer::globals::separator . $profilegid; # uniqueness guaranteed by gid
151 if ( ! -d $localprofilesdir ) { installer::systemactions::create_directory($localprofilesdir); }
153 my @onefile = ();
154 my $profileempty = 1;
156 for ( my $j = 0; $j <= $#{$profileitemsref}; $j++ )
158 my $oneprofileitem = ${$profileitemsref}[$j];
160 my $styles = "";
161 if ( $oneprofileitem->{'Styles'} ) { $styles = $oneprofileitem->{'Styles'}; }
162 if ( $styles =~ /\bINIFILETABLE\b/ ) { next; } # these values are written during installation, not during packing
164 my $profileid = $oneprofileitem->{'ProfileID'};
166 if ( $profileid eq $profilegid )
168 my $section = $oneprofileitem->{'Section'};
169 my $key = $oneprofileitem->{'Key'};
170 my $value = $oneprofileitem->{'Value'};
171 for (my $pk = 1; $pk <= 50; $pk++)
173 my $key = "ValueList" . $pk;
174 if ( $oneprofileitem->{$key} )
175 { $value = $value . " " . $oneprofileitem->{$key} }
177 my $order = $oneprofileitem->{'Order'}; # ignoring order at the moment
179 my $line = "[" . $section . "]" . "\n";
180 push(@onefile, $line);
181 $line = $key . "=" . $value . "\n";
182 push(@onefile, $line);
184 $profileempty = 0;
188 if ( $profileempty ) { next; } # ignoring empty profiles
190 # Sorting the array @onefile
191 my $onefileref = sorting_profile(\@onefile);
193 if ( $installer::globals::iswin && $^O =~ /cygwin/i) # Windows line ends only for Cygwin
195 include_windows_lineends($onefileref);
198 # Saving the profile as a file
199 $completeprofilename = $localprofilesdir . $installer::globals::separator . $profilename;
201 installer::files::save_file($completeprofilename, $onefileref);
203 # Adding the file to the filearray
204 # Some data are set now, others are taken from the file "soffice.exe" ("soffice.bin")
205 add_profile_into_filelist($filesarrayref, $oneprofile, $completeprofilename, $allvariables);
207 $infoline = "Created Profile: $completeprofilename\n";
208 push( @installer::globals::logfileinfo, $infoline);
211 $infoline = "\n";
212 push( @installer::globals::logfileinfo, $infoline);