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