Branch libreoffice-5-0-4
[LibreOffice.git] / solenv / bin / modules / installer / profiles.pm
bloba1a7b4507c7172a594d33089f9cc8dacdc19fd43
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 a file in the root module
80 if ( ! $allvariables->{'ROOTMODULEGID'} ) { installer::exiter::exit_program("ERROR: ROOTMODULEGID must be defined in list file!", "add_profile_into_filelist"); }
81 my $rootmodulegid = $allvariables->{'ROOTMODULEGID'};
82 my $rootfile;
83 foreach my $file (@{$filesarrayref}) {
84 if ($file->{'modules'} eq $rootmodulegid)
86 $rootfile = $file;
87 last;
90 if (! defined $rootfile) {
91 die "Could not find any file from module $rootmodulegid in list of files!";
94 # copying all base data
95 installer::converter::copy_item_object($rootfile, \%profile);
97 # and overriding all new values
99 $profile{'ismultilingual'} = 0;
100 $profile{'sourcepath'} = $completeprofilename;
101 $profile{'Name'} = $oneprofile->{'Name'};
102 $profile{'UnixRights'} = "644";
103 $profile{'gid'} = $oneprofile->{'gid'};
104 $profile{'Dir'} = $oneprofile->{'Dir'};
105 $profile{'destination'} = $oneprofile->{'destination'};
106 $profile{'Styles'} = "";
107 if ( $oneprofile->{'Styles'} ) { $profile{'Styles'} = $oneprofile->{'Styles'}; }
108 $profile{'modules'} = $oneprofile->{'ModuleID'}; # Profiles can only be added completely to a module
110 push(@{$filesarrayref}, \%profile);
113 ###################################################
114 # Including Windows line ends in ini files
115 # Profiles on Windows shall have \r\n line ends
116 ###################################################
118 sub include_windows_lineends
120 my ($onefile) = @_;
122 for ( my $i = 0; $i <= $#{$onefile}; $i++ )
124 ${$onefile}[$i] =~ s/\r?\n$/\r\n/;
128 ####################################
129 # Create profiles
130 ####################################
132 sub create_profiles
134 my ($profilesref, $profileitemsref, $filesarrayref, $languagestringref, $allvariables) = @_;
136 my $infoline;
138 my $profilesdir = installer::systemactions::create_directories("profiles", $languagestringref);
140 installer::logger::include_header_into_logfile("Creating profiles:");
142 # Attention: The module dependencies from ProfileItems have to be ignored, because
143 # the Profile has to be installed completely with all of its content and the correct name.
144 # Only complete profiles can belong to a specified module, but not ProfileItems!
146 # iterating over all files
148 for ( my $i = 0; $i <= $#{$profilesref}; $i++ )
150 my $oneprofile = ${$profilesref}[$i];
151 my $dir = $oneprofile->{'Dir'};
152 if ( $dir eq "PREDEFINED_CONFIGDIR" ) { next; } # ignoring the profile sversion file
154 my $profilegid = $oneprofile->{'gid'};
155 my $profilename = $oneprofile->{'Name'};
157 my $localprofilesdir = $profilesdir . $installer::globals::separator . $profilegid; # uniqueness guaranteed by gid
158 if ( ! -d $localprofilesdir ) { installer::systemactions::create_directory($localprofilesdir); }
160 my @onefile = ();
161 my $profileempty = 1;
163 for ( my $j = 0; $j <= $#{$profileitemsref}; $j++ )
165 my $oneprofileitem = ${$profileitemsref}[$j];
167 my $styles = "";
168 if ( $oneprofileitem->{'Styles'} ) { $styles = $oneprofileitem->{'Styles'}; }
169 if ( $styles =~ /\bINIFILETABLE\b/ ) { next; } # these values are written during installation, not during packing
171 my $profileid = $oneprofileitem->{'ProfileID'};
173 if ( $profileid eq $profilegid )
175 my $section = $oneprofileitem->{'Section'};
176 my $key = $oneprofileitem->{'Key'};
177 my $value = $oneprofileitem->{'Value'};
178 for (my $pk = 1; $pk <= 50; $pk++)
180 my $key = "ValueList" . $pk;
181 if ( $oneprofileitem->{$key} )
182 { $value = $value . " " . $oneprofileitem->{$key} }
184 my $order = $oneprofileitem->{'Order'}; # ignoring order at the moment
186 my $line = "[" . $section . "]" . "\n";
187 push(@onefile, $line);
188 $line = $key . "=" . $value . "\n";
189 push(@onefile, $line);
191 $profileempty = 0;
195 if ( $profileempty ) { next; } # ignoring empty profiles
197 # Sorting the array @onefile
198 my $onefileref = sorting_profile(\@onefile);
200 if ( $installer::globals::iswin && $^O =~ /cygwin/i) # Windows line ends only for Cygwin
202 include_windows_lineends($onefileref);
205 # Saving the profile as a file
206 $completeprofilename = $localprofilesdir . $installer::globals::separator . $profilename;
208 installer::files::save_file($completeprofilename, $onefileref);
210 # Adding the file to the filearray
211 # Some data are set now, others are taken from the file "soffice.exe" ("soffice.bin")
212 add_profile_into_filelist($filesarrayref, $oneprofile, $completeprofilename, $allvariables);
214 $infoline = "Created Profile: $completeprofilename\n";
215 push( @installer::globals::logfileinfo, $infoline);
218 $infoline = "\n";
219 push( @installer::globals::logfileinfo, $infoline);