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
;
24 use installer
::converter
;
26 use installer
::globals
;
27 use installer
::logger
;
28 use installer
::remover
;
29 use installer
::systemactions
;
31 #############################
33 #############################
35 #######################################################
36 # Sorting the content of a profile
37 #######################################################
40 my ($profilesref) = @_;
45 for ( my $i = 0; $i < @
{$profilesref}; $i++ ) {
46 my $line = ${$profilesref}[$i];
48 # Skip unless this is a section (every second line)
49 next unless ( $line =~ /^\s*(\[.*\])\s*$/ );
52 my $next_line = ${$profilesref}[$i+1];
54 if ( ! exists $section_content{$section} ) {
55 push @sections, $section;
58 push @
{ $section_content{$section} }, $next_line;
63 for my $section (@sections) {
64 push @profile, "$section\n";
65 push @profile, @
{ $section_content{$section} };
71 #####################################################################
72 # Adding the newly created profile into the file list
73 #####################################################################
75 sub add_profile_into_filelist
77 my ($filesarrayref, $oneprofile, $completeprofilename, $allvariables) = @_;
81 # Taking the base data from a file in the root module
83 if ( ! $allvariables->{'ROOTMODULEGID'} ) { installer
::exiter
::exit_program
("ERROR: ROOTMODULEGID must be defined in list file!", "add_profile_into_filelist"); }
84 my $rootmodulegid = $allvariables->{'ROOTMODULEGID'};
86 foreach my $file (@
{$filesarrayref}) {
87 if ($file->{'modules'} eq $rootmodulegid)
93 if (! defined $rootfile) {
94 die "Could not find any file from module $rootmodulegid in list of files!";
97 # copying all base data
98 installer
::converter
::copy_item_object
($rootfile, \
%profile);
100 # and overriding all new values
102 $profile{'ismultilingual'} = 0;
103 $profile{'sourcepath'} = $completeprofilename;
104 $profile{'Name'} = $oneprofile->{'Name'};
105 $profile{'UnixRights'} = "644";
106 $profile{'gid'} = $oneprofile->{'gid'};
107 $profile{'Dir'} = $oneprofile->{'Dir'};
108 $profile{'destination'} = $oneprofile->{'destination'};
109 $profile{'Styles'} = "";
110 if ( $oneprofile->{'Styles'} ) { $profile{'Styles'} = $oneprofile->{'Styles'}; }
111 $profile{'modules'} = $oneprofile->{'ModuleID'}; # Profiles can only be added completely to a module
113 push(@
{$filesarrayref}, \
%profile);
116 ###################################################
117 # Including Windows line ends in ini files
118 # Profiles on Windows shall have \r\n line ends
119 ###################################################
121 sub include_windows_lineends
125 for ( my $i = 0; $i <= $#{$onefile}; $i++ )
127 ${$onefile}[$i] =~ s/\r?\n$/\r\n/;
131 ####################################
133 ####################################
137 my ($profilesref, $profileitemsref, $filesarrayref, $languagestringref, $allvariables) = @_;
141 my $profilesdir = installer
::systemactions
::create_directories
("profiles", $languagestringref);
143 installer
::logger
::include_header_into_logfile
("Creating profiles:");
145 # Attention: The module dependencies from ProfileItems have to be ignored, because
146 # the Profile has to be installed completely with all of its content and the correct name.
147 # Only complete profiles can belong to a specified module, but not ProfileItems!
149 # iterating over all files
151 for ( my $i = 0; $i <= $#{$profilesref}; $i++ )
153 my $oneprofile = ${$profilesref}[$i];
154 my $dir = $oneprofile->{'Dir'};
155 if ( $dir eq "PREDEFINED_CONFIGDIR" ) { next; } # ignoring the profile sversion file
157 my $profilegid = $oneprofile->{'gid'};
158 my $profilename = $oneprofile->{'Name'};
160 my $localprofilesdir = $profilesdir . $installer::globals
::separator
. $profilegid; # uniqueness guaranteed by gid
161 if ( ! -d
$localprofilesdir ) { installer
::systemactions
::create_directory
($localprofilesdir); }
164 my $profileempty = 1;
166 for ( my $j = 0; $j <= $#{$profileitemsref}; $j++ )
168 my $oneprofileitem = ${$profileitemsref}[$j];
171 if ( $oneprofileitem->{'Styles'} ) { $styles = $oneprofileitem->{'Styles'}; }
172 if ( $styles =~ /\bINIFILETABLE\b/ ) { next; } # these values are written during installation, not during packing
174 my $profileid = $oneprofileitem->{'ProfileID'};
176 if ( $profileid eq $profilegid )
178 my $section = $oneprofileitem->{'Section'};
179 my $key = $oneprofileitem->{'Key'};
180 my $value = $oneprofileitem->{'Value'};
181 for (my $pk = 1; $pk <= 50; $pk++)
183 my $key = "ValueList" . $pk;
184 if ( $oneprofileitem->{$key} )
185 { $value = $value . " " . $oneprofileitem->{$key} }
187 my $order = $oneprofileitem->{'Order'}; # ignoring order at the moment
189 my $line = "[" . $section . "]" . "\n";
190 push(@onefile, $line);
191 $line = $key . "=" . $value . "\n";
192 push(@onefile, $line);
198 if ( $profileempty ) { next; } # ignoring empty profiles
200 # Sorting the array @onefile
201 my $onefileref = sorting_profile
(\
@onefile);
203 if ( $installer::globals
::iswin
&& $^O
=~ /cygwin/i) # Windows line ends only for Cygwin
205 include_windows_lineends
($onefileref);
208 # Saving the profile as a file
209 my $completeprofilename = $localprofilesdir . $installer::globals
::separator
. $profilename;
211 installer
::files
::save_file
($completeprofilename, $onefileref);
213 # Adding the file to the filearray
214 # Some data are set now, others are taken from the file "soffice.exe" ("soffice.bin")
215 add_profile_into_filelist
($filesarrayref, $oneprofile, $completeprofilename, $allvariables);
217 $infoline = "Created Profile: $completeprofilename\n";
218 push( @installer::globals
::logfileinfo
, $infoline);
222 push( @installer::globals
::logfileinfo
, $infoline);