19780544fSAndrew Rist#**************************************************************
29780544fSAndrew Rist#
39780544fSAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
49780544fSAndrew Rist#  or more contributor license agreements.  See the NOTICE file
59780544fSAndrew Rist#  distributed with this work for additional information
69780544fSAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
79780544fSAndrew Rist#  to you under the Apache License, Version 2.0 (the
89780544fSAndrew Rist#  "License"); you may not use this file except in compliance
99780544fSAndrew Rist#  with the License.  You may obtain a copy of the License at
109780544fSAndrew Rist#
119780544fSAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
129780544fSAndrew Rist#
139780544fSAndrew Rist#  Unless required by applicable law or agreed to in writing,
149780544fSAndrew Rist#  software distributed under the License is distributed on an
159780544fSAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169780544fSAndrew Rist#  KIND, either express or implied.  See the License for the
179780544fSAndrew Rist#  specific language governing permissions and limitations
189780544fSAndrew Rist#  under the License.
199780544fSAndrew Rist#
209780544fSAndrew Rist#**************************************************************
219780544fSAndrew Rist
229780544fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweirpackage installer::download;
25cdf0e10cSrcweir
26cdf0e10cSrcweiruse File::Spec;
27cdf0e10cSrcweiruse installer::exiter;
28cdf0e10cSrcweiruse installer::files;
29cdf0e10cSrcweiruse installer::globals;
30cdf0e10cSrcweiruse installer::logger;
31cdf0e10cSrcweiruse installer::pathanalyzer;
32cdf0e10cSrcweiruse installer::remover;
33cdf0e10cSrcweiruse installer::systemactions;
34cdf0e10cSrcweir
35cdf0e10cSrcweirBEGIN { # This is needed so that cygwin's perl evaluates ACLs
36cdf0e10cSrcweir	# (needed for correctly evaluating the -x test.)
37cdf0e10cSrcweir	if( $^O =~ /cygwin/i ) {
38cdf0e10cSrcweir		require filetest; import filetest "access";
39cdf0e10cSrcweir	}
40cdf0e10cSrcweir}
41cdf0e10cSrcweir
42cdf0e10cSrcweir##################################################################
43cdf0e10cSrcweir# Including the lowercase product name into the script template
44cdf0e10cSrcweir##################################################################
45cdf0e10cSrcweir
46cdf0e10cSrcweirsub put_productname_into_script
47cdf0e10cSrcweir{
48cdf0e10cSrcweir	my ($scriptfile, $variableshashref) = @_;
49cdf0e10cSrcweir
50cdf0e10cSrcweir	my $productname = $variableshashref->{'PRODUCTNAME'};
51cdf0e10cSrcweir	$productname = lc($productname);
52cdf0e10cSrcweir	$productname =~ s/\.//g;	# openoffice.org -> openofficeorg
53cdf0e10cSrcweir	$productname =~ s/\s*//g;
54cdf0e10cSrcweir
55cdf0e10cSrcweir	my $infoline = "Adding productname $productname into download shell script\n";
56cdf0e10cSrcweir	push( @installer::globals::logfileinfo, $infoline);
57cdf0e10cSrcweir
58cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
59cdf0e10cSrcweir	{
60cdf0e10cSrcweir		${$scriptfile}[$i] =~ s/PRODUCTNAMEPLACEHOLDER/$productname/;
61cdf0e10cSrcweir	}
62cdf0e10cSrcweir}
63cdf0e10cSrcweir
64cdf0e10cSrcweir#########################################################
65cdf0e10cSrcweir# Including the linenumber into the script template
66cdf0e10cSrcweir#########################################################
67cdf0e10cSrcweir
68cdf0e10cSrcweirsub put_linenumber_into_script
69cdf0e10cSrcweir{
70cdf0e10cSrcweir	my ( $scriptfile ) = @_;
71cdf0e10cSrcweir
72cdf0e10cSrcweir	my $linenumber =  $#{$scriptfile} + 2;
73cdf0e10cSrcweir
74cdf0e10cSrcweir	my $infoline = "Adding linenumber $linenumber into download shell script\n";
75cdf0e10cSrcweir	push( @installer::globals::logfileinfo, $infoline);
76cdf0e10cSrcweir
77cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
78cdf0e10cSrcweir	{
79cdf0e10cSrcweir		${$scriptfile}[$i] =~ s/LINENUMBERPLACEHOLDER/$linenumber/;
80cdf0e10cSrcweir	}
81cdf0e10cSrcweir}
82cdf0e10cSrcweir
83cdf0e10cSrcweir#########################################################
84cdf0e10cSrcweir# Determining the name of the new scriptfile
85cdf0e10cSrcweir#########################################################
86cdf0e10cSrcweir
87cdf0e10cSrcweirsub determine_scriptfile_name
88cdf0e10cSrcweir{
89cdf0e10cSrcweir	my ( $filename ) = @_;
90cdf0e10cSrcweir
91cdf0e10cSrcweir	$installer::globals::downloadfileextension = ".sh";
92cdf0e10cSrcweir	$filename = $filename . $installer::globals::downloadfileextension;
93cdf0e10cSrcweir	$installer::globals::downloadfilename = $filename;
94cdf0e10cSrcweir
95cdf0e10cSrcweir	my $infoline = "Setting download shell script file name to $filename\n";
96cdf0e10cSrcweir	push( @installer::globals::logfileinfo, $infoline);
97cdf0e10cSrcweir
98cdf0e10cSrcweir	return $filename;
99cdf0e10cSrcweir}
100cdf0e10cSrcweir
101cdf0e10cSrcweir#########################################################
102cdf0e10cSrcweir# Saving the script file in the installation directory
103cdf0e10cSrcweir#########################################################
104cdf0e10cSrcweir
105cdf0e10cSrcweirsub save_script_file
106cdf0e10cSrcweir{
107cdf0e10cSrcweir	my ($directory, $newscriptfilename, $scriptfile) = @_;
108cdf0e10cSrcweir
109cdf0e10cSrcweir	$newscriptfilename = $directory . $installer::globals::separator . $newscriptfilename;
110cdf0e10cSrcweir	installer::files::save_file($newscriptfilename, $scriptfile);
111cdf0e10cSrcweir
112cdf0e10cSrcweir	my $infoline = "Saving script file $newscriptfilename\n";
113cdf0e10cSrcweir	push( @installer::globals::logfileinfo, $infoline);
114cdf0e10cSrcweir
115cdf0e10cSrcweir	if ( ! $installer::globals::iswindowsbuild )
116cdf0e10cSrcweir	{
117cdf0e10cSrcweir		my $localcall = "chmod 775 $newscriptfilename \>\/dev\/null 2\>\&1";
118cdf0e10cSrcweir		system($localcall);
119cdf0e10cSrcweir	}
120cdf0e10cSrcweir
121cdf0e10cSrcweir	return $newscriptfilename;
122cdf0e10cSrcweir}
123cdf0e10cSrcweir
124cdf0e10cSrcweir#########################################################
125cdf0e10cSrcweir# Including checksum and size into script file
126cdf0e10cSrcweir#########################################################
127cdf0e10cSrcweir
128cdf0e10cSrcweirsub put_checksum_and_size_into_script
129cdf0e10cSrcweir{
130cdf0e10cSrcweir	my ($scriptfile, $sumout) = @_;
131cdf0e10cSrcweir
132cdf0e10cSrcweir	my $checksum = "";
133cdf0e10cSrcweir	my $size = "";
134cdf0e10cSrcweir
135cdf0e10cSrcweir	if  ( $sumout =~ /^\s*(\d+)\s+(\d+)\s*$/ )
136cdf0e10cSrcweir	{
137cdf0e10cSrcweir		$checksum = $1;
138cdf0e10cSrcweir		$size = $2;
139cdf0e10cSrcweir	}
140cdf0e10cSrcweir	else
141cdf0e10cSrcweir	{
142cdf0e10cSrcweir		installer::exiter::exit_program("ERROR: Incorrect return value from /usr/bin/sum: $sumout", "put_checksum_and_size_into_script");
143cdf0e10cSrcweir	}
144cdf0e10cSrcweir
145cdf0e10cSrcweir	my $infoline = "Adding checksum $checksum and size $size into download shell script\n";
146cdf0e10cSrcweir	push( @installer::globals::logfileinfo, $infoline);
147cdf0e10cSrcweir
148cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
149cdf0e10cSrcweir	{
150cdf0e10cSrcweir		${$scriptfile}[$i] =~ s/CHECKSUMPLACEHOLDER/$checksum/;
151cdf0e10cSrcweir		${$scriptfile}[$i] =~ s/DISCSPACEPLACEHOLDER/$size/;
152cdf0e10cSrcweir	}
153cdf0e10cSrcweir
154cdf0e10cSrcweir}
155cdf0e10cSrcweir
156cdf0e10cSrcweir#########################################################
157cdf0e10cSrcweir# Calling md5sum
158cdf0e10cSrcweir#########################################################
159cdf0e10cSrcweir
160cdf0e10cSrcweirsub call_md5sum
161cdf0e10cSrcweir{
162cdf0e10cSrcweir	my ($filename) = @_;
163cdf0e10cSrcweir
164cdf0e10cSrcweir	$md5sumfile = "/usr/bin/md5sum";
165cdf0e10cSrcweir
166cdf0e10cSrcweir	if ( ! -f $md5sumfile ) { installer::exiter::exit_program("ERROR: No file /usr/bin/md5sum", "call_md5sum"); }
167cdf0e10cSrcweir
168cdf0e10cSrcweir	my $systemcall = "$md5sumfile $filename |";
169cdf0e10cSrcweir
170cdf0e10cSrcweir	my $md5sumoutput = "";
171cdf0e10cSrcweir
172cdf0e10cSrcweir	open (SUM, "$systemcall");
173cdf0e10cSrcweir	$md5sumoutput = <SUM>;
174cdf0e10cSrcweir	close (SUM);
175cdf0e10cSrcweir
176cdf0e10cSrcweir	my $returnvalue = $?;	# $? contains the return value of the systemcall
177cdf0e10cSrcweir
178cdf0e10cSrcweir	my $infoline = "Systemcall: $systemcall\n";
179cdf0e10cSrcweir	push( @installer::globals::logfileinfo, $infoline);
180cdf0e10cSrcweir
181cdf0e10cSrcweir	if ($returnvalue)
182cdf0e10cSrcweir	{
183cdf0e10cSrcweir		$infoline = "ERROR: Could not execute \"$systemcall\"!\n";
184cdf0e10cSrcweir		push( @installer::globals::logfileinfo, $infoline);
185cdf0e10cSrcweir	}
186cdf0e10cSrcweir	else
187cdf0e10cSrcweir	{
188cdf0e10cSrcweir		$infoline = "Success: Executed \"$systemcall\" successfully!\n";
189cdf0e10cSrcweir		push( @installer::globals::logfileinfo, $infoline);
190cdf0e10cSrcweir	}
191cdf0e10cSrcweir
192cdf0e10cSrcweir	return $md5sumoutput;
193cdf0e10cSrcweir}
194cdf0e10cSrcweir
195cdf0e10cSrcweir#########################################################
196cdf0e10cSrcweir# Calling md5sum
197cdf0e10cSrcweir#########################################################
198cdf0e10cSrcweir
199cdf0e10cSrcweirsub get_md5sum
200cdf0e10cSrcweir{
201cdf0e10cSrcweir	($md5sumoutput) = @_;
202cdf0e10cSrcweir
203cdf0e10cSrcweir	my $md5sum;
204cdf0e10cSrcweir
205cdf0e10cSrcweir	if  ( $md5sumoutput =~ /^\s*(\w+?)\s+/ )
206cdf0e10cSrcweir	{
207cdf0e10cSrcweir		$md5sum = $1;
208cdf0e10cSrcweir	}
209cdf0e10cSrcweir	else
210cdf0e10cSrcweir	{
211cdf0e10cSrcweir		installer::exiter::exit_program("ERROR: Incorrect return value from /usr/bin/md5sum: $md5sumoutput", "get_md5sum");
212cdf0e10cSrcweir	}
213cdf0e10cSrcweir
214cdf0e10cSrcweir	my $infoline = "Setting md5sum: $md5sum\n";
215cdf0e10cSrcweir	push( @installer::globals::logfileinfo, $infoline);
216cdf0e10cSrcweir
217cdf0e10cSrcweir	return $md5sum;
218cdf0e10cSrcweir}
219cdf0e10cSrcweir
220cdf0e10cSrcweir#########################################################
221cdf0e10cSrcweir# Determining checksum and size of tar file
222cdf0e10cSrcweir#########################################################
223cdf0e10cSrcweir
224cdf0e10cSrcweirsub call_sum
225cdf0e10cSrcweir{
226cdf0e10cSrcweir	my ($filename, $getuidlibrary) = @_;
227cdf0e10cSrcweir
228cdf0e10cSrcweir	my $systemcall = "/usr/bin/sum $filename |";
229cdf0e10cSrcweir
230cdf0e10cSrcweir	my $sumoutput = "";
231cdf0e10cSrcweir
232cdf0e10cSrcweir	open (SUM, "$systemcall");
233cdf0e10cSrcweir	$sumoutput = <SUM>;
234cdf0e10cSrcweir	close (SUM);
235cdf0e10cSrcweir
236cdf0e10cSrcweir	my $returnvalue = $?;	# $? contains the return value of the systemcall
237cdf0e10cSrcweir
238cdf0e10cSrcweir	my $infoline = "Systemcall: $systemcall\n";
239cdf0e10cSrcweir	push( @installer::globals::logfileinfo, $infoline);
240cdf0e10cSrcweir
241cdf0e10cSrcweir	if ($returnvalue)
242cdf0e10cSrcweir	{
243cdf0e10cSrcweir		$infoline = "ERROR: Could not execute \"$systemcall\"!\n";
244cdf0e10cSrcweir		push( @installer::globals::logfileinfo, $infoline);
245cdf0e10cSrcweir	}
246cdf0e10cSrcweir	else
247cdf0e10cSrcweir	{
248cdf0e10cSrcweir		$infoline = "Success: Executed \"$systemcall\" successfully!\n";
249cdf0e10cSrcweir		push( @installer::globals::logfileinfo, $infoline);
250cdf0e10cSrcweir	}
251cdf0e10cSrcweir
252cdf0e10cSrcweir	$sumoutput =~ s/\s+$filename\s$//;
253cdf0e10cSrcweir	return $sumoutput;
254cdf0e10cSrcweir}
255cdf0e10cSrcweir
256cdf0e10cSrcweir#########################################################
257cdf0e10cSrcweir# Searching for the getuid.so in the solver
258cdf0e10cSrcweir#########################################################
259cdf0e10cSrcweir
260cdf0e10cSrcweirsub get_path_for_library
261cdf0e10cSrcweir{
262cdf0e10cSrcweir	my ($includepatharrayref) = @_;
263cdf0e10cSrcweir
264cdf0e10cSrcweir	my $getuidlibraryname = "getuid.so";
265cdf0e10cSrcweir
266cdf0e10cSrcweir	my $getuidlibraryref = "";
267cdf0e10cSrcweir
268cdf0e10cSrcweir	if ( $installer::globals::include_pathes_read )
269cdf0e10cSrcweir	{
270cdf0e10cSrcweir		$getuidlibraryref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$getuidlibraryname, $includepatharrayref, 0);
271cdf0e10cSrcweir	}
272cdf0e10cSrcweir	else
273cdf0e10cSrcweir	{
274cdf0e10cSrcweir		$getuidlibraryref = installer::scriptitems::get_sourcepath_from_filename_and_includepath_classic(\$getuidlibraryname, $includepatharrayref, 0);
275cdf0e10cSrcweir	}
276cdf0e10cSrcweir
277cdf0e10cSrcweir	if ($$getuidlibraryref eq "") { installer::exiter::exit_program("ERROR: Could not find $getuidlibraryname!", "get_path_for_library"); }
278cdf0e10cSrcweir
279cdf0e10cSrcweir	return $$getuidlibraryref;
280cdf0e10cSrcweir}
281cdf0e10cSrcweir
282cdf0e10cSrcweir#########################################################
283cdf0e10cSrcweir# Include the tar file into the script
284cdf0e10cSrcweir#########################################################
285cdf0e10cSrcweir
286cdf0e10cSrcweirsub include_tar_into_script
287cdf0e10cSrcweir{
288cdf0e10cSrcweir	my ($scriptfile, $temporary_tarfile) = @_;
289cdf0e10cSrcweir
290cdf0e10cSrcweir	my $systemcall = "cat $temporary_tarfile >> $scriptfile && rm $temporary_tarfile";
291cdf0e10cSrcweir	my $returnvalue = system($systemcall);
292cdf0e10cSrcweir
293cdf0e10cSrcweir	my $infoline = "Systemcall: $systemcall\n";
294cdf0e10cSrcweir	push( @installer::globals::logfileinfo, $infoline);
295cdf0e10cSrcweir
296cdf0e10cSrcweir	if ($returnvalue)
297cdf0e10cSrcweir	{
298cdf0e10cSrcweir		$infoline = "ERROR: Could not execute \"$systemcall\"!\n";
299cdf0e10cSrcweir		push( @installer::globals::logfileinfo, $infoline);
300cdf0e10cSrcweir	}
301cdf0e10cSrcweir	else
302cdf0e10cSrcweir	{
303cdf0e10cSrcweir		$infoline = "Success: Executed \"$systemcall\" successfully!\n";
304cdf0e10cSrcweir		push( @installer::globals::logfileinfo, $infoline);
305cdf0e10cSrcweir	}
306cdf0e10cSrcweir	return $returnvalue;
307cdf0e10cSrcweir}
308cdf0e10cSrcweir
309cdf0e10cSrcweir#########################################################
310cdf0e10cSrcweir# Create a tar file from the binary package
311cdf0e10cSrcweir#########################################################
312cdf0e10cSrcweir
313cdf0e10cSrcweirsub tar_package
314cdf0e10cSrcweir{
315cdf0e10cSrcweir	my ( $installdir, $tarfilename, $getuidlibrary) = @_;
316cdf0e10cSrcweir
317cdf0e10cSrcweir	my $ldpreloadstring = "";
318cdf0e10cSrcweir	if ( $getuidlibrary ne "" ) { $ldpreloadstring = "LD_PRELOAD=" . $getuidlibrary; }
319cdf0e10cSrcweir
320cdf0e10cSrcweir	my $systemcall = "cd $installdir; $ldpreloadstring tar -cf - * > $tarfilename";
321cdf0e10cSrcweir
322cdf0e10cSrcweir	my $returnvalue = system($systemcall);
323cdf0e10cSrcweir
324cdf0e10cSrcweir	my $infoline = "Systemcall: $systemcall\n";
325cdf0e10cSrcweir	push( @installer::globals::logfileinfo, $infoline);
326cdf0e10cSrcweir
327cdf0e10cSrcweir	if ($returnvalue)
328cdf0e10cSrcweir	{
329cdf0e10cSrcweir		$infoline = "ERROR: Could not execute \"$systemcall\"!\n";
330cdf0e10cSrcweir		push( @installer::globals::logfileinfo, $infoline);
331cdf0e10cSrcweir	}
332cdf0e10cSrcweir	else
333cdf0e10cSrcweir	{
334cdf0e10cSrcweir		$infoline = "Success: Executed \"$systemcall\" successfully!\n";
335cdf0e10cSrcweir		push( @installer::globals::logfileinfo, $infoline);
336cdf0e10cSrcweir	}
337cdf0e10cSrcweir
338cdf0e10cSrcweir	my $localcall = "chmod 775 $tarfilename \>\/dev\/null 2\>\&1";
339cdf0e10cSrcweir	$returnvalue = system($localcall);
340cdf0e10cSrcweir
341cdf0e10cSrcweir	return ( -s $tarfilename );
342cdf0e10cSrcweir}
343cdf0e10cSrcweir
344cdf0e10cSrcweir#########################################################
345cdf0e10cSrcweir# Creating a tar.gz file
346cdf0e10cSrcweir#########################################################
347cdf0e10cSrcweir
348cdf0e10cSrcweirsub create_tar_gz_file_from_package
349cdf0e10cSrcweir{
350cdf0e10cSrcweir	my ($installdir, $getuidlibrary) = @_;
351cdf0e10cSrcweir
352cdf0e10cSrcweir	my $infoline = "";
353cdf0e10cSrcweir	my $alldirs = installer::systemactions::get_all_directories($installdir);
354cdf0e10cSrcweir	my $onedir = ${$alldirs}[0];
355cdf0e10cSrcweir	$installdir = $onedir;
356cdf0e10cSrcweir
357cdf0e10cSrcweir	my $allfiles = installer::systemactions::get_all_files_from_one_directory($installdir);
358cdf0e10cSrcweir
359cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$allfiles}; $i++ )
360cdf0e10cSrcweir	{
361cdf0e10cSrcweir		my $onefile = ${$allfiles}[$i];
362cdf0e10cSrcweir		my $systemcall = "cd $installdir; rm $onefile";
363cdf0e10cSrcweir		my $returnvalue = system($systemcall);
364cdf0e10cSrcweir
365cdf0e10cSrcweir		$infoline = "Systemcall: $systemcall\n";
366cdf0e10cSrcweir		push( @installer::globals::logfileinfo, $infoline);
367cdf0e10cSrcweir
368cdf0e10cSrcweir		if ($returnvalue)
369cdf0e10cSrcweir		{
370cdf0e10cSrcweir			$infoline = "ERROR: Could not execute \"$systemcall\"!\n";
371cdf0e10cSrcweir			push( @installer::globals::logfileinfo, $infoline);
372cdf0e10cSrcweir		}
373cdf0e10cSrcweir		else
374cdf0e10cSrcweir		{
375cdf0e10cSrcweir			$infoline = "Success: Executed \"$systemcall\" successfully!\n";
376cdf0e10cSrcweir			push( @installer::globals::logfileinfo, $infoline);
377cdf0e10cSrcweir		}
378cdf0e10cSrcweir	}
379cdf0e10cSrcweir
380cdf0e10cSrcweir	$alldirs = installer::systemactions::get_all_directories($installdir);
381cdf0e10cSrcweir	$packagename = ${$alldirs}[0]; # only taking the first Solaris package
382cdf0e10cSrcweir	if ( $packagename eq "" ) { installer::exiter::exit_program("ERROR: Could not find package in directory $installdir!", "determine_packagename"); }
383cdf0e10cSrcweir
384cdf0e10cSrcweir	installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$packagename);
385cdf0e10cSrcweir
386cdf0e10cSrcweir	$installer::globals::downloadfileextension = ".tar.gz";
387cdf0e10cSrcweir	my $targzname = $packagename . $installer::globals::downloadfileextension;
388cdf0e10cSrcweir	$installer::globals::downloadfilename = $targzname;
389cdf0e10cSrcweir	my $ldpreloadstring = "";
390cdf0e10cSrcweir	if ( $getuidlibrary ne "" ) { $ldpreloadstring = "LD_PRELOAD=" . $getuidlibrary; }
391cdf0e10cSrcweir
392cdf0e10cSrcweir	$systemcall = "cd $installdir; $ldpreloadstring tar -cf - $packagename | gzip > $targzname";
393cdf0e10cSrcweir	print "... $systemcall ...\n";
394cdf0e10cSrcweir
395cdf0e10cSrcweir	my $returnvalue = system($systemcall);
396cdf0e10cSrcweir
397cdf0e10cSrcweir	$infoline = "Systemcall: $systemcall\n";
398cdf0e10cSrcweir	push( @installer::globals::logfileinfo, $infoline);
399cdf0e10cSrcweir
400cdf0e10cSrcweir	if ($returnvalue)
401cdf0e10cSrcweir	{
402cdf0e10cSrcweir		$infoline = "ERROR: Could not execute \"$systemcall\"!\n";
403cdf0e10cSrcweir		push( @installer::globals::logfileinfo, $infoline);
404cdf0e10cSrcweir	}
405cdf0e10cSrcweir	else
406cdf0e10cSrcweir	{
407cdf0e10cSrcweir		$infoline = "Success: Executed \"$systemcall\" successfully!\n";
408cdf0e10cSrcweir		push( @installer::globals::logfileinfo, $infoline);
409cdf0e10cSrcweir	}
410cdf0e10cSrcweir}
411cdf0e10cSrcweir
412cdf0e10cSrcweir#########################################################
413cdf0e10cSrcweir# Setting type of installation
414cdf0e10cSrcweir#########################################################
415cdf0e10cSrcweir
416cdf0e10cSrcweirsub get_installation_type
417cdf0e10cSrcweir{
418cdf0e10cSrcweir	my $type = "";
419cdf0e10cSrcweir
420cdf0e10cSrcweir	if ( $installer::globals::languagepack ) { $type = "langpack"; }
421cdf0e10cSrcweir	else { $type = "install"; }
422cdf0e10cSrcweir
423cdf0e10cSrcweir	return $type;
424cdf0e10cSrcweir}
425cdf0e10cSrcweir
426cdf0e10cSrcweir#########################################################
427cdf0e10cSrcweir# Setting installation languages
428cdf0e10cSrcweir#########################################################
429cdf0e10cSrcweir
430cdf0e10cSrcweirsub get_downloadname_language
431cdf0e10cSrcweir{
432cdf0e10cSrcweir	my ($languagestringref) = @_;
433cdf0e10cSrcweir
434cdf0e10cSrcweir	my $languages = $$languagestringref;
435cdf0e10cSrcweir
436cdf0e10cSrcweir	if ( $installer::globals::added_english )
437cdf0e10cSrcweir	{
438cdf0e10cSrcweir		$languages =~ s/en-US_//;
439cdf0e10cSrcweir		$languages =~ s/_en-US//;
440cdf0e10cSrcweir	}
441cdf0e10cSrcweir
442cdf0e10cSrcweir	# en-US is default language and can be removed therefore
443cdf0e10cSrcweir	# for one-language installation sets
444cdf0e10cSrcweir
445cdf0e10cSrcweir	# if ( $languages =~ /^\s*en-US\s*$/ )
446cdf0e10cSrcweir	# {
447cdf0e10cSrcweir	#	$languages = "";
448cdf0e10cSrcweir	# }
449cdf0e10cSrcweir
450cdf0e10cSrcweir	if ( length ($languages) > $installer::globals::max_lang_length )
451cdf0e10cSrcweir	{
452cdf0e10cSrcweir		$languages = 'multi';
453cdf0e10cSrcweir	}
454cdf0e10cSrcweir
455cdf0e10cSrcweir	return $languages;
456cdf0e10cSrcweir}
457cdf0e10cSrcweir
458cdf0e10cSrcweir#########################################################
459cdf0e10cSrcweir# Setting download name
460cdf0e10cSrcweir#########################################################
461cdf0e10cSrcweir
462cdf0e10cSrcweirsub get_downloadname_productname
463cdf0e10cSrcweir{
464*ff3f4ebcSOliver-Rainer Wittmann    my ($allvariables) = @_;
465957116b7SHerbert Dürr
466*ff3f4ebcSOliver-Rainer Wittmann    my $start;
467957116b7SHerbert Dürr
468*ff3f4ebcSOliver-Rainer Wittmann    if ( $allvariables->{'AOODOWNLOADNAMEPREFIX'} )
469*ff3f4ebcSOliver-Rainer Wittmann    {
470*ff3f4ebcSOliver-Rainer Wittmann        $start = $allvariables->{'AOODOWNLOADNAMEPREFIX'};
471*ff3f4ebcSOliver-Rainer Wittmann    }
472*ff3f4ebcSOliver-Rainer Wittmann    else
473*ff3f4ebcSOliver-Rainer Wittmann    {
474*ff3f4ebcSOliver-Rainer Wittmann        $start = "Apache_OpenOffice";
475*ff3f4ebcSOliver-Rainer Wittmann        if ( $allvariables->{'PRODUCTNAME'} eq "Apache OpenOffice" )
476*ff3f4ebcSOliver-Rainer Wittmann        {
477*ff3f4ebcSOliver-Rainer Wittmann            if ( $allvariables->{'POSTVERSIONEXTENSION'} eq "SDK" )
478*ff3f4ebcSOliver-Rainer Wittmann            {
479*ff3f4ebcSOliver-Rainer Wittmann                $start .= "-SDK";
480*ff3f4ebcSOliver-Rainer Wittmann            }
481*ff3f4ebcSOliver-Rainer Wittmann        }
482*ff3f4ebcSOliver-Rainer Wittmann
483*ff3f4ebcSOliver-Rainer Wittmann        if ( $allvariables->{'PRODUCTNAME'} eq "AOO-Developer-Build" )
484*ff3f4ebcSOliver-Rainer Wittmann        {
485*ff3f4ebcSOliver-Rainer Wittmann            if ( $allvariables->{'POSTVERSIONEXTENSION'} eq "SDK" )
486*ff3f4ebcSOliver-Rainer Wittmann            {
487*ff3f4ebcSOliver-Rainer Wittmann                $start .= "-Dev-SDK";
488*ff3f4ebcSOliver-Rainer Wittmann            }
489*ff3f4ebcSOliver-Rainer Wittmann            else
490*ff3f4ebcSOliver-Rainer Wittmann            {
491*ff3f4ebcSOliver-Rainer Wittmann                $start .= "-Dev";
492*ff3f4ebcSOliver-Rainer Wittmann            }
493*ff3f4ebcSOliver-Rainer Wittmann        }
494*ff3f4ebcSOliver-Rainer Wittmann
495*ff3f4ebcSOliver-Rainer Wittmann        if ( $allvariables->{'PRODUCTNAME'} eq "URE" )
496*ff3f4ebcSOliver-Rainer Wittmann        {
497*ff3f4ebcSOliver-Rainer Wittmann            $start .= "-URE";
498*ff3f4ebcSOliver-Rainer Wittmann        }
499*ff3f4ebcSOliver-Rainer Wittmann    }
500cdf0e10cSrcweir
501*ff3f4ebcSOliver-Rainer Wittmann    return $start;
502cdf0e10cSrcweir}
503cdf0e10cSrcweir
504cdf0e10cSrcweir#########################################################
505cdf0e10cSrcweir# Setting download version
506cdf0e10cSrcweir#########################################################
507cdf0e10cSrcweir
508cdf0e10cSrcweirsub get_download_version
509cdf0e10cSrcweir{
510cdf0e10cSrcweir	my ($allvariables) = @_;
511cdf0e10cSrcweir
512cdf0e10cSrcweir	my $version = "";
513cdf0e10cSrcweir
514cdf0e10cSrcweir	my $devproduct = 0;
515cdf0e10cSrcweir	if (( $allvariables->{'DEVELOPMENTPRODUCT'} ) && ( $allvariables->{'DEVELOPMENTPRODUCT'} == 1 )) { $devproduct = 1; }
516cdf0e10cSrcweir
517cdf0e10cSrcweir	my $cwsproduct = 0;
518cdf0e10cSrcweir	# the environment variable CWS_WORK_STAMP is set only in CWS
519cdf0e10cSrcweir	if ( $ENV{'CWS_WORK_STAMP'} ) { $cwsproduct = 1; }
520cdf0e10cSrcweir
521cdf0e10cSrcweir	if (( $cwsproduct ) || ( $devproduct ))  # use "DEV300m75"
522cdf0e10cSrcweir	{
523cdf0e10cSrcweir		my $source = uc($installer::globals::build); # DEV300
524cdf0e10cSrcweir		my $localminor = "";
525cdf0e10cSrcweir		if ( $installer::globals::minor ne "" ) { $localminor = $installer::globals::minor; }
526cdf0e10cSrcweir		else { $localminor = $installer::globals::lastminor; }
527cdf0e10cSrcweir		$version = $source . $localminor;
528cdf0e10cSrcweir	}
529cdf0e10cSrcweir	else  # use 3.2.0rc1
530cdf0e10cSrcweir	{
531cdf0e10cSrcweir		$version = $allvariables->{'PRODUCTVERSION'};
532cdf0e10cSrcweir		if (( $allvariables->{'ABOUTBOXPRODUCTVERSION'} ) && ( $allvariables->{'ABOUTBOXPRODUCTVERSION'} ne "" )) { $version = $allvariables->{'ABOUTBOXPRODUCTVERSION'}; }
533cdf0e10cSrcweir		if (( $allvariables->{'SHORT_PRODUCTEXTENSION'} ) && ( $allvariables->{'SHORT_PRODUCTEXTENSION'} ne "" )) { $version = $version . $allvariables->{'SHORT_PRODUCTEXTENSION'}; }
534cdf0e10cSrcweir	}
535cdf0e10cSrcweir
536cdf0e10cSrcweir	return $version;
537cdf0e10cSrcweir}
538cdf0e10cSrcweir
539cdf0e10cSrcweir###############################################################
540cdf0e10cSrcweir# Set date string, format: yymmdd
541cdf0e10cSrcweir###############################################################
542cdf0e10cSrcweir
543cdf0e10cSrcweirsub set_date_string
544cdf0e10cSrcweir{
545cdf0e10cSrcweir	my ($allvariables) = @_;
546cdf0e10cSrcweir
547cdf0e10cSrcweir	my $datestring = "";
548cdf0e10cSrcweir
549cdf0e10cSrcweir	my $devproduct = 0;
550cdf0e10cSrcweir	if (( $allvariables->{'DEVELOPMENTPRODUCT'} ) && ( $allvariables->{'DEVELOPMENTPRODUCT'} == 1 )) { $devproduct = 1; }
551cdf0e10cSrcweir
552cdf0e10cSrcweir	my $cwsproduct = 0;
553cdf0e10cSrcweir	# the environment variable CWS_WORK_STAMP is set only in CWS
554cdf0e10cSrcweir	if ( $ENV{'CWS_WORK_STAMP'} ) { $cwsproduct = 1; }
555cdf0e10cSrcweir
556cdf0e10cSrcweir	my $releasebuild = 1;
557cdf0e10cSrcweir	if (( $allvariables->{'SHORT_PRODUCTEXTENSION'} ) && ( $allvariables->{'SHORT_PRODUCTEXTENSION'} ne "" )) { $releasebuild = 0; }
558cdf0e10cSrcweir
559cdf0e10cSrcweir	if (( ! $devproduct ) && ( ! $cwsproduct ) && ( ! $releasebuild ))
560cdf0e10cSrcweir	{
561cdf0e10cSrcweir		my @timearray = localtime(time);
562cdf0e10cSrcweir
563cdf0e10cSrcweir		my $day = $timearray[3];
564cdf0e10cSrcweir		my $month = $timearray[4] + 1;
565cdf0e10cSrcweir		my $year = $timearray[5] + 1900;
566cdf0e10cSrcweir
567cdf0e10cSrcweir		if ( $month < 10 ) { $month = "0" . $month; }
568cdf0e10cSrcweir		if ( $day < 10 ) { $day = "0" . $day; }
569cdf0e10cSrcweir
570cdf0e10cSrcweir		$datestring = $year . $month . $day;
571cdf0e10cSrcweir	}
572cdf0e10cSrcweir
573cdf0e10cSrcweir	return $datestring;
574cdf0e10cSrcweir}
575cdf0e10cSrcweir
576cdf0e10cSrcweir#################################################################
577cdf0e10cSrcweir# Setting the platform name for download
578cdf0e10cSrcweir#################################################################
579cdf0e10cSrcweir
580cdf0e10cSrcweirsub get_download_platformname
581cdf0e10cSrcweir{
582cdf0e10cSrcweir	my $platformname = "";
583cdf0e10cSrcweir
584cdf0e10cSrcweir	if ( $installer::globals::islinuxbuild )
585cdf0e10cSrcweir	{
586cdf0e10cSrcweir		$platformname = "Linux";
587cdf0e10cSrcweir	}
588cdf0e10cSrcweir	elsif ( $installer::globals::issolarisbuild )
589cdf0e10cSrcweir	{
590cdf0e10cSrcweir		$platformname = "Solaris";
591cdf0e10cSrcweir	}
592cdf0e10cSrcweir	elsif ( $installer::globals::iswindowsbuild )
593cdf0e10cSrcweir	{
594cdf0e10cSrcweir		$platformname = "Win";
595cdf0e10cSrcweir	}
596cdf0e10cSrcweir	elsif ( $installer::globals::isfreebsdbuild )
597cdf0e10cSrcweir	{
598cdf0e10cSrcweir		$platformname = "FreeBSD";
599cdf0e10cSrcweir	}
600cdf0e10cSrcweir	elsif ( $installer::globals::ismacbuild )
601cdf0e10cSrcweir	{
602cdf0e10cSrcweir		$platformname = "MacOS";
603cdf0e10cSrcweir	}
604cdf0e10cSrcweir	else
605cdf0e10cSrcweir	{
606cdf0e10cSrcweir		# $platformname = $installer::globals::packageformat;
607cdf0e10cSrcweir		$platformname = $installer::globals::compiler;
608cdf0e10cSrcweir	}
609cdf0e10cSrcweir
610cdf0e10cSrcweir	return $platformname;
611cdf0e10cSrcweir}
612cdf0e10cSrcweir
613cdf0e10cSrcweir#########################################################
614cdf0e10cSrcweir# Setting the architecture for the download name
615cdf0e10cSrcweir#########################################################
616cdf0e10cSrcweir
617cdf0e10cSrcweirsub get_download_architecture
618cdf0e10cSrcweir{
619cdf0e10cSrcweir	my $arch = "";
620cdf0e10cSrcweir
621cdf0e10cSrcweir	if ( $installer::globals::compiler =~ /unxlngi/ )
622cdf0e10cSrcweir	{
623cdf0e10cSrcweir		$arch = "x86";
624cdf0e10cSrcweir	}
625cdf0e10cSrcweir	elsif ( $installer::globals::compiler =~ /unxlngppc/ )
626cdf0e10cSrcweir	{
627cdf0e10cSrcweir		$arch = "PPC";
628cdf0e10cSrcweir	}
629cdf0e10cSrcweir	elsif ( $installer::globals::compiler =~ /unxlngx/ )
630cdf0e10cSrcweir	{
631cdf0e10cSrcweir		$arch = "x86-64";
632cdf0e10cSrcweir	}
633cdf0e10cSrcweir	elsif ( $installer::globals::issolarissparcbuild )
634cdf0e10cSrcweir	{
635cdf0e10cSrcweir		$arch = "Sparc";
636cdf0e10cSrcweir	}
637cdf0e10cSrcweir	elsif ( $installer::globals::issolarisx86build )
638cdf0e10cSrcweir	{
639cdf0e10cSrcweir		$arch = "x86";
640cdf0e10cSrcweir	}
641cdf0e10cSrcweir	elsif ( $installer::globals::iswindowsbuild )
642cdf0e10cSrcweir	{
643cdf0e10cSrcweir		$arch = "x86";
644cdf0e10cSrcweir	}
645cdf0e10cSrcweir	elsif ( $installer::globals::compiler =~ /^unxmacxi/ )
646cdf0e10cSrcweir	{
647cdf0e10cSrcweir		$arch = "x86";
648cdf0e10cSrcweir	}
649cdf0e10cSrcweir	elsif ( $installer::globals::compiler =~ /^unxmacxp/ )
650cdf0e10cSrcweir	{
651cdf0e10cSrcweir		$arch = "PPC";
652cdf0e10cSrcweir	}
653cdf0e10cSrcweir
654cdf0e10cSrcweir	return $arch;
655cdf0e10cSrcweir}
656cdf0e10cSrcweir
657cdf0e10cSrcweir#########################################################
658cdf0e10cSrcweir# Setting the installation type for the download name
659cdf0e10cSrcweir#########################################################
660cdf0e10cSrcweir
661cdf0e10cSrcweirsub get_install_type
662cdf0e10cSrcweir{
663cdf0e10cSrcweir	my ($allvariables) = @_;
664cdf0e10cSrcweir
665cdf0e10cSrcweir	my $type = "";
666cdf0e10cSrcweir
667cdf0e10cSrcweir	if ( $installer::globals::languagepack )
668cdf0e10cSrcweir	{
669cdf0e10cSrcweir		$type = "langpack";
670cdf0e10cSrcweir
671cdf0e10cSrcweir		if ( $installer::globals::islinuxrpmbuild )
672cdf0e10cSrcweir		{
673cdf0e10cSrcweir			$type = $type . "-rpm";
674cdf0e10cSrcweir		}
675cdf0e10cSrcweir
676cdf0e10cSrcweir		if ( $installer::globals::islinuxdebbuild )
677cdf0e10cSrcweir		{
678cdf0e10cSrcweir			$type = $type . "-deb";
679cdf0e10cSrcweir		}
680cdf0e10cSrcweir
681cdf0e10cSrcweir		if ( $installer::globals::packageformat eq "archive" )
682cdf0e10cSrcweir		{
683cdf0e10cSrcweir			$type = $type . "-arc";
684cdf0e10cSrcweir		}
685cdf0e10cSrcweir	}
686cdf0e10cSrcweir	else
687cdf0e10cSrcweir	{
688cdf0e10cSrcweir		$type = "install";
689cdf0e10cSrcweir
690cdf0e10cSrcweir		if ( $installer::globals::islinuxrpmbuild )
691cdf0e10cSrcweir		{
692cdf0e10cSrcweir			$type = $type . "-rpm";
693cdf0e10cSrcweir		}
694cdf0e10cSrcweir
695cdf0e10cSrcweir		if ( $installer::globals::islinuxdebbuild )
696cdf0e10cSrcweir		{
697cdf0e10cSrcweir			$type = $type . "-deb";
698cdf0e10cSrcweir		}
699cdf0e10cSrcweir
700cdf0e10cSrcweir		if ( $installer::globals::packageformat eq "archive" )
701cdf0e10cSrcweir		{
702cdf0e10cSrcweir			$type = $type . "-arc";
703cdf0e10cSrcweir		}
704cdf0e10cSrcweir
705cdf0e10cSrcweir		if (( $allvariables->{'WITHJREPRODUCT'} ) && ( $allvariables->{'WITHJREPRODUCT'} == 1 ))
706cdf0e10cSrcweir		{
707cdf0e10cSrcweir			$type = $type . "-wJRE";
708cdf0e10cSrcweir		}
709cdf0e10cSrcweir
710cdf0e10cSrcweir	}
711cdf0e10cSrcweir
712cdf0e10cSrcweir	return $type;
713cdf0e10cSrcweir}
714cdf0e10cSrcweir
715cdf0e10cSrcweir#########################################################
716cdf0e10cSrcweir# Setting installation addons
717cdf0e10cSrcweir#########################################################
718cdf0e10cSrcweir
719cdf0e10cSrcweirsub get_downloadname_addon
720cdf0e10cSrcweir{
721cdf0e10cSrcweir	my $addon = "";
722cdf0e10cSrcweir
723cdf0e10cSrcweir	if ( $installer::globals::islinuxdebbuild ) { $addon = $addon . "_deb"; }
724cdf0e10cSrcweir
725cdf0e10cSrcweir	if ( $installer::globals::product =~ /_wJRE\s*$/ ) { $addon = "_wJRE"; }
726cdf0e10cSrcweir
727cdf0e10cSrcweir	return $addon;
728cdf0e10cSrcweir}
729cdf0e10cSrcweir
730cdf0e10cSrcweir#########################################################
731cdf0e10cSrcweir# Looking for versionstring in version.info
732cdf0e10cSrcweir# This has to be the only content of this file.
733cdf0e10cSrcweir#########################################################
734cdf0e10cSrcweir
735cdf0e10cSrcweirsub get_versionstring
736cdf0e10cSrcweir{
737cdf0e10cSrcweir	my ( $versionfile ) = @_;
738cdf0e10cSrcweir
739cdf0e10cSrcweir	my $versionstring = "";
740cdf0e10cSrcweir
741cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$versionfile}; $i++ )
742cdf0e10cSrcweir	{
743cdf0e10cSrcweir		my $oneline = ${$versionfile}[$i];
744cdf0e10cSrcweir
745cdf0e10cSrcweir		if ( $oneline =~ /^\s*\#/ ) { next; } # comment line
746cdf0e10cSrcweir		if ( $oneline =~ /^\s*\"\s*(.*?)\s*\"\s*$/ )
747cdf0e10cSrcweir		{
748cdf0e10cSrcweir			$versionstring = $1;
749cdf0e10cSrcweir			last;
750cdf0e10cSrcweir		}
751cdf0e10cSrcweir	}
752cdf0e10cSrcweir
753cdf0e10cSrcweir	return $versionstring;
754cdf0e10cSrcweir}
755cdf0e10cSrcweir
756cdf0e10cSrcweir#########################################################
757cdf0e10cSrcweir# Returning the current product version
758cdf0e10cSrcweir# This has to be defined in file "version.info"
759cdf0e10cSrcweir# in directory $installer::globals::ooouploaddir
760cdf0e10cSrcweir#########################################################
761cdf0e10cSrcweir
762cdf0e10cSrcweirsub get_current_version
763cdf0e10cSrcweir{
764cdf0e10cSrcweir	my $infoline = "";
765cdf0e10cSrcweir	my $versionstring = "";
766cdf0e10cSrcweir	my $filename = "version.info";
767cdf0e10cSrcweir	# $filename = $installer::globals::ooouploaddir . $installer::globals::separator . $filename;
768cdf0e10cSrcweir
769cdf0e10cSrcweir	if ( -f $filename )
770cdf0e10cSrcweir	{
771cdf0e10cSrcweir		$infoline = "File $filename exists. Trying to find current version.\n";
772cdf0e10cSrcweir		push( @installer::globals::logfileinfo, $infoline);
773cdf0e10cSrcweir		my $versionfile = installer::files::read_file($filename);
774cdf0e10cSrcweir		$versionstring = get_versionstring($versionfile);
775cdf0e10cSrcweir		$infoline = "Setting version string: $versionstring\n";
776cdf0e10cSrcweir		push( @installer::globals::logfileinfo, $infoline);
777cdf0e10cSrcweir	}
778cdf0e10cSrcweir	else
779cdf0e10cSrcweir	{
780cdf0e10cSrcweir		$infoline = "File $filename does not exist. No version setting in download file name.\n";
781cdf0e10cSrcweir		push( @installer::globals::logfileinfo, $infoline);
782cdf0e10cSrcweir	}
783cdf0e10cSrcweir
784cdf0e10cSrcweir	$installer::globals::oooversionstring = $versionstring;
785cdf0e10cSrcweir
786cdf0e10cSrcweir	return $versionstring;
787cdf0e10cSrcweir}
788cdf0e10cSrcweir
789cdf0e10cSrcweir###############################################################################################
790cdf0e10cSrcweir# Setting the download file name
791cdf0e10cSrcweir# Syntax:
792cdf0e10cSrcweir# (PRODUCTNAME)_(VERSION)_(TIMESTAMP)_(OS)_(ARCH)_(INSTALLTYPE)_(LANGUAGE).(FILEEXTENSION)
793cdf0e10cSrcweir# Rules:
794cdf0e10cSrcweir# Timestamp only for Beta and Release Candidate
795cdf0e10cSrcweir###############################################################################################
796cdf0e10cSrcweir
797cdf0e10cSrcweirsub set_download_filename
798cdf0e10cSrcweir{
799cdf0e10cSrcweir	my ($languagestringref, $allvariables) = @_;
800cdf0e10cSrcweir
801cdf0e10cSrcweir	my $start = get_downloadname_productname($allvariables);
802cdf0e10cSrcweir	my $versionstring = get_download_version($allvariables);
803cdf0e10cSrcweir	my $date = set_date_string($allvariables);
804cdf0e10cSrcweir	my $platform = get_download_platformname();
805cdf0e10cSrcweir	my $architecture = get_download_architecture();
806cdf0e10cSrcweir	my $type = get_install_type($allvariables);
807cdf0e10cSrcweir	my $language = get_downloadname_language($languagestringref);
808cdf0e10cSrcweir
809cdf0e10cSrcweir	# Setting the extension happens automatically
810cdf0e10cSrcweir
811cdf0e10cSrcweir	my $filename = $start . "_" . $versionstring . "_" . $date . "_" . $platform . "_" . $architecture . "_" . $type . "_" . $language;
812cdf0e10cSrcweir
813cdf0e10cSrcweir	$filename =~ s/\_\_/\_/g;	# necessary, if $versionstring or $platform or $language are empty
814cdf0e10cSrcweir	$filename =~ s/\_\s*$//;	# necessary, if $language and $addon are empty
815cdf0e10cSrcweir
816cdf0e10cSrcweir	$installer::globals::ooodownloadfilename = $filename;
817cdf0e10cSrcweir
818cdf0e10cSrcweir	return $filename;
819cdf0e10cSrcweir}
820cdf0e10cSrcweir
821cdf0e10cSrcweir#########################################################
822cdf0e10cSrcweir# Creating a tar.gz file
823cdf0e10cSrcweir#########################################################
824cdf0e10cSrcweir
825cdf0e10cSrcweirsub create_tar_gz_file_from_directory
826cdf0e10cSrcweir{
827cdf0e10cSrcweir	my ($installdir, $getuidlibrary, $downloaddir, $downloadfilename) = @_;
828cdf0e10cSrcweir
829cdf0e10cSrcweir	my $infoline = "";
830cdf0e10cSrcweir
831cdf0e10cSrcweir	my $packdir = $installdir;
832cdf0e10cSrcweir	installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$packdir);
833cdf0e10cSrcweir	my $changedir = $installdir;
834cdf0e10cSrcweir	installer::pathanalyzer::get_path_from_fullqualifiedname(\$changedir);
835cdf0e10cSrcweir
836cdf0e10cSrcweir	my $ldpreloadstring = "";
837cdf0e10cSrcweir	if ( $getuidlibrary ne "" ) { $ldpreloadstring = "LD_PRELOAD=" . $getuidlibrary; }
838cdf0e10cSrcweir
839cdf0e10cSrcweir	$installer::globals::downloadfileextension = ".tar.gz";
840cdf0e10cSrcweir	$installer::globals::downloadfilename = $downloadfilename . $installer::globals::downloadfileextension;
841cdf0e10cSrcweir	my $targzname = $downloaddir . $installer::globals::separator . $installer::globals::downloadfilename;
842cdf0e10cSrcweir
843cdf0e10cSrcweir	$systemcall = "cd $changedir; $ldpreloadstring tar -cf - $packdir | gzip > $targzname";
844cdf0e10cSrcweir
845cdf0e10cSrcweir	my $returnvalue = system($systemcall);
846cdf0e10cSrcweir
847cdf0e10cSrcweir	$infoline = "Systemcall: $systemcall\n";
848cdf0e10cSrcweir	push( @installer::globals::logfileinfo, $infoline);
849cdf0e10cSrcweir
850cdf0e10cSrcweir	if ($returnvalue)
851cdf0e10cSrcweir	{
852cdf0e10cSrcweir		$infoline = "ERROR: Could not execute \"$systemcall\"!\n";
853cdf0e10cSrcweir		push( @installer::globals::logfileinfo, $infoline);
854cdf0e10cSrcweir	}
855cdf0e10cSrcweir	else
856cdf0e10cSrcweir	{
857cdf0e10cSrcweir		$infoline = "Success: Executed \"$systemcall\" successfully!\n";
858cdf0e10cSrcweir		push( @installer::globals::logfileinfo, $infoline);
859cdf0e10cSrcweir	}
860cdf0e10cSrcweir
861cdf0e10cSrcweir	return $targzname;
862cdf0e10cSrcweir}
863cdf0e10cSrcweir
864cdf0e10cSrcweir#########################################################
865cdf0e10cSrcweir# Setting the variables in the download name
866cdf0e10cSrcweir#########################################################
867cdf0e10cSrcweir
868cdf0e10cSrcweirsub resolve_variables_in_downloadname
869cdf0e10cSrcweir{
870cdf0e10cSrcweir	my ($allvariables, $downloadname, $languagestringref) = @_;
871cdf0e10cSrcweir
872cdf0e10cSrcweir	# Typical name: soa-{productversion}-{extension}-bin-{os}-{languages}
873cdf0e10cSrcweir
874cdf0e10cSrcweir	my $productversion = "";
875cdf0e10cSrcweir	if ( $allvariables->{'PRODUCTVERSION'} ) { $productversion = $allvariables->{'PRODUCTVERSION'}; }
876cdf0e10cSrcweir	$downloadname =~ s/\{productversion\}/$productversion/;
877cdf0e10cSrcweir
878cdf0e10cSrcweir	my $ppackageversion = "";
879cdf0e10cSrcweir	if ( $allvariables->{'PACKAGEVERSION'} ) { $packageversion = $allvariables->{'PACKAGEVERSION'}; }
880cdf0e10cSrcweir	$downloadname =~ s/\{packageversion\}/$packageversion/;
881cdf0e10cSrcweir
882cdf0e10cSrcweir	my $extension = "";
883cdf0e10cSrcweir	if ( $allvariables->{'SHORT_PRODUCTEXTENSION'} ) { $extension = $allvariables->{'SHORT_PRODUCTEXTENSION'}; }
884cdf0e10cSrcweir	$extension = lc($extension);
885cdf0e10cSrcweir	$downloadname =~ s/\{extension\}/$extension/;
886cdf0e10cSrcweir
887cdf0e10cSrcweir	my $os = "";
888cdf0e10cSrcweir	if ( $installer::globals::iswindowsbuild ) { $os = "windows"; }
889cdf0e10cSrcweir	elsif ( $installer::globals::issolarissparcbuild ) { $os = "solsparc"; }
890cdf0e10cSrcweir	elsif ( $installer::globals::issolarisx86build ) { $os = "solia"; }
891cdf0e10cSrcweir	elsif ( $installer::globals::islinuxbuild ) { $os = "linux"; }
892cdf0e10cSrcweir	elsif ( $installer::globals::compiler =~ /unxmacxi/ ) { $os = "macosxi"; }
893cdf0e10cSrcweir	elsif ( $installer::globals::compiler =~ /unxmacxp/ ) { $os = "macosxp"; }
894cdf0e10cSrcweir	else { $os = ""; }
895cdf0e10cSrcweir	$downloadname =~ s/\{os\}/$os/;
896cdf0e10cSrcweir
897cdf0e10cSrcweir	my $languages = $$languagestringref;
898cdf0e10cSrcweir	$downloadname =~ s/\{languages\}/$languages/;
899cdf0e10cSrcweir
900cdf0e10cSrcweir	$downloadname =~ s/\-\-\-/\-/g;
901cdf0e10cSrcweir	$downloadname =~ s/\-\-/\-/g;
902cdf0e10cSrcweir	$downloadname =~ s/\-\s*$//;
903cdf0e10cSrcweir
904cdf0e10cSrcweir	return $downloadname;
905cdf0e10cSrcweir}
906cdf0e10cSrcweir
907cdf0e10cSrcweir##################################################################
908cdf0e10cSrcweir# Windows: Replacing one placeholder with the specified value
909cdf0e10cSrcweir##################################################################
910cdf0e10cSrcweir
911cdf0e10cSrcweirsub replace_one_variable
912cdf0e10cSrcweir{
913cdf0e10cSrcweir	my ($templatefile, $placeholder, $value) = @_;
914cdf0e10cSrcweir
915cdf0e10cSrcweir	my $infoline = "Replacing $placeholder by $value in nsi file\n";
916cdf0e10cSrcweir	push( @installer::globals::logfileinfo, $infoline);
917cdf0e10cSrcweir
918cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$templatefile}; $i++ )
919cdf0e10cSrcweir	{
920cdf0e10cSrcweir		${$templatefile}[$i] =~ s/$placeholder/$value/g;
921cdf0e10cSrcweir	}
922cdf0e10cSrcweir
923cdf0e10cSrcweir}
924cdf0e10cSrcweir
925cdf0e10cSrcweir########################################################################################
926cdf0e10cSrcweir# Converting a string to a unicode string
927cdf0e10cSrcweir########################################################################################
928cdf0e10cSrcweir
929cdf0e10cSrcweirsub convert_to_unicode
930cdf0e10cSrcweir{
931cdf0e10cSrcweir	my ($string) = @_;
932cdf0e10cSrcweir
933cdf0e10cSrcweir	my $unicodestring = "";
934cdf0e10cSrcweir
935cdf0e10cSrcweir	my $stringlength = length($string);
936cdf0e10cSrcweir
937cdf0e10cSrcweir	for ( my $i = 0; $i < $stringlength; $i++ )
938cdf0e10cSrcweir	{
939cdf0e10cSrcweir		$unicodestring = $unicodestring . substr($string, $i, 1);
940cdf0e10cSrcweir		$unicodestring = $unicodestring . chr(0);
941cdf0e10cSrcweir	}
942cdf0e10cSrcweir
943cdf0e10cSrcweir	return $unicodestring;
944cdf0e10cSrcweir}
945cdf0e10cSrcweir
946cdf0e10cSrcweir##################################################################
947cdf0e10cSrcweir# Windows: Setting nsis version is necessary because of small
948cdf0e10cSrcweir# changes in nsis from version 2.0.4 to 2.3.1
949cdf0e10cSrcweir##################################################################
950cdf0e10cSrcweir
951cdf0e10cSrcweirsub set_nsis_version
952cdf0e10cSrcweir{
953cdf0e10cSrcweir	my ($nshfile) = @_;
954cdf0e10cSrcweir
955cdf0e10cSrcweir	my $searchstring = "\$\{LangFileString\}"; # occurs only in nsis 2.3.1 or similar
956cdf0e10cSrcweir
957cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$nshfile}; $i++ )
958cdf0e10cSrcweir	{
959cdf0e10cSrcweir		if ( ${$nshfile}[$i] =~ /\Q$searchstring\E/ )
960cdf0e10cSrcweir		{
961cdf0e10cSrcweir			# this is nsis 2.3.1 or similar
962cdf0e10cSrcweir			$installer::globals::nsis231 = 1;
963cdf0e10cSrcweir			$installer::globals::unicodensis = 0;
964cdf0e10cSrcweir			last;
965cdf0e10cSrcweir		}
966cdf0e10cSrcweir	}
967cdf0e10cSrcweir
968cdf0e10cSrcweir	# checking unicode version
969cdf0e10cSrcweir	$searchstring = convert_to_unicode($searchstring);
970cdf0e10cSrcweir
971cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$nshfile}; $i++ )
972cdf0e10cSrcweir	{
973cdf0e10cSrcweir		if ( ${$nshfile}[$i] =~ /\Q$searchstring\E/ )
974cdf0e10cSrcweir		{
975cdf0e10cSrcweir			# this is nsis 2.3.1 or similar
976cdf0e10cSrcweir			$installer::globals::nsis231 = 1;
977cdf0e10cSrcweir			$installer::globals::unicodensis = 1;
978cdf0e10cSrcweir			last;
979cdf0e10cSrcweir		}
980cdf0e10cSrcweir	}
981cdf0e10cSrcweir
982cdf0e10cSrcweir	if ( ! $installer::globals::nsis231 ) { $installer::globals::nsis204 = 1; }
983cdf0e10cSrcweir}
984cdf0e10cSrcweir
985cdf0e10cSrcweir##################################################################
986cdf0e10cSrcweir# Windows: Including the product name into nsi template
987cdf0e10cSrcweir##################################################################
988cdf0e10cSrcweir
989cdf0e10cSrcweirsub put_windows_productname_into_template
990cdf0e10cSrcweir{
991cdf0e10cSrcweir	my ($templatefile, $variableshashref) = @_;
992cdf0e10cSrcweir
993cdf0e10cSrcweir	my $productname = $variableshashref->{'PRODUCTNAME'};
994cdf0e10cSrcweir	$productname =~ s/\.//g;	# OpenOffice.org -> OpenOfficeorg
995cdf0e10cSrcweir
996cdf0e10cSrcweir	replace_one_variable($templatefile, "PRODUCTNAMEPLACEHOLDER", $productname);
997cdf0e10cSrcweir}
998cdf0e10cSrcweir
999cdf0e10cSrcweir##################################################################
1000cdf0e10cSrcweir# Windows: Including the path to the banner.bmp into nsi template
1001cdf0e10cSrcweir##################################################################
1002cdf0e10cSrcweir
1003cdf0e10cSrcweirsub put_banner_bmp_into_template
1004cdf0e10cSrcweir{
1005cdf0e10cSrcweir	my ($templatefile, $includepatharrayref, $allvariables) = @_;
1006cdf0e10cSrcweir
1007cdf0e10cSrcweir	# my $filename = "downloadbanner.bmp";
1008cdf0e10cSrcweir	if ( ! $allvariables->{'DOWNLOADBANNER'} ) { installer::exiter::exit_program("ERROR: DOWNLOADBANNER not defined in product definition!", "put_banner_bmp_into_template"); }
1009cdf0e10cSrcweir	my $filename = $allvariables->{'DOWNLOADBANNER'};
1010cdf0e10cSrcweir
1011cdf0e10cSrcweir	my $completefilenameref = "";
1012cdf0e10cSrcweir
1013cdf0e10cSrcweir	if ( $installer::globals::include_pathes_read )
1014cdf0e10cSrcweir	{
1015cdf0e10cSrcweir		$completefilenameref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$filename, $includepatharrayref, 0);
1016cdf0e10cSrcweir	}
1017cdf0e10cSrcweir	else
1018cdf0e10cSrcweir	{
1019cdf0e10cSrcweir		$completefilenameref = installer::scriptitems::get_sourcepath_from_filename_and_includepath_classic(\$filename, $includepatharrayref, 0);
1020cdf0e10cSrcweir	}
1021cdf0e10cSrcweir
1022cdf0e10cSrcweir	if ($$completefilenameref eq "") { installer::exiter::exit_program("ERROR: Could not find download file $filename!", "put_banner_bmp_into_template"); }
1023cdf0e10cSrcweir
1024cdf0e10cSrcweir	if ( $^O =~ /cygwin/i ) { $$completefilenameref =~ s/\//\\/g; }
1025cdf0e10cSrcweir
1026cdf0e10cSrcweir	replace_one_variable($templatefile, "BANNERBMPPLACEHOLDER", $$completefilenameref);
1027cdf0e10cSrcweir}
1028cdf0e10cSrcweir
1029cdf0e10cSrcweir##################################################################
1030cdf0e10cSrcweir# Windows: Including the path to the welcome.bmp into nsi template
1031cdf0e10cSrcweir##################################################################
1032cdf0e10cSrcweir
1033cdf0e10cSrcweirsub put_welcome_bmp_into_template
1034cdf0e10cSrcweir{
1035cdf0e10cSrcweir	my ($templatefile, $includepatharrayref, $allvariables) = @_;
1036cdf0e10cSrcweir
1037cdf0e10cSrcweir	# my $filename = "downloadbitmap.bmp";
1038cdf0e10cSrcweir	if ( ! $allvariables->{'DOWNLOADBITMAP'} ) { installer::exiter::exit_program("ERROR: DOWNLOADBITMAP not defined in product definition!", "put_welcome_bmp_into_template"); }
1039cdf0e10cSrcweir	my $filename = $allvariables->{'DOWNLOADBITMAP'};
1040cdf0e10cSrcweir
1041cdf0e10cSrcweir	my $completefilenameref = "";
1042cdf0e10cSrcweir
1043cdf0e10cSrcweir	if ( $installer::globals::include_pathes_read )
1044cdf0e10cSrcweir	{
1045cdf0e10cSrcweir		$completefilenameref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$filename, $includepatharrayref, 0);
1046cdf0e10cSrcweir	}
1047cdf0e10cSrcweir	else
1048cdf0e10cSrcweir	{
1049cdf0e10cSrcweir		$completefilenameref = installer::scriptitems::get_sourcepath_from_filename_and_includepath_classic(\$filename, $includepatharrayref, 0);
1050cdf0e10cSrcweir	}
1051cdf0e10cSrcweir
1052cdf0e10cSrcweir	if ($$completefilenameref eq "") { installer::exiter::exit_program("ERROR: Could not find download file $filename!", "put_welcome_bmp_into_template"); }
1053cdf0e10cSrcweir
1054cdf0e10cSrcweir	if ( $^O =~ /cygwin/i ) { $$completefilenameref =~ s/\//\\/g; }
1055cdf0e10cSrcweir
1056cdf0e10cSrcweir	replace_one_variable($templatefile, "WELCOMEBMPPLACEHOLDER", $$completefilenameref);
1057cdf0e10cSrcweir}
1058cdf0e10cSrcweir
1059cdf0e10cSrcweir##################################################################
1060cdf0e10cSrcweir# Windows: Including the path to the setup.ico into nsi template
1061cdf0e10cSrcweir##################################################################
1062cdf0e10cSrcweir
1063cdf0e10cSrcweirsub put_setup_ico_into_template
1064cdf0e10cSrcweir{
1065cdf0e10cSrcweir	my ($templatefile, $includepatharrayref, $allvariables) = @_;
1066cdf0e10cSrcweir
1067cdf0e10cSrcweir	# my $filename = "downloadsetup.ico";
1068cdf0e10cSrcweir	if ( ! $allvariables->{'DOWNLOADSETUPICO'} ) { installer::exiter::exit_program("ERROR: DOWNLOADSETUPICO not defined in product definition!", "put_setup_ico_into_template"); }
1069cdf0e10cSrcweir	my $filename = $allvariables->{'DOWNLOADSETUPICO'};
1070cdf0e10cSrcweir
1071cdf0e10cSrcweir	my $completefilenameref = "";
1072cdf0e10cSrcweir
1073cdf0e10cSrcweir	if ( $installer::globals::include_pathes_read )
1074cdf0e10cSrcweir	{
1075cdf0e10cSrcweir		$completefilenameref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$filename, $includepatharrayref, 0);
1076cdf0e10cSrcweir	}
1077cdf0e10cSrcweir	else
1078cdf0e10cSrcweir	{
1079cdf0e10cSrcweir		$completefilenameref = installer::scriptitems::get_sourcepath_from_filename_and_includepath_classic(\$filename, $includepatharrayref, 0);
1080cdf0e10cSrcweir	}
1081cdf0e10cSrcweir
1082cdf0e10cSrcweir	if ($$completefilenameref eq "") { installer::exiter::exit_program("ERROR: Could not find download file $filename!", "put_setup_ico_into_template"); }
1083cdf0e10cSrcweir
1084cdf0e10cSrcweir	if ( $^O =~ /cygwin/i ) { $$completefilenameref =~ s/\//\\/g; }
1085cdf0e10cSrcweir
1086cdf0e10cSrcweir	replace_one_variable($templatefile, "SETUPICOPLACEHOLDER", $$completefilenameref);
1087cdf0e10cSrcweir}
1088cdf0e10cSrcweir
1089cdf0e10cSrcweir##################################################################
1090cdf0e10cSrcweir# Windows: Including the publisher into nsi template
1091cdf0e10cSrcweir##################################################################
1092cdf0e10cSrcweir
1093cdf0e10cSrcweirsub put_publisher_into_template
1094cdf0e10cSrcweir{
1095cdf0e10cSrcweir	my ($templatefile) = @_;
1096cdf0e10cSrcweir
1097cdf0e10cSrcweir	my $publisher = "Sun Microsystems, Inc.";
1098cdf0e10cSrcweir
1099cdf0e10cSrcweir	replace_one_variable($templatefile, "PUBLISHERPLACEHOLDER", $publisher);
1100cdf0e10cSrcweir}
1101cdf0e10cSrcweir
1102cdf0e10cSrcweir##################################################################
1103cdf0e10cSrcweir# Windows: Including the web site into nsi template
1104cdf0e10cSrcweir##################################################################
1105cdf0e10cSrcweir
1106cdf0e10cSrcweirsub put_website_into_template
1107cdf0e10cSrcweir{
1108cdf0e10cSrcweir	my ($templatefile) = @_;
1109cdf0e10cSrcweir
1110cdf0e10cSrcweir	my $website = "http\:\/\/www\.sun\.com\/staroffice";
1111cdf0e10cSrcweir
1112cdf0e10cSrcweir	replace_one_variable($templatefile, "WEBSITEPLACEHOLDER", $website);
1113cdf0e10cSrcweir}
1114cdf0e10cSrcweir
1115cdf0e10cSrcweir##################################################################
1116cdf0e10cSrcweir# Windows: Including the Java file name into nsi template
1117cdf0e10cSrcweir##################################################################
1118cdf0e10cSrcweir
1119cdf0e10cSrcweirsub put_javafilename_into_template
1120cdf0e10cSrcweir{
1121cdf0e10cSrcweir	my ($templatefile, $variableshashref) = @_;
1122cdf0e10cSrcweir
1123cdf0e10cSrcweir	my $javaversion = "";
1124cdf0e10cSrcweir
1125cdf0e10cSrcweir	if ( $variableshashref->{'WINDOWSJAVAFILENAME'} ) { $javaversion = $variableshashref->{'WINDOWSJAVAFILENAME'}; }
1126cdf0e10cSrcweir
1127cdf0e10cSrcweir	replace_one_variable($templatefile, "WINDOWSJAVAFILENAMEPLACEHOLDER", $javaversion);
1128cdf0e10cSrcweir}
1129cdf0e10cSrcweir
1130cdf0e10cSrcweir##################################################################
1131cdf0e10cSrcweir# Windows: Including the product version into nsi template
1132cdf0e10cSrcweir##################################################################
1133cdf0e10cSrcweir
1134cdf0e10cSrcweirsub put_windows_productversion_into_template
1135cdf0e10cSrcweir{
1136cdf0e10cSrcweir	my ($templatefile, $variableshashref) = @_;
1137cdf0e10cSrcweir
1138cdf0e10cSrcweir	my $productversion = $variableshashref->{'PRODUCTVERSION'};
1139cdf0e10cSrcweir
1140cdf0e10cSrcweir	replace_one_variable($templatefile, "PRODUCTVERSIONPLACEHOLDER", $productversion);
1141cdf0e10cSrcweir}
1142cdf0e10cSrcweir
1143cdf0e10cSrcweir##################################################################
1144cdf0e10cSrcweir# Windows: Including the product version into nsi template
1145cdf0e10cSrcweir##################################################################
1146cdf0e10cSrcweir
1147cdf0e10cSrcweirsub put_windows_productpath_into_template
1148cdf0e10cSrcweir{
1149cdf0e10cSrcweir	my ($templatefile, $variableshashref, $languagestringref, $localnsisdir) = @_;
1150cdf0e10cSrcweir
1151cdf0e10cSrcweir	my $productpath = $variableshashref->{'PROPERTYTABLEPRODUCTNAME'};
1152cdf0e10cSrcweir
1153cdf0e10cSrcweir	my $locallangs = $$languagestringref;
1154cdf0e10cSrcweir	$locallangs =~ s/_/ /g;
1155cdf0e10cSrcweir	if (length($locallangs) > $installer::globals::max_lang_length) { $locallangs = "multi lingual"; }
1156cdf0e10cSrcweir
1157cdf0e10cSrcweir	if ( ! $installer::globals::languagepack ) { $productpath = $productpath . " (" . $locallangs . ")"; }
1158cdf0e10cSrcweir
1159cdf0e10cSrcweir	# if (( $installer::globals::languagepack ) && ( $installer::globals::unicodensis )) { $productpath = convert_textstring_to_utf16($productpath, $localnsisdir, "stringhelper.txt"); }
1160cdf0e10cSrcweir
1161cdf0e10cSrcweir	replace_one_variable($templatefile, "PRODUCTPATHPLACEHOLDER", $productpath);
1162cdf0e10cSrcweir}
1163cdf0e10cSrcweir
1164cdf0e10cSrcweir##################################################################
1165cdf0e10cSrcweir# Windows: Including download file name into nsi template
1166cdf0e10cSrcweir##################################################################
1167cdf0e10cSrcweir
1168cdf0e10cSrcweirsub put_outputfilename_into_template
1169cdf0e10cSrcweir{
1170cdf0e10cSrcweir	my ($templatefile, $downloadname) = @_;
1171cdf0e10cSrcweir
1172cdf0e10cSrcweir	$installer::globals::downloadfileextension = ".exe";
1173cdf0e10cSrcweir	$downloadname = $downloadname . $installer::globals::downloadfileextension;
1174cdf0e10cSrcweir	$installer::globals::downloadfilename = $downloadname;
1175cdf0e10cSrcweir
1176cdf0e10cSrcweir	replace_one_variable($templatefile, "DOWNLOADNAMEPLACEHOLDER", $downloadname);
1177cdf0e10cSrcweir}
1178cdf0e10cSrcweir
1179cdf0e10cSrcweir##################################################################
1180cdf0e10cSrcweir# Windows: Generating the file list in nsi file format
1181cdf0e10cSrcweir##################################################################
1182cdf0e10cSrcweir
1183cdf0e10cSrcweirsub get_file_list
1184cdf0e10cSrcweir{
1185cdf0e10cSrcweir	my ( $basedir ) = @_;
1186cdf0e10cSrcweir
1187cdf0e10cSrcweir	my @filelist = ();
1188cdf0e10cSrcweir
1189cdf0e10cSrcweir	my $alldirs = installer::systemactions::get_all_directories($basedir);
1190cdf0e10cSrcweir	unshift(@{$alldirs}, $basedir);	# $basedir is the first directory in $alldirs
1191cdf0e10cSrcweir
1192cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$alldirs}; $i++ )
1193cdf0e10cSrcweir	{
1194cdf0e10cSrcweir		my $onedir = ${$alldirs}[$i];
1195cdf0e10cSrcweir
1196cdf0e10cSrcweir		# Syntax:
1197cdf0e10cSrcweir		# SetOutPath "$INSTDIR"
1198cdf0e10cSrcweir
1199cdf0e10cSrcweir		my $relativedir = $onedir;
1200cdf0e10cSrcweir		$relativedir =~ s/\Q$basedir\E//;
1201cdf0e10cSrcweir
1202cdf0e10cSrcweir		my $oneline = " " . "SetOutPath" . " " . "\"\$INSTDIR" . $relativedir . "\"" . "\n";
1203cdf0e10cSrcweir
1204cdf0e10cSrcweir		if ( $^O =~ /cygwin/i ) {
1205cdf0e10cSrcweir			$oneline =~ s/\//\\/g;
1206cdf0e10cSrcweir		}
1207cdf0e10cSrcweir		push(@filelist, $oneline);
1208cdf0e10cSrcweir
1209cdf0e10cSrcweir		# Collecting all files in the specific directory
1210cdf0e10cSrcweir
1211cdf0e10cSrcweir		my $files = installer::systemactions::get_all_files_from_one_directory($onedir);
1212cdf0e10cSrcweir
1213cdf0e10cSrcweir		for ( my $j = 0; $j <= $#{$files}; $j++ )
1214cdf0e10cSrcweir		{
1215cdf0e10cSrcweir			my $onefile = ${$files}[$j];
1216cdf0e10cSrcweir
1217cdf0e10cSrcweir			my $fileline = "  " . "File" . " " . "\"" . $onefile . "\"" . "\n";
1218cdf0e10cSrcweir
1219cdf0e10cSrcweir			if ( $^O =~ /cygwin/i ) {
1220cdf0e10cSrcweir				$fileline =~ s/\//\\/g;
1221cdf0e10cSrcweir			}
1222cdf0e10cSrcweir			push(@filelist, $fileline);
1223cdf0e10cSrcweir		}
1224cdf0e10cSrcweir	}
1225cdf0e10cSrcweir
1226cdf0e10cSrcweir	return \@filelist;
1227cdf0e10cSrcweir}
1228cdf0e10cSrcweir
1229cdf0e10cSrcweir##################################################################
1230cdf0e10cSrcweir# Windows: Including list of all files into nsi template
1231cdf0e10cSrcweir##################################################################
1232cdf0e10cSrcweir
1233cdf0e10cSrcweirsub put_filelist_into_template
1234cdf0e10cSrcweir{
1235cdf0e10cSrcweir	my ($templatefile, $installationdir) = @_;
1236cdf0e10cSrcweir
1237cdf0e10cSrcweir	my $filelist = get_file_list($installationdir);
1238cdf0e10cSrcweir
1239cdf0e10cSrcweir	my $filestring = "";
1240cdf0e10cSrcweir
1241cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$filelist}; $i++ )
1242cdf0e10cSrcweir	{
1243cdf0e10cSrcweir		$filestring = $filestring . ${$filelist}[$i];
1244cdf0e10cSrcweir	}
1245cdf0e10cSrcweir
1246cdf0e10cSrcweir	$filestring =~ s/\s*$//;
1247cdf0e10cSrcweir
1248cdf0e10cSrcweir	replace_one_variable($templatefile, "ALLFILESPLACEHOLDER", $filestring);
1249cdf0e10cSrcweir}
1250cdf0e10cSrcweir
1251cdf0e10cSrcweir##################################################################
1252cdf0e10cSrcweir# Windows: NSIS uses specific language names
1253cdf0e10cSrcweir##################################################################
1254cdf0e10cSrcweir
1255cdf0e10cSrcweirsub nsis_language_converter
1256cdf0e10cSrcweir{
1257cdf0e10cSrcweir	my ($language) = @_;
1258cdf0e10cSrcweir
1259cdf0e10cSrcweir	my $nsislanguage = "";
1260cdf0e10cSrcweir
1261cdf0e10cSrcweir	# Assign language used by NSIS.
1262cdf0e10cSrcweir	# The files "$nsislanguage.nsh" and "$nsislanguage.nlf"
1263cdf0e10cSrcweir	# are needed in the NSIS environment.
1264cdf0e10cSrcweir	# Directory: <NSIS-Dir>/Contrib/Language files
1265cdf0e10cSrcweir	if ( $language eq "en-US" ) { $nsislanguage = "English"; }
1266cdf0e10cSrcweir	elsif ( $language eq "sq" ) { $nsislanguage = "Albanian"; }
1267cdf0e10cSrcweir	elsif ( $language eq "ar" ) { $nsislanguage = "Arabic"; }
1268cdf0e10cSrcweir	elsif ( $language eq "bg" ) { $nsislanguage = "Bulgarian"; }
1269cdf0e10cSrcweir	elsif ( $language eq "ca" ) { $nsislanguage = "Catalan"; }
1270cdf0e10cSrcweir	elsif ( $language eq "hr" ) { $nsislanguage = "Croatian"; }
1271cdf0e10cSrcweir	elsif ( $language eq "cs" ) { $nsislanguage = "Czech"; }
1272cdf0e10cSrcweir	elsif ( $language eq "da" ) { $nsislanguage = "Danish"; }
1273cdf0e10cSrcweir	elsif ( $language eq "nl" ) { $nsislanguage = "Dutch"; }
1274cdf0e10cSrcweir	elsif ( $language eq "de" ) { $nsislanguage = "German"; }
1275cdf0e10cSrcweir	elsif ( $language eq "de-LU" ) { $nsislanguage = "Luxembourgish"; }
1276cdf0e10cSrcweir	elsif ( $language eq "et" ) { $nsislanguage = "Estonian"; }
1277cdf0e10cSrcweir	elsif ( $language eq "fa" ) { $nsislanguage = "Farsi"; }
1278cdf0e10cSrcweir	elsif ( $language eq "el" ) { $nsislanguage = "Greek"; }
1279cdf0e10cSrcweir	elsif ( $language eq "fi" ) { $nsislanguage = "Finnish"; }
1280cdf0e10cSrcweir	elsif ( $language eq "fr" ) { $nsislanguage = "French"; }
1281cdf0e10cSrcweir	elsif ( $language eq "hu" ) { $nsislanguage = "Hungarian"; }
1282cdf0e10cSrcweir	elsif ( $language eq "he" ) { $nsislanguage = "Hebrew"; }
1283cdf0e10cSrcweir	elsif ( $language eq "is" ) { $nsislanguage = "Icelandic"; }
1284cdf0e10cSrcweir	elsif ( $language eq "id" ) { $nsislanguage = "Indonesian"; }
1285cdf0e10cSrcweir	elsif ( $language eq "it" ) { $nsislanguage = "Italian"; }
1286cdf0e10cSrcweir	elsif ( $language eq "lv" ) { $nsislanguage = "Latvian"; }
1287cdf0e10cSrcweir	elsif ( $language eq "lt" ) { $nsislanguage = "Lithuanian"; }
1288cdf0e10cSrcweir	elsif ( $language eq "mk" ) { $nsislanguage = "Macedonian"; }
1289cdf0e10cSrcweir	elsif ( $language eq "mn" ) { $nsislanguage = "Mongolian"; }
1290cdf0e10cSrcweir	elsif ( $language eq "no" ) { $nsislanguage = "Norwegian"; }
1291cdf0e10cSrcweir	elsif ( $language eq "no-NO" ) { $nsislanguage = "Norwegian"; }
1292cdf0e10cSrcweir	elsif ( $language eq "es" ) { $nsislanguage = "Spanish"; }
1293cdf0e10cSrcweir	elsif ( $language eq "sl" ) { $nsislanguage = "Slovenian"; }
1294cdf0e10cSrcweir	elsif ( $language eq "sv" ) { $nsislanguage = "Swedish"; }
1295cdf0e10cSrcweir	elsif ( $language eq "sk" ) { $nsislanguage = "Slovak"; }
1296cdf0e10cSrcweir	elsif ( $language eq "pl" ) { $nsislanguage = "Polish"; }
1297cdf0e10cSrcweir	elsif ( $language eq "pt-BR" ) { $nsislanguage = "PortugueseBR"; }
1298cdf0e10cSrcweir	elsif ( $language eq "pt" ) { $nsislanguage = "Portuguese"; }
1299cdf0e10cSrcweir	elsif ( $language eq "ro" ) { $nsislanguage = "Romanian"; }
1300cdf0e10cSrcweir	elsif ( $language eq "ru" ) { $nsislanguage = "Russian"; }
1301cdf0e10cSrcweir	elsif ( $language eq "sh" ) { $nsislanguage = "SerbianLatin"; }
1302cdf0e10cSrcweir	elsif ( $language eq "sr" ) { $nsislanguage = "Serbian"; }
1303cdf0e10cSrcweir	elsif ( $language eq "sr-SP" ) { $nsislanguage = "Serbian"; }
1304cdf0e10cSrcweir	elsif ( $language eq "uk" ) { $nsislanguage = "Ukrainian"; }
1305cdf0e10cSrcweir	elsif ( $language eq "tr" ) { $nsislanguage = "Turkish"; }
1306cdf0e10cSrcweir	elsif ( $language eq "ja" ) { $nsislanguage = "Japanese"; }
1307cdf0e10cSrcweir	elsif ( $language eq "ko" ) { $nsislanguage = "Korean"; }
1308cdf0e10cSrcweir	elsif ( $language eq "th" ) { $nsislanguage = "Thai"; }
1309cdf0e10cSrcweir	elsif ( $language eq "vi" ) { $nsislanguage = "Vietnamese"; }
1310cdf0e10cSrcweir	elsif ( $language eq "zh-CN" ) { $nsislanguage = "SimpChinese"; }
1311cdf0e10cSrcweir	elsif ( $language eq "zh-TW" ) { $nsislanguage = "TradChinese"; }
1312cdf0e10cSrcweir	else {
1313cdf0e10cSrcweir		my $infoline = "NSIS language_converter : Could not find nsis language for $language!\n";
1314cdf0e10cSrcweir		push( @installer::globals::logfileinfo, $infoline);
1315cdf0e10cSrcweir		$nsislanguage = "English";
1316cdf0e10cSrcweir		# installer::exiter::exit_program("ERROR: Could not find nsis language for $language!", "nsis_language_converter");
1317cdf0e10cSrcweir	}
1318cdf0e10cSrcweir
1319cdf0e10cSrcweir	return $nsislanguage;
1320cdf0e10cSrcweir}
1321cdf0e10cSrcweir
1322cdf0e10cSrcweir##################################################################
1323cdf0e10cSrcweir# Windows: Including list of all languages into nsi template
1324cdf0e10cSrcweir##################################################################
1325cdf0e10cSrcweir
1326cdf0e10cSrcweirsub put_language_list_into_template
1327cdf0e10cSrcweir{
1328cdf0e10cSrcweir	my ($templatefile, $languagesarrayref) = @_;
1329cdf0e10cSrcweir
1330cdf0e10cSrcweir	my $alllangstring = "";
1331cdf0e10cSrcweir	my %nsislangs;
1332cdf0e10cSrcweir
1333cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$languagesarrayref}; $i++ )
1334cdf0e10cSrcweir	{
1335cdf0e10cSrcweir		my $onelanguage = ${$languagesarrayref}[$i];
1336cdf0e10cSrcweir		my $nsislanguage = nsis_language_converter($onelanguage);
1337cdf0e10cSrcweir		$nsislangs{$nsislanguage}++;
1338cdf0e10cSrcweir	}
1339cdf0e10cSrcweir
1340cdf0e10cSrcweir	foreach my $nsislanguage ( keys(%nsislangs) )
1341cdf0e10cSrcweir	{
1342cdf0e10cSrcweir		# Syntax: !insertmacro MUI_LANGUAGE "English"
1343cdf0e10cSrcweir		my $langstring = "\!insertmacro MUI_LANGUAGE_PACK " . $nsislanguage . "\n";
1344cdf0e10cSrcweir		if ( $nsislanguage eq "English" )
1345cdf0e10cSrcweir		{
1346cdf0e10cSrcweir			$alllangstring = $langstring . $alllangstring;
1347cdf0e10cSrcweir		}
1348cdf0e10cSrcweir		else
1349cdf0e10cSrcweir		{
1350cdf0e10cSrcweir			$alllangstring = $alllangstring . $langstring;
1351cdf0e10cSrcweir		}
1352cdf0e10cSrcweir	}
1353cdf0e10cSrcweir
1354cdf0e10cSrcweir	$alllangstring =~ s/\s*$//;
1355cdf0e10cSrcweir
1356cdf0e10cSrcweir	replace_one_variable($templatefile, "ALLLANGUAGESPLACEHOLDER", $alllangstring);
1357cdf0e10cSrcweir}
1358cdf0e10cSrcweir
1359cdf0e10cSrcweir##################################################################
1360cdf0e10cSrcweir# Windows: Collecting all identifier from mlf file
1361cdf0e10cSrcweir##################################################################
1362cdf0e10cSrcweir
1363cdf0e10cSrcweirsub get_identifier
1364cdf0e10cSrcweir{
1365cdf0e10cSrcweir	my ( $mlffile ) = @_;
1366cdf0e10cSrcweir
1367cdf0e10cSrcweir	my @identifier = ();
1368cdf0e10cSrcweir
1369cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$mlffile}; $i++ )
1370cdf0e10cSrcweir	{
1371cdf0e10cSrcweir		my $oneline = ${$mlffile}[$i];
1372cdf0e10cSrcweir
1373cdf0e10cSrcweir		if ( $oneline =~ /^\s*\[(.+)\]\s*$/ )
1374cdf0e10cSrcweir		{
1375cdf0e10cSrcweir			my $identifier = $1;
1376cdf0e10cSrcweir			push(@identifier, $identifier);
1377cdf0e10cSrcweir		}
1378cdf0e10cSrcweir	}
1379cdf0e10cSrcweir
1380cdf0e10cSrcweir	return \@identifier;
1381cdf0e10cSrcweir}
1382cdf0e10cSrcweir
1383cdf0e10cSrcweir##############################################################
1384cdf0e10cSrcweir# Returning the complete block in all languages
1385cdf0e10cSrcweir# for a specified string
1386cdf0e10cSrcweir##############################################################
1387cdf0e10cSrcweir
1388cdf0e10cSrcweirsub get_language_block_from_language_file
1389cdf0e10cSrcweir{
1390cdf0e10cSrcweir	my ($searchstring, $languagefile) = @_;
1391cdf0e10cSrcweir
1392cdf0e10cSrcweir	my @language_block = ();
1393cdf0e10cSrcweir
1394cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$languagefile}; $i++ )
1395cdf0e10cSrcweir	{
1396cdf0e10cSrcweir		if ( ${$languagefile}[$i] =~ /^\s*\[\s*$searchstring\s*\]\s*$/ )
1397cdf0e10cSrcweir		{
1398cdf0e10cSrcweir			my $counter = $i;
1399cdf0e10cSrcweir
1400cdf0e10cSrcweir			push(@language_block, ${$languagefile}[$counter]);
1401cdf0e10cSrcweir			$counter++;
1402cdf0e10cSrcweir
1403cdf0e10cSrcweir			while (( $counter <= $#{$languagefile} ) && (!( ${$languagefile}[$counter] =~ /^\s*\[/ )))
1404cdf0e10cSrcweir			{
1405cdf0e10cSrcweir				push(@language_block, ${$languagefile}[$counter]);
1406cdf0e10cSrcweir				$counter++;
1407cdf0e10cSrcweir			}
1408cdf0e10cSrcweir
1409cdf0e10cSrcweir			last;
1410cdf0e10cSrcweir		}
1411cdf0e10cSrcweir	}
1412cdf0e10cSrcweir
1413cdf0e10cSrcweir	return \@language_block;
1414cdf0e10cSrcweir}
1415cdf0e10cSrcweir
1416cdf0e10cSrcweir##############################################################
1417cdf0e10cSrcweir# Returning a specific language string from the block
1418cdf0e10cSrcweir# of all translations
1419cdf0e10cSrcweir##############################################################
1420cdf0e10cSrcweir
1421cdf0e10cSrcweirsub get_language_string_from_language_block
1422cdf0e10cSrcweir{
1423cdf0e10cSrcweir	my ($language_block, $language) = @_;
1424cdf0e10cSrcweir
1425cdf0e10cSrcweir	my $newstring = "";
1426cdf0e10cSrcweir
1427cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$language_block}; $i++ )
1428cdf0e10cSrcweir	{
1429cdf0e10cSrcweir		if ( ${$language_block}[$i] =~ /^\s*$language\s*\=\s*\"(.*)\"\s*$/ )
1430cdf0e10cSrcweir		{
1431cdf0e10cSrcweir			$newstring = $1;
1432cdf0e10cSrcweir			last;
1433cdf0e10cSrcweir		}
1434cdf0e10cSrcweir	}
1435cdf0e10cSrcweir
1436cdf0e10cSrcweir	if ( $newstring eq "" )
1437cdf0e10cSrcweir	{
1438cdf0e10cSrcweir		$language = "en-US"; 	# defaulting to english
1439cdf0e10cSrcweir
1440cdf0e10cSrcweir		for ( my $i = 0; $i <= $#{$language_block}; $i++ )
1441cdf0e10cSrcweir		{
1442cdf0e10cSrcweir			if ( ${$language_block}[$i] =~ /^\s*$language\s*\=\s*\"(.*)\"\s*$/ )
1443cdf0e10cSrcweir			{
1444cdf0e10cSrcweir				$newstring = $1;
1445cdf0e10cSrcweir				last;
1446cdf0e10cSrcweir			}
1447cdf0e10cSrcweir		}
1448cdf0e10cSrcweir	}
1449cdf0e10cSrcweir
1450cdf0e10cSrcweir	return $newstring;
1451cdf0e10cSrcweir}
1452cdf0e10cSrcweir
1453cdf0e10cSrcweir##################################################################
1454cdf0e10cSrcweir# Windows: Replacing strings in NSIS nsh file
1455cdf0e10cSrcweir# nsh file syntax:
1456cdf0e10cSrcweir# !define MUI_TEXT_DIRECTORY_TITLE "Zielverzeichnis ausw�hlen"
1457cdf0e10cSrcweir##################################################################
1458cdf0e10cSrcweir
1459cdf0e10cSrcweirsub replace_identifier_in_nshfile
1460cdf0e10cSrcweir{
1461cdf0e10cSrcweir	my ( $nshfile, $identifier, $newstring, $nshfilename, $onelanguage ) = @_;
1462cdf0e10cSrcweir
1463cdf0e10cSrcweir	if ( $installer::globals::nsis231 )
1464cdf0e10cSrcweir	{
1465cdf0e10cSrcweir		$newstring =~ s/\\r/\$\\r/g;	# \r -> $\r  in modern nsis versions
1466cdf0e10cSrcweir		$newstring =~ s/\\n/\$\\n/g;	# \n -> $\n  in modern nsis versions
1467cdf0e10cSrcweir	}
1468cdf0e10cSrcweir
1469cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$nshfile}; $i++ )
1470cdf0e10cSrcweir	{
1471cdf0e10cSrcweir		if ( ${$nshfile}[$i] =~ /\s+\Q$identifier\E\s+\"(.+)\"\s*$/ )
1472cdf0e10cSrcweir		{
1473cdf0e10cSrcweir			my $oldstring = $1;
1474cdf0e10cSrcweir			${$nshfile}[$i] =~ s/\Q$oldstring\E/$newstring/;
1475cdf0e10cSrcweir			my $infoline = "NSIS replacement in $nshfilename ($onelanguage): $oldstring \-\> $newstring\n";
1476cdf0e10cSrcweir			push( @installer::globals::logfileinfo, $infoline);
1477cdf0e10cSrcweir		}
1478cdf0e10cSrcweir	}
1479cdf0e10cSrcweir}
1480cdf0e10cSrcweir
1481cdf0e10cSrcweir##################################################################
1482cdf0e10cSrcweir# Windows: Replacing strings in NSIS nlf file
1483cdf0e10cSrcweir# nlf file syntax (2 lines):
1484cdf0e10cSrcweir# # ^DirSubText
1485cdf0e10cSrcweir# Zielverzeichnis
1486cdf0e10cSrcweir##################################################################
1487cdf0e10cSrcweir
1488cdf0e10cSrcweirsub replace_identifier_in_nlffile
1489cdf0e10cSrcweir{
1490cdf0e10cSrcweir	my ( $nlffile, $identifier, $newstring, $nlffilename, $onelanguage ) = @_;
1491cdf0e10cSrcweir
1492cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$nlffile}; $i++ )
1493cdf0e10cSrcweir	{
1494cdf0e10cSrcweir		if ( ${$nlffile}[$i] =~ /^\s*\#\s+\^\s*\Q$identifier\E\s*$/ )
1495cdf0e10cSrcweir		{
1496cdf0e10cSrcweir			my $next = $i+1;
1497cdf0e10cSrcweir			my $oldstring = ${$nlffile}[$next];
1498cdf0e10cSrcweir			${$nlffile}[$next] = $newstring . "\n";
1499cdf0e10cSrcweir			$oldstring =~ s/\s*$//;
1500cdf0e10cSrcweir			my $infoline = "NSIS replacement in $nlffilename ($onelanguage): $oldstring \-\> $newstring\n";
1501cdf0e10cSrcweir			push( @installer::globals::logfileinfo, $infoline);
1502cdf0e10cSrcweir		}
1503cdf0e10cSrcweir	}
1504cdf0e10cSrcweir}
1505cdf0e10cSrcweir
1506cdf0e10cSrcweir##################################################################
1507cdf0e10cSrcweir# Windows: Translating the NSIS nsh and nlf file
1508cdf0e10cSrcweir##################################################################
1509cdf0e10cSrcweir
1510cdf0e10cSrcweirsub translate_nsh_nlf_file
1511cdf0e10cSrcweir{
1512cdf0e10cSrcweir	my ($nshfile, $nlffile, $mlffile, $onelanguage, $nshfilename, $nlffilename, $nsislanguage) = @_;
1513cdf0e10cSrcweir
1514cdf0e10cSrcweir	# Analyzing the mlf file, collecting all Identifier
1515cdf0e10cSrcweir	my $allidentifier = get_identifier($mlffile);
1516cdf0e10cSrcweir
1517cdf0e10cSrcweir	$onelanguage = "en-US" if ( $nsislanguage eq "English" && $onelanguage ne "en-US");
1518cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$allidentifier}; $i++ )
1519cdf0e10cSrcweir	{
1520cdf0e10cSrcweir		my $identifier = ${$allidentifier}[$i];
1521cdf0e10cSrcweir		my $language_block = get_language_block_from_language_file($identifier, $mlffile);
1522cdf0e10cSrcweir		my $newstring = get_language_string_from_language_block($language_block, $onelanguage);
1523cdf0e10cSrcweir
1524cdf0e10cSrcweir		# removing mask
1525cdf0e10cSrcweir		$newstring =~ s/\\\'/\'/g;
1526cdf0e10cSrcweir
1527cdf0e10cSrcweir		replace_identifier_in_nshfile($nshfile, $identifier, $newstring, $nshfilename, $onelanguage);
1528cdf0e10cSrcweir		replace_identifier_in_nlffile($nlffile, $identifier, $newstring, $nlffilename, $onelanguage);
1529cdf0e10cSrcweir	}
1530cdf0e10cSrcweir}
1531cdf0e10cSrcweir
1532cdf0e10cSrcweir##################################################################
1533cdf0e10cSrcweir# Converting utf 16 file to utf 8
1534cdf0e10cSrcweir##################################################################
1535cdf0e10cSrcweir
1536cdf0e10cSrcweirsub convert_utf16_to_utf8
1537cdf0e10cSrcweir{
1538cdf0e10cSrcweir	my ( $filename ) = @_;
1539cdf0e10cSrcweir
1540cdf0e10cSrcweir	my @localfile = ();
1541cdf0e10cSrcweir
1542cdf0e10cSrcweir	my $savfilename = $filename . "_before.utf16";
1543cdf0e10cSrcweir	installer::systemactions::copy_one_file($filename, $savfilename);
1544cdf0e10cSrcweir
1545cdf0e10cSrcweir#	open( IN, "<:utf16", $filename ) || installer::exiter::exit_program("ERROR: Cannot open file $filename for reading", "convert_utf16_to_utf8");
1546cdf0e10cSrcweir#	open( IN, "<:para:crlf:uni", $filename ) || installer::exiter::exit_program("ERROR: Cannot open file $filename for reading", "convert_utf16_to_utf8");
1547cdf0e10cSrcweir	open( IN, "<:encoding(UTF16-LE)", $filename ) || installer::exiter::exit_program("ERROR: Cannot open file $filename for reading", "convert_utf16_to_utf8");
1548cdf0e10cSrcweir	while ( $line = <IN> ) {
1549cdf0e10cSrcweir		push @localfile, $line;
1550cdf0e10cSrcweir	}
1551cdf0e10cSrcweir	close( IN );
1552cdf0e10cSrcweir
1553cdf0e10cSrcweir	if ( open( OUT, ">:utf8", $filename ) )
1554cdf0e10cSrcweir	{
1555cdf0e10cSrcweir		print OUT @localfile;
1556cdf0e10cSrcweir		close(OUT);
1557cdf0e10cSrcweir	}
1558cdf0e10cSrcweir
1559cdf0e10cSrcweir	$savfilename = $filename . "_before.utf8";
1560cdf0e10cSrcweir	installer::systemactions::copy_one_file($filename, $savfilename);
1561cdf0e10cSrcweir}
1562cdf0e10cSrcweir
1563cdf0e10cSrcweir##################################################################
1564cdf0e10cSrcweir# Converting utf 8 file to utf 16
1565cdf0e10cSrcweir##################################################################
1566cdf0e10cSrcweir
1567cdf0e10cSrcweirsub convert_utf8_to_utf16
1568cdf0e10cSrcweir{
1569cdf0e10cSrcweir	my ( $filename ) = @_;
1570cdf0e10cSrcweir
1571cdf0e10cSrcweir	my @localfile = ();
1572cdf0e10cSrcweir
1573cdf0e10cSrcweir	my $savfilename = $filename . "_after.utf8";
1574cdf0e10cSrcweir	installer::systemactions::copy_one_file($filename, $savfilename);
1575cdf0e10cSrcweir
1576cdf0e10cSrcweir	open( IN, "<:utf8", $filename ) || installer::exiter::exit_program("ERROR: Cannot open file $filename for reading", "convert_utf8_to_utf16");
1577cdf0e10cSrcweir	while ( $line = <IN> ) {
1578cdf0e10cSrcweir		push @localfile, $line;
1579cdf0e10cSrcweir	}
1580cdf0e10cSrcweir	close( IN );
1581cdf0e10cSrcweir
1582cdf0e10cSrcweir	if ( open( OUT, ">:raw:encoding(UTF16-LE):crlf:utf8", $filename ) )
1583cdf0e10cSrcweir	{
1584cdf0e10cSrcweir		print OUT @localfile;
1585cdf0e10cSrcweir		close(OUT);
1586cdf0e10cSrcweir	}
1587cdf0e10cSrcweir
1588cdf0e10cSrcweir	$savfilename = $filename . "_after.utf16";
1589cdf0e10cSrcweir	installer::systemactions::copy_one_file($filename, $savfilename);
1590cdf0e10cSrcweir}
1591cdf0e10cSrcweir
1592cdf0e10cSrcweir##################################################################
1593cdf0e10cSrcweir# Converting text string to utf 16
1594cdf0e10cSrcweir##################################################################
1595cdf0e10cSrcweir
1596cdf0e10cSrcweirsub convert_textstring_to_utf16
1597cdf0e10cSrcweir{
1598cdf0e10cSrcweir	my ( $textstring, $localnsisdir, $shortfilename ) = @_;
1599cdf0e10cSrcweir
1600cdf0e10cSrcweir	my $filename = $localnsisdir . $installer::globals::separator . $shortfilename;
1601cdf0e10cSrcweir	my @filecontent = ();
1602cdf0e10cSrcweir	push(@filecontent, $textstring);
1603cdf0e10cSrcweir	installer::files::save_file($filename, \@filecontent);
1604cdf0e10cSrcweir	convert_utf8_to_utf16($filename);
1605cdf0e10cSrcweir	my $newfile = installer::files::read_file($filename);
1606cdf0e10cSrcweir	my $utf16string = "";
1607cdf0e10cSrcweir	if ( ${$newfile}[0] ne "" ) { $utf16string = ${$newfile}[0]; }
1608cdf0e10cSrcweir
1609cdf0e10cSrcweir	return $utf16string;
1610cdf0e10cSrcweir}
1611cdf0e10cSrcweir
1612cdf0e10cSrcweir##################################################################
1613cdf0e10cSrcweir# Windows: Copying NSIS language files to local nsis directory
1614cdf0e10cSrcweir##################################################################
1615cdf0e10cSrcweir
1616cdf0e10cSrcweirsub copy_and_translate_nsis_language_files
1617cdf0e10cSrcweir{
1618cdf0e10cSrcweir	my ($nsispath, $localnsisdir, $languagesarrayref, $allvariables) = @_;
1619cdf0e10cSrcweir
1620cdf0e10cSrcweir	my $nlffilepath = $nsispath . $installer::globals::separator . "Contrib" . $installer::globals::separator . "Language\ files" . $installer::globals::separator;
1621cdf0e10cSrcweir	my $nshfilepath = $nsispath . $installer::globals::separator . "Contrib" . $installer::globals::separator . "Modern\ UI" . $installer::globals::separator . "Language files" . $installer::globals::separator;
1622cdf0e10cSrcweir
1623cdf0e10cSrcweir	my $infoline = "";
1624cdf0e10cSrcweir
1625cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$languagesarrayref}; $i++ )
1626cdf0e10cSrcweir	{
1627cdf0e10cSrcweir		my $onelanguage = ${$languagesarrayref}[$i];
1628cdf0e10cSrcweir		my $nsislanguage = nsis_language_converter($onelanguage);
1629cdf0e10cSrcweir
1630cdf0e10cSrcweir		# Copying the nlf file
1631cdf0e10cSrcweir		my $sourcepath = $nlffilepath . $nsislanguage . "\.nlf";
1632cdf0e10cSrcweir		if ( ! -f $sourcepath ) { installer::exiter::exit_program("ERROR: Could not find nsis file: $sourcepath!", "copy_and_translate_nsis_language_files"); }
1633cdf0e10cSrcweir		my $nlffilename = $localnsisdir . $installer::globals::separator . $nsislanguage . "_pack.nlf";
1634cdf0e10cSrcweir		if ( $^O =~ /cygwin/i ) { $nlffilename =~ s/\//\\/g; }
1635cdf0e10cSrcweir		installer::systemactions::copy_one_file($sourcepath, $nlffilename);
1636cdf0e10cSrcweir
1637cdf0e10cSrcweir		# Copying the nsh file
1638cdf0e10cSrcweir		# In newer nsis versions, the nsh file is located next to the nlf file
1639cdf0e10cSrcweir		$sourcepath = $nshfilepath . $nsislanguage . "\.nsh";
1640cdf0e10cSrcweir		if ( ! -f $sourcepath )
1641cdf0e10cSrcweir		{
1642cdf0e10cSrcweir			# trying to find the nsh file next to the nlf file
1643cdf0e10cSrcweir			$sourcepath = $nlffilepath . $nsislanguage . "\.nsh";
1644cdf0e10cSrcweir			if ( ! -f $sourcepath )
1645cdf0e10cSrcweir			{
1646cdf0e10cSrcweir				installer::exiter::exit_program("ERROR: Could not find nsis file: $sourcepath!", "copy_and_translate_nsis_language_files");
1647cdf0e10cSrcweir			}
1648cdf0e10cSrcweir		}
1649cdf0e10cSrcweir		my $nshfilename = $localnsisdir . $installer::globals::separator . $nsislanguage . "_pack.nsh";
1650cdf0e10cSrcweir		if ( $^O =~ /cygwin/i ) { $nshfilename =~ s/\//\\/g; }
1651cdf0e10cSrcweir		installer::systemactions::copy_one_file($sourcepath, $nshfilename);
1652cdf0e10cSrcweir
1653cdf0e10cSrcweir		# Changing the macro name in nsh file: MUI_LANGUAGEFILE_BEGIN -> MUI_LANGUAGEFILE_PACK_BEGIN
1654cdf0e10cSrcweir		my $nshfile = installer::files::read_file($nshfilename);
1655cdf0e10cSrcweir		set_nsis_version($nshfile);
1656cdf0e10cSrcweir
1657cdf0e10cSrcweir		if ( $installer::globals::unicodensis )
1658cdf0e10cSrcweir		{
1659cdf0e10cSrcweir			$infoline = "This is Unicode NSIS!\n";
1660cdf0e10cSrcweir			push( @installer::globals::logfileinfo, $infoline);
1661cdf0e10cSrcweir			convert_utf16_to_utf8($nshfilename);
1662cdf0e10cSrcweir			convert_utf16_to_utf8($nlffilename);
1663cdf0e10cSrcweir			$nshfile = installer::files::read_file($nshfilename);	# read nsh file again
1664cdf0e10cSrcweir		}
1665cdf0e10cSrcweir
1666cdf0e10cSrcweir		replace_one_variable($nshfile, "MUI_LANGUAGEFILE_BEGIN", "MUI_LANGUAGEFILE_PACK_BEGIN");
1667cdf0e10cSrcweir
1668cdf0e10cSrcweir		# find the ulf file for translation
1669cdf0e10cSrcweir		my $mlffile = get_translation_file($allvariables);
1670cdf0e10cSrcweir
1671cdf0e10cSrcweir		# Translate the files
1672cdf0e10cSrcweir		my $nlffile = installer::files::read_file($nlffilename);
1673cdf0e10cSrcweir		translate_nsh_nlf_file($nshfile, $nlffile, $mlffile, $onelanguage, $nshfilename, $nlffilename, $nsislanguage);
1674cdf0e10cSrcweir
1675cdf0e10cSrcweir		installer::files::save_file($nshfilename, $nshfile);
1676cdf0e10cSrcweir		installer::files::save_file($nlffilename, $nlffile);
1677cdf0e10cSrcweir
1678cdf0e10cSrcweir		if ( $installer::globals::unicodensis )
1679cdf0e10cSrcweir		{
1680cdf0e10cSrcweir			convert_utf8_to_utf16($nshfilename);
1681cdf0e10cSrcweir			convert_utf8_to_utf16($nlffilename);
1682cdf0e10cSrcweir		}
1683cdf0e10cSrcweir	}
1684cdf0e10cSrcweir
1685cdf0e10cSrcweir}
1686cdf0e10cSrcweir
1687cdf0e10cSrcweir##################################################################
1688cdf0e10cSrcweir# Windows: Including the nsis path into the nsi template
1689cdf0e10cSrcweir##################################################################
1690cdf0e10cSrcweir
1691cdf0e10cSrcweirsub put_nsis_path_into_template
1692cdf0e10cSrcweir{
1693cdf0e10cSrcweir	my ($templatefile, $nsisdir) = @_;
1694cdf0e10cSrcweir
1695cdf0e10cSrcweir	replace_one_variable($templatefile, "NSISPATHPLACEHOLDER", $nsisdir);
1696cdf0e10cSrcweir}
1697cdf0e10cSrcweir
1698cdf0e10cSrcweir##################################################################
1699cdf0e10cSrcweir# Windows: Including the output path into the nsi template
1700cdf0e10cSrcweir##################################################################
1701cdf0e10cSrcweir
1702cdf0e10cSrcweirsub put_output_path_into_template
1703cdf0e10cSrcweir{
1704cdf0e10cSrcweir	my ($templatefile, $downloaddir) = @_;
1705cdf0e10cSrcweir
1706cdf0e10cSrcweir	if ( $^O =~ /cygwin/i ) { $downloaddir =~ s/\//\\/g; }
1707cdf0e10cSrcweir
1708cdf0e10cSrcweir	replace_one_variable($templatefile, "OUTPUTDIRPLACEHOLDER", $downloaddir);
1709cdf0e10cSrcweir}
1710cdf0e10cSrcweir
1711cdf0e10cSrcweir##################################################################
1712cdf0e10cSrcweir# Windows: Only allow specific code for nsis 2.0.4 or nsis 2.3.1
1713cdf0e10cSrcweir##################################################################
1714cdf0e10cSrcweir
1715cdf0e10cSrcweirsub put_version_specific_code_into_template
1716cdf0e10cSrcweir{
1717cdf0e10cSrcweir	my ($templatefile) = @_;
1718cdf0e10cSrcweir
1719cdf0e10cSrcweir	my $subst204 = "";
1720cdf0e10cSrcweir	my $subst231 = "";
1721cdf0e10cSrcweir
1722cdf0e10cSrcweir	if ( $installer::globals::nsis204 )
1723cdf0e10cSrcweir	{
1724cdf0e10cSrcweir		$subst231 = ";";
1725cdf0e10cSrcweir	}
1726cdf0e10cSrcweir	else
1727cdf0e10cSrcweir	{
1728cdf0e10cSrcweir		$subst204 = ";";
1729cdf0e10cSrcweir	}
1730cdf0e10cSrcweir
1731cdf0e10cSrcweir	replace_one_variable($templatefile, "\#204\#", $subst204);
1732cdf0e10cSrcweir	replace_one_variable($templatefile, "\#231\#", $subst231);
1733cdf0e10cSrcweir}
1734cdf0e10cSrcweir
1735cdf0e10cSrcweir##################################################################
1736cdf0e10cSrcweir# Windows: Finding the path to the nsis SDK
1737cdf0e10cSrcweir##################################################################
1738cdf0e10cSrcweir
1739cdf0e10cSrcweirsub get_path_to_nsis_sdk
1740cdf0e10cSrcweir{
1741cdf0e10cSrcweir	my $vol;
1742cdf0e10cSrcweir	my $dir;
1743cdf0e10cSrcweir	my $file;
1744cdf0e10cSrcweir	my $nsispath = "";
1745cdf0e10cSrcweir
1746cdf0e10cSrcweir	if ( $ENV{'NSIS_PATH'} ) {
1747cdf0e10cSrcweir		$nsispath = $ENV{'NSIS_PATH'};
1748cdf0e10cSrcweir	} elsif ( $ENV{'SOLARROOT'} ) {
1749cdf0e10cSrcweir		$nsispath = $ENV{'SOLARROOT'} . $installer::globals::separator . "NSIS";
1750cdf0e10cSrcweir	} else {
1751cdf0e10cSrcweir		# do we have nsis already in path ?
1752cdf0e10cSrcweir		@paths = split(/:/, $ENV{'PATH'});
1753cdf0e10cSrcweir		foreach $paths (@paths) {
1754cdf0e10cSrcweir			$paths =~ s/[\/\\]+$//; # remove trailing slashes;
1755cdf0e10cSrcweir			$nsispath = $paths . "/nsis";
1756cdf0e10cSrcweir
1757cdf0e10cSrcweir			if ( -x $nsispath ) {
1758cdf0e10cSrcweir				$nsispath = $paths;
1759cdf0e10cSrcweir				last;
1760cdf0e10cSrcweir			}
1761cdf0e10cSrcweir			else {
1762cdf0e10cSrcweir				$nsispath = "";
1763cdf0e10cSrcweir			}
1764cdf0e10cSrcweir		}
1765cdf0e10cSrcweir	}
1766cdf0e10cSrcweir	if ( $ENV{'NSISSDK_SOURCE'} ) {
1767cdf0e10cSrcweir	    installer::logger::print_warning( "NSISSDK_SOURCE is deprecated. use NSIS_PATH instead.\n" );
1768cdf0e10cSrcweir        $nsispath = $ENV{'NSISSDK_SOURCE'};	# overriding the NSIS SDK with NSISSDK_SOURCE
1769cdf0e10cSrcweir    }
1770cdf0e10cSrcweir
1771cdf0e10cSrcweir#	if( ($^O =~ /cygwin/i) and $nsispath =~ /\\/ ) {
1772cdf0e10cSrcweir#		# We need a POSIX path for W32-4nt-cygwin-perl
1773cdf0e10cSrcweir#		$nsispath =~ s/\\/\\\\/g;
1774cdf0e10cSrcweir#		chomp( $nsispath = qx{cygpath -u "$nsispath"} );
1775cdf0e10cSrcweir#	}
1776cdf0e10cSrcweir
1777cdf0e10cSrcweir	if ( $nsispath eq "" )
1778cdf0e10cSrcweir	{
1779cdf0e10cSrcweir		installer::logger::print_message( "... no Environment variable \"SOLARROOT\", \"NSIS_PATH\" or \"NSISSDK_SOURCE\" found and NSIS not found in path!", "get_path_to_nsis_sdk");
1780cdf0e10cSrcweir	} elsif ( ! -d $nsispath )
1781cdf0e10cSrcweir	{
1782cdf0e10cSrcweir		installer::exiter::exit_program("ERROR: NSIS path $nsispath does not exist!", "get_path_to_nsis_sdk");
1783cdf0e10cSrcweir	}
1784cdf0e10cSrcweir
1785cdf0e10cSrcweir	return $nsispath;
1786cdf0e10cSrcweir}
1787cdf0e10cSrcweir
1788cdf0e10cSrcweir##################################################################
1789cdf0e10cSrcweir# Windows: Executing NSIS to create the installation set
1790cdf0e10cSrcweir##################################################################
1791cdf0e10cSrcweir
1792cdf0e10cSrcweirsub call_nsis
1793cdf0e10cSrcweir{
1794cdf0e10cSrcweir	my ( $nsispath, $nsifile ) = @_;
1795cdf0e10cSrcweir
1796cdf0e10cSrcweir	my $makensisexe = $nsispath . $installer::globals::separator . "makensis.exe";
1797cdf0e10cSrcweir
1798cdf0e10cSrcweir	installer::logger::print_message( "... starting $makensisexe ... \n" );
1799cdf0e10cSrcweir
1800cdf0e10cSrcweir	if( $^O =~ /cygwin/i ) { $nsifile =~ s/\\/\//g;	}
1801cdf0e10cSrcweir
1802cdf0e10cSrcweir	my $systemcall = "$makensisexe $nsifile |";
1803cdf0e10cSrcweir
1804cdf0e10cSrcweir	my $infoline = "Systemcall: $systemcall\n";
1805cdf0e10cSrcweir	push( @installer::globals::logfileinfo, $infoline);
1806cdf0e10cSrcweir
1807cdf0e10cSrcweir	my @nsisoutput = ();
1808cdf0e10cSrcweir
1809cdf0e10cSrcweir	open (NSI, "$systemcall");
1810cdf0e10cSrcweir	while (<NSI>) {push(@nsisoutput, $_); }
1811cdf0e10cSrcweir	close (NSI);
1812cdf0e10cSrcweir
1813cdf0e10cSrcweir	my $returnvalue = $?;	# $? contains the return value of the systemcall
1814cdf0e10cSrcweir
1815cdf0e10cSrcweir	if ($returnvalue)
1816cdf0e10cSrcweir	{
1817cdf0e10cSrcweir		$infoline = "ERROR: $systemcall !\n";
1818cdf0e10cSrcweir		push( @installer::globals::logfileinfo, $infoline);
1819cdf0e10cSrcweir	}
1820cdf0e10cSrcweir	else
1821cdf0e10cSrcweir	{
1822cdf0e10cSrcweir		$infoline = "Success: $systemcall\n";
1823cdf0e10cSrcweir		push( @installer::globals::logfileinfo, $infoline);
1824cdf0e10cSrcweir	}
1825cdf0e10cSrcweir
1826cdf0e10cSrcweir	for ( my $i = 0; $i <= $#nsisoutput; $i++ ) { push( @installer::globals::logfileinfo, "$nsisoutput[$i]"); }
1827cdf0e10cSrcweir
1828cdf0e10cSrcweir}
1829cdf0e10cSrcweir
1830cdf0e10cSrcweir#################################################################################
1831cdf0e10cSrcweir# Replacing one variable in one files
1832cdf0e10cSrcweir#################################################################################
1833cdf0e10cSrcweir
1834cdf0e10cSrcweirsub replace_one_variable_in_translationfile
1835cdf0e10cSrcweir{
1836cdf0e10cSrcweir	my ($translationfile, $variable, $searchstring) = @_;
1837cdf0e10cSrcweir
1838cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$translationfile}; $i++ )
1839cdf0e10cSrcweir	{
1840cdf0e10cSrcweir		${$translationfile}[$i] =~ s/\%$searchstring/$variable/g;
1841cdf0e10cSrcweir	}
1842cdf0e10cSrcweir}
1843cdf0e10cSrcweir
1844cdf0e10cSrcweir#################################################################################
1845cdf0e10cSrcweir# Replacing the variables in the translation file
1846cdf0e10cSrcweir#################################################################################
1847cdf0e10cSrcweir
1848cdf0e10cSrcweirsub replace_variables
1849cdf0e10cSrcweir{
1850cdf0e10cSrcweir	my ($translationfile, $variableshashref) = @_;
1851cdf0e10cSrcweir
1852cdf0e10cSrcweir	foreach $key (keys %{$variableshashref})
1853cdf0e10cSrcweir	{
1854cdf0e10cSrcweir		my $value = $variableshashref->{$key};
1855cdf0e10cSrcweir
1856cdf0e10cSrcweir		# special handling for PRODUCTVERSION, if $allvariables->{'POSTVERSIONEXTENSION'}
1857cdf0e10cSrcweir		if (( $key eq "PRODUCTVERSION" ) && ( $variableshashref->{'POSTVERSIONEXTENSION'} )) { $value = $value . " " . $variableshashref->{'POSTVERSIONEXTENSION'}; }
1858cdf0e10cSrcweir
1859cdf0e10cSrcweir		replace_one_variable_in_translationfile($translationfile, $value, $key);
1860cdf0e10cSrcweir	}
1861cdf0e10cSrcweir}
1862cdf0e10cSrcweir
1863cdf0e10cSrcweir#########################################################
1864cdf0e10cSrcweir# Getting the translation file for the nsis installer
1865cdf0e10cSrcweir#########################################################
1866cdf0e10cSrcweir
1867cdf0e10cSrcweirsub get_translation_file
1868cdf0e10cSrcweir{
1869cdf0e10cSrcweir	my ($allvariableshashref) = @_;
1870cdf0e10cSrcweir	my $translationfilename = $installer::globals::idtlanguagepath . $installer::globals::separator . $installer::globals::nsisfilename;
1871cdf0e10cSrcweir	if ( $installer::globals::unicodensis ) { $translationfilename = $translationfilename . ".uulf"; }
1872cdf0e10cSrcweir	else { $translationfilename = $translationfilename . ".mlf"; }
1873cdf0e10cSrcweir	if ( ! -f $translationfilename ) { installer::exiter::exit_program("ERROR: Could not find language file $translationfilename!", "get_translation_file"); }
1874cdf0e10cSrcweir	my $translationfile = installer::files::read_file($translationfilename);
1875cdf0e10cSrcweir	replace_variables($translationfile, $allvariableshashref);
1876cdf0e10cSrcweir
1877cdf0e10cSrcweir	my $infoline = "Reading translation file: $translationfilename\n";
1878cdf0e10cSrcweir	push( @installer::globals::logfileinfo, $infoline);
1879cdf0e10cSrcweir
1880cdf0e10cSrcweir	return $translationfile;
1881cdf0e10cSrcweir}
1882cdf0e10cSrcweir
1883cdf0e10cSrcweir####################################################
1884cdf0e10cSrcweir# Removing english, if it was added before
1885cdf0e10cSrcweir####################################################
1886cdf0e10cSrcweir
1887cdf0e10cSrcweirsub remove_english_for_nsis_installer
1888cdf0e10cSrcweir{
1889cdf0e10cSrcweir	my ($languagestringref, $languagesarrayref) = @_;
1890cdf0e10cSrcweir
1891cdf0e10cSrcweir	# $$languagestringref =~ s/en-US_//;
1892cdf0e10cSrcweir	# shift(@{$languagesarrayref});
1893cdf0e10cSrcweir
1894cdf0e10cSrcweir	@{$languagesarrayref} = ("en-US");	# only english for NSIS installer!
1895cdf0e10cSrcweir}
1896cdf0e10cSrcweir
1897cdf0e10cSrcweir####################################################
1898cdf0e10cSrcweir# Creating link tree for upload
1899cdf0e10cSrcweir####################################################
1900cdf0e10cSrcweir
1901cdf0e10cSrcweirsub create_link_tree
1902cdf0e10cSrcweir{
1903cdf0e10cSrcweir	my ($sourcedownloadfile, $destfilename, $versionstring) = @_;
1904cdf0e10cSrcweir
1905957116b7SHerbert Dürr	if ( ! $installer::globals::ooouploaddir ) { installer::exiter::exit_program("ERROR: Directory for AOO upload not defined!", "create_link_tree"); }
1906cdf0e10cSrcweir	my $versiondir = $installer::globals::ooouploaddir . $installer::globals::separator . $versionstring;
1907cdf0e10cSrcweir	my $infoline = "Directory for the link: $versiondir\n";
1908cdf0e10cSrcweir	push(@installer::globals::logfileinfo, $infoline);
1909cdf0e10cSrcweir
1910cdf0e10cSrcweir	if ( ! -d $versiondir ) { installer::systemactions::create_directory_structure($versiondir); }
1911cdf0e10cSrcweir
1912cdf0e10cSrcweir	# inside directory $versiondir all links have to be created
1913cdf0e10cSrcweir	my $linkdestination = $versiondir . $installer::globals::separator . $destfilename;
1914cdf0e10cSrcweir
1915cdf0e10cSrcweir	# If there is an older version of this file (link), it has to be removed
1916cdf0e10cSrcweir	if ( -f $linkdestination ) { unlink($linkdestination); }
1917cdf0e10cSrcweir
1918cdf0e10cSrcweir	$infoline = "Creating hard link from $sourcedownloadfile to $linkdestination\n";
1919cdf0e10cSrcweir	push(@installer::globals::logfileinfo, $infoline);
1920cdf0e10cSrcweir	installer::systemactions::hardlink_one_file($sourcedownloadfile, $linkdestination);
1921cdf0e10cSrcweir}
1922cdf0e10cSrcweir
1923cdf0e10cSrcweir#######################################################
1924cdf0e10cSrcweir# Setting supported platform for Sun OpenOffice.org
1925cdf0e10cSrcweir# builds
1926cdf0e10cSrcweir#######################################################
1927cdf0e10cSrcweir
1928cdf0e10cSrcweirsub is_supported_platform
1929cdf0e10cSrcweir{
1930cdf0e10cSrcweir	my $is_supported = 0;
1931cdf0e10cSrcweir
1932cdf0e10cSrcweir	if (( $installer::globals::islinuxrpmbuild ) ||
1933cdf0e10cSrcweir		( $installer::globals::issolarissparcbuild ) ||
1934cdf0e10cSrcweir		( $installer::globals::issolarisx86build ) ||
1935cdf0e10cSrcweir		( $installer::globals::iswindowsbuild ))
1936cdf0e10cSrcweir	{
1937cdf0e10cSrcweir		$is_supported = 1;
1938cdf0e10cSrcweir	}
1939cdf0e10cSrcweir
1940cdf0e10cSrcweir	return $is_supported;
1941cdf0e10cSrcweir}
1942cdf0e10cSrcweir
1943cdf0e10cSrcweir####################################################
1944cdf0e10cSrcweir# Creating download installation sets
1945cdf0e10cSrcweir####################################################
1946cdf0e10cSrcweir
1947cdf0e10cSrcweirsub create_download_sets
1948cdf0e10cSrcweir{
1949cdf0e10cSrcweir	my ($installationdir, $includepatharrayref, $allvariableshashref, $downloadname, $languagestringref, $languagesarrayref) = @_;
1950cdf0e10cSrcweir
1951cdf0e10cSrcweir	my $infoline = "";
1952cdf0e10cSrcweir
1953cdf0e10cSrcweir	my $force = 1; # print this message even in 'quiet' mode
1954cdf0e10cSrcweir	installer::logger::print_message( "\n******************************************\n" );
1955cdf0e10cSrcweir	installer::logger::print_message( "... creating download installation set ...\n", $force );
1956cdf0e10cSrcweir	installer::logger::print_message( "******************************************\n" );
1957cdf0e10cSrcweir
1958cdf0e10cSrcweir	installer::logger::include_header_into_logfile("Creating download installation sets:");
1959cdf0e10cSrcweir
1960cdf0e10cSrcweir	# special handling for installation sets, to which english was added automatically
1961cdf0e10cSrcweir	if ( $installer::globals::added_english ) { remove_english_for_nsis_installer($languagestringref, $languagesarrayref); }
1962cdf0e10cSrcweir
1963cdf0e10cSrcweir	my $firstdir = $installationdir;
1964cdf0e10cSrcweir	installer::pathanalyzer::get_path_from_fullqualifiedname(\$firstdir);
1965cdf0e10cSrcweir
1966cdf0e10cSrcweir	my $lastdir = $installationdir;
1967cdf0e10cSrcweir	installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$lastdir);
1968cdf0e10cSrcweir
1969cdf0e10cSrcweir	if ( $lastdir =~ /\./ ) { $lastdir =~ s/\./_download_inprogress\./ }
1970cdf0e10cSrcweir	else { $lastdir = $lastdir . "_download_inprogress"; }
1971cdf0e10cSrcweir
1972cdf0e10cSrcweir	# removing existing directory "_native_packed_inprogress" and "_native_packed_witherror" and "_native_packed"
1973cdf0e10cSrcweir
1974cdf0e10cSrcweir	my $downloaddir = $firstdir . $lastdir;
1975cdf0e10cSrcweir
1976cdf0e10cSrcweir	if ( -d $downloaddir ) { installer::systemactions::remove_complete_directory($downloaddir); }
1977cdf0e10cSrcweir
1978cdf0e10cSrcweir	my $olddir = $downloaddir;
1979cdf0e10cSrcweir	$olddir =~ s/_inprogress/_witherror/;
1980cdf0e10cSrcweir	if ( -d $olddir ) { installer::systemactions::remove_complete_directory($olddir); }
1981cdf0e10cSrcweir
1982cdf0e10cSrcweir	$olddir = $downloaddir;
1983cdf0e10cSrcweir	$olddir =~ s/_inprogress//;
1984cdf0e10cSrcweir	if ( -d $olddir ) { installer::systemactions::remove_complete_directory($olddir); }
1985cdf0e10cSrcweir
1986cdf0e10cSrcweir	# creating the new directory
1987cdf0e10cSrcweir
1988cdf0e10cSrcweir	installer::systemactions::create_directory($downloaddir);
1989cdf0e10cSrcweir
1990cdf0e10cSrcweir	$installer::globals::saveinstalldir = $downloaddir;
1991cdf0e10cSrcweir
1992cdf0e10cSrcweir	# evaluating the name of the download file
1993cdf0e10cSrcweir
1994*ff3f4ebcSOliver-Rainer Wittmann	if ( $allvariableshashref->{'AOODOWNLOADNAME'} )
1995*ff3f4ebcSOliver-Rainer Wittmann    {
1996*ff3f4ebcSOliver-Rainer Wittmann        $downloadname = set_download_filename($languagestringref, $allvariableshashref);
1997*ff3f4ebcSOliver-Rainer Wittmann    }
1998*ff3f4ebcSOliver-Rainer Wittmann	else
1999*ff3f4ebcSOliver-Rainer Wittmann    {
2000*ff3f4ebcSOliver-Rainer Wittmann        $downloadname = resolve_variables_in_downloadname($allvariableshashref, $downloadname, $languagestringref);
2001*ff3f4ebcSOliver-Rainer Wittmann    }
2002cdf0e10cSrcweir
2003cdf0e10cSrcweir	if ( ! $installer::globals::iswindowsbuild )	# Unix specific part
2004cdf0e10cSrcweir	{
2005cdf0e10cSrcweir
2006cdf0e10cSrcweir		# getting the path of the getuid.so (only required for Solaris and Linux)
2007cdf0e10cSrcweir		my $getuidlibrary = "";
2008cdf0e10cSrcweir		if (( $installer::globals::issolarisbuild ) || ( $installer::globals::islinuxbuild )) {	$getuidlibrary = get_path_for_library($includepatharrayref); }
2009cdf0e10cSrcweir
2010*ff3f4ebcSOliver-Rainer Wittmann		if ( $allvariableshashref->{'AOODOWNLOADNAME'} )
2011cdf0e10cSrcweir		{
2012cdf0e10cSrcweir			my $downloadfile = create_tar_gz_file_from_directory($installationdir, $getuidlibrary, $downloaddir, $downloadname);
2013cdf0e10cSrcweir		}
2014cdf0e10cSrcweir		else
2015cdf0e10cSrcweir		{
2016cdf0e10cSrcweir			# find and read setup script template
2017cdf0e10cSrcweir			my $scriptfilename = "downloadscript.sh";
2018cdf0e10cSrcweir
2019cdf0e10cSrcweir			my $scriptref = "";
2020cdf0e10cSrcweir
2021cdf0e10cSrcweir			if ( $installer::globals::include_pathes_read )
2022cdf0e10cSrcweir			{
2023cdf0e10cSrcweir				$scriptref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$scriptfilename, $includepatharrayref, 0);
2024cdf0e10cSrcweir			}
2025cdf0e10cSrcweir			else
2026cdf0e10cSrcweir			{
2027cdf0e10cSrcweir				$scriptref = installer::scriptitems::get_sourcepath_from_filename_and_includepath_classic(\$scriptfilename, $includepatharrayref, 0);
2028cdf0e10cSrcweir			}
2029cdf0e10cSrcweir
2030cdf0e10cSrcweir			if ($$scriptref eq "") { installer::exiter::exit_program("ERROR: Could not find script file $scriptfilename!", "create_download_sets"); }
2031cdf0e10cSrcweir			my $scriptfile = installer::files::read_file($$scriptref);
2032cdf0e10cSrcweir
2033cdf0e10cSrcweir			$infoline = "Found  script file $scriptfilename: $$scriptref \n";
2034cdf0e10cSrcweir			push( @installer::globals::logfileinfo, $infoline);
2035cdf0e10cSrcweir
2036cdf0e10cSrcweir			# add product name into script template
2037cdf0e10cSrcweir			put_productname_into_script($scriptfile, $allvariableshashref);
2038cdf0e10cSrcweir
2039cdf0e10cSrcweir			# replace linenumber in script template
2040cdf0e10cSrcweir			put_linenumber_into_script($scriptfile);
2041cdf0e10cSrcweir
2042cdf0e10cSrcweir			# create tar file
2043cdf0e10cSrcweir			my $temporary_tarfile_name = $downloaddir . $installer::globals::separator . 'installset.tar';
2044cdf0e10cSrcweir			my $size = tar_package($installationdir, $temporary_tarfile_name, $getuidlibrary);
2045cdf0e10cSrcweir			installer::exiter::exit_program("ERROR: Could not create tar file $temporary_tarfile_name!", "create_download_sets") unless $size;
2046cdf0e10cSrcweir
2047cdf0e10cSrcweir			# calling sum to determine checksum and size of the tar file
2048cdf0e10cSrcweir			my $sumout = call_sum($temporary_tarfile_name);
2049cdf0e10cSrcweir
2050cdf0e10cSrcweir			# writing checksum and size into scriptfile
2051cdf0e10cSrcweir			put_checksum_and_size_into_script($scriptfile, $sumout);
2052cdf0e10cSrcweir
2053cdf0e10cSrcweir			# saving the script file
2054cdf0e10cSrcweir			my $newscriptfilename = determine_scriptfile_name($downloadname);
2055cdf0e10cSrcweir			$newscriptfilename = save_script_file($downloaddir, $newscriptfilename, $scriptfile);
2056cdf0e10cSrcweir
2057cdf0e10cSrcweir			installer::logger::print_message( "... including installation set into $newscriptfilename ... \n" );
2058cdf0e10cSrcweir            # Append tar file to script
2059cdf0e10cSrcweir			include_tar_into_script($newscriptfilename, $temporary_tarfile_name);
2060cdf0e10cSrcweir		}
2061cdf0e10cSrcweir	}
2062cdf0e10cSrcweir	else	# Windows specific part
2063cdf0e10cSrcweir	{
2064cdf0e10cSrcweir		my $localnsisdir = installer::systemactions::create_directories("nsis", $languagestringref);
2065cdf0e10cSrcweir		# push(@installer::globals::removedirs, $localnsisdir);
2066cdf0e10cSrcweir
2067cdf0e10cSrcweir		# find nsis in the system
2068cdf0e10cSrcweir		my $nsispath = get_path_to_nsis_sdk();
2069cdf0e10cSrcweir
2070cdf0e10cSrcweir		if ( $nsispath eq "" ) {
2071cdf0e10cSrcweir			# If nsis is not found just skip the rest of this function
2072cdf0e10cSrcweir			# and do not create the NSIS file.
2073cdf0e10cSrcweir			$infoline = "\nNo NSIS SDK found. Skipping the generation of NSIS file.\n";
2074cdf0e10cSrcweir			push(@installer::globals::logfileinfo, $infoline);
2075cdf0e10cSrcweir			installer::logger::print_message( "... no NSIS SDK found. Skipping the generation of NSIS file ... \n" );
2076cdf0e10cSrcweir			return $downloaddir;
2077cdf0e10cSrcweir		}
2078cdf0e10cSrcweir
2079cdf0e10cSrcweir		# copy language files into nsis directory and translate them
2080cdf0e10cSrcweir		copy_and_translate_nsis_language_files($nsispath, $localnsisdir, $languagesarrayref, $allvariableshashref);
2081cdf0e10cSrcweir
2082cdf0e10cSrcweir		# find and read the nsi file template
2083cdf0e10cSrcweir		my $templatefilename = "downloadtemplate.nsi";
2084cdf0e10cSrcweir
2085cdf0e10cSrcweir		my $templateref = "";
2086cdf0e10cSrcweir
2087cdf0e10cSrcweir		if ( $installer::globals::include_pathes_read )
2088cdf0e10cSrcweir		{
2089cdf0e10cSrcweir			$templateref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$templatefilename, $includepatharrayref, 0);
2090cdf0e10cSrcweir		}
2091cdf0e10cSrcweir		else
2092cdf0e10cSrcweir		{
2093cdf0e10cSrcweir			$templateref = installer::scriptitems::get_sourcepath_from_filename_and_includepath_classic(\$templatefilename, $includepatharrayref, 0);
2094cdf0e10cSrcweir		}
2095cdf0e10cSrcweir
2096cdf0e10cSrcweir		if ($$templateref eq "") { installer::exiter::exit_program("ERROR: Could not find nsi template file $templatefilename!", "create_download_sets"); }
2097cdf0e10cSrcweir		my $templatefile = installer::files::read_file($$templateref);
2098cdf0e10cSrcweir
2099cdf0e10cSrcweir		# add product name into script template
2100cdf0e10cSrcweir		put_windows_productname_into_template($templatefile, $allvariableshashref);
2101cdf0e10cSrcweir		put_banner_bmp_into_template($templatefile, $includepatharrayref, $allvariableshashref);
2102cdf0e10cSrcweir		put_welcome_bmp_into_template($templatefile, $includepatharrayref, $allvariableshashref);
2103cdf0e10cSrcweir		put_setup_ico_into_template($templatefile, $includepatharrayref, $allvariableshashref);
2104cdf0e10cSrcweir		put_publisher_into_template($templatefile);
2105cdf0e10cSrcweir		put_website_into_template($templatefile);
2106cdf0e10cSrcweir		put_javafilename_into_template($templatefile, $allvariableshashref);
2107cdf0e10cSrcweir		put_windows_productversion_into_template($templatefile, $allvariableshashref);
2108cdf0e10cSrcweir		put_windows_productpath_into_template($templatefile, $allvariableshashref, $languagestringref, $localnsisdir);
2109cdf0e10cSrcweir		put_outputfilename_into_template($templatefile, $downloadname);
2110cdf0e10cSrcweir		put_filelist_into_template($templatefile, $installationdir);
2111cdf0e10cSrcweir		put_language_list_into_template($templatefile, $languagesarrayref);
2112cdf0e10cSrcweir		put_nsis_path_into_template($templatefile, $localnsisdir);
2113cdf0e10cSrcweir		put_output_path_into_template($templatefile, $downloaddir);
2114cdf0e10cSrcweir		put_version_specific_code_into_template($templatefile);
2115cdf0e10cSrcweir
2116cdf0e10cSrcweir		my $nsifilename = save_script_file($localnsisdir, $templatefilename, $templatefile);
2117cdf0e10cSrcweir
2118cdf0e10cSrcweir		installer::logger::print_message( "... created NSIS file $nsifilename ... \n" );
2119cdf0e10cSrcweir
2120cdf0e10cSrcweir		# starting the NSIS SDK to create the download file
2121cdf0e10cSrcweir		call_nsis($nsispath, $nsifilename);
2122cdf0e10cSrcweir	}
2123cdf0e10cSrcweir
2124cdf0e10cSrcweir	return $downloaddir;
2125cdf0e10cSrcweir}
2126cdf0e10cSrcweir
2127cdf0e10cSrcweir####################################################
2128957116b7SHerbert Dürr# Creating AOO upload tree
2129cdf0e10cSrcweir####################################################
2130cdf0e10cSrcweir
2131cdf0e10cSrcweirsub create_download_link_tree
2132cdf0e10cSrcweir{
2133cdf0e10cSrcweir	my ($downloaddir, $languagestringref, $allvariableshashref) = @_;
2134cdf0e10cSrcweir
2135cdf0e10cSrcweir	my $infoline;
2136cdf0e10cSrcweir
2137cdf0e10cSrcweir	installer::logger::print_message( "\n******************************************\n" );
2138cdf0e10cSrcweir	installer::logger::print_message( "... creating download hard link ...\n" );
2139cdf0e10cSrcweir	installer::logger::print_message( "******************************************\n" );
2140cdf0e10cSrcweir
2141cdf0e10cSrcweir	installer::logger::include_header_into_logfile("Creating download hard link:");
2142cdf0e10cSrcweir	installer::logger::include_timestamp_into_logfile("\nPerformance Info: Creating hard link, start");
2143cdf0e10cSrcweir
2144cdf0e10cSrcweir	if ( is_supported_platform() )
2145cdf0e10cSrcweir	{
2146cdf0e10cSrcweir		my $versionstring = "";
2147cdf0e10cSrcweir		# Already defined $installer::globals::oooversionstring and $installer::globals::ooodownloadfilename ?
2148cdf0e10cSrcweir
2149cdf0e10cSrcweir		if ( ! $installer::globals::oooversionstring ) { $versionstring = get_current_version(); }
2150cdf0e10cSrcweir		else { $versionstring = $installer::globals::oooversionstring; }
2151cdf0e10cSrcweir
2152cdf0e10cSrcweir		# Is $versionstring empty? If yes, there is nothing to do now.
2153cdf0e10cSrcweir
2154cdf0e10cSrcweir		$infoline = "Version string is set to: $versionstring\n";
2155cdf0e10cSrcweir		push( @installer::globals::logfileinfo, $infoline);
2156cdf0e10cSrcweir
2157cdf0e10cSrcweir		if ( $versionstring )
2158cdf0e10cSrcweir		{
2159cdf0e10cSrcweir			# Now the downloadfilename has to be set (if not already done)
2160cdf0e10cSrcweir			my $destdownloadfilename = "";
2161cdf0e10cSrcweir			if ( ! $installer::globals::ooodownloadfilename ) { $destdownloadfilename = set_download_filename($languagestringref, $versionstring, $allvariableshashref); }
2162cdf0e10cSrcweir			else { $destdownloadfilename = $installer::globals::ooodownloadfilename; }
2163cdf0e10cSrcweir
2164cdf0e10cSrcweir			if ( $destdownloadfilename )
2165cdf0e10cSrcweir			{
2166cdf0e10cSrcweir				$destdownloadfilename = $destdownloadfilename . $installer::globals::downloadfileextension;
2167cdf0e10cSrcweir
2168cdf0e10cSrcweir				$infoline = "Setting destination download file name: $destdownloadfilename\n";
2169cdf0e10cSrcweir				push( @installer::globals::logfileinfo, $infoline);
2170cdf0e10cSrcweir
2171cdf0e10cSrcweir				my $sourcedownloadfile = $downloaddir . $installer::globals::separator . $installer::globals::downloadfilename;
2172cdf0e10cSrcweir
2173cdf0e10cSrcweir				$infoline = "Setting source download file name: $sourcedownloadfile\n";
2174cdf0e10cSrcweir				push( @installer::globals::logfileinfo, $infoline);
2175cdf0e10cSrcweir
2176cdf0e10cSrcweir				create_link_tree($sourcedownloadfile, $destdownloadfilename, $versionstring);
2177cdf0e10cSrcweir				# my $md5sumoutput = call_md5sum($downloadfile);
2178cdf0e10cSrcweir				# my $md5sum = get_md5sum($md5sumoutput);
2179cdf0e10cSrcweir
2180cdf0e10cSrcweir			}
2181cdf0e10cSrcweir		}
2182cdf0e10cSrcweir		else
2183cdf0e10cSrcweir		{
2184cdf0e10cSrcweir			$infoline = "Version string is empty. Nothing to do!\n";
2185cdf0e10cSrcweir			push( @installer::globals::logfileinfo, $infoline);
2186cdf0e10cSrcweir		}
2187cdf0e10cSrcweir	}
2188cdf0e10cSrcweir	else
2189cdf0e10cSrcweir	{
2190cdf0e10cSrcweir		$infoline = "Platform not used for hard linking. Nothing to do!\n";
2191cdf0e10cSrcweir		push( @installer::globals::logfileinfo, $infoline);
2192cdf0e10cSrcweir	}
2193cdf0e10cSrcweir
2194cdf0e10cSrcweir	installer::logger::include_timestamp_into_logfile("Performance Info: Creating hard link, stop");
2195cdf0e10cSrcweir}
2196cdf0e10cSrcweir
2197cdf0e10cSrcweir1;
2198