1*cdf0e10cSrcweir#*************************************************************************
2*cdf0e10cSrcweir#
3*cdf0e10cSrcweir# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir#
5*cdf0e10cSrcweir# Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir#
7*cdf0e10cSrcweir# OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir#
9*cdf0e10cSrcweir# This file is part of OpenOffice.org.
10*cdf0e10cSrcweir#
11*cdf0e10cSrcweir# OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir# it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir# only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir#
15*cdf0e10cSrcweir# OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir# but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir# GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir# (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir#
21*cdf0e10cSrcweir# You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir# version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir# <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir# for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir#
26*cdf0e10cSrcweir#*************************************************************************
27*cdf0e10cSrcweir
28*cdf0e10cSrcweirpackage installer::profiles;
29*cdf0e10cSrcweir
30*cdf0e10cSrcweiruse installer::converter;
31*cdf0e10cSrcweiruse installer::existence;
32*cdf0e10cSrcweiruse installer::exiter;
33*cdf0e10cSrcweiruse installer::files;
34*cdf0e10cSrcweiruse installer::globals;
35*cdf0e10cSrcweiruse installer::logger;
36*cdf0e10cSrcweiruse installer::remover;
37*cdf0e10cSrcweiruse installer::systemactions;
38*cdf0e10cSrcweir
39*cdf0e10cSrcweir#############################
40*cdf0e10cSrcweir# Profiles
41*cdf0e10cSrcweir#############################
42*cdf0e10cSrcweir
43*cdf0e10cSrcweir#######################################################
44*cdf0e10cSrcweir# Sorting the content of a profile
45*cdf0e10cSrcweir#######################################################
46*cdf0e10cSrcweir
47*cdf0e10cSrcweirsub sorting_profile
48*cdf0e10cSrcweir{
49*cdf0e10cSrcweir	my ($profilesref) = @_;
50*cdf0e10cSrcweir
51*cdf0e10cSrcweir	my @profile = ();
52*cdf0e10cSrcweir	my @definedsections = ();
53*cdf0e10cSrcweir
54*cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$profilesref}; $i++ )
55*cdf0e10cSrcweir	{
56*cdf0e10cSrcweir		my $line = ${$profilesref}[$i];
57*cdf0e10cSrcweir
58*cdf0e10cSrcweir		if ( $line =~ /^\s*(\[.*\])\s*$/ )	# this is a section (every second line)
59*cdf0e10cSrcweir		{
60*cdf0e10cSrcweir			my $section = $1;
61*cdf0e10cSrcweir
62*cdf0e10cSrcweir			if (!(installer::existence::exists_in_array($section, \@definedsections)))
63*cdf0e10cSrcweir			{
64*cdf0e10cSrcweir				my $sectionline = $section . "\n";
65*cdf0e10cSrcweir				push(@definedsections, $section);
66*cdf0e10cSrcweir				push(@profile, $sectionline);
67*cdf0e10cSrcweir
68*cdf0e10cSrcweir				for ( my $j = 0; $j <= $#{$profilesref}; $j++ )
69*cdf0e10cSrcweir				{
70*cdf0e10cSrcweir					my $oneline = ${$profilesref}[$j];
71*cdf0e10cSrcweir					installer::remover::remove_leading_and_ending_whitespaces(\$oneline);
72*cdf0e10cSrcweir
73*cdf0e10cSrcweir					if ( $oneline eq $section )
74*cdf0e10cSrcweir					{
75*cdf0e10cSrcweir						my $nextline = ${$profilesref}[$j+1];
76*cdf0e10cSrcweir						push(@profile, $nextline);
77*cdf0e10cSrcweir					}
78*cdf0e10cSrcweir				}
79*cdf0e10cSrcweir			}
80*cdf0e10cSrcweir		}
81*cdf0e10cSrcweir	}
82*cdf0e10cSrcweir
83*cdf0e10cSrcweir	return \@profile;
84*cdf0e10cSrcweir}
85*cdf0e10cSrcweir
86*cdf0e10cSrcweir#####################################################################
87*cdf0e10cSrcweir# Adding the newly created profile into the file list
88*cdf0e10cSrcweir#####################################################################
89*cdf0e10cSrcweir
90*cdf0e10cSrcweirsub add_profile_into_filelist
91*cdf0e10cSrcweir{
92*cdf0e10cSrcweir	my ($filesarrayref, $oneprofile, $completeprofilename, $allvariables) = @_;
93*cdf0e10cSrcweir
94*cdf0e10cSrcweir	my %profile = ();
95*cdf0e10cSrcweir
96*cdf0e10cSrcweir	# Taking the base data from the "gid_File_Lib_Vcl"
97*cdf0e10cSrcweir
98*cdf0e10cSrcweir	my $vclgid = "gid_File_Lib_Vcl";
99*cdf0e10cSrcweir	if ( $allvariables->{'GLOBALFILEGID'} ) { $vclgid = $allvariables->{'GLOBALFILEGID'}; }
100*cdf0e10cSrcweir	my $vclfile = installer::existence::get_specified_file($filesarrayref, $vclgid);
101*cdf0e10cSrcweir
102*cdf0e10cSrcweir	# copying all base data
103*cdf0e10cSrcweir	installer::converter::copy_item_object($vclfile, \%profile);
104*cdf0e10cSrcweir
105*cdf0e10cSrcweir	# and overriding all new values
106*cdf0e10cSrcweir
107*cdf0e10cSrcweir	$profile{'ismultilingual'} = 0;
108*cdf0e10cSrcweir	$profile{'sourcepath'} = $completeprofilename;
109*cdf0e10cSrcweir	$profile{'Name'} = $oneprofile->{'Name'};
110*cdf0e10cSrcweir	$profile{'UnixRights'} = "444";
111*cdf0e10cSrcweir	$profile{'gid'} = $oneprofile->{'gid'};
112*cdf0e10cSrcweir	$profile{'Dir'} = $oneprofile->{'Dir'};
113*cdf0e10cSrcweir	$profile{'destination'} = $oneprofile->{'destination'};
114*cdf0e10cSrcweir	$profile{'Styles'} = "";
115*cdf0e10cSrcweir	if ( $oneprofile->{'Styles'} ) { $profile{'Styles'} = $oneprofile->{'Styles'}; }
116*cdf0e10cSrcweir	$profile{'modules'} = $oneprofile->{'ModuleID'};	# Profiles can only be added completely to a module
117*cdf0e10cSrcweir
118*cdf0e10cSrcweir	push(@{$filesarrayref}, \%profile);
119*cdf0e10cSrcweir}
120*cdf0e10cSrcweir
121*cdf0e10cSrcweir###################################################
122*cdf0e10cSrcweir# Including Windows line ends in ini files
123*cdf0e10cSrcweir# Profiles on Windows shall have \r\n line ends
124*cdf0e10cSrcweir###################################################
125*cdf0e10cSrcweir
126*cdf0e10cSrcweirsub include_windows_lineends
127*cdf0e10cSrcweir{
128*cdf0e10cSrcweir	my ($onefile) = @_;
129*cdf0e10cSrcweir
130*cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$onefile}; $i++ )
131*cdf0e10cSrcweir	{
132*cdf0e10cSrcweir		${$onefile}[$i] =~ s/\r?\n$/\r\n/;
133*cdf0e10cSrcweir	}
134*cdf0e10cSrcweir}
135*cdf0e10cSrcweir
136*cdf0e10cSrcweir####################################
137*cdf0e10cSrcweir# Create profiles
138*cdf0e10cSrcweir####################################
139*cdf0e10cSrcweir
140*cdf0e10cSrcweirsub create_profiles
141*cdf0e10cSrcweir{
142*cdf0e10cSrcweir	my ($profilesref, $profileitemsref, $filesarrayref, $languagestringref, $allvariables) = @_;
143*cdf0e10cSrcweir
144*cdf0e10cSrcweir	my $infoline;
145*cdf0e10cSrcweir
146*cdf0e10cSrcweir	my $profilesdir = installer::systemactions::create_directories("profiles", $languagestringref);
147*cdf0e10cSrcweir
148*cdf0e10cSrcweir	installer::logger::include_header_into_logfile("Creating profiles:");
149*cdf0e10cSrcweir
150*cdf0e10cSrcweir	# Attention: The module dependencies from ProfileItems have to be ignored, because
151*cdf0e10cSrcweir	# the Profile has to be installed completely with all of its content and the correct name.
152*cdf0e10cSrcweir	# Only complete profiles can belong to a specified module, but not ProfileItems!
153*cdf0e10cSrcweir
154*cdf0e10cSrcweir	# iterating over all files
155*cdf0e10cSrcweir
156*cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$profilesref}; $i++ )
157*cdf0e10cSrcweir	{
158*cdf0e10cSrcweir		my $oneprofile = ${$profilesref}[$i];
159*cdf0e10cSrcweir		my $dir = $oneprofile->{'Dir'};
160*cdf0e10cSrcweir		if ( $dir eq "PREDEFINED_CONFIGDIR" ) { next; } 	# ignoring the profile sversion file
161*cdf0e10cSrcweir
162*cdf0e10cSrcweir		my $profilegid = $oneprofile->{'gid'};
163*cdf0e10cSrcweir		my $profilename = $oneprofile->{'Name'};
164*cdf0e10cSrcweir
165*cdf0e10cSrcweir		my $localprofilesdir = $profilesdir . $installer::globals::separator . $profilegid; # uniqueness guaranteed by gid
166*cdf0e10cSrcweir		if ( ! -d $localprofilesdir ) { installer::systemactions::create_directory($localprofilesdir); }
167*cdf0e10cSrcweir
168*cdf0e10cSrcweir		my @onefile = ();
169*cdf0e10cSrcweir		my $profileempty = 1;
170*cdf0e10cSrcweir
171*cdf0e10cSrcweir		for ( my $j = 0; $j <= $#{$profileitemsref}; $j++ )
172*cdf0e10cSrcweir		{
173*cdf0e10cSrcweir			my $oneprofileitem = ${$profileitemsref}[$j];
174*cdf0e10cSrcweir
175*cdf0e10cSrcweir			my $styles = "";
176*cdf0e10cSrcweir			if ( $oneprofileitem->{'Styles'} ) { $styles = $oneprofileitem->{'Styles'}; }
177*cdf0e10cSrcweir			if ( $styles =~ /\bINIFILETABLE\b/ ) { next; }	# these values are written during installation, not during packing
178*cdf0e10cSrcweir
179*cdf0e10cSrcweir			my $profileid = $oneprofileitem->{'ProfileID'};
180*cdf0e10cSrcweir
181*cdf0e10cSrcweir			if ( $profileid eq $profilegid )
182*cdf0e10cSrcweir			{
183*cdf0e10cSrcweir				my $section = $oneprofileitem->{'Section'};
184*cdf0e10cSrcweir				my $key = $oneprofileitem->{'Key'};
185*cdf0e10cSrcweir				my $value = $oneprofileitem->{'Value'};
186*cdf0e10cSrcweir				for (my $pk = 1; $pk <= 50; $pk++)
187*cdf0e10cSrcweir				{
188*cdf0e10cSrcweir					my $key = "ValueList" . $pk;
189*cdf0e10cSrcweir					if ( $oneprofileitem->{$key} )
190*cdf0e10cSrcweir						{ $value = $value . " " . $oneprofileitem->{$key} }
191*cdf0e10cSrcweir				}
192*cdf0e10cSrcweir				my $order = $oneprofileitem->{'Order'};	# ignoring order at the moment
193*cdf0e10cSrcweir
194*cdf0e10cSrcweir				my $line = "[" . $section . "]" . "\n";
195*cdf0e10cSrcweir				push(@onefile, $line);
196*cdf0e10cSrcweir				$line = $key . "=" . $value . "\n";
197*cdf0e10cSrcweir				push(@onefile, $line);
198*cdf0e10cSrcweir
199*cdf0e10cSrcweir				$profileempty = 0;
200*cdf0e10cSrcweir			}
201*cdf0e10cSrcweir		}
202*cdf0e10cSrcweir
203*cdf0e10cSrcweir		if ( $profileempty ) { next; } 	# ignoring empty profiles
204*cdf0e10cSrcweir
205*cdf0e10cSrcweir		# Sorting the array @onefile
206*cdf0e10cSrcweir		my $onefileref = sorting_profile(\@onefile);
207*cdf0e10cSrcweir
208*cdf0e10cSrcweir		if ( $installer::globals::iswin && $installer::globals::plat =~ /cygwin/i)		# Windows line ends only for Cygwin
209*cdf0e10cSrcweir		{
210*cdf0e10cSrcweir			include_windows_lineends($onefileref);
211*cdf0e10cSrcweir		}
212*cdf0e10cSrcweir
213*cdf0e10cSrcweir		# Saving the profile as a file
214*cdf0e10cSrcweir		$completeprofilename = $localprofilesdir . $installer::globals::separator . $profilename;
215*cdf0e10cSrcweir
216*cdf0e10cSrcweir		installer::files::save_file($completeprofilename, $onefileref);
217*cdf0e10cSrcweir
218*cdf0e10cSrcweir		# Adding the file to the filearray
219*cdf0e10cSrcweir		# Some data are set now, others are taken from the file "soffice.exe" ("soffice.bin")
220*cdf0e10cSrcweir		add_profile_into_filelist($filesarrayref, $oneprofile, $completeprofilename, $allvariables);
221*cdf0e10cSrcweir
222*cdf0e10cSrcweir		$infoline = "Created Profile: $completeprofilename\n";
223*cdf0e10cSrcweir		push( @installer::globals::logfileinfo, $infoline);
224*cdf0e10cSrcweir	}
225*cdf0e10cSrcweir
226*cdf0e10cSrcweir	$infoline = "\n";
227*cdf0e10cSrcweir	push( @installer::globals::logfileinfo, $infoline);
228*cdf0e10cSrcweir}
229*cdf0e10cSrcweir
230*cdf0e10cSrcweir
231*cdf0e10cSrcweir1;
232