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