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