merge the formfield patch from ooo-build
[ooovba.git] / solenv / bin / modules / installer / profiles.pm
blobcdcf2f373f7bfd78b34a34fee2b95e2e57ec17bb
1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 #
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # $RCSfile: profiles.pm,v $
11 # $Revision: 1.9 $
13 # This file is part of OpenOffice.org.
15 # OpenOffice.org is free software: you can redistribute it and/or modify
16 # it under the terms of the GNU Lesser General Public License version 3
17 # only, as published by the Free Software Foundation.
19 # OpenOffice.org is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU Lesser General Public License version 3 for more details
23 # (a copy is included in the LICENSE file that accompanied this code).
25 # You should have received a copy of the GNU Lesser General Public License
26 # version 3 along with OpenOffice.org. If not, see
27 # <http://www.openoffice.org/license.html>
28 # for a copy of the LGPLv3 License.
30 #*************************************************************************
32 package installer::profiles;
34 use installer::converter;
35 use installer::existence;
36 use installer::exiter;
37 use installer::files;
38 use installer::globals;
39 use installer::logger;
40 use installer::remover;
41 use installer::systemactions;
43 #############################
44 # Profiles
45 #############################
47 #######################################################
48 # Sorting the content of a profile
49 #######################################################
51 sub sorting_profile
53 my ($profilesref) = @_;
55 my @profile = ();
56 my @definedsections = ();
58 for ( my $i = 0; $i <= $#{$profilesref}; $i++ )
60 my $line = ${$profilesref}[$i];
62 if ( $line =~ /^\s*(\[.*\])\s*$/ ) # this is a section (every second line)
64 my $section = $1;
66 if (!(installer::existence::exists_in_array($section, \@definedsections)))
68 my $sectionline = $section . "\n";
69 push(@definedsections, $section);
70 push(@profile, $sectionline);
72 for ( my $j = 0; $j <= $#{$profilesref}; $j++ )
74 my $oneline = ${$profilesref}[$j];
75 installer::remover::remove_leading_and_ending_whitespaces(\$oneline);
77 if ( $oneline eq $section )
79 my $nextline = ${$profilesref}[$j+1];
80 push(@profile, $nextline);
87 return \@profile;
90 #####################################################################
91 # Adding the newly created profile into the file list
92 #####################################################################
94 sub add_profile_into_filelist
96 my ($filesarrayref, $oneprofile, $completeprofilename, $allvariables) = @_;
98 my %profile = ();
100 # Taking the base data from the "gid_File_Lib_Vcl"
102 my $vclgid = "gid_File_Lib_Vcl";
103 if ( $allvariables->{'GLOBALFILEGID'} ) { $vclgid = $allvariables->{'GLOBALFILEGID'}; }
104 my $vclfile = installer::existence::get_specified_file($filesarrayref, $vclgid);
106 # copying all base data
107 installer::converter::copy_item_object($vclfile, \%profile);
109 # and overriding all new values
111 $profile{'ismultilingual'} = 0;
112 $profile{'sourcepath'} = $completeprofilename;
113 $profile{'Name'} = $oneprofile->{'Name'};
114 $profile{'UnixRights'} = "444";
115 $profile{'gid'} = $oneprofile->{'gid'};
116 $profile{'Dir'} = $oneprofile->{'Dir'};
117 $profile{'destination'} = $oneprofile->{'destination'};
118 $profile{'Styles'} = "";
119 if ( $oneprofile->{'Styles'} ) { $profile{'Styles'} = $oneprofile->{'Styles'}; }
120 $profile{'modules'} = $oneprofile->{'ModuleID'}; # Profiles can only be added completely to a module
122 push(@{$filesarrayref}, \%profile);
125 ###################################################
126 # Including Windows line ends in ini files
127 # Profiles on Windows shall have \r\n line ends
128 ###################################################
130 sub include_windows_lineends
132 my ($onefile) = @_;
134 for ( my $i = 0; $i <= $#{$onefile}; $i++ )
136 ${$onefile}[$i] =~ s/\r?\n$/\r\n/;
140 ####################################
141 # Create profiles
142 ####################################
144 sub create_profiles
146 my ($profilesref, $profileitemsref, $filesarrayref, $languagestringref, $allvariables) = @_;
148 my $infoline;
150 my $profilesdir = installer::systemactions::create_directories("profiles", $languagestringref);
152 installer::logger::include_header_into_logfile("Creating profiles:");
154 # Attention: The module dependencies from ProfileItems have to be ignored, because
155 # the Profile has to be installed completely with all of its content and the correct name.
156 # Only complete profiles can belong to a specified module, but not ProfileItems!
158 # iterating over all files
160 for ( my $i = 0; $i <= $#{$profilesref}; $i++ )
162 my $oneprofile = ${$profilesref}[$i];
163 my $dir = $oneprofile->{'Dir'};
164 if ( $dir eq "PREDEFINED_CONFIGDIR" ) { next; } # ignoring the profile sversion file
166 my $profilegid = $oneprofile->{'gid'};
167 my $profilename = $oneprofile->{'Name'};
169 my $localprofilesdir = $profilesdir . $installer::globals::separator . $profilegid; # uniqueness guaranteed by gid
170 if ( ! -d $localprofilesdir ) { installer::systemactions::create_directory($localprofilesdir); }
172 my @onefile = ();
173 my $profileempty = 1;
175 for ( my $j = 0; $j <= $#{$profileitemsref}; $j++ )
177 my $oneprofileitem = ${$profileitemsref}[$j];
179 my $styles = "";
180 if ( $oneprofileitem->{'Styles'} ) { $styles = $oneprofileitem->{'Styles'}; }
181 if ( $styles =~ /\bINIFILETABLE\b/ ) { next; } # these values are written during installation, not during packing
183 my $profileid = $oneprofileitem->{'ProfileID'};
185 if ( $profileid eq $profilegid )
187 my $section = $oneprofileitem->{'Section'};
188 my $key = $oneprofileitem->{'Key'};
189 my $value = $oneprofileitem->{'Value'};
190 for (my $pk = 1; $pk <= 50; $pk++)
192 my $key = "ValueList" . $pk;
193 if ( $oneprofileitem->{$key} )
194 { $value = $value . " " . $oneprofileitem->{$key} }
196 my $order = $oneprofileitem->{'Order'}; # ignoring order at the moment
198 my $line = "[" . $section . "]" . "\n";
199 push(@onefile, $line);
200 $line = $key . "=" . $value . "\n";
201 push(@onefile, $line);
203 $profileempty = 0;
207 if ( $profileempty ) { next; } # ignoring empty profiles
209 # Sorting the array @onefile
210 my $onefileref = sorting_profile(\@onefile);
212 if ( $installer::globals::iswin && $installer::globals::plat =~ /cygwin/i) # Windows line ends only for Cygwin
214 include_windows_lineends($onefileref);
217 # Saving the profile as a file
218 $completeprofilename = $localprofilesdir . $installer::globals::separator . $profilename;
220 installer::files::save_file($completeprofilename, $onefileref);
222 # Adding the file to the filearray
223 # Some data are set now, others are taken from the file "soffice.exe" ("soffice.bin")
224 add_profile_into_filelist($filesarrayref, $oneprofile, $completeprofilename, $allvariables);
226 $infoline = "Created Profile: $completeprofilename\n";
227 push( @installer::globals::logfileinfo, $infoline);
230 $infoline = "\n";
231 push( @installer::globals::logfileinfo, $infoline);