19780544fSAndrew Rist#**************************************************************
2fe0288c8SMatthias Seidel#
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
10fe0288c8SMatthias Seidel#
119780544fSAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
12fe0288c8SMatthias Seidel#
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.
19fe0288c8SMatthias Seidel#
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
350b2dfbacSAndre Fischeruse strict;
360b2dfbacSAndre Fischer
371dba2a1aSmseidelBEGIN { # This is needed so that Cygwin's perl evaluates ACLs
38cdf0e10cSrcweir	# (needed for correctly evaluating the -x test.)
39cdf0e10cSrcweir	if( $^O =~ /cygwin/i ) {
40cdf0e10cSrcweir		require filetest; import filetest "access";
41cdf0e10cSrcweir	}
42cdf0e10cSrcweir}
43cdf0e10cSrcweir
44cdf0e10cSrcweir##################################################################
45c974372aSMatthias Seidel# Including the lowercase product name into the script template
46cdf0e10cSrcweir##################################################################
47cdf0e10cSrcweir
48cdf0e10cSrcweirsub put_productname_into_script
49cdf0e10cSrcweir{
50cdf0e10cSrcweir	my ($scriptfile, $variableshashref) = @_;
511dba2a1aSmseidel
52cdf0e10cSrcweir	my $productname = $variableshashref->{'PRODUCTNAME'};
53cdf0e10cSrcweir	$productname = lc($productname);
54cdf0e10cSrcweir	$productname =~ s/\.//g;	# openoffice.org -> openofficeorg
55cdf0e10cSrcweir	$productname =~ s/\s*//g;
56b274bc22SAndre Fischer
57fe0288c8SMatthias Seidel	$installer::logger::Lang->printf("Adding productname %s into download shell script\n", $productname);
58cdf0e10cSrcweir
59cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
60cdf0e10cSrcweir	{
61cdf0e10cSrcweir		${$scriptfile}[$i] =~ s/PRODUCTNAMEPLACEHOLDER/$productname/;
62cdf0e10cSrcweir	}
63cdf0e10cSrcweir}
64cdf0e10cSrcweir
65cdf0e10cSrcweir#########################################################
66c974372aSMatthias Seidel# Including the linenumber into the script template
67cdf0e10cSrcweir#########################################################
68cdf0e10cSrcweir
69cdf0e10cSrcweirsub put_linenumber_into_script
70cdf0e10cSrcweir{
71cdf0e10cSrcweir	my ( $scriptfile ) = @_;
721dba2a1aSmseidel
73fe0288c8SMatthias Seidel	my $linenumber = $#{$scriptfile} + 2;
74cdf0e10cSrcweir
75fe0288c8SMatthias Seidel	$installer::logger::Lang->printf("Adding linenumber %d into download shell script\n", $linenumber);
76cdf0e10cSrcweir
77cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
78cdf0e10cSrcweir	{
79cdf0e10cSrcweir		${$scriptfile}[$i] =~ s/LINENUMBERPLACEHOLDER/$linenumber/;
801dba2a1aSmseidel	}
81cdf0e10cSrcweir}
82cdf0e10cSrcweir
83cdf0e10cSrcweir#########################################################
84c974372aSMatthias Seidel# 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
95fe0288c8SMatthias Seidel	$installer::logger::Lang->printf("Setting download shell script file name to %s\n", $filename);
96cdf0e10cSrcweir
97cdf0e10cSrcweir	return $filename;
98cdf0e10cSrcweir}
99cdf0e10cSrcweir
100cdf0e10cSrcweir#########################################################
101c974372aSMatthias Seidel# Saving the script file in the installation directory
102cdf0e10cSrcweir#########################################################
103cdf0e10cSrcweir
104cdf0e10cSrcweirsub save_script_file
105cdf0e10cSrcweir{
106cdf0e10cSrcweir	my ($directory, $newscriptfilename, $scriptfile) = @_;
1071dba2a1aSmseidel
108cdf0e10cSrcweir	$newscriptfilename = $directory . $installer::globals::separator . $newscriptfilename;
109cdf0e10cSrcweir	installer::files::save_file($newscriptfilename, $scriptfile);
110b274bc22SAndre Fischer
111fe0288c8SMatthias Seidel	$installer::logger::Lang->printf("Saving script file %s\n", $newscriptfilename);
112cdf0e10cSrcweir
113cdf0e10cSrcweir	if ( ! $installer::globals::iswindowsbuild )
114cdf0e10cSrcweir	{
115cdf0e10cSrcweir		my $localcall = "chmod 775 $newscriptfilename \>\/dev\/null 2\>\&1";
116cdf0e10cSrcweir		system($localcall);
117cdf0e10cSrcweir	}
1181dba2a1aSmseidel
119cdf0e10cSrcweir	return $newscriptfilename;
120cdf0e10cSrcweir}
121cdf0e10cSrcweir
122cdf0e10cSrcweir#########################################################
123c974372aSMatthias Seidel# Including checksum and size into script file
124cdf0e10cSrcweir#########################################################
125cdf0e10cSrcweir
126cdf0e10cSrcweirsub put_checksum_and_size_into_script
127cdf0e10cSrcweir{
128cdf0e10cSrcweir	my ($scriptfile, $sumout) = @_;
129cdf0e10cSrcweir
130cdf0e10cSrcweir	my $checksum = "";
131cdf0e10cSrcweir	my $size = "";
1321dba2a1aSmseidel
1331dba2a1aSmseidel	if ( $sumout =~ /^\s*(\d+)\s+(\d+)\s*$/ )
134cdf0e10cSrcweir	{
135cdf0e10cSrcweir		$checksum = $1;
1361dba2a1aSmseidel		$size = $2;
137cdf0e10cSrcweir	}
138cdf0e10cSrcweir	else
139cdf0e10cSrcweir	{
140cdf0e10cSrcweir		installer::exiter::exit_program("ERROR: Incorrect return value from /usr/bin/sum: $sumout", "put_checksum_and_size_into_script");
141cdf0e10cSrcweir	}
142cdf0e10cSrcweir
143fe0288c8SMatthias Seidel	$installer::logger::Lang->printf(
144fe0288c8SMatthias Seidel		"Adding checksum %s and size %s into download shell script\n", $checksum, $size);
145cdf0e10cSrcweir
146cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
147cdf0e10cSrcweir	{
148cdf0e10cSrcweir		${$scriptfile}[$i] =~ s/CHECKSUMPLACEHOLDER/$checksum/;
149cdf0e10cSrcweir		${$scriptfile}[$i] =~ s/DISCSPACEPLACEHOLDER/$size/;
150cdf0e10cSrcweir	}
1511dba2a1aSmseidel
152cdf0e10cSrcweir}
153cdf0e10cSrcweir
154cdf0e10cSrcweir#########################################################
155c974372aSMatthias Seidel# Calling md5sum
156cdf0e10cSrcweir#########################################################
157cdf0e10cSrcweir
158cdf0e10cSrcweirsub call_md5sum
159cdf0e10cSrcweir{
160cdf0e10cSrcweir	my ($filename) = @_;
161cdf0e10cSrcweir
1620b2dfbacSAndre Fischer	my $md5sumfile = "/usr/bin/md5sum";
1631dba2a1aSmseidel
164cdf0e10cSrcweir	if ( ! -f $md5sumfile ) { installer::exiter::exit_program("ERROR: No file /usr/bin/md5sum", "call_md5sum"); }
1651dba2a1aSmseidel
166cdf0e10cSrcweir	my $systemcall = "$md5sumfile $filename |";
1671dba2a1aSmseidel
168cdf0e10cSrcweir	my $md5sumoutput = "";
169cdf0e10cSrcweir
170cdf0e10cSrcweir	open (SUM, "$systemcall");
171cdf0e10cSrcweir	$md5sumoutput = <SUM>;
172cdf0e10cSrcweir	close (SUM);
173cdf0e10cSrcweir
174cdf0e10cSrcweir	my $returnvalue = $?;	# $? contains the return value of the systemcall
175cdf0e10cSrcweir
176fe0288c8SMatthias Seidel	$installer::logger::Lang->printf("Systemcall: %s\n", $systemcall);
1771dba2a1aSmseidel
178cdf0e10cSrcweir	if ($returnvalue)
179cdf0e10cSrcweir	{
180fe0288c8SMatthias Seidel		$installer::logger::Lang->printf("ERROR: Could not execute \"%s\"!\n", $systemcall);
181cdf0e10cSrcweir	}
182cdf0e10cSrcweir	else
183cdf0e10cSrcweir	{
184fe0288c8SMatthias Seidel		$installer::logger::Lang->print("Success: Executed \"%s\" successfully!\n", $systemcall);
185cdf0e10cSrcweir	}
1861dba2a1aSmseidel
1871dba2a1aSmseidel	return $md5sumoutput;
188cdf0e10cSrcweir}
189cdf0e10cSrcweir
190cdf0e10cSrcweir#########################################################
191c974372aSMatthias Seidel# Calling md5sum
192cdf0e10cSrcweir#########################################################
193cdf0e10cSrcweir
194cdf0e10cSrcweirsub get_md5sum
195cdf0e10cSrcweir{
1960b2dfbacSAndre Fischer	my ($md5sumoutput) = @_;
1971dba2a1aSmseidel
198cdf0e10cSrcweir	my $md5sum;
1991dba2a1aSmseidel
2001dba2a1aSmseidel	if ( $md5sumoutput =~ /^\s*(\w+?)\s+/ )
201cdf0e10cSrcweir	{
202cdf0e10cSrcweir		$md5sum = $1;
203cdf0e10cSrcweir	}
204cdf0e10cSrcweir	else
205cdf0e10cSrcweir	{
206cdf0e10cSrcweir		installer::exiter::exit_program("ERROR: Incorrect return value from /usr/bin/md5sum: $md5sumoutput", "get_md5sum");
207cdf0e10cSrcweir	}
208cdf0e10cSrcweir
209fe0288c8SMatthias Seidel	$installer::logger::Lang->printf("Setting md5sum: %s\n", $md5sum);
210cdf0e10cSrcweir
211cdf0e10cSrcweir	return $md5sum;
212cdf0e10cSrcweir}
213cdf0e10cSrcweir
214cdf0e10cSrcweir#########################################################
215c974372aSMatthias Seidel# Determining checksum and size of tar file
216cdf0e10cSrcweir#########################################################
217cdf0e10cSrcweir
218cdf0e10cSrcweirsub call_sum
219cdf0e10cSrcweir{
220cdf0e10cSrcweir	my ($filename, $getuidlibrary) = @_;
221cdf0e10cSrcweir
222cdf0e10cSrcweir	my $systemcall = "/usr/bin/sum $filename |";
2231dba2a1aSmseidel
224cdf0e10cSrcweir	my $sumoutput = "";
225cdf0e10cSrcweir
226cdf0e10cSrcweir	open (SUM, "$systemcall");
227cdf0e10cSrcweir	$sumoutput = <SUM>;
228cdf0e10cSrcweir	close (SUM);
229cdf0e10cSrcweir
230cdf0e10cSrcweir	my $returnvalue = $?;	# $? contains the return value of the systemcall
231cdf0e10cSrcweir
232fe0288c8SMatthias Seidel	$installer::logger::Lang->printf("Systemcall: %s\n", $systemcall);
2331dba2a1aSmseidel
234cdf0e10cSrcweir	if ($returnvalue)
235cdf0e10cSrcweir	{
236fe0288c8SMatthias Seidel		$installer::logger::Lang->printf("ERROR: Could not execute \"%s\"!\n", $systemcall);
237cdf0e10cSrcweir	}
238cdf0e10cSrcweir	else
239cdf0e10cSrcweir	{
240fe0288c8SMatthias Seidel		$installer::logger::Lang->printf("Success: Executed \"%s\" successfully!\n", $systemcall);
241cdf0e10cSrcweir	}
2421dba2a1aSmseidel
243cdf0e10cSrcweir	$sumoutput =~ s/\s+$filename\s$//;
2441dba2a1aSmseidel	return $sumoutput;
245cdf0e10cSrcweir}
246cdf0e10cSrcweir
247cdf0e10cSrcweir#########################################################
248c974372aSMatthias Seidel# Searching for the getuid.so in the solver
249cdf0e10cSrcweir#########################################################
250cdf0e10cSrcweir
251cdf0e10cSrcweirsub get_path_for_library
252cdf0e10cSrcweir{
253cdf0e10cSrcweir	my ($includepatharrayref) = @_;
2541dba2a1aSmseidel
255cdf0e10cSrcweir	my $getuidlibraryname = "getuid.so";
256cdf0e10cSrcweir
257cdf0e10cSrcweir	my $getuidlibraryref = "";
258cdf0e10cSrcweir
259cdf0e10cSrcweir	if ( $installer::globals::include_pathes_read )
260cdf0e10cSrcweir	{
261cdf0e10cSrcweir		$getuidlibraryref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$getuidlibraryname, $includepatharrayref, 0);
262cdf0e10cSrcweir	}
263cdf0e10cSrcweir	else
264cdf0e10cSrcweir	{
265cdf0e10cSrcweir		$getuidlibraryref = installer::scriptitems::get_sourcepath_from_filename_and_includepath_classic(\$getuidlibraryname, $includepatharrayref, 0);
266cdf0e10cSrcweir	}
267cdf0e10cSrcweir
268cdf0e10cSrcweir	if ($$getuidlibraryref eq "") { installer::exiter::exit_program("ERROR: Could not find $getuidlibraryname!", "get_path_for_library"); }
2691dba2a1aSmseidel
270cdf0e10cSrcweir	return $$getuidlibraryref;
271cdf0e10cSrcweir}
272cdf0e10cSrcweir
273cdf0e10cSrcweir#########################################################
274c974372aSMatthias Seidel# Include the tar file into the script
275cdf0e10cSrcweir#########################################################
276cdf0e10cSrcweir
277cdf0e10cSrcweirsub include_tar_into_script
278cdf0e10cSrcweir{
279cdf0e10cSrcweir	my ($scriptfile, $temporary_tarfile) = @_;
280cdf0e10cSrcweir
281cdf0e10cSrcweir	my $systemcall = "cat $temporary_tarfile >> $scriptfile && rm $temporary_tarfile";
282cdf0e10cSrcweir	my $returnvalue = system($systemcall);
283cdf0e10cSrcweir
284fe0288c8SMatthias Seidel	$installer::logger::Lang->printf("Systemcall: %s\n", $systemcall);
2851dba2a1aSmseidel
286cdf0e10cSrcweir	if ($returnvalue)
287cdf0e10cSrcweir	{
288fe0288c8SMatthias Seidel		$installer::logger::Lang->printf("ERROR: Could not execute \"%s\"!\n", $systemcall);
289cdf0e10cSrcweir	}
290cdf0e10cSrcweir	else
291cdf0e10cSrcweir	{
292fe0288c8SMatthias Seidel		$installer::logger::Lang->printf("Success: Executed \"%s\" successfully!\n", $systemcall);
293cdf0e10cSrcweir	}
294cdf0e10cSrcweir	return $returnvalue;
295cdf0e10cSrcweir}
296cdf0e10cSrcweir
297cdf0e10cSrcweir#########################################################
298c974372aSMatthias Seidel# Create a tar file from the binary package
299cdf0e10cSrcweir#########################################################
300cdf0e10cSrcweir
301cdf0e10cSrcweirsub tar_package
302cdf0e10cSrcweir{
303cdf0e10cSrcweir	my ( $installdir, $tarfilename, $getuidlibrary) = @_;
304cdf0e10cSrcweir
30560203e34SJim Jagielski	my $ldpreloadstring = $ENV{'FAKEROOT'};
306cdf0e10cSrcweir
307cdf0e10cSrcweir	my $systemcall = "cd $installdir; $ldpreloadstring tar -cf - * > $tarfilename";
3081dba2a1aSmseidel
309cdf0e10cSrcweir	my $returnvalue = system($systemcall);
310cdf0e10cSrcweir
311fe0288c8SMatthias Seidel	$installer::logger::Lang->printf("Systemcall: %s\n", $systemcall);
3121dba2a1aSmseidel
313cdf0e10cSrcweir	if ($returnvalue)
314cdf0e10cSrcweir	{
315fe0288c8SMatthias Seidel		$installer::logger::Lang->printf("ERROR: Could not execute \"%s\"!\n", $systemcall);
316cdf0e10cSrcweir	}
317cdf0e10cSrcweir	else
318cdf0e10cSrcweir	{
319fe0288c8SMatthias Seidel		$installer::logger::Lang->printf("Success: Executed \"\" successfully!\n", $systemcall);
320cdf0e10cSrcweir	}
3211dba2a1aSmseidel
322cdf0e10cSrcweir	my $localcall = "chmod 775 $tarfilename \>\/dev\/null 2\>\&1";
323cdf0e10cSrcweir	$returnvalue = system($localcall);
324cdf0e10cSrcweir
325cdf0e10cSrcweir	return ( -s $tarfilename );
326cdf0e10cSrcweir}
327cdf0e10cSrcweir
328cdf0e10cSrcweir#########################################################
329cdf0e10cSrcweir# Creating a tar.gz file
330cdf0e10cSrcweir#########################################################
331cdf0e10cSrcweir
332cdf0e10cSrcweirsub create_tar_gz_file_from_package
333cdf0e10cSrcweir{
334cdf0e10cSrcweir	my ($installdir, $getuidlibrary) = @_;
335cdf0e10cSrcweir
336cdf0e10cSrcweir	my $alldirs = installer::systemactions::get_all_directories($installdir);
337cdf0e10cSrcweir	my $onedir = ${$alldirs}[0];
338cdf0e10cSrcweir	$installdir = $onedir;
339cdf0e10cSrcweir
340cdf0e10cSrcweir	my $allfiles = installer::systemactions::get_all_files_from_one_directory($installdir);
341cdf0e10cSrcweir
342cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$allfiles}; $i++ )
343cdf0e10cSrcweir	{
344cdf0e10cSrcweir		my $onefile = ${$allfiles}[$i];
345cdf0e10cSrcweir		my $systemcall = "cd $installdir; rm $onefile";
346cdf0e10cSrcweir		my $returnvalue = system($systemcall);
347cdf0e10cSrcweir
348fe0288c8SMatthias Seidel		$installer::logger::Lang->printf("Systemcall: %s\n", $systemcall);
3491dba2a1aSmseidel
350cdf0e10cSrcweir		if ($returnvalue)
351cdf0e10cSrcweir		{
352fe0288c8SMatthias Seidel			$installer::logger::Lang->printf("ERROR: Could not execute \"%s\"!\n", $systemcall);
353cdf0e10cSrcweir		}
354cdf0e10cSrcweir		else
355cdf0e10cSrcweir		{
356fe0288c8SMatthias Seidel			$installer::logger::Lang->printf("Success: Executed \"%s\" successfully!\n", $systemcall);
357cdf0e10cSrcweir		}
358cdf0e10cSrcweir	}
359cdf0e10cSrcweir
360cdf0e10cSrcweir	$alldirs = installer::systemactions::get_all_directories($installdir);
3611dba2a1aSmseidel	my $packagename = ${$alldirs}[0]; # only taking the first Solaris package
362fe0288c8SMatthias Seidel	if ( $packagename eq "" ) { installer::exiter::exit_program("ERROR: Could not find package in directory $installdir!", "determine_packagename"); }
363cdf0e10cSrcweir
364cdf0e10cSrcweir	installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$packagename);
3651dba2a1aSmseidel
366cdf0e10cSrcweir	$installer::globals::downloadfileextension = ".tar.gz";
367cdf0e10cSrcweir	my $targzname = $packagename . $installer::globals::downloadfileextension;
368cdf0e10cSrcweir	$installer::globals::downloadfilename = $targzname;
369914ff780SJim Jagielski
37060203e34SJim Jagielski	my $ldpreloadstring = $ENV{'FAKEROOT'};
371cdf0e10cSrcweir
3720b2dfbacSAndre Fischer	my $systemcall = "cd $installdir; $ldpreloadstring tar -cf - $packagename | gzip > $targzname";
373fe0288c8SMatthias Seidel	$installer::logger::Info->printf("... %s ...\n", $systemcall);
374cdf0e10cSrcweir
375cdf0e10cSrcweir	my $returnvalue = system($systemcall);
376cdf0e10cSrcweir
377fe0288c8SMatthias Seidel	$installer::logger::Lang->printf("Systemcall: %s\n", $systemcall);
3781dba2a1aSmseidel
379cdf0e10cSrcweir	if ($returnvalue)
380cdf0e10cSrcweir	{
381fe0288c8SMatthias Seidel		$installer::logger::Lang->printf("ERROR: Could not execute \"%s\"!\n", $systemcall);
382cdf0e10cSrcweir	}
383cdf0e10cSrcweir	else
384cdf0e10cSrcweir	{
385fe0288c8SMatthias Seidel		$installer::logger::Lang->printf("Success: Executed \"%s\" successfully!\n", $systemcall);
386cdf0e10cSrcweir	}
387cdf0e10cSrcweir}
388cdf0e10cSrcweir
389cdf0e10cSrcweir#########################################################
390cdf0e10cSrcweir# Setting type of installation
391cdf0e10cSrcweir#########################################################
392cdf0e10cSrcweir
393cdf0e10cSrcweirsub get_installation_type
394cdf0e10cSrcweir{
395cdf0e10cSrcweir	my $type = "";
3961dba2a1aSmseidel
397cdf0e10cSrcweir	if ( $installer::globals::languagepack ) { $type = "langpack"; }
398cdf0e10cSrcweir	else { $type = "install"; }
3991dba2a1aSmseidel
400cdf0e10cSrcweir	return $type;
401cdf0e10cSrcweir}
402cdf0e10cSrcweir
403cdf0e10cSrcweir#########################################################
404cdf0e10cSrcweir# Setting installation languages
405cdf0e10cSrcweir#########################################################
406cdf0e10cSrcweir
407cdf0e10cSrcweirsub get_downloadname_language
408cdf0e10cSrcweir{
409cdf0e10cSrcweir	my ($languagestringref) = @_;
410cdf0e10cSrcweir
411cdf0e10cSrcweir	my $languages = $$languagestringref;
412cdf0e10cSrcweir
413cdf0e10cSrcweir	if ( $installer::globals::added_english )
414cdf0e10cSrcweir	{
415cdf0e10cSrcweir		$languages =~ s/en-US_//;
416cdf0e10cSrcweir		$languages =~ s/_en-US//;
417cdf0e10cSrcweir	}
418cdf0e10cSrcweir
419cdf0e10cSrcweir	# en-US is default language and can be removed therefore
420cdf0e10cSrcweir	# for one-language installation sets
4211dba2a1aSmseidel
422cdf0e10cSrcweir	# if ( $languages =~ /^\s*en-US\s*$/ )
423cdf0e10cSrcweir	# {
424cdf0e10cSrcweir	#	$languages = "";
4251dba2a1aSmseidel	# }
426cdf0e10cSrcweir
427cdf0e10cSrcweir	if ( length ($languages) > $installer::globals::max_lang_length )
428cdf0e10cSrcweir	{
429cdf0e10cSrcweir		$languages = 'multi';
430cdf0e10cSrcweir	}
431cdf0e10cSrcweir
432cdf0e10cSrcweir	return $languages;
433cdf0e10cSrcweir}
434cdf0e10cSrcweir
435cdf0e10cSrcweir#########################################################
436cdf0e10cSrcweir# Setting download name
437cdf0e10cSrcweir#########################################################
438cdf0e10cSrcweir
439cdf0e10cSrcweirsub get_downloadname_productname
440cdf0e10cSrcweir{
441fe0288c8SMatthias Seidel	my ($allvariables) = @_;
442fe0288c8SMatthias Seidel
443fe0288c8SMatthias Seidel	my $start;
444fe0288c8SMatthias Seidel
445fe0288c8SMatthias Seidel	if ( $allvariables->{'AOODOWNLOADNAMEPREFIX'} )
446fe0288c8SMatthias Seidel	{
447fe0288c8SMatthias Seidel		$start = $allvariables->{'AOODOWNLOADNAMEPREFIX'};
448fe0288c8SMatthias Seidel	}
449fe0288c8SMatthias Seidel	else
450fe0288c8SMatthias Seidel	{
451fe0288c8SMatthias Seidel		$start = "Apache_OpenOffice";
452fe0288c8SMatthias Seidel		if ( $allvariables->{'PRODUCTNAME'} eq "OpenOffice" )
453fe0288c8SMatthias Seidel		{
454fe0288c8SMatthias Seidel			if ( $allvariables->{'POSTVERSIONEXTENSION'} eq "SDK" )
455fe0288c8SMatthias Seidel			{
456fe0288c8SMatthias Seidel				$start .= "-SDK";
457fe0288c8SMatthias Seidel			}
458fe0288c8SMatthias Seidel		}
459fe0288c8SMatthias Seidel
460fe0288c8SMatthias Seidel		if ( $allvariables->{'PRODUCTNAME'} eq "OpenOffice Developer Build" )
461fe0288c8SMatthias Seidel		{
462fe0288c8SMatthias Seidel			if ( $allvariables->{'POSTVERSIONEXTENSION'} eq "SDK" )
463fe0288c8SMatthias Seidel			{
464fe0288c8SMatthias Seidel				$start .= "_Dev-SDK";
465fe0288c8SMatthias Seidel			}
466fe0288c8SMatthias Seidel			else
467fe0288c8SMatthias Seidel			{
468fe0288c8SMatthias Seidel				$start .= "_Dev";
469fe0288c8SMatthias Seidel			}
470fe0288c8SMatthias Seidel		}
471fe0288c8SMatthias Seidel
472fe0288c8SMatthias Seidel		if ( $allvariables->{'PRODUCTNAME'} eq "URE" )
473fe0288c8SMatthias Seidel		{
474fe0288c8SMatthias Seidel			$start .= "-URE";
475fe0288c8SMatthias Seidel		}
476fe0288c8SMatthias Seidel	}
477fe0288c8SMatthias Seidel
478fe0288c8SMatthias Seidel	return $start;
479cdf0e10cSrcweir}
480cdf0e10cSrcweir
481cdf0e10cSrcweir#########################################################
482cdf0e10cSrcweir# Setting download version
483cdf0e10cSrcweir#########################################################
484cdf0e10cSrcweir
485cdf0e10cSrcweirsub get_download_version
486cdf0e10cSrcweir{
487cdf0e10cSrcweir	my ($allvariables) = @_;
4881dba2a1aSmseidel
489cdf0e10cSrcweir	my $version = "";
4901dba2a1aSmseidel
491cdf0e10cSrcweir	my $devproduct = 0;
492cdf0e10cSrcweir	if (( $allvariables->{'DEVELOPMENTPRODUCT'} ) && ( $allvariables->{'DEVELOPMENTPRODUCT'} == 1 )) { $devproduct = 1; }
4931dba2a1aSmseidel
494cdf0e10cSrcweir	my $cwsproduct = 0;
495cdf0e10cSrcweir	# the environment variable CWS_WORK_STAMP is set only in CWS
496cdf0e10cSrcweir	if ( $ENV{'CWS_WORK_STAMP'} ) { $cwsproduct = 1; }
497cdf0e10cSrcweir
498fe0288c8SMatthias Seidel	if (( $cwsproduct ) || ( $devproduct )) # use "DEV300m75"
499cdf0e10cSrcweir	{
500cdf0e10cSrcweir		my $source = uc($installer::globals::build); # DEV300
501cdf0e10cSrcweir		my $localminor = "";
502cdf0e10cSrcweir		if ( $installer::globals::minor ne "" ) { $localminor = $installer::globals::minor; }
503cdf0e10cSrcweir		else { $localminor = $installer::globals::lastminor; }
504fe0288c8SMatthias Seidel		$version = $source . $localminor;
505cdf0e10cSrcweir	}
506fe0288c8SMatthias Seidel	else # use 3.2.0rc1
507cdf0e10cSrcweir	{
508cdf0e10cSrcweir		$version = $allvariables->{'PRODUCTVERSION'};
509cdf0e10cSrcweir		if (( $allvariables->{'ABOUTBOXPRODUCTVERSION'} ) && ( $allvariables->{'ABOUTBOXPRODUCTVERSION'} ne "" )) { $version = $allvariables->{'ABOUTBOXPRODUCTVERSION'}; }
5101dba2a1aSmseidel		if (( $allvariables->{'SHORT_PRODUCTEXTENSION'} ) && ( $allvariables->{'SHORT_PRODUCTEXTENSION'} ne "" )) { $version = $version . $allvariables->{'SHORT_PRODUCTEXTENSION'}; }
511cdf0e10cSrcweir	}
5121dba2a1aSmseidel
513cdf0e10cSrcweir	return $version;
514cdf0e10cSrcweir}
515cdf0e10cSrcweir
516cdf0e10cSrcweir###############################################################
517cdf0e10cSrcweir# Set date string, format: yymmdd
518cdf0e10cSrcweir###############################################################
519cdf0e10cSrcweir
520cdf0e10cSrcweirsub set_date_string
521cdf0e10cSrcweir{
522cdf0e10cSrcweir	my ($allvariables) = @_;
523cdf0e10cSrcweir
524cdf0e10cSrcweir	my $datestring = "";
525cdf0e10cSrcweir
526cdf0e10cSrcweir	my $devproduct = 0;
527cdf0e10cSrcweir	if (( $allvariables->{'DEVELOPMENTPRODUCT'} ) && ( $allvariables->{'DEVELOPMENTPRODUCT'} == 1 )) { $devproduct = 1; }
5281dba2a1aSmseidel
529cdf0e10cSrcweir	my $cwsproduct = 0;
530cdf0e10cSrcweir	# the environment variable CWS_WORK_STAMP is set only in CWS
531cdf0e10cSrcweir	if ( $ENV{'CWS_WORK_STAMP'} ) { $cwsproduct = 1; }
532cdf0e10cSrcweir
533cdf0e10cSrcweir	my $releasebuild = 1;
5341dba2a1aSmseidel	if (( $allvariables->{'SHORT_PRODUCTEXTENSION'} ) && ( $allvariables->{'SHORT_PRODUCTEXTENSION'} ne "" )) { $releasebuild = 0; }
535cdf0e10cSrcweir
536cdf0e10cSrcweir	if (( ! $devproduct ) && ( ! $cwsproduct ) && ( ! $releasebuild ))
537cdf0e10cSrcweir	{
538cdf0e10cSrcweir		my @timearray = localtime(time);
539cdf0e10cSrcweir
540cdf0e10cSrcweir		my $day = $timearray[3];
541cdf0e10cSrcweir		my $month = $timearray[4] + 1;
542cdf0e10cSrcweir		my $year = $timearray[5] + 1900;
5431dba2a1aSmseidel
544fe0288c8SMatthias Seidel		if ( $month < 10 ) { $month = "0" . $month; }
545fe0288c8SMatthias Seidel		if ( $day < 10 ) { $day = "0" . $day; }
546cdf0e10cSrcweir
547cdf0e10cSrcweir		$datestring = $year . $month . $day;
548cdf0e10cSrcweir	}
549cdf0e10cSrcweir
550cdf0e10cSrcweir	return $datestring;
551cdf0e10cSrcweir}
552cdf0e10cSrcweir
553cdf0e10cSrcweir#################################################################
554cdf0e10cSrcweir# Setting the platform name for download
555cdf0e10cSrcweir#################################################################
556cdf0e10cSrcweir
557cdf0e10cSrcweirsub get_download_platformname
558cdf0e10cSrcweir{
559cdf0e10cSrcweir	my $platformname = "";
5601dba2a1aSmseidel
561cdf0e10cSrcweir	if ( $installer::globals::islinuxbuild )
562cdf0e10cSrcweir	{
563cdf0e10cSrcweir		$platformname = "Linux";
564cdf0e10cSrcweir	}
565cdf0e10cSrcweir	elsif ( $installer::globals::issolarisbuild )
566cdf0e10cSrcweir	{
567cdf0e10cSrcweir		$platformname = "Solaris";
568cdf0e10cSrcweir	}
569cdf0e10cSrcweir	elsif ( $installer::globals::iswindowsbuild )
570cdf0e10cSrcweir	{
571cdf0e10cSrcweir		$platformname = "Win";
572cdf0e10cSrcweir	}
573cdf0e10cSrcweir	elsif ( $installer::globals::isfreebsdbuild )
574cdf0e10cSrcweir	{
5751dba2a1aSmseidel		$platformname = "FreeBSD";
576cdf0e10cSrcweir	}
577cdf0e10cSrcweir	elsif ( $installer::globals::ismacbuild )
578cdf0e10cSrcweir	{
579cdf0e10cSrcweir		$platformname = "MacOS";
580cdf0e10cSrcweir	}
581cdf0e10cSrcweir	else
582cdf0e10cSrcweir	{
583cdf0e10cSrcweir		# $platformname = $installer::globals::packageformat;
5841dba2a1aSmseidel		$platformname = $installer::globals::compiler;
585cdf0e10cSrcweir	}
5861dba2a1aSmseidel
587cdf0e10cSrcweir	return $platformname;
588cdf0e10cSrcweir}
589cdf0e10cSrcweir
590cdf0e10cSrcweir#########################################################
591cdf0e10cSrcweir# Setting the architecture for the download name
592cdf0e10cSrcweir#########################################################
593cdf0e10cSrcweir
594cdf0e10cSrcweirsub get_download_architecture
595cdf0e10cSrcweir{
596cdf0e10cSrcweir	my $arch = "";
5971dba2a1aSmseidel
5984101619dSHerbert Dürr	if(( $installer::globals::compiler =~ /^unxlngi/ )
5994101619dSHerbert Dürr	|| ( $installer::globals::compiler =~ /^unxmac.i/ )
6004101619dSHerbert Dürr	|| ( $installer::globals::issolarisx86build )
6014101619dSHerbert Dürr	|| ( $installer::globals::iswindowsbuild ))
602cdf0e10cSrcweir	{
603cdf0e10cSrcweir		$arch = "x86";
604cdf0e10cSrcweir	}
6054101619dSHerbert Dürr	elsif(( $installer::globals::compiler =~ /^unxlngx/ )
6064101619dSHerbert Dürr	||    ( $installer::globals::compiler =~ /^unxmaccx/ ))
607cdf0e10cSrcweir	{
608cdf0e10cSrcweir		$arch = "x86-64";
609cdf0e10cSrcweir	}
610cdf0e10cSrcweir	elsif ( $installer::globals::issolarissparcbuild )
611cdf0e10cSrcweir	{
612cdf0e10cSrcweir		$arch = "Sparc";
613cdf0e10cSrcweir	}
6144101619dSHerbert Dürr	elsif(( $installer::globals::compiler =~ /^unxmacxp/ )
6154101619dSHerbert Dürr	||    ( $installer::globals::compiler =~ /^unxlngppc/ ))
616cdf0e10cSrcweir	{
617cdf0e10cSrcweir		$arch = "PPC";
618cdf0e10cSrcweir	}
6191dba2a1aSmseidel
6201dba2a1aSmseidel	return $arch;
621cdf0e10cSrcweir}
622cdf0e10cSrcweir
623cdf0e10cSrcweir#########################################################
624cdf0e10cSrcweir# Setting the installation type for the download name
625cdf0e10cSrcweir#########################################################
626cdf0e10cSrcweir
627cdf0e10cSrcweirsub get_install_type
628cdf0e10cSrcweir{
629cdf0e10cSrcweir	my ($allvariables) = @_;
6301dba2a1aSmseidel
631cdf0e10cSrcweir	my $type = "";
6321dba2a1aSmseidel
633cdf0e10cSrcweir	if ( $installer::globals::languagepack )
634cdf0e10cSrcweir	{
635cdf0e10cSrcweir		$type = "langpack";
636cdf0e10cSrcweir
637cdf0e10cSrcweir		if ( $installer::globals::islinuxrpmbuild )
638cdf0e10cSrcweir		{
639cdf0e10cSrcweir			$type = $type . "-rpm";
640cdf0e10cSrcweir		}
6411dba2a1aSmseidel
642cdf0e10cSrcweir		if ( $installer::globals::islinuxdebbuild )
643cdf0e10cSrcweir		{
644cdf0e10cSrcweir			$type = $type . "-deb";
645cdf0e10cSrcweir		}
6461dba2a1aSmseidel
647cdf0e10cSrcweir		if ( $installer::globals::packageformat eq "archive" )
648cdf0e10cSrcweir		{
6491dba2a1aSmseidel			$type = $type . "-arc";
650cdf0e10cSrcweir		}
651cdf0e10cSrcweir	}
652cdf0e10cSrcweir	else
653cdf0e10cSrcweir	{
654cdf0e10cSrcweir		$type = "install";
655cdf0e10cSrcweir
656cdf0e10cSrcweir		if ( $installer::globals::islinuxrpmbuild )
657cdf0e10cSrcweir		{
658cdf0e10cSrcweir			$type = $type . "-rpm";
659cdf0e10cSrcweir		}
6601dba2a1aSmseidel
661cdf0e10cSrcweir		if ( $installer::globals::islinuxdebbuild )
662cdf0e10cSrcweir		{
663cdf0e10cSrcweir			$type = $type . "-deb";
664cdf0e10cSrcweir		}
6651dba2a1aSmseidel
666cdf0e10cSrcweir		if ( $installer::globals::packageformat eq "archive" )
667cdf0e10cSrcweir		{
6681dba2a1aSmseidel			$type = $type . "-arc";
669cdf0e10cSrcweir		}
670cdf0e10cSrcweir
671cdf0e10cSrcweir	}
6721dba2a1aSmseidel
673cdf0e10cSrcweir	return $type;
674cdf0e10cSrcweir}
675cdf0e10cSrcweir
676cdf0e10cSrcweir#########################################################
677cdf0e10cSrcweir# Setting installation addons
678cdf0e10cSrcweir#########################################################
679cdf0e10cSrcweir
680cdf0e10cSrcweirsub get_downloadname_addon
681cdf0e10cSrcweir{
682cdf0e10cSrcweir	my $addon = "";
683cdf0e10cSrcweir
684cdf0e10cSrcweir	if ( $installer::globals::islinuxdebbuild ) { $addon = $addon . "_deb"; }
6851dba2a1aSmseidel
686cdf0e10cSrcweir	return $addon;
687cdf0e10cSrcweir}
688cdf0e10cSrcweir
689cdf0e10cSrcweir#########################################################
690cdf0e10cSrcweir# Looking for versionstring in version.info
691cdf0e10cSrcweir# This has to be the only content of this file.
692cdf0e10cSrcweir#########################################################
693cdf0e10cSrcweir
694cdf0e10cSrcweirsub get_versionstring
695cdf0e10cSrcweir{
696cdf0e10cSrcweir	my ( $versionfile ) = @_;
6971dba2a1aSmseidel
698cdf0e10cSrcweir	my $versionstring = "";
699cdf0e10cSrcweir
700cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$versionfile}; $i++ )
701cdf0e10cSrcweir	{
702cdf0e10cSrcweir		my $oneline = ${$versionfile}[$i];
7031dba2a1aSmseidel
704cdf0e10cSrcweir		if ( $oneline =~ /^\s*\#/ ) { next; } # comment line
705cdf0e10cSrcweir		if ( $oneline =~ /^\s*\"\s*(.*?)\s*\"\s*$/ )
706cdf0e10cSrcweir		{
707cdf0e10cSrcweir			$versionstring = $1;
708cdf0e10cSrcweir			last;
709cdf0e10cSrcweir		}
710cdf0e10cSrcweir	}
7111dba2a1aSmseidel
712cdf0e10cSrcweir	return $versionstring;
713cdf0e10cSrcweir}
714cdf0e10cSrcweir
715cdf0e10cSrcweir#########################################################
716cdf0e10cSrcweir# Returning the current product version
717cdf0e10cSrcweir# This has to be defined in file "version.info"
718cdf0e10cSrcweir# in directory $installer::globals::ooouploaddir
719cdf0e10cSrcweir#########################################################
720cdf0e10cSrcweir
721cdf0e10cSrcweirsub get_current_version
722cdf0e10cSrcweir{
723cdf0e10cSrcweir	my $versionstring = "";
724cdf0e10cSrcweir	my $filename = "version.info";
725cdf0e10cSrcweir	# $filename = $installer::globals::ooouploaddir . $installer::globals::separator . $filename;
7261dba2a1aSmseidel
727cdf0e10cSrcweir	if ( -f $filename )
728cdf0e10cSrcweir	{
729fe0288c8SMatthias Seidel		$installer::logger::Lang->printf("File %s exists. Trying to find current version.\n", $filename);
730cdf0e10cSrcweir		my $versionfile = installer::files::read_file($filename);
731cdf0e10cSrcweir		$versionstring = get_versionstring($versionfile);
732fe0288c8SMatthias Seidel		$installer::logger::Lang->printf("Setting version string: %s\n", $versionstring);
733cdf0e10cSrcweir	}
734cdf0e10cSrcweir	else
735cdf0e10cSrcweir	{
736fe0288c8SMatthias Seidel		$installer::logger::Lang->printf("File %s does not exist. No version setting in download file name.\n", $filename);
737cdf0e10cSrcweir	}
738cdf0e10cSrcweir
739cdf0e10cSrcweir	$installer::globals::oooversionstring = $versionstring;
7401dba2a1aSmseidel
741cdf0e10cSrcweir	return $versionstring;
742cdf0e10cSrcweir}
743cdf0e10cSrcweir
744cdf0e10cSrcweir###############################################################################################
745cdf0e10cSrcweir# Setting the download file name
746cdf0e10cSrcweir# Syntax:
747cdf0e10cSrcweir# (PRODUCTNAME)_(VERSION)_(TIMESTAMP)_(OS)_(ARCH)_(INSTALLTYPE)_(LANGUAGE).(FILEEXTENSION)
748cdf0e10cSrcweir# Rules:
749cdf0e10cSrcweir# Timestamp only for Beta and Release Candidate
750cdf0e10cSrcweir###############################################################################################
751cdf0e10cSrcweir
752cdf0e10cSrcweirsub set_download_filename
753cdf0e10cSrcweir{
754cdf0e10cSrcweir	my ($languagestringref, $allvariables) = @_;
7551dba2a1aSmseidel
756cdf0e10cSrcweir	my $start = get_downloadname_productname($allvariables);
757cdf0e10cSrcweir	my $versionstring = get_download_version($allvariables);
758cdf0e10cSrcweir	my $date = set_date_string($allvariables);
759cdf0e10cSrcweir	my $platform = get_download_platformname();
760cdf0e10cSrcweir	my $architecture = get_download_architecture();
761cdf0e10cSrcweir	my $type = get_install_type($allvariables);
762cdf0e10cSrcweir	my $language = get_downloadname_language($languagestringref);
7631dba2a1aSmseidel
764cdf0e10cSrcweir	# Setting the extension happens automatically
765cdf0e10cSrcweir
766c974372aSMatthias Seidel	my $filename = $start . "_" . $versionstring . "_" . $date . "_" . $platform . "_" . $architecture . "_" . $type . "_" . $language;
7671dba2a1aSmseidel
768cdf0e10cSrcweir	$filename =~ s/\_\_/\_/g;	# necessary, if $versionstring or $platform or $language are empty
769cdf0e10cSrcweir	$filename =~ s/\_\s*$//;	# necessary, if $language and $addon are empty
7701dba2a1aSmseidel
771cdf0e10cSrcweir	$installer::globals::ooodownloadfilename = $filename;
7721dba2a1aSmseidel
773cdf0e10cSrcweir	return $filename;
774cdf0e10cSrcweir}
775cdf0e10cSrcweir
776cdf0e10cSrcweir#########################################################
777cdf0e10cSrcweir# Creating a tar.gz file
778cdf0e10cSrcweir#########################################################
779cdf0e10cSrcweir
780cdf0e10cSrcweirsub create_tar_gz_file_from_directory
781cdf0e10cSrcweir{
782cdf0e10cSrcweir	my ($installdir, $getuidlibrary, $downloaddir, $downloadfilename) = @_;
783cdf0e10cSrcweir
784cdf0e10cSrcweir	my $packdir = $installdir;
785cdf0e10cSrcweir	installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$packdir);
786cdf0e10cSrcweir	my $changedir = $installdir;
787cdf0e10cSrcweir	installer::pathanalyzer::get_path_from_fullqualifiedname(\$changedir);
788cdf0e10cSrcweir
78960203e34SJim Jagielski	my $ldpreloadstring = $ENV{'FAKEROOT'};
790cdf0e10cSrcweir
791cdf0e10cSrcweir	$installer::globals::downloadfileextension = ".tar.gz";
792cdf0e10cSrcweir	$installer::globals::downloadfilename = $downloadfilename . $installer::globals::downloadfileextension;
793cdf0e10cSrcweir	my $targzname = $downloaddir . $installer::globals::separator . $installer::globals::downloadfilename;
794cdf0e10cSrcweir
7950b2dfbacSAndre Fischer	my $systemcall = "cd $changedir; $ldpreloadstring tar -cf - $packdir | gzip > $targzname";
7961dba2a1aSmseidel
797cdf0e10cSrcweir	my $returnvalue = system($systemcall);
798cdf0e10cSrcweir
799fe0288c8SMatthias Seidel	$installer::logger::Lang->printf("Systemcall: %s\n", $systemcall);
8001dba2a1aSmseidel
801cdf0e10cSrcweir	if ($returnvalue)
802cdf0e10cSrcweir	{
803fe0288c8SMatthias Seidel		$installer::logger::Lang->printf("ERROR: Could not execute \"%s\"!\n", $systemcall);
804cdf0e10cSrcweir	}
805cdf0e10cSrcweir	else
806cdf0e10cSrcweir	{
807fe0288c8SMatthias Seidel		$installer::logger::Lang->printf("Success: Executed \"%s\" successfully!\n", $systemcall);
808cdf0e10cSrcweir	}
8091dba2a1aSmseidel
810cdf0e10cSrcweir	return $targzname;
811cdf0e10cSrcweir}
812cdf0e10cSrcweir
813cdf0e10cSrcweir#########################################################
814cdf0e10cSrcweir# Setting the variables in the download name
815cdf0e10cSrcweir#########################################################
816cdf0e10cSrcweir
817cdf0e10cSrcweirsub resolve_variables_in_downloadname
818cdf0e10cSrcweir{
819cdf0e10cSrcweir	my ($allvariables, $downloadname, $languagestringref) = @_;
820cdf0e10cSrcweir
821cdf0e10cSrcweir	# Typical name: soa-{productversion}-{extension}-bin-{os}-{languages}
822cdf0e10cSrcweir
823d62abd1aSAndre Fischer	my $productversion = $allvariables->{'PRODUCTVERSION'};
824d62abd1aSAndre Fischer	$productversion = "" unless defined $productversion;
825cdf0e10cSrcweir	$downloadname =~ s/\{productversion\}/$productversion/;
826cdf0e10cSrcweir
827d62abd1aSAndre Fischer	my $packageversion = $allvariables->{'PACKAGEVERSION'};
828d62abd1aSAndre Fischer	$packageversion = "" unless defined $packageversion;
829cdf0e10cSrcweir	$downloadname =~ s/\{packageversion\}/$packageversion/;
830cdf0e10cSrcweir
831d62abd1aSAndre Fischer	my $extension = $allvariables->{'SHORT_PRODUCTEXTENSION'};
832d62abd1aSAndre Fischer	$extension = "" unless defined $extension;
833cdf0e10cSrcweir	$extension = lc($extension);
834cdf0e10cSrcweir	$downloadname =~ s/\{extension\}/$extension/;
835cdf0e10cSrcweir
836cdf0e10cSrcweir	my $os = "";
837cdf0e10cSrcweir	if ( $installer::globals::iswindowsbuild ) { $os = "windows"; }
838cdf0e10cSrcweir	elsif ( $installer::globals::issolarissparcbuild ) { $os = "solsparc"; }
839cdf0e10cSrcweir	elsif ( $installer::globals::issolarisx86build ) { $os = "solia"; }
840cdf0e10cSrcweir	elsif ( $installer::globals::islinuxbuild ) { $os = "linux"; }
8414101619dSHerbert Dürr	elsif ( $installer::globals::compiler =~ /unxmac.i/ ) { $os = "macosi"; }
8424101619dSHerbert Dürr	elsif ( $installer::globals::compiler =~ /unxmac.x/ ) { $os = "macosx"; }
8434101619dSHerbert Dürr	elsif ( $installer::globals::compiler =~ /unxmacxp/ ) { $os = "macosp"; }
8441dba2a1aSmseidel	else { $os = ""; }
845cdf0e10cSrcweir	$downloadname =~ s/\{os\}/$os/;
846cdf0e10cSrcweir
847cdf0e10cSrcweir	my $languages = $$languagestringref;
848cdf0e10cSrcweir	$downloadname =~ s/\{languages\}/$languages/;
8491dba2a1aSmseidel
850cdf0e10cSrcweir	$downloadname =~ s/\-\-\-/\-/g;
851cdf0e10cSrcweir	$downloadname =~ s/\-\-/\-/g;
852cdf0e10cSrcweir	$downloadname =~ s/\-\s*$//;
853cdf0e10cSrcweir
854cdf0e10cSrcweir	return $downloadname;
855cdf0e10cSrcweir}
856cdf0e10cSrcweir
857cdf0e10cSrcweir##################################################################
858c974372aSMatthias Seidel# Windows: Replacing one placeholder with the specified value
859cdf0e10cSrcweir##################################################################
860cdf0e10cSrcweir
861cdf0e10cSrcweirsub replace_one_variable
862cdf0e10cSrcweir{
863cdf0e10cSrcweir	my ($templatefile, $placeholder, $value) = @_;
864cdf0e10cSrcweir
865fe0288c8SMatthias Seidel	$installer::logger::Lang->printf("Replacing %s by %s in nsi file\n", $placeholder, $value);
866cdf0e10cSrcweir
867cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$templatefile}; $i++ )
868cdf0e10cSrcweir	{
869cdf0e10cSrcweir		${$templatefile}[$i] =~ s/$placeholder/$value/g;
870cdf0e10cSrcweir	}
871cdf0e10cSrcweir
872cdf0e10cSrcweir}
873cdf0e10cSrcweir
874cdf0e10cSrcweir########################################################################################
875cdf0e10cSrcweir# Converting a string to a unicode string
876cdf0e10cSrcweir########################################################################################
877cdf0e10cSrcweir
878cdf0e10cSrcweirsub convert_to_unicode
879cdf0e10cSrcweir{
880cdf0e10cSrcweir	my ($string) = @_;
8811dba2a1aSmseidel
882cdf0e10cSrcweir	my $unicodestring = "";
8831dba2a1aSmseidel
884cdf0e10cSrcweir	my $stringlength = length($string);
8851dba2a1aSmseidel
886cdf0e10cSrcweir	for ( my $i = 0; $i < $stringlength; $i++ )
887cdf0e10cSrcweir	{
888cdf0e10cSrcweir		$unicodestring = $unicodestring . substr($string, $i, 1);
889cdf0e10cSrcweir		$unicodestring = $unicodestring . chr(0);
8901dba2a1aSmseidel	}
891cdf0e10cSrcweir
892cdf0e10cSrcweir	return $unicodestring;
893cdf0e10cSrcweir}
894cdf0e10cSrcweir
895cdf0e10cSrcweir##################################################################
896c974372aSMatthias Seidel# Windows: Including the product name into nsi template
897cdf0e10cSrcweir##################################################################
898cdf0e10cSrcweir
899cdf0e10cSrcweirsub put_windows_productname_into_template
900cdf0e10cSrcweir{
901cdf0e10cSrcweir	my ($templatefile, $variableshashref) = @_;
9021dba2a1aSmseidel
903cdf0e10cSrcweir	my $productname = $variableshashref->{'PRODUCTNAME'};
904cdf0e10cSrcweir	$productname =~ s/\.//g;	# OpenOffice.org -> OpenOfficeorg
905cdf0e10cSrcweir
906cdf0e10cSrcweir	replace_one_variable($templatefile, "PRODUCTNAMEPLACEHOLDER", $productname);
907cdf0e10cSrcweir}
908cdf0e10cSrcweir
909cdf0e10cSrcweir##################################################################
910c974372aSMatthias Seidel# Windows: Including the path to the banner.bmp into nsi template
911cdf0e10cSrcweir##################################################################
912cdf0e10cSrcweir
913cdf0e10cSrcweirsub put_banner_bmp_into_template
914cdf0e10cSrcweir{
915cdf0e10cSrcweir	my ($templatefile, $includepatharrayref, $allvariables) = @_;
9161dba2a1aSmseidel
917cdf0e10cSrcweir	# my $filename = "downloadbanner.bmp";
918cdf0e10cSrcweir	if ( ! $allvariables->{'DOWNLOADBANNER'} ) { installer::exiter::exit_program("ERROR: DOWNLOADBANNER not defined in product definition!", "put_banner_bmp_into_template"); }
919cdf0e10cSrcweir	my $filename = $allvariables->{'DOWNLOADBANNER'};
920cdf0e10cSrcweir
921cdf0e10cSrcweir	my $completefilenameref = "";
922cdf0e10cSrcweir
923cdf0e10cSrcweir	if ( $installer::globals::include_pathes_read )
924cdf0e10cSrcweir	{
9251dba2a1aSmseidel		$completefilenameref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$filename, $includepatharrayref, 0);
926cdf0e10cSrcweir	}
927cdf0e10cSrcweir	else
928cdf0e10cSrcweir	{
929cdf0e10cSrcweir		$completefilenameref = installer::scriptitems::get_sourcepath_from_filename_and_includepath_classic(\$filename, $includepatharrayref, 0);
930cdf0e10cSrcweir	}
931cdf0e10cSrcweir
932cdf0e10cSrcweir	if ($$completefilenameref eq "") { installer::exiter::exit_program("ERROR: Could not find download file $filename!", "put_banner_bmp_into_template"); }
933cdf0e10cSrcweir
934cdf0e10cSrcweir	if ( $^O =~ /cygwin/i ) { $$completefilenameref =~ s/\//\\/g; }
935cdf0e10cSrcweir
936cdf0e10cSrcweir	replace_one_variable($templatefile, "BANNERBMPPLACEHOLDER", $$completefilenameref);
937cdf0e10cSrcweir}
938cdf0e10cSrcweir
939cdf0e10cSrcweir##################################################################
940c974372aSMatthias Seidel# Windows: Including the path to the welcome.bmp into nsi template
941cdf0e10cSrcweir##################################################################
942cdf0e10cSrcweir
943cdf0e10cSrcweirsub put_welcome_bmp_into_template
944cdf0e10cSrcweir{
945cdf0e10cSrcweir	my ($templatefile, $includepatharrayref, $allvariables) = @_;
946cdf0e10cSrcweir
947cdf0e10cSrcweir	# my $filename = "downloadbitmap.bmp";
948cdf0e10cSrcweir	if ( ! $allvariables->{'DOWNLOADBITMAP'} ) { installer::exiter::exit_program("ERROR: DOWNLOADBITMAP not defined in product definition!", "put_welcome_bmp_into_template"); }
949cdf0e10cSrcweir	my $filename = $allvariables->{'DOWNLOADBITMAP'};
950cdf0e10cSrcweir
951cdf0e10cSrcweir	my $completefilenameref = "";
952cdf0e10cSrcweir
953cdf0e10cSrcweir	if ( $installer::globals::include_pathes_read )
954cdf0e10cSrcweir	{
955cdf0e10cSrcweir		$completefilenameref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$filename, $includepatharrayref, 0);
956cdf0e10cSrcweir	}
957cdf0e10cSrcweir	else
958cdf0e10cSrcweir	{
959cdf0e10cSrcweir		$completefilenameref = installer::scriptitems::get_sourcepath_from_filename_and_includepath_classic(\$filename, $includepatharrayref, 0);
960cdf0e10cSrcweir	}
961cdf0e10cSrcweir
962cdf0e10cSrcweir	if ($$completefilenameref eq "") { installer::exiter::exit_program("ERROR: Could not find download file $filename!", "put_welcome_bmp_into_template"); }
963cdf0e10cSrcweir
964cdf0e10cSrcweir	if ( $^O =~ /cygwin/i ) { $$completefilenameref =~ s/\//\\/g; }
965cdf0e10cSrcweir
966cdf0e10cSrcweir	replace_one_variable($templatefile, "WELCOMEBMPPLACEHOLDER", $$completefilenameref);
967cdf0e10cSrcweir}
968cdf0e10cSrcweir
969cdf0e10cSrcweir##################################################################
970c974372aSMatthias Seidel# Windows: Including the path to the setup.ico into nsi template
971cdf0e10cSrcweir##################################################################
972cdf0e10cSrcweir
973cdf0e10cSrcweirsub put_setup_ico_into_template
974cdf0e10cSrcweir{
975cdf0e10cSrcweir	my ($templatefile, $includepatharrayref, $allvariables) = @_;
976cdf0e10cSrcweir
977cdf0e10cSrcweir	# my $filename = "downloadsetup.ico";
978cdf0e10cSrcweir	if ( ! $allvariables->{'DOWNLOADSETUPICO'} ) { installer::exiter::exit_program("ERROR: DOWNLOADSETUPICO not defined in product definition!", "put_setup_ico_into_template"); }
979cdf0e10cSrcweir	my $filename = $allvariables->{'DOWNLOADSETUPICO'};
980cdf0e10cSrcweir
981cdf0e10cSrcweir	my $completefilenameref = "";
982cdf0e10cSrcweir
983cdf0e10cSrcweir	if ( $installer::globals::include_pathes_read )
984cdf0e10cSrcweir	{
985cdf0e10cSrcweir		$completefilenameref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$filename, $includepatharrayref, 0);
986cdf0e10cSrcweir	}
987cdf0e10cSrcweir	else
988cdf0e10cSrcweir	{
989cdf0e10cSrcweir		$completefilenameref = installer::scriptitems::get_sourcepath_from_filename_and_includepath_classic(\$filename, $includepatharrayref, 0);
990cdf0e10cSrcweir	}
991cdf0e10cSrcweir
992cdf0e10cSrcweir	if ($$completefilenameref eq "") { installer::exiter::exit_program("ERROR: Could not find download file $filename!", "put_setup_ico_into_template"); }
993cdf0e10cSrcweir
994cdf0e10cSrcweir	if ( $^O =~ /cygwin/i ) { $$completefilenameref =~ s/\//\\/g; }
995cdf0e10cSrcweir
996cdf0e10cSrcweir	replace_one_variable($templatefile, "SETUPICOPLACEHOLDER", $$completefilenameref);
997cdf0e10cSrcweir}
998cdf0e10cSrcweir
999cdf0e10cSrcweir##################################################################
1000c974372aSMatthias Seidel# Windows: Including the publisher into nsi template
1001cdf0e10cSrcweir##################################################################
1002cdf0e10cSrcweir
10030b2dfbacSAndre Fischersub put_publisher_into_template ($$)
1004cdf0e10cSrcweir{
1005fe0288c8SMatthias Seidel	my ($templatefile, $variables) = @_;
10061dba2a1aSmseidel
1007fe0288c8SMatthias Seidel	my $publisher = $variables->{'OOOVENDOR'};
1008fe0288c8SMatthias Seidel	$publisher = "" unless defined $publisher;
1009cdf0e10cSrcweir
1010fe0288c8SMatthias Seidel	replace_one_variable($templatefile, "PUBLISHERPLACEHOLDER", $publisher);
1011cdf0e10cSrcweir}
1012cdf0e10cSrcweir
1013cdf0e10cSrcweir##################################################################
1014c974372aSMatthias Seidel# Windows: Including the web site into nsi template
1015cdf0e10cSrcweir##################################################################
1016cdf0e10cSrcweir
10170b2dfbacSAndre Fischersub put_website_into_template ($$)
1018cdf0e10cSrcweir{
1019fe0288c8SMatthias Seidel	my ($templatefile, $variables) = @_;
1020cdf0e10cSrcweir
1021fe0288c8SMatthias Seidel	my $website = $variables->{'STARTCENTER_INFO_URL'};
1022fe0288c8SMatthias Seidel	$website = "" unless defined $website;
1023cdf0e10cSrcweir
1024fe0288c8SMatthias Seidel	replace_one_variable($templatefile, "WEBSITEPLACEHOLDER", $website);
1025cdf0e10cSrcweir}
1026cdf0e10cSrcweir
1027cdf0e10cSrcweir##################################################################
1028c974372aSMatthias Seidel# Windows: Including the Java file name into nsi template
1029cdf0e10cSrcweir##################################################################
1030cdf0e10cSrcweir
1031cdf0e10cSrcweirsub put_javafilename_into_template
1032cdf0e10cSrcweir{
1033cdf0e10cSrcweir	my ($templatefile, $variableshashref) = @_;
10341dba2a1aSmseidel
1035cdf0e10cSrcweir	my $javaversion = "";
10361dba2a1aSmseidel
1037cdf0e10cSrcweir	if ( $variableshashref->{'WINDOWSJAVAFILENAME'} ) { $javaversion = $variableshashref->{'WINDOWSJAVAFILENAME'}; }
10381dba2a1aSmseidel
1039cdf0e10cSrcweir	replace_one_variable($templatefile, "WINDOWSJAVAFILENAMEPLACEHOLDER", $javaversion);
1040cdf0e10cSrcweir}
1041cdf0e10cSrcweir
1042cdf0e10cSrcweir##################################################################
1043c974372aSMatthias Seidel# Windows: Including the product version into nsi template
1044cdf0e10cSrcweir##################################################################
1045cdf0e10cSrcweir
1046cdf0e10cSrcweirsub put_windows_productversion_into_template
1047cdf0e10cSrcweir{
1048cdf0e10cSrcweir	my ($templatefile, $variableshashref) = @_;
10491dba2a1aSmseidel
1050cdf0e10cSrcweir	my $productversion = $variableshashref->{'PRODUCTVERSION'};
10511dba2a1aSmseidel
1052cdf0e10cSrcweir	replace_one_variable($templatefile, "PRODUCTVERSIONPLACEHOLDER", $productversion);
1053cdf0e10cSrcweir}
1054cdf0e10cSrcweir
1055cdf0e10cSrcweir##################################################################
1056c974372aSMatthias Seidel# Windows: Including the product version into nsi template
1057cdf0e10cSrcweir##################################################################
1058cdf0e10cSrcweir
1059cdf0e10cSrcweirsub put_windows_productpath_into_template
1060cdf0e10cSrcweir{
1061cdf0e10cSrcweir	my ($templatefile, $variableshashref, $languagestringref, $localnsisdir) = @_;
10621dba2a1aSmseidel
1063cdf0e10cSrcweir	my $productpath = $variableshashref->{'PROPERTYTABLEPRODUCTNAME'};
10641dba2a1aSmseidel
1065cdf0e10cSrcweir	my $locallangs = $$languagestringref;
1066cdf0e10cSrcweir	$locallangs =~ s/_/ /g;
1067cdf0e10cSrcweir	if (length($locallangs) > $installer::globals::max_lang_length) { $locallangs = "multi lingual"; }
1068cdf0e10cSrcweir
10691dba2a1aSmseidel	if ( ! $installer::globals::languagepack ) { $productpath = $productpath . " (" . $locallangs . ")"; }
1070b871de36Sarielch
1071cdf0e10cSrcweir	replace_one_variable($templatefile, "PRODUCTPATHPLACEHOLDER", $productpath);
1072cdf0e10cSrcweir}
1073cdf0e10cSrcweir
1074cdf0e10cSrcweir##################################################################
1075c974372aSMatthias Seidel# Windows: Including download file name into nsi template
1076cdf0e10cSrcweir##################################################################
1077cdf0e10cSrcweir
1078cdf0e10cSrcweirsub put_outputfilename_into_template
1079cdf0e10cSrcweir{
1080cdf0e10cSrcweir	my ($templatefile, $downloadname) = @_;
10811dba2a1aSmseidel
1082cdf0e10cSrcweir	$installer::globals::downloadfileextension = ".exe";
1083cdf0e10cSrcweir	$downloadname = $downloadname . $installer::globals::downloadfileextension;
1084cdf0e10cSrcweir	$installer::globals::downloadfilename = $downloadname;
1085cdf0e10cSrcweir
1086cdf0e10cSrcweir	replace_one_variable($templatefile, "DOWNLOADNAMEPLACEHOLDER", $downloadname);
1087cdf0e10cSrcweir}
1088cdf0e10cSrcweir
1089cdf0e10cSrcweir##################################################################
1090c974372aSMatthias Seidel# Windows: Generating the file list in nsi file format
1091cdf0e10cSrcweir##################################################################
1092cdf0e10cSrcweir
1093cdf0e10cSrcweirsub get_file_list
1094cdf0e10cSrcweir{
1095cdf0e10cSrcweir	my ( $basedir ) = @_;
1096cdf0e10cSrcweir
1097cdf0e10cSrcweir	my @filelist = ();
1098cdf0e10cSrcweir
1099cdf0e10cSrcweir	my $alldirs = installer::systemactions::get_all_directories($basedir);
1100cdf0e10cSrcweir	unshift(@{$alldirs}, $basedir);	# $basedir is the first directory in $alldirs
11011dba2a1aSmseidel
1102cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$alldirs}; $i++ )
1103cdf0e10cSrcweir	{
1104cdf0e10cSrcweir		my $onedir = ${$alldirs}[$i];
11051dba2a1aSmseidel
1106cdf0e10cSrcweir		# Syntax:
1107cdf0e10cSrcweir		# SetOutPath "$INSTDIR"
1108cdf0e10cSrcweir
1109cdf0e10cSrcweir		my $relativedir = $onedir;
1110cdf0e10cSrcweir		$relativedir =~ s/\Q$basedir\E//;
1111cdf0e10cSrcweir
1112cdf0e10cSrcweir		my $oneline = " " . "SetOutPath" . " " . "\"\$INSTDIR" . $relativedir . "\"" . "\n";
11131dba2a1aSmseidel
1114cdf0e10cSrcweir		if ( $^O =~ /cygwin/i ) {
1115cdf0e10cSrcweir			$oneline =~ s/\//\\/g;
1116cdf0e10cSrcweir		}
1117cdf0e10cSrcweir		push(@filelist, $oneline);
11181dba2a1aSmseidel
1119cdf0e10cSrcweir		# Collecting all files in the specific directory
11201dba2a1aSmseidel
1121cdf0e10cSrcweir		my $files = installer::systemactions::get_all_files_from_one_directory($onedir);
11221dba2a1aSmseidel
1123cdf0e10cSrcweir		for ( my $j = 0; $j <= $#{$files}; $j++ )
1124cdf0e10cSrcweir		{
1125cdf0e10cSrcweir			my $onefile = ${$files}[$j];
11261dba2a1aSmseidel
1127cdf0e10cSrcweir			my $fileline = "  " . "File" . " " . "\"" . $onefile . "\"" . "\n";
1128cdf0e10cSrcweir
1129cdf0e10cSrcweir			if ( $^O =~ /cygwin/i ) {
1130cdf0e10cSrcweir				$fileline =~ s/\//\\/g;
1131cdf0e10cSrcweir			}
1132cdf0e10cSrcweir			push(@filelist, $fileline);
1133cdf0e10cSrcweir		}
1134cdf0e10cSrcweir	}
1135cdf0e10cSrcweir
1136cdf0e10cSrcweir	return \@filelist;
1137cdf0e10cSrcweir}
1138cdf0e10cSrcweir
1139cdf0e10cSrcweir##################################################################
1140c974372aSMatthias Seidel# Windows: Including list of all files into nsi template
1141cdf0e10cSrcweir##################################################################
1142cdf0e10cSrcweir
1143cdf0e10cSrcweirsub put_filelist_into_template
1144cdf0e10cSrcweir{
1145cdf0e10cSrcweir	my ($templatefile, $installationdir) = @_;
11461dba2a1aSmseidel
1147cdf0e10cSrcweir	my $filelist = get_file_list($installationdir);
1148cdf0e10cSrcweir
1149cdf0e10cSrcweir	my $filestring = "";
1150cdf0e10cSrcweir
1151cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$filelist}; $i++ )
1152cdf0e10cSrcweir	{
1153cdf0e10cSrcweir		$filestring = $filestring . ${$filelist}[$i];
1154cdf0e10cSrcweir	}
11551dba2a1aSmseidel
1156cdf0e10cSrcweir	$filestring =~ s/\s*$//;
11571dba2a1aSmseidel
1158cdf0e10cSrcweir	replace_one_variable($templatefile, "ALLFILESPLACEHOLDER", $filestring);
1159cdf0e10cSrcweir}
1160cdf0e10cSrcweir
1161cdf0e10cSrcweir##################################################################
1162c974372aSMatthias Seidel# Windows: NSIS uses specific language names
1163cdf0e10cSrcweir##################################################################
1164cdf0e10cSrcweir
1165cdf0e10cSrcweirsub nsis_language_converter
1166cdf0e10cSrcweir{
1167cdf0e10cSrcweir	my ($language) = @_;
11681dba2a1aSmseidel
1169cdf0e10cSrcweir	my $nsislanguage = "";
1170cdf0e10cSrcweir
1171fe0288c8SMatthias Seidel	# Assign language used by NSIS.
1172cdf0e10cSrcweir	# The files "$nsislanguage.nsh" and "$nsislanguage.nlf"
1173cdf0e10cSrcweir	# are needed in the NSIS environment.
1174cdf0e10cSrcweir	# Directory: <NSIS-Dir>/Contrib/Language files
1175cdf0e10cSrcweir	if ( $language eq "en-US" ) { $nsislanguage = "English"; }
11769955fd11SMatthias Seidel	elsif ( $language eq "af" ) { $nsislanguage = "Afrikaans"; }
1177cdf0e10cSrcweir	elsif ( $language eq "sq" ) { $nsislanguage = "Albanian"; }
11786d8c51f2Smseidel	elsif ( $language eq "ar" ) { $nsislanguage = "Arabic"; }
11799955fd11SMatthias Seidel	elsif ( $language eq "hy" ) { $nsislanguage = "Armenian"; }
11809955fd11SMatthias Seidel	elsif ( $language eq "ast" ) { $nsislanguage = "Asturian"; }
11815e7cbc64SMatthias Seidel	elsif ( $language eq "eu" ) { $nsislanguage = "Basque"; }
1182cdf0e10cSrcweir	elsif ( $language eq "bg" ) { $nsislanguage = "Bulgarian"; }
1183cdf0e10cSrcweir	elsif ( $language eq "ca" ) { $nsislanguage = "Catalan"; }
1184cdf0e10cSrcweir	elsif ( $language eq "hr" ) { $nsislanguage = "Croatian"; }
1185cdf0e10cSrcweir	elsif ( $language eq "cs" ) { $nsislanguage = "Czech"; }
1186cdf0e10cSrcweir	elsif ( $language eq "da" ) { $nsislanguage = "Danish"; }
1187cdf0e10cSrcweir	elsif ( $language eq "nl" ) { $nsislanguage = "Dutch"; }
11889955fd11SMatthias Seidel	elsif ( $language eq "en-GB" ) { $nsislanguage = "English"; }
1189cdf0e10cSrcweir	elsif ( $language eq "et" ) { $nsislanguage = "Estonian"; }
1190cdf0e10cSrcweir	elsif ( $language eq "fa" ) { $nsislanguage = "Farsi"; }
1191cdf0e10cSrcweir	elsif ( $language eq "fi" ) { $nsislanguage = "Finnish"; }
1192cdf0e10cSrcweir	elsif ( $language eq "fr" ) { $nsislanguage = "French"; }
11939955fd11SMatthias Seidel	elsif ( $language eq "gl" ) { $nsislanguage = "Galician"; }
11949955fd11SMatthias Seidel	elsif ( $language eq "de" ) { $nsislanguage = "German"; }
11959955fd11SMatthias Seidel	elsif ( $language eq "el" ) { $nsislanguage = "Greek"; }
1196cdf0e10cSrcweir	elsif ( $language eq "he" ) { $nsislanguage = "Hebrew"; }
1197*ba4b6514Smseidel	elsif ( $language eq "hi" ) { $nsislanguage = "Hindi"; }
11989955fd11SMatthias Seidel	elsif ( $language eq "hu" ) { $nsislanguage = "Hungarian"; }
1199cdf0e10cSrcweir	elsif ( $language eq "is" ) { $nsislanguage = "Icelandic"; }
1200cdf0e10cSrcweir	elsif ( $language eq "id" ) { $nsislanguage = "Indonesian"; }
1201cdf0e10cSrcweir	elsif ( $language eq "it" ) { $nsislanguage = "Italian"; }
12029955fd11SMatthias Seidel	elsif ( $language eq "ja" ) { $nsislanguage = "Japanese"; }
12039955fd11SMatthias Seidel	elsif ( $language eq "ko" ) { $nsislanguage = "Korean"; }
1204cdf0e10cSrcweir	elsif ( $language eq "lv" ) { $nsislanguage = "Latvian"; }
1205cdf0e10cSrcweir	elsif ( $language eq "lt" ) { $nsislanguage = "Lithuanian"; }
12069955fd11SMatthias Seidel	elsif ( $language eq "de-LU" ) { $nsislanguage = "Luxembourgish"; }
1207cdf0e10cSrcweir	elsif ( $language eq "mk" ) { $nsislanguage = "Macedonian"; }
1208cdf0e10cSrcweir	elsif ( $language eq "mn" ) { $nsislanguage = "Mongolian"; }
12094ff3bb4aSMatthias Seidel	elsif ( $language eq "nb" ) { $nsislanguage = "Norwegian"; }
1210cdf0e10cSrcweir	elsif ( $language eq "no" ) { $nsislanguage = "Norwegian"; }
1211cdf0e10cSrcweir	elsif ( $language eq "no-NO" ) { $nsislanguage = "Norwegian"; }
12129955fd11SMatthias Seidel	elsif ( $language eq "nn" ) { $nsislanguage = "NorwegianNynorsk"; }
1213cdf0e10cSrcweir	elsif ( $language eq "pl" ) { $nsislanguage = "Polish"; }
1214cdf0e10cSrcweir	elsif ( $language eq "pt" ) { $nsislanguage = "Portuguese"; }
12159955fd11SMatthias Seidel	elsif ( $language eq "pt-BR" ) { $nsislanguage = "PortugueseBR"; }
1216cdf0e10cSrcweir	elsif ( $language eq "ro" ) { $nsislanguage = "Romanian"; }
1217cdf0e10cSrcweir	elsif ( $language eq "ru" ) { $nsislanguage = "Russian"; }
12189955fd11SMatthias Seidel	elsif ( $language eq "gd" ) { $nsislanguage = "ScotsGaelic"; }
1219cdf0e10cSrcweir	elsif ( $language eq "sr" ) { $nsislanguage = "Serbian"; }
1220cdf0e10cSrcweir	elsif ( $language eq "sr-SP" ) { $nsislanguage = "Serbian"; }
12219955fd11SMatthias Seidel	elsif ( $language eq "sh" ) { $nsislanguage = "SerbianLatin"; }
1222cdf0e10cSrcweir	elsif ( $language eq "zh-CN" ) { $nsislanguage = "SimpChinese"; }
12239955fd11SMatthias Seidel	elsif ( $language eq "sl" ) { $nsislanguage = "Slovenian"; }
12249955fd11SMatthias Seidel	elsif ( $language eq "sk" ) { $nsislanguage = "Slovak"; }
12259955fd11SMatthias Seidel	elsif ( $language eq "es" ) { $nsislanguage = "Spanish"; }
12269955fd11SMatthias Seidel	elsif ( $language eq "sv" ) { $nsislanguage = "Swedish"; }
12279955fd11SMatthias Seidel	elsif ( $language eq "th" ) { $nsislanguage = "Thai"; }
1228cdf0e10cSrcweir	elsif ( $language eq "zh-TW" ) { $nsislanguage = "TradChinese"; }
12299955fd11SMatthias Seidel	elsif ( $language eq "tr" ) { $nsislanguage = "Turkish"; }
12306d8c51f2Smseidel	elsif ( $language eq "uk" ) { $nsislanguage = "Ukrainian"; }
12319955fd11SMatthias Seidel	elsif ( $language eq "vi" ) { $nsislanguage = "Vietnamese"; }
12329955fd11SMatthias Seidel	elsif ( $language eq "cy" ) { $nsislanguage = "Welsh"; }
1233b274bc22SAndre Fischer	else
1234fe0288c8SMatthias Seidel	{
1235fe0288c8SMatthias Seidel		$installer::logger::Lang->printf("NSIS language_converter : Could not find nsis language for %s!\n", $language);
1236cdf0e10cSrcweir		$nsislanguage = "English";
1237cdf0e10cSrcweir	}
1238cdf0e10cSrcweir
1239cdf0e10cSrcweir	return $nsislanguage;
1240cdf0e10cSrcweir}
1241cdf0e10cSrcweir
1242cdf0e10cSrcweir##################################################################
1243c974372aSMatthias Seidel# Windows: Including list of all languages into nsi template
1244cdf0e10cSrcweir##################################################################
1245cdf0e10cSrcweir
1246cdf0e10cSrcweirsub put_language_list_into_template
1247cdf0e10cSrcweir{
1248cdf0e10cSrcweir	my ($templatefile, $languagesarrayref) = @_;
1249cdf0e10cSrcweir
1250cdf0e10cSrcweir	my $alllangstring = "";
1251cdf0e10cSrcweir	my %nsislangs;
1252fe0288c8SMatthias Seidel
1253cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$languagesarrayref}; $i++ )
1254cdf0e10cSrcweir	{
1255cdf0e10cSrcweir		my $onelanguage = ${$languagesarrayref}[$i];
1256cdf0e10cSrcweir		my $nsislanguage = nsis_language_converter($onelanguage);
1257cdf0e10cSrcweir		$nsislangs{$nsislanguage}++;
1258cdf0e10cSrcweir	}
1259cdf0e10cSrcweir
1260cdf0e10cSrcweir	foreach my $nsislanguage ( keys(%nsislangs) )
1261cdf0e10cSrcweir	{
1262cdf0e10cSrcweir		# Syntax: !insertmacro MUI_LANGUAGE "English"
1263cdf0e10cSrcweir		my $langstring = "\!insertmacro MUI_LANGUAGE_PACK " . $nsislanguage . "\n";
1264cdf0e10cSrcweir		if ( $nsislanguage eq "English" )
1265cdf0e10cSrcweir		{
1266cdf0e10cSrcweir			$alllangstring = $langstring . $alllangstring;
1267cdf0e10cSrcweir		}
1268cdf0e10cSrcweir		else
1269cdf0e10cSrcweir		{
12701dba2a1aSmseidel			$alllangstring = $alllangstring . $langstring;
1271cdf0e10cSrcweir		}
1272cdf0e10cSrcweir	}
1273cdf0e10cSrcweir
1274cdf0e10cSrcweir	$alllangstring =~ s/\s*$//;
12751dba2a1aSmseidel
1276cdf0e10cSrcweir	replace_one_variable($templatefile, "ALLLANGUAGESPLACEHOLDER", $alllangstring);
1277cdf0e10cSrcweir}
1278cdf0e10cSrcweir
1279cdf0e10cSrcweir##################################################################
1280c974372aSMatthias Seidel# Windows: Collecting all identifier from mlf file
1281cdf0e10cSrcweir##################################################################
1282cdf0e10cSrcweir
1283cdf0e10cSrcweirsub get_identifier
1284cdf0e10cSrcweir{
1285cdf0e10cSrcweir	my ( $mlffile ) = @_;
12861dba2a1aSmseidel
1287cdf0e10cSrcweir	my @identifier = ();
12881dba2a1aSmseidel
1289cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$mlffile}; $i++ )
1290cdf0e10cSrcweir	{
1291cdf0e10cSrcweir		my $oneline = ${$mlffile}[$i];
1292cdf0e10cSrcweir
1293cdf0e10cSrcweir		if ( $oneline =~ /^\s*\[(.+)\]\s*$/ )
1294cdf0e10cSrcweir		{
1295cdf0e10cSrcweir			my $identifier = $1;
1296cdf0e10cSrcweir			push(@identifier, $identifier);
1297cdf0e10cSrcweir		}
1298cdf0e10cSrcweir	}
1299cdf0e10cSrcweir
1300cdf0e10cSrcweir	return \@identifier;
1301cdf0e10cSrcweir}
1302cdf0e10cSrcweir
1303cdf0e10cSrcweir##############################################################
1304cdf0e10cSrcweir# Returning the complete block in all languages
1305cdf0e10cSrcweir# for a specified string
1306cdf0e10cSrcweir##############################################################
1307cdf0e10cSrcweir
1308cdf0e10cSrcweirsub get_language_block_from_language_file
1309cdf0e10cSrcweir{
1310cdf0e10cSrcweir	my ($searchstring, $languagefile) = @_;
1311cdf0e10cSrcweir
1312cdf0e10cSrcweir	my @language_block = ();
1313cdf0e10cSrcweir
1314cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$languagefile}; $i++ )
13151dba2a1aSmseidel	{
1316cdf0e10cSrcweir		if ( ${$languagefile}[$i] =~ /^\s*\[\s*$searchstring\s*\]\s*$/ )
1317cdf0e10cSrcweir		{
1318cdf0e10cSrcweir			my $counter = $i;
1319cdf0e10cSrcweir
1320cdf0e10cSrcweir			push(@language_block, ${$languagefile}[$counter]);
1321cdf0e10cSrcweir			$counter++;
13221dba2a1aSmseidel
1323cdf0e10cSrcweir			while (( $counter <= $#{$languagefile} ) && (!( ${$languagefile}[$counter] =~ /^\s*\[/ )))
1324cdf0e10cSrcweir			{
1325cdf0e10cSrcweir				push(@language_block, ${$languagefile}[$counter]);
1326cdf0e10cSrcweir				$counter++;
1327cdf0e10cSrcweir			}
13281dba2a1aSmseidel
1329cdf0e10cSrcweir			last;
1330cdf0e10cSrcweir		}
13311dba2a1aSmseidel	}
13321dba2a1aSmseidel
1333cdf0e10cSrcweir	return \@language_block;
1334cdf0e10cSrcweir}
1335cdf0e10cSrcweir
1336cdf0e10cSrcweir##############################################################
1337cdf0e10cSrcweir# Returning a specific language string from the block
1338cdf0e10cSrcweir# of all translations
1339cdf0e10cSrcweir##############################################################
1340cdf0e10cSrcweir
1341cdf0e10cSrcweirsub get_language_string_from_language_block
1342cdf0e10cSrcweir{
1343cdf0e10cSrcweir	my ($language_block, $language) = @_;
13441dba2a1aSmseidel
1345cdf0e10cSrcweir	my $newstring = "";
1346cdf0e10cSrcweir
1347cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$language_block}; $i++ )
1348cdf0e10cSrcweir	{
1349cdf0e10cSrcweir		if ( ${$language_block}[$i] =~ /^\s*$language\s*\=\s*\"(.*)\"\s*$/ )
1350cdf0e10cSrcweir		{
1351cdf0e10cSrcweir			$newstring = $1;
1352cdf0e10cSrcweir			last;
13531dba2a1aSmseidel		}
13541dba2a1aSmseidel	}
13551dba2a1aSmseidel
1356cdf0e10cSrcweir	if ( $newstring eq "" )
1357cdf0e10cSrcweir	{
13581dba2a1aSmseidel		$language = "en-US"; 	# defaulting to English
1359cdf0e10cSrcweir
1360cdf0e10cSrcweir		for ( my $i = 0; $i <= $#{$language_block}; $i++ )
13611dba2a1aSmseidel		{
1362cdf0e10cSrcweir			if ( ${$language_block}[$i] =~ /^\s*$language\s*\=\s*\"(.*)\"\s*$/ )
1363cdf0e10cSrcweir			{
1364cdf0e10cSrcweir				$newstring = $1;
1365cdf0e10cSrcweir				last;
1366cdf0e10cSrcweir			}
1367cdf0e10cSrcweir		}
1368cdf0e10cSrcweir	}
13691dba2a1aSmseidel
1370cdf0e10cSrcweir	return $newstring;
1371cdf0e10cSrcweir}
1372cdf0e10cSrcweir
1373cdf0e10cSrcweir##################################################################
1374c974372aSMatthias Seidel# Windows: Replacing strings in NSIS nsh file
1375cdf0e10cSrcweir# nsh file syntax:
1376c974372aSMatthias Seidel# !define MUI_TEXT_DIRECTORY_TITLE "Choose Install Location"
1377cdf0e10cSrcweir##################################################################
1378cdf0e10cSrcweir
1379cdf0e10cSrcweirsub replace_identifier_in_nshfile
1380cdf0e10cSrcweir{
1381cdf0e10cSrcweir	my ( $nshfile, $identifier, $newstring, $nshfilename, $onelanguage ) = @_;
1382cdf0e10cSrcweir
13831dba2a1aSmseidel	$newstring =~ s/\\r/\$\\r/g; # \r -> $\r in modern nsis versions
13841dba2a1aSmseidel	$newstring =~ s/\\n/\$\\n/g; # \n -> $\n in modern nsis versions
13851dba2a1aSmseidel
1386cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$nshfile}; $i++ )
1387cdf0e10cSrcweir	{
1388cdf0e10cSrcweir		if ( ${$nshfile}[$i] =~ /\s+\Q$identifier\E\s+\"(.+)\"\s*$/ )
1389cdf0e10cSrcweir		{
1390cdf0e10cSrcweir			my $oldstring = $1;
1391cdf0e10cSrcweir			${$nshfile}[$i] =~ s/\Q$oldstring\E/$newstring/;
1392fe0288c8SMatthias Seidel			$installer::logger::Lang->printf("NSIS replacement in %s (%s): \-\> %s\n",
1393fe0288c8SMatthias Seidel				$nshfilename,
1394fe0288c8SMatthias Seidel				$onelanguage,
1395fe0288c8SMatthias Seidel				$oldstring,
1396fe0288c8SMatthias Seidel				$newstring);
1397cdf0e10cSrcweir		}
1398cdf0e10cSrcweir	}
1399cdf0e10cSrcweir}
1400cdf0e10cSrcweir
1401cdf0e10cSrcweir##################################################################
1402c974372aSMatthias Seidel# Windows: Replacing strings in NSIS nlf file
1403cdf0e10cSrcweir# nlf file syntax (2 lines):
1404cdf0e10cSrcweir# # ^DirSubText
1405c974372aSMatthias Seidel# Destination Folder
1406cdf0e10cSrcweir##################################################################
1407cdf0e10cSrcweir
1408cdf0e10cSrcweirsub replace_identifier_in_nlffile
1409cdf0e10cSrcweir{
1410cdf0e10cSrcweir	my ( $nlffile, $identifier, $newstring, $nlffilename, $onelanguage ) = @_;
1411cdf0e10cSrcweir
1412cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$nlffile}; $i++ )
1413cdf0e10cSrcweir	{
1414cdf0e10cSrcweir		if ( ${$nlffile}[$i] =~ /^\s*\#\s+\^\s*\Q$identifier\E\s*$/ )
1415cdf0e10cSrcweir		{
1416cdf0e10cSrcweir			my $next = $i+1;
1417cdf0e10cSrcweir			my $oldstring = ${$nlffile}[$next];
1418cdf0e10cSrcweir			${$nlffile}[$next] = $newstring . "\n";
1419cdf0e10cSrcweir			$oldstring =~ s/\s*$//;
1420fe0288c8SMatthias Seidel			$installer::logger::Lang->printf("NSIS replacement in %s (%s): %s \-\> %s\n",
1421fe0288c8SMatthias Seidel				$nlffilename,
1422fe0288c8SMatthias Seidel				$onelanguage,
1423fe0288c8SMatthias Seidel				$oldstring,
1424fe0288c8SMatthias Seidel				$newstring);
1425cdf0e10cSrcweir		}
14261dba2a1aSmseidel	}
1427cdf0e10cSrcweir}
1428cdf0e10cSrcweir
1429cdf0e10cSrcweir##################################################################
1430c974372aSMatthias Seidel# Windows: Translating the NSIS nsh and nlf file
1431cdf0e10cSrcweir##################################################################
1432cdf0e10cSrcweir
1433cdf0e10cSrcweirsub translate_nsh_nlf_file
1434cdf0e10cSrcweir{
1435cdf0e10cSrcweir	my ($nshfile, $nlffile, $mlffile, $onelanguage, $nshfilename, $nlffilename, $nsislanguage) = @_;
1436cdf0e10cSrcweir
1437cdf0e10cSrcweir	# Analyzing the mlf file, collecting all Identifier
1438cdf0e10cSrcweir	my $allidentifier = get_identifier($mlffile);
14391dba2a1aSmseidel
1440cdf0e10cSrcweir	$onelanguage = "en-US" if ( $nsislanguage eq "English" && $onelanguage ne "en-US");
1441cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$allidentifier}; $i++ )
1442cdf0e10cSrcweir	{
1443cdf0e10cSrcweir		my $identifier = ${$allidentifier}[$i];
1444cdf0e10cSrcweir		my $language_block = get_language_block_from_language_file($identifier, $mlffile);
1445cdf0e10cSrcweir		my $newstring = get_language_string_from_language_block($language_block, $onelanguage);
14461dba2a1aSmseidel
1447cdf0e10cSrcweir		# removing mask
1448cdf0e10cSrcweir		$newstring =~ s/\\\'/\'/g;
14491dba2a1aSmseidel
1450cdf0e10cSrcweir		replace_identifier_in_nshfile($nshfile, $identifier, $newstring, $nshfilename, $onelanguage);
14511dba2a1aSmseidel		replace_identifier_in_nlffile($nlffile, $identifier, $newstring, $nlffilename, $onelanguage);
1452cdf0e10cSrcweir	}
1453cdf0e10cSrcweir}
1454cdf0e10cSrcweir
1455cdf0e10cSrcweir##################################################################
1456c974372aSMatthias Seidel# Converting utf 16 file to utf 8
1457cdf0e10cSrcweir##################################################################
1458cdf0e10cSrcweir
1459cdf0e10cSrcweirsub convert_utf16_to_utf8
1460cdf0e10cSrcweir{
1461cdf0e10cSrcweir	my ( $filename ) = @_;
1462cdf0e10cSrcweir
1463cdf0e10cSrcweir	my @localfile = ();
1464cdf0e10cSrcweir
1465cdf0e10cSrcweir	my $savfilename = $filename . "_before.utf16";
1466cdf0e10cSrcweir	installer::systemactions::copy_one_file($filename, $savfilename);
1467cdf0e10cSrcweir
1468cdf0e10cSrcweir#	open( IN, "<:utf16", $filename ) || installer::exiter::exit_program("ERROR: Cannot open file $filename for reading", "convert_utf16_to_utf8");
1469cdf0e10cSrcweir#	open( IN, "<:para:crlf:uni", $filename ) || installer::exiter::exit_program("ERROR: Cannot open file $filename for reading", "convert_utf16_to_utf8");
1470cdf0e10cSrcweir	open( IN, "<:encoding(UTF16-LE)", $filename ) || installer::exiter::exit_program("ERROR: Cannot open file $filename for reading", "convert_utf16_to_utf8");
14710b2dfbacSAndre Fischer	while ( my $line = <IN> )
1472fe0288c8SMatthias Seidel	{
1473cdf0e10cSrcweir		push @localfile, $line;
1474cdf0e10cSrcweir	}
1475cdf0e10cSrcweir	close( IN );
1476cdf0e10cSrcweir
1477cdf0e10cSrcweir	if ( open( OUT, ">:utf8", $filename ) )
1478cdf0e10cSrcweir	{
1479cdf0e10cSrcweir		print OUT @localfile;
14801dba2a1aSmseidel		close(OUT);
1481cdf0e10cSrcweir	}
1482cdf0e10cSrcweir
1483cdf0e10cSrcweir	$savfilename = $filename . "_before.utf8";
1484cdf0e10cSrcweir	installer::systemactions::copy_one_file($filename, $savfilename);
1485cdf0e10cSrcweir}
1486cdf0e10cSrcweir
1487cdf0e10cSrcweir##################################################################
1488c974372aSMatthias Seidel# Converting utf 8 file to utf 16
1489cdf0e10cSrcweir##################################################################
1490cdf0e10cSrcweir
1491cdf0e10cSrcweirsub convert_utf8_to_utf16
1492cdf0e10cSrcweir{
1493c974372aSMatthias Seidel	my ( $filename ) = @_;
1494cdf0e10cSrcweir
1495cdf0e10cSrcweir	my @localfile = ();
1496cdf0e10cSrcweir
1497cdf0e10cSrcweir	my $savfilename = $filename . "_after.utf8";
1498cdf0e10cSrcweir	installer::systemactions::copy_one_file($filename, $savfilename);
1499cdf0e10cSrcweir
1500cdf0e10cSrcweir	open( IN, "<:utf8", $filename ) || installer::exiter::exit_program("ERROR: Cannot open file $filename for reading", "convert_utf8_to_utf16");
1501fe0288c8SMatthias Seidel	while (my $line = <IN>)
1502fe0288c8SMatthias Seidel	{
1503cdf0e10cSrcweir		push @localfile, $line;
1504cdf0e10cSrcweir	}
1505cdf0e10cSrcweir	close( IN );
1506cdf0e10cSrcweir
1507cdf0e10cSrcweir	if ( open( OUT, ">:raw:encoding(UTF16-LE):crlf:utf8", $filename ) )
1508cdf0e10cSrcweir	{
1509cdf0e10cSrcweir		print OUT @localfile;
15101dba2a1aSmseidel		close(OUT);
1511cdf0e10cSrcweir	}
1512cdf0e10cSrcweir
1513cdf0e10cSrcweir	$savfilename = $filename . "_after.utf16";
1514cdf0e10cSrcweir	installer::systemactions::copy_one_file($filename, $savfilename);
1515cdf0e10cSrcweir}
1516cdf0e10cSrcweir
1517cdf0e10cSrcweir##################################################################
1518c974372aSMatthias Seidel# Converting text string to utf 16
1519cdf0e10cSrcweir##################################################################
1520cdf0e10cSrcweir
1521cdf0e10cSrcweirsub convert_textstring_to_utf16
1522cdf0e10cSrcweir{
1523c974372aSMatthias Seidel	my ( $textstring, $localnsisdir, $shortfilename ) = @_;
1524cdf0e10cSrcweir
1525cdf0e10cSrcweir	my $filename = $localnsisdir . $installer::globals::separator . $shortfilename;
1526cdf0e10cSrcweir	my @filecontent = ();
1527cdf0e10cSrcweir	push(@filecontent, $textstring);
1528cdf0e10cSrcweir	installer::files::save_file($filename, \@filecontent);
1529cdf0e10cSrcweir	convert_utf8_to_utf16($filename);
1530cdf0e10cSrcweir	my $newfile = installer::files::read_file($filename);
1531cdf0e10cSrcweir	my $utf16string = "";
1532cdf0e10cSrcweir	if ( ${$newfile}[0] ne "" ) { $utf16string = ${$newfile}[0]; }
1533cdf0e10cSrcweir
1534cdf0e10cSrcweir	return $utf16string;
1535cdf0e10cSrcweir}
1536cdf0e10cSrcweir
1537cdf0e10cSrcweir##################################################################
1538c974372aSMatthias Seidel# Windows: Copying NSIS language files to local nsis directory
1539cdf0e10cSrcweir##################################################################
1540cdf0e10cSrcweir
1541cdf0e10cSrcweirsub copy_and_translate_nsis_language_files
1542cdf0e10cSrcweir{
1543cdf0e10cSrcweir	my ($nsispath, $localnsisdir, $languagesarrayref, $allvariables) = @_;
15441dba2a1aSmseidel
1545cdf0e10cSrcweir	my $nlffilepath = $nsispath . $installer::globals::separator . "Contrib" . $installer::globals::separator . "Language\ files" . $installer::globals::separator;
1546cdf0e10cSrcweir	my $nshfilepath = $nsispath . $installer::globals::separator . "Contrib" . $installer::globals::separator . "Modern\ UI" . $installer::globals::separator . "Language files" . $installer::globals::separator;
1547cdf0e10cSrcweir
1548cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$languagesarrayref}; $i++ )
1549cdf0e10cSrcweir	{
1550cdf0e10cSrcweir		my $onelanguage = ${$languagesarrayref}[$i];
1551cdf0e10cSrcweir		my $nsislanguage = nsis_language_converter($onelanguage);
1552cdf0e10cSrcweir
1553cdf0e10cSrcweir		# Copying the nlf file
1554cdf0e10cSrcweir		my $sourcepath = $nlffilepath . $nsislanguage . "\.nlf";
1555cdf0e10cSrcweir		if ( ! -f $sourcepath ) { installer::exiter::exit_program("ERROR: Could not find nsis file: $sourcepath!", "copy_and_translate_nsis_language_files"); }
1556cdf0e10cSrcweir		my $nlffilename = $localnsisdir . $installer::globals::separator . $nsislanguage . "_pack.nlf";
1557cdf0e10cSrcweir		if ( $^O =~ /cygwin/i ) { $nlffilename =~ s/\//\\/g; }
1558cdf0e10cSrcweir		installer::systemactions::copy_one_file($sourcepath, $nlffilename);
15591dba2a1aSmseidel
1560cdf0e10cSrcweir		# Copying the nsh file
1561cdf0e10cSrcweir		# In newer nsis versions, the nsh file is located next to the nlf file
1562cdf0e10cSrcweir		$sourcepath = $nshfilepath . $nsislanguage . "\.nsh";
1563cdf0e10cSrcweir		if ( ! -f $sourcepath )
1564cdf0e10cSrcweir		{
1565cdf0e10cSrcweir			# trying to find the nsh file next to the nlf file
1566cdf0e10cSrcweir			$sourcepath = $nlffilepath . $nsislanguage . "\.nsh";
1567cdf0e10cSrcweir			if ( ! -f $sourcepath )
1568cdf0e10cSrcweir			{
1569cdf0e10cSrcweir				installer::exiter::exit_program("ERROR: Could not find nsis file: $sourcepath!", "copy_and_translate_nsis_language_files");
1570cdf0e10cSrcweir			}
1571cdf0e10cSrcweir		}
1572cdf0e10cSrcweir		my $nshfilename = $localnsisdir . $installer::globals::separator . $nsislanguage . "_pack.nsh";
1573cdf0e10cSrcweir		if ( $^O =~ /cygwin/i ) { $nshfilename =~ s/\//\\/g; }
15741dba2a1aSmseidel		installer::systemactions::copy_one_file($sourcepath, $nshfilename);
1575cdf0e10cSrcweir
1576cdf0e10cSrcweir		# Changing the macro name in nsh file: MUI_LANGUAGEFILE_BEGIN -> MUI_LANGUAGEFILE_PACK_BEGIN
15771dba2a1aSmseidel		#convert_utf16_to_utf8($nshfilename);
15781dba2a1aSmseidel		#convert_utf16_to_utf8($nlffilename);
1579fe0288c8SMatthias Seidel		my $nshfile = installer::files::read_file($nshfilename);
1580cdf0e10cSrcweir		replace_one_variable($nshfile, "MUI_LANGUAGEFILE_BEGIN", "MUI_LANGUAGEFILE_PACK_BEGIN");
1581cdf0e10cSrcweir
1582cdf0e10cSrcweir		# find the ulf file for translation
1583cdf0e10cSrcweir		my $mlffile = get_translation_file($allvariables);
15841dba2a1aSmseidel
1585cdf0e10cSrcweir		# Translate the files
1586cdf0e10cSrcweir		my $nlffile = installer::files::read_file($nlffilename);
1587cdf0e10cSrcweir		translate_nsh_nlf_file($nshfile, $nlffile, $mlffile, $onelanguage, $nshfilename, $nlffilename, $nsislanguage);
15881dba2a1aSmseidel
1589cdf0e10cSrcweir		installer::files::save_file($nshfilename, $nshfile);
1590cdf0e10cSrcweir		installer::files::save_file($nlffilename, $nlffile);
1591cdf0e10cSrcweir
15921dba2a1aSmseidel		#convert_utf8_to_utf16($nshfilename);
15931dba2a1aSmseidel		#convert_utf8_to_utf16($nlffilename);
1594cdf0e10cSrcweir	}
1595cdf0e10cSrcweir
1596cdf0e10cSrcweir}
1597cdf0e10cSrcweir
1598cdf0e10cSrcweir##################################################################
1599c974372aSMatthias Seidel# Windows: Including the nsis path into the nsi template
1600cdf0e10cSrcweir##################################################################
1601cdf0e10cSrcweir
1602cdf0e10cSrcweirsub put_nsis_path_into_template
1603cdf0e10cSrcweir{
1604cdf0e10cSrcweir	my ($templatefile, $nsisdir) = @_;
1605cdf0e10cSrcweir
1606cdf0e10cSrcweir	replace_one_variable($templatefile, "NSISPATHPLACEHOLDER", $nsisdir);
1607cdf0e10cSrcweir}
1608cdf0e10cSrcweir
1609cdf0e10cSrcweir##################################################################
1610c974372aSMatthias Seidel# Windows: Including the output path into the nsi template
1611cdf0e10cSrcweir##################################################################
1612cdf0e10cSrcweir
1613cdf0e10cSrcweirsub put_output_path_into_template
1614cdf0e10cSrcweir{
1615cdf0e10cSrcweir	my ($templatefile, $downloaddir) = @_;
1616cdf0e10cSrcweir
1617cdf0e10cSrcweir	if ( $^O =~ /cygwin/i ) { $downloaddir =~ s/\//\\/g; }
1618cdf0e10cSrcweir
1619cdf0e10cSrcweir	replace_one_variable($templatefile, "OUTPUTDIRPLACEHOLDER", $downloaddir);
1620cdf0e10cSrcweir}
1621cdf0e10cSrcweir
1622cdf0e10cSrcweir##################################################################
1623c974372aSMatthias Seidel# Windows: Finding the path to the nsis SDK
1624cdf0e10cSrcweir##################################################################
1625cdf0e10cSrcweir
1626cdf0e10cSrcweirsub get_path_to_nsis_sdk
1627cdf0e10cSrcweir{
1628cdf0e10cSrcweir	my $nsispath = "";
1629cdf0e10cSrcweir
16300b2dfbacSAndre Fischer	if ( $ENV{'NSIS_PATH'} )
1631fe0288c8SMatthias Seidel	{
1632cdf0e10cSrcweir		$nsispath = $ENV{'NSIS_PATH'};
16330b2dfbacSAndre Fischer	}
1634cdf0e10cSrcweir	if ( $nsispath eq "" )
1635cdf0e10cSrcweir	{
1636fe0288c8SMatthias Seidel		$installer::logger::Info->print("... no Environment variable \"NSIS_PATH\"!\n");
1637b274bc22SAndre Fischer	}
1638fe0288c8SMatthias Seidel	elsif ( ! -d $nsispath )
1639cdf0e10cSrcweir	{
1640cdf0e10cSrcweir		installer::exiter::exit_program("ERROR: NSIS path $nsispath does not exist!", "get_path_to_nsis_sdk");
1641cdf0e10cSrcweir	}
16421dba2a1aSmseidel
1643cdf0e10cSrcweir	return $nsispath;
1644cdf0e10cSrcweir}
1645cdf0e10cSrcweir
1646cdf0e10cSrcweir##################################################################
1647c974372aSMatthias Seidel# Windows: Executing NSIS to create the installation set
1648cdf0e10cSrcweir##################################################################
1649cdf0e10cSrcweir
1650cdf0e10cSrcweirsub call_nsis
1651cdf0e10cSrcweir{
1652cdf0e10cSrcweir	my ( $nsispath, $nsifile ) = @_;
16531dba2a1aSmseidel
1654cdf0e10cSrcweir	my $makensisexe = $nsispath . $installer::globals::separator . "makensis.exe";
1655cdf0e10cSrcweir
1656fe0288c8SMatthias Seidel	$installer::logger::Info->printf("... starting %s ... \n", $makensisexe);
1657cdf0e10cSrcweir
1658cdf0e10cSrcweir	if( $^O =~ /cygwin/i ) { $nsifile =~ s/\\/\//g;	}
1659cdf0e10cSrcweir
1660cdf0e10cSrcweir	my $systemcall = "$makensisexe $nsifile |";
1661cdf0e10cSrcweir
1662fe0288c8SMatthias Seidel	$installer::logger::Lang->printf("Systemcall: %s\n", $systemcall);
1663cdf0e10cSrcweir
1664cdf0e10cSrcweir	my @nsisoutput = ();
1665cdf0e10cSrcweir
1666cdf0e10cSrcweir	open (NSI, "$systemcall");
1667cdf0e10cSrcweir	while (<NSI>) {push(@nsisoutput, $_); }
1668cdf0e10cSrcweir	close (NSI);
1669cdf0e10cSrcweir
1670cdf0e10cSrcweir	my $returnvalue = $?;	# $? contains the return value of the systemcall
1671cdf0e10cSrcweir
1672cdf0e10cSrcweir	if ($returnvalue)
1673cdf0e10cSrcweir	{
1674fe0288c8SMatthias Seidel		$installer::logger::Lang->printf("ERROR: %s !\n", $systemcall);
1675cdf0e10cSrcweir	}
1676cdf0e10cSrcweir	else
1677cdf0e10cSrcweir	{
1678fe0288c8SMatthias Seidel		$installer::logger::Lang->printf("Success: %s\n", $systemcall);
16791dba2a1aSmseidel	}
1680cdf0e10cSrcweir
1681b274bc22SAndre Fischer	foreach my $line (@nsisoutput)
1682fe0288c8SMatthias Seidel	{
1683fe0288c8SMatthias Seidel		$installer::logger::Lang->print($line);
1684fe0288c8SMatthias Seidel	}
1685cdf0e10cSrcweir}
1686cdf0e10cSrcweir
1687cdf0e10cSrcweir#################################################################################
1688cdf0e10cSrcweir# Replacing one variable in one files
1689cdf0e10cSrcweir#################################################################################
1690cdf0e10cSrcweir
1691cdf0e10cSrcweirsub replace_one_variable_in_translationfile
1692cdf0e10cSrcweir{
1693cdf0e10cSrcweir	my ($translationfile, $variable, $searchstring) = @_;
16941dba2a1aSmseidel
1695cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$translationfile}; $i++ )
1696cdf0e10cSrcweir	{
1697cdf0e10cSrcweir		${$translationfile}[$i] =~ s/\%$searchstring/$variable/g;
16981dba2a1aSmseidel	}
1699cdf0e10cSrcweir}
1700cdf0e10cSrcweir
1701cdf0e10cSrcweir#################################################################################
1702cdf0e10cSrcweir# Replacing the variables in the translation file
1703cdf0e10cSrcweir#################################################################################
1704cdf0e10cSrcweir
1705cdf0e10cSrcweirsub replace_variables
1706cdf0e10cSrcweir{
1707cdf0e10cSrcweir	my ($translationfile, $variableshashref) = @_;
1708cdf0e10cSrcweir
17090b2dfbacSAndre Fischer	foreach my $key (keys %{$variableshashref})
1710cdf0e10cSrcweir	{
1711cdf0e10cSrcweir		my $value = $variableshashref->{$key};
1712cdf0e10cSrcweir
1713cdf0e10cSrcweir		# special handling for PRODUCTVERSION, if $allvariables->{'POSTVERSIONEXTENSION'}
1714cdf0e10cSrcweir		if (( $key eq "PRODUCTVERSION" ) && ( $variableshashref->{'POSTVERSIONEXTENSION'} )) { $value = $value . " " . $variableshashref->{'POSTVERSIONEXTENSION'}; }
1715cdf0e10cSrcweir
1716cdf0e10cSrcweir		replace_one_variable_in_translationfile($translationfile, $value, $key);
1717cdf0e10cSrcweir	}
1718cdf0e10cSrcweir}
1719cdf0e10cSrcweir
1720cdf0e10cSrcweir#########################################################
1721cdf0e10cSrcweir# Getting the translation file for the nsis installer
1722cdf0e10cSrcweir#########################################################
1723cdf0e10cSrcweir
1724cdf0e10cSrcweirsub get_translation_file
1725cdf0e10cSrcweir{
1726cdf0e10cSrcweir	my ($allvariableshashref) = @_;
1727b871de36Sarielch	my $translationfilename = $installer::globals::idtlanguagepath . $installer::globals::separator . $installer::globals::nsisfilename . ".uulf";
1728cdf0e10cSrcweir	if ( ! -f $translationfilename ) { installer::exiter::exit_program("ERROR: Could not find language file $translationfilename!", "get_translation_file"); }
1729cdf0e10cSrcweir	my $translationfile = installer::files::read_file($translationfilename);
1730cdf0e10cSrcweir	replace_variables($translationfile, $allvariableshashref);
1731cdf0e10cSrcweir
1732fe0288c8SMatthias Seidel	$installer::logger::Lang->printf("Reading translation file: %s\n", $translationfilename);
17331dba2a1aSmseidel
1734cdf0e10cSrcweir	return $translationfile;
1735cdf0e10cSrcweir}
1736cdf0e10cSrcweir
1737cdf0e10cSrcweir####################################################
17381dba2a1aSmseidel# Removing English, if it was added before
1739cdf0e10cSrcweir####################################################
1740cdf0e10cSrcweir
1741cdf0e10cSrcweirsub remove_english_for_nsis_installer
1742cdf0e10cSrcweir{
1743cdf0e10cSrcweir	my ($languagestringref, $languagesarrayref) = @_;
1744cdf0e10cSrcweir
1745cdf0e10cSrcweir	# $$languagestringref =~ s/en-US_//;
1746cdf0e10cSrcweir	# shift(@{$languagesarrayref});
1747cdf0e10cSrcweir
17481dba2a1aSmseidel	@{$languagesarrayref} = ("en-US");	# only English for NSIS installer!
1749cdf0e10cSrcweir}
1750cdf0e10cSrcweir
1751cdf0e10cSrcweir####################################################
1752cdf0e10cSrcweir# Creating link tree for upload
1753cdf0e10cSrcweir####################################################
1754cdf0e10cSrcweir
1755cdf0e10cSrcweirsub create_link_tree
1756cdf0e10cSrcweir{
1757cdf0e10cSrcweir	my ($sourcedownloadfile, $destfilename, $versionstring) = @_;
17581dba2a1aSmseidel
1759957116b7SHerbert Dürr	if ( ! $installer::globals::ooouploaddir ) { installer::exiter::exit_program("ERROR: Directory for AOO upload not defined!", "create_link_tree"); }
1760cdf0e10cSrcweir	my $versiondir = $installer::globals::ooouploaddir . $installer::globals::separator . $versionstring;
1761fe0288c8SMatthias Seidel	$installer::logger::Lang->printf("Directory for the link: %s\n", $versiondir);
17621dba2a1aSmseidel
1763cdf0e10cSrcweir	if ( ! -d $versiondir ) { installer::systemactions::create_directory_structure($versiondir); }
17641dba2a1aSmseidel
17651dba2a1aSmseidel	# inside directory $versiondir all links have to be created
1766cdf0e10cSrcweir	my $linkdestination = $versiondir . $installer::globals::separator . $destfilename;
1767cdf0e10cSrcweir
1768cdf0e10cSrcweir	# If there is an older version of this file (link), it has to be removed
1769cdf0e10cSrcweir	if ( -f $linkdestination ) { unlink($linkdestination); }
1770cdf0e10cSrcweir
1771fe0288c8SMatthias Seidel	$installer::logger::Lang->printf("Creating hard link from %s to %s\n", $sourcedownloadfile, $linkdestination);
17721dba2a1aSmseidel	installer::systemactions::hardlink_one_file($sourcedownloadfile, $linkdestination);
1773cdf0e10cSrcweir}
1774cdf0e10cSrcweir
1775cdf0e10cSrcweir#######################################################
1776c974372aSMatthias Seidel# Setting supported platform for OpenOffice builds
1777cdf0e10cSrcweir#######################################################
1778cdf0e10cSrcweir
1779cdf0e10cSrcweirsub is_supported_platform
1780cdf0e10cSrcweir{
1781cdf0e10cSrcweir	my $is_supported = 0;
17821dba2a1aSmseidel
1783cdf0e10cSrcweir	if (( $installer::globals::islinuxrpmbuild ) ||
1784cdf0e10cSrcweir		( $installer::globals::issolarissparcbuild ) ||
1785cdf0e10cSrcweir		( $installer::globals::issolarisx86build ) ||
1786cdf0e10cSrcweir		( $installer::globals::iswindowsbuild ))
1787cdf0e10cSrcweir	{
1788cdf0e10cSrcweir		$is_supported = 1;
1789cdf0e10cSrcweir	}
1790cdf0e10cSrcweir
1791cdf0e10cSrcweir	return $is_supported;
1792cdf0e10cSrcweir}
1793cdf0e10cSrcweir
1794cdf0e10cSrcweir####################################################
1795cdf0e10cSrcweir# Creating download installation sets
1796cdf0e10cSrcweir####################################################
1797cdf0e10cSrcweir
1798cdf0e10cSrcweirsub create_download_sets
1799cdf0e10cSrcweir{
1800cdf0e10cSrcweir	my ($installationdir, $includepatharrayref, $allvariableshashref, $downloadname, $languagestringref, $languagesarrayref) = @_;
18011dba2a1aSmseidel
1802fe0288c8SMatthias Seidel	$installer::logger::Info->print("\n");
1803fe0288c8SMatthias Seidel	$installer::logger::Info->print("******************************************\n");
1804fe0288c8SMatthias Seidel	$installer::logger::Info->print("... creating download installation set ...\n", 1);
1805fe0288c8SMatthias Seidel	$installer::logger::Info->print("******************************************\n");
1806cdf0e10cSrcweir
1807cdf0e10cSrcweir	installer::logger::include_header_into_logfile("Creating download installation sets:");
1808cdf0e10cSrcweir
1809cdf0e10cSrcweir	# special handling for installation sets, to which english was added automatically
1810cdf0e10cSrcweir	if ( $installer::globals::added_english ) { remove_english_for_nsis_installer($languagestringref, $languagesarrayref); }
1811cdf0e10cSrcweir
1812cdf0e10cSrcweir	my $firstdir = $installationdir;
1813cdf0e10cSrcweir	installer::pathanalyzer::get_path_from_fullqualifiedname(\$firstdir);
18141dba2a1aSmseidel
1815cdf0e10cSrcweir	my $lastdir = $installationdir;
1816cdf0e10cSrcweir	installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$lastdir);
1817cdf0e10cSrcweir
1818cdf0e10cSrcweir	if ( $lastdir =~ /\./ ) { $lastdir =~ s/\./_download_inprogress\./ }
1819cdf0e10cSrcweir	else { $lastdir = $lastdir . "_download_inprogress"; }
1820cdf0e10cSrcweir
1821cdf0e10cSrcweir	# removing existing directory "_native_packed_inprogress" and "_native_packed_witherror" and "_native_packed"
1822cdf0e10cSrcweir
1823cdf0e10cSrcweir	my $downloaddir = $firstdir . $lastdir;
18241dba2a1aSmseidel
1825cdf0e10cSrcweir	if ( -d $downloaddir ) { installer::systemactions::remove_complete_directory($downloaddir); }
18261dba2a1aSmseidel
1827cdf0e10cSrcweir	my $olddir = $downloaddir;
1828cdf0e10cSrcweir	$olddir =~ s/_inprogress/_witherror/;
1829cdf0e10cSrcweir	if ( -d $olddir ) { installer::systemactions::remove_complete_directory($olddir); }
1830cdf0e10cSrcweir
1831cdf0e10cSrcweir	$olddir = $downloaddir;
1832cdf0e10cSrcweir	$olddir =~ s/_inprogress//;
1833cdf0e10cSrcweir	if ( -d $olddir ) { installer::systemactions::remove_complete_directory($olddir); }
1834cdf0e10cSrcweir
1835cdf0e10cSrcweir	# creating the new directory
18361dba2a1aSmseidel
1837cdf0e10cSrcweir	installer::systemactions::create_directory($downloaddir);
1838cdf0e10cSrcweir
1839cdf0e10cSrcweir	$installer::globals::saveinstalldir = $downloaddir;
1840cdf0e10cSrcweir
1841cdf0e10cSrcweir	# evaluating the name of the download file
1842cdf0e10cSrcweir
1843c974372aSMatthias Seidel	if ( $allvariableshashref->{'AOODOWNLOADNAME'} )
1844fe0288c8SMatthias Seidel	{
1845fe0288c8SMatthias Seidel		$downloadname = set_download_filename($languagestringref, $allvariableshashref);
1846fe0288c8SMatthias Seidel	}
1847fe0288c8SMatthias Seidel	else
1848fe0288c8SMatthias Seidel	{
1849fe0288c8SMatthias Seidel		$downloadname = resolve_variables_in_downloadname($allvariableshashref, $downloadname, $languagestringref);
1850fe0288c8SMatthias Seidel	}
1851cdf0e10cSrcweir
1852cdf0e10cSrcweir	if ( ! $installer::globals::iswindowsbuild )	# Unix specific part
1853cdf0e10cSrcweir	{
1854cdf0e10cSrcweir
1855cdf0e10cSrcweir		# getting the path of the getuid.so (only required for Solaris and Linux)
1856cdf0e10cSrcweir		my $getuidlibrary = "";
1857cdf0e10cSrcweir		if (( $installer::globals::issolarisbuild ) || ( $installer::globals::islinuxbuild )) {	$getuidlibrary = get_path_for_library($includepatharrayref); }
1858cdf0e10cSrcweir
1859ff3f4ebcSOliver-Rainer Wittmann		if ( $allvariableshashref->{'AOODOWNLOADNAME'} )
1860cdf0e10cSrcweir		{
1861cdf0e10cSrcweir			my $downloadfile = create_tar_gz_file_from_directory($installationdir, $getuidlibrary, $downloaddir, $downloadname);
1862cdf0e10cSrcweir		}
1863cdf0e10cSrcweir		else
1864cdf0e10cSrcweir		{
1865cdf0e10cSrcweir			# find and read setup script template
1866cdf0e10cSrcweir			my $scriptfilename = "downloadscript.sh";
1867cdf0e10cSrcweir
1868cdf0e10cSrcweir			my $scriptref = "";
1869cdf0e10cSrcweir
1870cdf0e10cSrcweir			if ( $installer::globals::include_pathes_read )
1871cdf0e10cSrcweir			{
1872cdf0e10cSrcweir				$scriptref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$scriptfilename, $includepatharrayref, 0);
1873cdf0e10cSrcweir			}
1874cdf0e10cSrcweir			else
1875cdf0e10cSrcweir			{
1876cdf0e10cSrcweir				$scriptref = installer::scriptitems::get_sourcepath_from_filename_and_includepath_classic(\$scriptfilename, $includepatharrayref, 0);
1877cdf0e10cSrcweir			}
1878cdf0e10cSrcweir
1879cdf0e10cSrcweir			if ($$scriptref eq "") { installer::exiter::exit_program("ERROR: Could not find script file $scriptfilename!", "create_download_sets"); }
1880cdf0e10cSrcweir			my $scriptfile = installer::files::read_file($$scriptref);
1881cdf0e10cSrcweir
1882fe0288c8SMatthias Seidel			$installer::logger::Lang->printf("Found script file %s: %s \n", $scriptfilename, $$scriptref);
18831dba2a1aSmseidel
1884cdf0e10cSrcweir			# add product name into script template
1885cdf0e10cSrcweir			put_productname_into_script($scriptfile, $allvariableshashref);
1886cdf0e10cSrcweir
1887cdf0e10cSrcweir			# replace linenumber in script template
1888cdf0e10cSrcweir			put_linenumber_into_script($scriptfile);
1889cdf0e10cSrcweir
1890cdf0e10cSrcweir			# create tar file
1891cdf0e10cSrcweir			my $temporary_tarfile_name = $downloaddir . $installer::globals::separator . 'installset.tar';
1892c974372aSMatthias Seidel			my $size = tar_package($installationdir, $temporary_tarfile_name, $getuidlibrary);
1893fe0288c8SMatthias Seidel			installer::exiter::exit_program("ERROR: Could not create tar file $temporary_tarfile_name!", "create_download_sets") unless $size;
1894cdf0e10cSrcweir
1895cdf0e10cSrcweir			# calling sum to determine checksum and size of the tar file
1896cdf0e10cSrcweir			my $sumout = call_sum($temporary_tarfile_name);
18971dba2a1aSmseidel
1898cdf0e10cSrcweir			# writing checksum and size into scriptfile
1899cdf0e10cSrcweir			put_checksum_and_size_into_script($scriptfile, $sumout);
19001dba2a1aSmseidel
1901cdf0e10cSrcweir			# saving the script file
1902cdf0e10cSrcweir			my $newscriptfilename = determine_scriptfile_name($downloadname);
1903cdf0e10cSrcweir			$newscriptfilename = save_script_file($downloaddir, $newscriptfilename, $scriptfile);
1904cdf0e10cSrcweir
1905fe0288c8SMatthias Seidel			$installer::logger::Info->printf("... including installation set into %s ... \n", $newscriptfilename);
1906fe0288c8SMatthias Seidel			# Append tar file to script
1907c974372aSMatthias Seidel			include_tar_into_script($newscriptfilename, $temporary_tarfile_name);
1908cdf0e10cSrcweir		}
1909cdf0e10cSrcweir	}
1910cdf0e10cSrcweir	else	# Windows specific part
1911cdf0e10cSrcweir	{
1912cdf0e10cSrcweir		my $localnsisdir = installer::systemactions::create_directories("nsis", $languagestringref);
1913cdf0e10cSrcweir		# push(@installer::globals::removedirs, $localnsisdir);
1914cdf0e10cSrcweir
1915cdf0e10cSrcweir		# find nsis in the system
1916cdf0e10cSrcweir		my $nsispath = get_path_to_nsis_sdk();
1917cdf0e10cSrcweir
1918cdf0e10cSrcweir		if ( $nsispath eq "" ) {
1919cdf0e10cSrcweir			# If nsis is not found just skip the rest of this function
1920cdf0e10cSrcweir			# and do not create the NSIS file.
1921fe0288c8SMatthias Seidel			$installer::logger::Lang->print("\n");
1922fe0288c8SMatthias Seidel			$installer::logger::Lang->printf("No NSIS SDK found. Skipping the generation of NSIS file.\n");
1923fe0288c8SMatthias Seidel			$installer::logger::Info->print("... no NSIS SDK found. Skipping the generation of NSIS file ... \n");
1924cdf0e10cSrcweir			return $downloaddir;
1925cdf0e10cSrcweir		}
1926cdf0e10cSrcweir
1927cdf0e10cSrcweir		# copy language files into nsis directory and translate them
1928cdf0e10cSrcweir		copy_and_translate_nsis_language_files($nsispath, $localnsisdir, $languagesarrayref, $allvariableshashref);
19291dba2a1aSmseidel
1930cdf0e10cSrcweir		# find and read the nsi file template
1931cdf0e10cSrcweir		my $templatefilename = "downloadtemplate.nsi";
1932cdf0e10cSrcweir
1933cdf0e10cSrcweir		my $templateref = "";
1934cdf0e10cSrcweir
1935cdf0e10cSrcweir		if ( $installer::globals::include_pathes_read )
1936cdf0e10cSrcweir		{
1937cdf0e10cSrcweir			$templateref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$templatefilename, $includepatharrayref, 0);
1938cdf0e10cSrcweir		}
1939cdf0e10cSrcweir		else
1940cdf0e10cSrcweir		{
1941cdf0e10cSrcweir			$templateref = installer::scriptitems::get_sourcepath_from_filename_and_includepath_classic(\$templatefilename, $includepatharrayref, 0);
1942cdf0e10cSrcweir		}
1943cdf0e10cSrcweir
1944cdf0e10cSrcweir		if ($$templateref eq "") { installer::exiter::exit_program("ERROR: Could not find nsi template file $templatefilename!", "create_download_sets"); }
1945cdf0e10cSrcweir		my $templatefile = installer::files::read_file($$templateref);
1946cdf0e10cSrcweir
1947cdf0e10cSrcweir		# add product name into script template
1948cdf0e10cSrcweir		put_windows_productname_into_template($templatefile, $allvariableshashref);
1949cdf0e10cSrcweir		put_banner_bmp_into_template($templatefile, $includepatharrayref, $allvariableshashref);
1950cdf0e10cSrcweir		put_welcome_bmp_into_template($templatefile, $includepatharrayref, $allvariableshashref);
1951cdf0e10cSrcweir		put_setup_ico_into_template($templatefile, $includepatharrayref, $allvariableshashref);
19520b2dfbacSAndre Fischer		put_publisher_into_template($templatefile, $allvariableshashref);
19530b2dfbacSAndre Fischer		put_website_into_template($templatefile, $allvariableshashref);
1954cdf0e10cSrcweir		put_javafilename_into_template($templatefile, $allvariableshashref);
1955cdf0e10cSrcweir		put_windows_productversion_into_template($templatefile, $allvariableshashref);
1956cdf0e10cSrcweir		put_windows_productpath_into_template($templatefile, $allvariableshashref, $languagestringref, $localnsisdir);
1957cdf0e10cSrcweir		put_outputfilename_into_template($templatefile, $downloadname);
1958cdf0e10cSrcweir		put_filelist_into_template($templatefile, $installationdir);
1959cdf0e10cSrcweir		put_language_list_into_template($templatefile, $languagesarrayref);
1960cdf0e10cSrcweir		put_nsis_path_into_template($templatefile, $localnsisdir);
1961cdf0e10cSrcweir		put_output_path_into_template($templatefile, $downloaddir);
19621dba2a1aSmseidel
1963cdf0e10cSrcweir		my $nsifilename = save_script_file($localnsisdir, $templatefilename, $templatefile);
1964b274bc22SAndre Fischer
1965fe0288c8SMatthias Seidel		$installer::logger::Info->printf("... created NSIS file %s ... \n", $nsifilename);
19661dba2a1aSmseidel
1967cdf0e10cSrcweir		# starting the NSIS SDK to create the download file
19681dba2a1aSmseidel		call_nsis($nsispath, $nsifilename);
1969cdf0e10cSrcweir	}
19701dba2a1aSmseidel
1971cdf0e10cSrcweir	return $downloaddir;
1972cdf0e10cSrcweir}
1973cdf0e10cSrcweir
1974cdf0e10cSrcweir####################################################
1975957116b7SHerbert Dürr# Creating AOO upload tree
1976cdf0e10cSrcweir####################################################
1977cdf0e10cSrcweir
1978cdf0e10cSrcweirsub create_download_link_tree
1979cdf0e10cSrcweir{
1980cdf0e10cSrcweir	my ($downloaddir, $languagestringref, $allvariableshashref) = @_;
1981cdf0e10cSrcweir
1982fe0288c8SMatthias Seidel	$installer::logger::Info->print("\n");
1983fe0288c8SMatthias Seidel	$installer::logger::Info->print("******************************************\n");
1984fe0288c8SMatthias Seidel	$installer::logger::Info->print("... creating download hard link ...\n");
1985fe0288c8SMatthias Seidel	$installer::logger::Info->print("******************************************\n");
1986cdf0e10cSrcweir
1987cdf0e10cSrcweir	installer::logger::include_header_into_logfile("Creating download hard link:");
1988b274bc22SAndre Fischer	$installer::logger::Lang->print("\n");
1989b274bc22SAndre Fischer	$installer::logger::Lang->add_timestamp("Performance Info: Creating hard link, start");
1990cdf0e10cSrcweir
1991cdf0e10cSrcweir	if ( is_supported_platform() )
1992cdf0e10cSrcweir	{
1993cdf0e10cSrcweir		my $versionstring = "";
1994cdf0e10cSrcweir		# Already defined $installer::globals::oooversionstring and $installer::globals::ooodownloadfilename ?
19951dba2a1aSmseidel
1996cdf0e10cSrcweir		if ( ! $installer::globals::oooversionstring ) { $versionstring = get_current_version(); }
1997fe0288c8SMatthias Seidel		else { $versionstring = $installer::globals::oooversionstring; }
19981dba2a1aSmseidel
1999fe0288c8SMatthias Seidel		# Is $versionstring empty? If yes, there is nothing to do now.
2000cdf0e10cSrcweir
2001fe0288c8SMatthias Seidel		$installer::logger::Lang->printf("Version string is set to: %s\n", $versionstring);
20021dba2a1aSmseidel
2003cdf0e10cSrcweir		if ( $versionstring )
2004cdf0e10cSrcweir		{
2005cdf0e10cSrcweir			# Now the downloadfilename has to be set (if not already done)
2006cdf0e10cSrcweir			my $destdownloadfilename = "";
2007cdf0e10cSrcweir			if ( ! $installer::globals::ooodownloadfilename ) { $destdownloadfilename = set_download_filename($languagestringref, $versionstring, $allvariableshashref); }
2008cdf0e10cSrcweir			else { $destdownloadfilename = $installer::globals::ooodownloadfilename; }
2009cdf0e10cSrcweir
2010cdf0e10cSrcweir			if ( $destdownloadfilename )
2011cdf0e10cSrcweir			{
2012cdf0e10cSrcweir				$destdownloadfilename = $destdownloadfilename . $installer::globals::downloadfileextension;
2013b274bc22SAndre Fischer
2014fe0288c8SMatthias Seidel				$installer::logger::Lang->printf("Setting destination download file name: %s\n", $destdownloadfilename);
2015cdf0e10cSrcweir
2016cdf0e10cSrcweir				my $sourcedownloadfile = $downloaddir . $installer::globals::separator . $installer::globals::downloadfilename;
2017cdf0e10cSrcweir
2018fe0288c8SMatthias Seidel				$installer::logger::Lang->printf("Setting source download file name: %s\n", $sourcedownloadfile);
2019cdf0e10cSrcweir
2020cdf0e10cSrcweir				create_link_tree($sourcedownloadfile, $destdownloadfilename, $versionstring);
2021cdf0e10cSrcweir				# my $md5sumoutput = call_md5sum($downloadfile);
2022cdf0e10cSrcweir				# my $md5sum = get_md5sum($md5sumoutput);
20231dba2a1aSmseidel
2024cdf0e10cSrcweir			}
2025cdf0e10cSrcweir		}
2026cdf0e10cSrcweir		else
2027cdf0e10cSrcweir		{
2028fe0288c8SMatthias Seidel			$installer::logger::Lang->printf("Version string is empty. Nothing to do!\n");
2029fe0288c8SMatthias Seidel		}
20301dba2a1aSmseidel	}
2031cdf0e10cSrcweir	else
2032cdf0e10cSrcweir	{
2033fe0288c8SMatthias Seidel		$installer::logger::Lang->printf("Platform not used for hard linking. Nothing to do!\n");
2034cdf0e10cSrcweir	}
2035cdf0e10cSrcweir
2036b274bc22SAndre Fischer	$installer::logger::Lang->add_timestamp("Performance Info: Creating hard link, stop");
2037cdf0e10cSrcweir}
2038cdf0e10cSrcweir
2039cdf0e10cSrcweir1;
2040