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