1*b1cdbd2cSJim Jagielski#**************************************************************
2*b1cdbd2cSJim Jagielski#
3*b1cdbd2cSJim Jagielski#  Licensed to the Apache Software Foundation (ASF) under one
4*b1cdbd2cSJim Jagielski#  or more contributor license agreements.  See the NOTICE file
5*b1cdbd2cSJim Jagielski#  distributed with this work for additional information
6*b1cdbd2cSJim Jagielski#  regarding copyright ownership.  The ASF licenses this file
7*b1cdbd2cSJim Jagielski#  to you under the Apache License, Version 2.0 (the
8*b1cdbd2cSJim Jagielski#  "License"); you may not use this file except in compliance
9*b1cdbd2cSJim Jagielski#  with the License.  You may obtain a copy of the License at
10*b1cdbd2cSJim Jagielski#
11*b1cdbd2cSJim Jagielski#    http://www.apache.org/licenses/LICENSE-2.0
12*b1cdbd2cSJim Jagielski#
13*b1cdbd2cSJim Jagielski#  Unless required by applicable law or agreed to in writing,
14*b1cdbd2cSJim Jagielski#  software distributed under the License is distributed on an
15*b1cdbd2cSJim Jagielski#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b1cdbd2cSJim Jagielski#  KIND, either express or implied.  See the License for the
17*b1cdbd2cSJim Jagielski#  specific language governing permissions and limitations
18*b1cdbd2cSJim Jagielski#  under the License.
19*b1cdbd2cSJim Jagielski#
20*b1cdbd2cSJim Jagielski#**************************************************************
21*b1cdbd2cSJim Jagielski
22*b1cdbd2cSJim Jagielski
23*b1cdbd2cSJim Jagielski
24*b1cdbd2cSJim Jagielskipackage installer::profiles;
25*b1cdbd2cSJim Jagielski
26*b1cdbd2cSJim Jagielskiuse installer::converter;
27*b1cdbd2cSJim Jagielskiuse installer::existence;
28*b1cdbd2cSJim Jagielskiuse installer::exiter;
29*b1cdbd2cSJim Jagielskiuse installer::files;
30*b1cdbd2cSJim Jagielskiuse installer::globals;
31*b1cdbd2cSJim Jagielskiuse installer::logger;
32*b1cdbd2cSJim Jagielskiuse installer::remover;
33*b1cdbd2cSJim Jagielskiuse installer::systemactions;
34*b1cdbd2cSJim Jagielski
35*b1cdbd2cSJim Jagielski#############################
36*b1cdbd2cSJim Jagielski# Profiles
37*b1cdbd2cSJim Jagielski#############################
38*b1cdbd2cSJim Jagielski
39*b1cdbd2cSJim Jagielski#######################################################
40*b1cdbd2cSJim Jagielski# Sorting the content of a profile
41*b1cdbd2cSJim Jagielski#######################################################
42*b1cdbd2cSJim Jagielski
43*b1cdbd2cSJim Jagielskisub sorting_profile
44*b1cdbd2cSJim Jagielski{
45*b1cdbd2cSJim Jagielski	my ($profilesref) = @_;
46*b1cdbd2cSJim Jagielski
47*b1cdbd2cSJim Jagielski	my @profile = ();
48*b1cdbd2cSJim Jagielski	my @definedsections = ();
49*b1cdbd2cSJim Jagielski
50*b1cdbd2cSJim Jagielski	for ( my $i = 0; $i <= $#{$profilesref}; $i++ )
51*b1cdbd2cSJim Jagielski	{
52*b1cdbd2cSJim Jagielski		my $line = ${$profilesref}[$i];
53*b1cdbd2cSJim Jagielski
54*b1cdbd2cSJim Jagielski		if ( $line =~ /^\s*(\[.*\])\s*$/ )	# this is a section (every second line)
55*b1cdbd2cSJim Jagielski		{
56*b1cdbd2cSJim Jagielski			my $section = $1;
57*b1cdbd2cSJim Jagielski
58*b1cdbd2cSJim Jagielski			if (!(installer::existence::exists_in_array($section, \@definedsections)))
59*b1cdbd2cSJim Jagielski			{
60*b1cdbd2cSJim Jagielski				my $sectionline = $section . "\n";
61*b1cdbd2cSJim Jagielski				push(@definedsections, $section);
62*b1cdbd2cSJim Jagielski				push(@profile, $sectionline);
63*b1cdbd2cSJim Jagielski
64*b1cdbd2cSJim Jagielski				for ( my $j = 0; $j <= $#{$profilesref}; $j++ )
65*b1cdbd2cSJim Jagielski				{
66*b1cdbd2cSJim Jagielski					my $oneline = ${$profilesref}[$j];
67*b1cdbd2cSJim Jagielski					installer::remover::remove_leading_and_ending_whitespaces(\$oneline);
68*b1cdbd2cSJim Jagielski
69*b1cdbd2cSJim Jagielski					if ( $oneline eq $section )
70*b1cdbd2cSJim Jagielski					{
71*b1cdbd2cSJim Jagielski						my $nextline = ${$profilesref}[$j+1];
72*b1cdbd2cSJim Jagielski						push(@profile, $nextline);
73*b1cdbd2cSJim Jagielski					}
74*b1cdbd2cSJim Jagielski				}
75*b1cdbd2cSJim Jagielski			}
76*b1cdbd2cSJim Jagielski		}
77*b1cdbd2cSJim Jagielski	}
78*b1cdbd2cSJim Jagielski
79*b1cdbd2cSJim Jagielski	return \@profile;
80*b1cdbd2cSJim Jagielski}
81*b1cdbd2cSJim Jagielski
82*b1cdbd2cSJim Jagielski#####################################################################
83*b1cdbd2cSJim Jagielski# Adding the newly created profile into the file list
84*b1cdbd2cSJim Jagielski#####################################################################
85*b1cdbd2cSJim Jagielski
86*b1cdbd2cSJim Jagielskisub add_profile_into_filelist
87*b1cdbd2cSJim Jagielski{
88*b1cdbd2cSJim Jagielski	my ($filesarrayref, $oneprofile, $completeprofilename, $allvariables) = @_;
89*b1cdbd2cSJim Jagielski
90*b1cdbd2cSJim Jagielski	my %profile = ();
91*b1cdbd2cSJim Jagielski
92*b1cdbd2cSJim Jagielski	# Taking the base data from the "gid_File_Lib_Vcl"
93*b1cdbd2cSJim Jagielski
94*b1cdbd2cSJim Jagielski	my $vclgid = "gid_File_Lib_Vcl";
95*b1cdbd2cSJim Jagielski	if ( $allvariables->{'GLOBALFILEGID'} ) { $vclgid = $allvariables->{'GLOBALFILEGID'}; }
96*b1cdbd2cSJim Jagielski	my $vclfile = installer::existence::get_specified_file($filesarrayref, $vclgid);
97*b1cdbd2cSJim Jagielski
98*b1cdbd2cSJim Jagielski	# copying all base data
99*b1cdbd2cSJim Jagielski	installer::converter::copy_item_object($vclfile, \%profile);
100*b1cdbd2cSJim Jagielski
101*b1cdbd2cSJim Jagielski	# and overriding all new values
102*b1cdbd2cSJim Jagielski
103*b1cdbd2cSJim Jagielski	$profile{'ismultilingual'} = 0;
104*b1cdbd2cSJim Jagielski	$profile{'sourcepath'} = $completeprofilename;
105*b1cdbd2cSJim Jagielski	$profile{'Name'} = $oneprofile->{'Name'};
106*b1cdbd2cSJim Jagielski	$profile{'UnixRights'} = "444";
107*b1cdbd2cSJim Jagielski	$profile{'gid'} = $oneprofile->{'gid'};
108*b1cdbd2cSJim Jagielski	$profile{'Dir'} = $oneprofile->{'Dir'};
109*b1cdbd2cSJim Jagielski	$profile{'destination'} = $oneprofile->{'destination'};
110*b1cdbd2cSJim Jagielski	$profile{'Styles'} = "";
111*b1cdbd2cSJim Jagielski	if ( $oneprofile->{'Styles'} ) { $profile{'Styles'} = $oneprofile->{'Styles'}; }
112*b1cdbd2cSJim Jagielski	$profile{'modules'} = $oneprofile->{'ModuleID'};	# Profiles can only be added completely to a module
113*b1cdbd2cSJim Jagielski
114*b1cdbd2cSJim Jagielski	push(@{$filesarrayref}, \%profile);
115*b1cdbd2cSJim Jagielski}
116*b1cdbd2cSJim Jagielski
117*b1cdbd2cSJim Jagielski###################################################
118*b1cdbd2cSJim Jagielski# Including Windows line ends in ini files
119*b1cdbd2cSJim Jagielski# Profiles on Windows shall have \r\n line ends
120*b1cdbd2cSJim Jagielski###################################################
121*b1cdbd2cSJim Jagielski
122*b1cdbd2cSJim Jagielskisub include_windows_lineends
123*b1cdbd2cSJim Jagielski{
124*b1cdbd2cSJim Jagielski	my ($onefile) = @_;
125*b1cdbd2cSJim Jagielski
126*b1cdbd2cSJim Jagielski	for ( my $i = 0; $i <= $#{$onefile}; $i++ )
127*b1cdbd2cSJim Jagielski	{
128*b1cdbd2cSJim Jagielski		${$onefile}[$i] =~ s/\r?\n$/\r\n/;
129*b1cdbd2cSJim Jagielski	}
130*b1cdbd2cSJim Jagielski}
131*b1cdbd2cSJim Jagielski
132*b1cdbd2cSJim Jagielski####################################
133*b1cdbd2cSJim Jagielski# Create profiles
134*b1cdbd2cSJim Jagielski####################################
135*b1cdbd2cSJim Jagielski
136*b1cdbd2cSJim Jagielskisub create_profiles
137*b1cdbd2cSJim Jagielski{
138*b1cdbd2cSJim Jagielski	my ($profilesref, $profileitemsref, $filesarrayref, $languagestringref, $allvariables) = @_;
139*b1cdbd2cSJim Jagielski
140*b1cdbd2cSJim Jagielski	my $infoline;
141*b1cdbd2cSJim Jagielski
142*b1cdbd2cSJim Jagielski	my $profilesdir = installer::systemactions::create_directories("profiles", $languagestringref);
143*b1cdbd2cSJim Jagielski
144*b1cdbd2cSJim Jagielski	installer::logger::include_header_into_logfile("Creating profiles:");
145*b1cdbd2cSJim Jagielski
146*b1cdbd2cSJim Jagielski	# Attention: The module dependencies from ProfileItems have to be ignored, because
147*b1cdbd2cSJim Jagielski	# the Profile has to be installed completely with all of its content and the correct name.
148*b1cdbd2cSJim Jagielski	# Only complete profiles can belong to a specified module, but not ProfileItems!
149*b1cdbd2cSJim Jagielski
150*b1cdbd2cSJim Jagielski	# iterating over all files
151*b1cdbd2cSJim Jagielski
152*b1cdbd2cSJim Jagielski	for ( my $i = 0; $i <= $#{$profilesref}; $i++ )
153*b1cdbd2cSJim Jagielski	{
154*b1cdbd2cSJim Jagielski		my $oneprofile = ${$profilesref}[$i];
155*b1cdbd2cSJim Jagielski		my $dir = $oneprofile->{'Dir'};
156*b1cdbd2cSJim Jagielski		if ( $dir eq "PREDEFINED_CONFIGDIR" ) { next; } 	# ignoring the profile sversion file
157*b1cdbd2cSJim Jagielski
158*b1cdbd2cSJim Jagielski		my $profilegid = $oneprofile->{'gid'};
159*b1cdbd2cSJim Jagielski		my $profilename = $oneprofile->{'Name'};
160*b1cdbd2cSJim Jagielski
161*b1cdbd2cSJim Jagielski		my $localprofilesdir = $profilesdir . $installer::globals::separator . $profilegid; # uniqueness guaranteed by gid
162*b1cdbd2cSJim Jagielski		if ( ! -d $localprofilesdir ) { installer::systemactions::create_directory($localprofilesdir); }
163*b1cdbd2cSJim Jagielski
164*b1cdbd2cSJim Jagielski		my @onefile = ();
165*b1cdbd2cSJim Jagielski		my $profileempty = 1;
166*b1cdbd2cSJim Jagielski
167*b1cdbd2cSJim Jagielski		for ( my $j = 0; $j <= $#{$profileitemsref}; $j++ )
168*b1cdbd2cSJim Jagielski		{
169*b1cdbd2cSJim Jagielski			my $oneprofileitem = ${$profileitemsref}[$j];
170*b1cdbd2cSJim Jagielski
171*b1cdbd2cSJim Jagielski			my $styles = "";
172*b1cdbd2cSJim Jagielski			if ( $oneprofileitem->{'Styles'} ) { $styles = $oneprofileitem->{'Styles'}; }
173*b1cdbd2cSJim Jagielski			if ( $styles =~ /\bINIFILETABLE\b/ ) { next; }	# these values are written during installation, not during packing
174*b1cdbd2cSJim Jagielski
175*b1cdbd2cSJim Jagielski			my $profileid = $oneprofileitem->{'ProfileID'};
176*b1cdbd2cSJim Jagielski
177*b1cdbd2cSJim Jagielski			if ( $profileid eq $profilegid )
178*b1cdbd2cSJim Jagielski			{
179*b1cdbd2cSJim Jagielski				my $section = $oneprofileitem->{'Section'};
180*b1cdbd2cSJim Jagielski				my $key = $oneprofileitem->{'Key'};
181*b1cdbd2cSJim Jagielski				my $value = $oneprofileitem->{'Value'};
182*b1cdbd2cSJim Jagielski				for (my $pk = 1; $pk <= 50; $pk++)
183*b1cdbd2cSJim Jagielski				{
184*b1cdbd2cSJim Jagielski					my $key = "ValueList" . $pk;
185*b1cdbd2cSJim Jagielski					if ( $oneprofileitem->{$key} )
186*b1cdbd2cSJim Jagielski						{ $value = $value . " " . $oneprofileitem->{$key} }
187*b1cdbd2cSJim Jagielski				}
188*b1cdbd2cSJim Jagielski				my $order = $oneprofileitem->{'Order'};	# ignoring order at the moment
189*b1cdbd2cSJim Jagielski
190*b1cdbd2cSJim Jagielski				my $line = "[" . $section . "]" . "\n";
191*b1cdbd2cSJim Jagielski				push(@onefile, $line);
192*b1cdbd2cSJim Jagielski				$line = $key . "=" . $value . "\n";
193*b1cdbd2cSJim Jagielski				push(@onefile, $line);
194*b1cdbd2cSJim Jagielski
195*b1cdbd2cSJim Jagielski				$profileempty = 0;
196*b1cdbd2cSJim Jagielski			}
197*b1cdbd2cSJim Jagielski		}
198*b1cdbd2cSJim Jagielski
199*b1cdbd2cSJim Jagielski		if ( $profileempty ) { next; } 	# ignoring empty profiles
200*b1cdbd2cSJim Jagielski
201*b1cdbd2cSJim Jagielski		# Sorting the array @onefile
202*b1cdbd2cSJim Jagielski		my $onefileref = sorting_profile(\@onefile);
203*b1cdbd2cSJim Jagielski
204*b1cdbd2cSJim Jagielski		if ( $installer::globals::iswin && $installer::globals::plat =~ /cygwin/i)		# Windows line ends only for Cygwin
205*b1cdbd2cSJim Jagielski		{
206*b1cdbd2cSJim Jagielski			include_windows_lineends($onefileref);
207*b1cdbd2cSJim Jagielski		}
208*b1cdbd2cSJim Jagielski
209*b1cdbd2cSJim Jagielski		# Saving the profile as a file
210*b1cdbd2cSJim Jagielski		$completeprofilename = $localprofilesdir . $installer::globals::separator . $profilename;
211*b1cdbd2cSJim Jagielski
212*b1cdbd2cSJim Jagielski		installer::files::save_file($completeprofilename, $onefileref);
213*b1cdbd2cSJim Jagielski
214*b1cdbd2cSJim Jagielski		# Adding the file to the filearray
215*b1cdbd2cSJim Jagielski		# Some data are set now, others are taken from the file "soffice.exe" ("soffice.bin")
216*b1cdbd2cSJim Jagielski		add_profile_into_filelist($filesarrayref, $oneprofile, $completeprofilename, $allvariables);
217*b1cdbd2cSJim Jagielski
218*b1cdbd2cSJim Jagielski        $installer::logger::Lang->printf("Created Profile: %s\n", $completeprofilename);
219*b1cdbd2cSJim Jagielski	}
220*b1cdbd2cSJim Jagielski
221*b1cdbd2cSJim Jagielski    $installer::logger::Lang->printf("\n");
222*b1cdbd2cSJim Jagielski}
223*b1cdbd2cSJim Jagielski
224*b1cdbd2cSJim Jagielski
225*b1cdbd2cSJim Jagielski1;
226