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