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