xref: /trunk/main/solenv/bin/modules/installer/windows/msiglobal.pm (revision 8ac570c6d50c1ad9896c5c4a0f44668dbe040aef)
19780544fSAndrew Rist#**************************************************************
2cdf0e10cSrcweir#
39780544fSAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
49780544fSAndrew Rist#  or more contributor license agreements.  See the NOTICE file
59780544fSAndrew Rist#  distributed with this work for additional information
69780544fSAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
79780544fSAndrew Rist#  to you under the Apache License, Version 2.0 (the
89780544fSAndrew Rist#  "License"); you may not use this file except in compliance
99780544fSAndrew Rist#  with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir#
119780544fSAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir#
139780544fSAndrew Rist#  Unless required by applicable law or agreed to in writing,
149780544fSAndrew Rist#  software distributed under the License is distributed on an
159780544fSAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169780544fSAndrew Rist#  KIND, either express or implied.  See the License for the
179780544fSAndrew Rist#  specific language governing permissions and limitations
189780544fSAndrew Rist#  under the License.
19cdf0e10cSrcweir#
209780544fSAndrew Rist#**************************************************************
219780544fSAndrew Rist
22cdf0e10cSrcweirpackage installer::windows::msiglobal;
23cdf0e10cSrcweir
24cdf0e10cSrcweiruse Cwd;
25cdf0e10cSrcweiruse Digest::MD5;
26cdf0e10cSrcweiruse installer::converter;
27cdf0e10cSrcweiruse installer::exiter;
28cdf0e10cSrcweiruse installer::files;
29cdf0e10cSrcweiruse installer::globals;
30cdf0e10cSrcweiruse installer::logger;
31cdf0e10cSrcweiruse installer::pathanalyzer;
32cdf0e10cSrcweiruse installer::remover;
33cdf0e10cSrcweiruse installer::scriptitems;
34cdf0e10cSrcweiruse installer::systemactions;
35cdf0e10cSrcweiruse installer::worker;
36cdf0e10cSrcweiruse installer::windows::idtglobal;
37cdf0e10cSrcweiruse installer::windows::language;
389f91b7e3SAndre Fischeruse installer::patch::ReleasesList;
399f91b7e3SAndre Fischer
401ba1fd99SAndre Fischeruse strict;
41cdf0e10cSrcweir
42cdf0e10cSrcweir###########################################################################
43cdf0e10cSrcweir# Generating the header of the ddf file.
44cdf0e10cSrcweir# The usage of ddf files is needed, because makecab.exe can only include
45cdf0e10cSrcweir# one sourcefile into a cab file
46cdf0e10cSrcweir###########################################################################
47cdf0e10cSrcweir
48cdf0e10cSrcweirsub write_ddf_file_header
49cdf0e10cSrcweir{
50cdf0e10cSrcweir    my ($ddffileref, $cabinetfile, $installdir) = @_;
51cdf0e10cSrcweir
52cdf0e10cSrcweir    my $oneline;
53cdf0e10cSrcweir
54cdf0e10cSrcweir    $oneline = ".Set CabinetName1=" . $cabinetfile . "\n";
55cdf0e10cSrcweir    push(@{$ddffileref} ,$oneline);
56cdf0e10cSrcweir    $oneline = ".Set ReservePerCabinetSize=128\n";  # This reserves space for a digital signature.
57cdf0e10cSrcweir    push(@{$ddffileref} ,$oneline);
58cdf0e10cSrcweir    $oneline = ".Set MaxDiskSize=2147483648\n";     # This allows the .cab file to get a size of 2 GB.
59cdf0e10cSrcweir    push(@{$ddffileref} ,$oneline);
60cdf0e10cSrcweir    $oneline = ".Set CompressionType=LZX\n";
61cdf0e10cSrcweir    push(@{$ddffileref} ,$oneline);
62cdf0e10cSrcweir    $oneline = ".Set Compress=ON\n";
63cdf0e10cSrcweir    push(@{$ddffileref} ,$oneline);
64cdf0e10cSrcweir    $oneline = ".Set CompressionLevel=$installer::globals::cabfilecompressionlevel\n";
65cdf0e10cSrcweir    push(@{$ddffileref} ,$oneline);
66cdf0e10cSrcweir    $oneline = ".Set Cabinet=ON\n";
67cdf0e10cSrcweir    push(@{$ddffileref} ,$oneline);
68cdf0e10cSrcweir    $oneline = ".Set DiskDirectoryTemplate=" . $installdir . "\n";
69cdf0e10cSrcweir    push(@{$ddffileref} ,$oneline);
70cdf0e10cSrcweir}
71cdf0e10cSrcweir
72cdf0e10cSrcweir##########################################################################
73cdf0e10cSrcweir# Lines in ddf files must not contain more than 256 characters
74cdf0e10cSrcweir##########################################################################
75cdf0e10cSrcweir
76cdf0e10cSrcweirsub check_ddf_file
77cdf0e10cSrcweir{
78cdf0e10cSrcweir    my ( $ddffile, $ddffilename ) = @_;
79cdf0e10cSrcweir
80cdf0e10cSrcweir    my $maxlength = 0;
81cdf0e10cSrcweir    my $maxline = 0;
82cdf0e10cSrcweir    my $linelength = 0;
83cdf0e10cSrcweir    my $linenumber = 0;
84cdf0e10cSrcweir
85cdf0e10cSrcweir    for ( my $i = 0; $i <= $#{$ddffile}; $i++ )
86cdf0e10cSrcweir    {
87cdf0e10cSrcweir        my $oneline = ${$ddffile}[$i];
88cdf0e10cSrcweir
89cdf0e10cSrcweir        $linelength = length($oneline);
90cdf0e10cSrcweir        $linenumber = $i + 1;
91cdf0e10cSrcweir
92cdf0e10cSrcweir        if ( $linelength > 256 )
93cdf0e10cSrcweir        {
94cdf0e10cSrcweir            installer::exiter::exit_program("ERROR \"$ddffilename\" line $linenumber: Lines in ddf files must not contain more than 256 characters!", "check_ddf_file");
95cdf0e10cSrcweir        }
96cdf0e10cSrcweir
97cdf0e10cSrcweir        if ( $linelength > $maxlength )
98cdf0e10cSrcweir        {
99cdf0e10cSrcweir            $maxlength = $linelength;
100cdf0e10cSrcweir            $maxline = $linenumber;
101cdf0e10cSrcweir        }
102cdf0e10cSrcweir    }
103cdf0e10cSrcweir
104cdf0e10cSrcweir    my $infoline = "Check of ddf file \"$ddffilename\": Maximum length \"$maxlength\" in line \"$maxline\" (allowed line length: 256 characters)\n";
105b274bc22SAndre Fischer    $installer::logger::Lang->print($infoline);
106cdf0e10cSrcweir}
107cdf0e10cSrcweir
108cdf0e10cSrcweir##########################################################################
109cdf0e10cSrcweir# Lines in ddf files must not be longer than 256 characters.
11086e1cf34SPedro Giffuni# Therefore it can be useful to use relative paths. Then it is
111cdf0e10cSrcweir# necessary to change into temp directory before calling
112cdf0e10cSrcweir# makecab.exe.
113cdf0e10cSrcweir##########################################################################
114cdf0e10cSrcweir
115cdf0e10cSrcweirsub make_relative_ddf_path
116cdf0e10cSrcweir{
117cdf0e10cSrcweir    my ( $sourcepath ) = @_;
118cdf0e10cSrcweir
119cdf0e10cSrcweir    my $windowstemppath = $installer::globals::temppath;
120cdf0e10cSrcweir
121cdf0e10cSrcweir    if ( $^O =~ /cygwin/i )
122cdf0e10cSrcweir    {
123cdf0e10cSrcweir        $windowstemppath = $installer::globals::cyg_temppath;
124cdf0e10cSrcweir    }
125cdf0e10cSrcweir
126cdf0e10cSrcweir    $sourcepath =~ s/\Q$windowstemppath\E//;
127cdf0e10cSrcweir    $sourcepath =~ s/^\\//;
128cdf0e10cSrcweir
129cdf0e10cSrcweir    return $sourcepath;
130cdf0e10cSrcweir}
131cdf0e10cSrcweir
132cdf0e10cSrcweir
133cdf0e10cSrcweir##########################################################################
134*8ac570c6Smseidel# Generating the list, in which the source of the files is connected
135cdf0e10cSrcweir# with the cabinet destination file. Because more than one file needs
136cdf0e10cSrcweir# to be included into a cab file, this has to be done via ddf files.
137cdf0e10cSrcweir##########################################################################
138cdf0e10cSrcweir
139677600b0SAndre Fischersub generate_cab_file_list ($$$$)
140cdf0e10cSrcweir{
141cdf0e10cSrcweir    my ($filesref, $installdir, $ddfdir, $allvariables) = @_;
142cdf0e10cSrcweir
143cdf0e10cSrcweir    installer::logger::include_header_into_logfile("Generating ddf files");
144cdf0e10cSrcweir
145677600b0SAndre Fischer    if ( $^O =~ /cygwin/i )
146cdf0e10cSrcweir    {
147677600b0SAndre Fischer        installer::worker::generate_cygwin_pathes($filesref);
148cdf0e10cSrcweir    }
149cdf0e10cSrcweir
150677600b0SAndre Fischer    # Make sure that all files point to the same cabinet file.
151677600b0SAndre Fischer    # Multiple cabinet files are not supported anymore.
152677600b0SAndre Fischer    my $cabinetfile = $filesref->[0]->{'cabinet'};
153677600b0SAndre Fischer    foreach my $onefile (@$filesref)
154677600b0SAndre Fischer    {
155677600b0SAndre Fischer        if ($onefile->{'cabinet'} ne $cabinetfile)
156677600b0SAndre Fischer        {
157677600b0SAndre Fischer            installer::exiter::exit_program(
158677600b0SAndre Fischer                "ERROR: multiple cabinet files are not supported",
159677600b0SAndre Fischer                "generate_cab_file_list");
160677600b0SAndre Fischer        }
161677600b0SAndre Fischer    }
162677600b0SAndre Fischer
163677600b0SAndre Fischer    # Sort files on the sequence number.
164677600b0SAndre Fischer    my @sorted_files = sort {$a->{'sequencenumber'} <=> $b->{'sequencenumber'}} @$filesref;
165677600b0SAndre Fischer
166677600b0SAndre Fischer    my @ddffile = ();
167677600b0SAndre Fischer    write_ddf_file_header(\@ddffile, $cabinetfile, $installdir);
168677600b0SAndre Fischer    foreach my $onefile (@sorted_files)
169677600b0SAndre Fischer    {
170d62abd1aSAndre Fischer        my $styles = $onefile->{'Styles'};
171d62abd1aSAndre Fischer        $styles = "" unless defined $styles;
172677600b0SAndre Fischer        if ($styles =~ /\bDONT_PACK\b/)
173677600b0SAndre Fischer        {
174677600b0SAndre Fischer            $installer::logger::Lang->printf("    excluding '%s' from ddf\n", $onefile->{'uniquename'});
175677600b0SAndre Fischer        }
176677600b0SAndre Fischer
177677600b0SAndre Fischer        my $uniquename = $onefile->{'uniquename'};
178677600b0SAndre Fischer        my $sourcepath = $onefile->{'sourcepath'};
179677600b0SAndre Fischer        if ( $^O =~ /cygwin/i )
180677600b0SAndre Fischer        {
181677600b0SAndre Fischer            $sourcepath = $onefile->{'cyg_sourcepath'};
182677600b0SAndre Fischer        }
183677600b0SAndre Fischer
18486e1cf34SPedro Giffuni        # to avoid lines with more than 256 characters, it can be useful to use relative paths
185677600b0SAndre Fischer        if ($allvariables->{'RELATIVE_PATHES_IN_DDF'})
186677600b0SAndre Fischer        {
187677600b0SAndre Fischer            $sourcepath = make_relative_ddf_path($sourcepath);
188677600b0SAndre Fischer        }
189677600b0SAndre Fischer
190677600b0SAndre Fischer        my $ddfline = "\"" . $sourcepath . "\"" . " " . $uniquename . "\n";
191677600b0SAndre Fischer        push(@ddffile, $ddfline);
192677600b0SAndre Fischer
193677600b0SAndre Fischer        $installer::logger::Lang->printf("    adding '%s' with sequence %d to ddf\n",
194677600b0SAndre Fischer            $onefile->{'uniquename'},
195677600b0SAndre Fischer            $onefile->{'sequencenumber'});
196677600b0SAndre Fischer    }
197cdf0e10cSrcweir    # creating the DDF file
198cdf0e10cSrcweir
199cdf0e10cSrcweir    my $ddffilename = $cabinetfile;
200cdf0e10cSrcweir    $ddffilename =~ s/.cab/.ddf/;
201cdf0e10cSrcweir    $ddfdir =~ s/\Q$installer::globals::separator\E\s*$//;
202cdf0e10cSrcweir    $ddffilename = $ddfdir . $installer::globals::separator . $ddffilename;
203cdf0e10cSrcweir
204cdf0e10cSrcweir    installer::files::save_file($ddffilename ,\@ddffile);
205677600b0SAndre Fischer    $installer::logger::Lang->print("Created ddf file: %s\n", $ddffilename);
206cdf0e10cSrcweir
207cdf0e10cSrcweir    # lines in ddf files must not be longer than 256 characters
208cdf0e10cSrcweir    check_ddf_file(\@ddffile, $ddffilename);
209cdf0e10cSrcweir
210cdf0e10cSrcweir    # collecting all ddf files
211cdf0e10cSrcweir    push(@installer::globals::allddffiles, $ddffilename);
212cdf0e10cSrcweir
213cdf0e10cSrcweir    # Writing the makecab system call
214677600b0SAndre Fischer    # Return a list with all system calls for packaging process.
215677600b0SAndre Fischer    my @cabfilelist = ("makecab.exe /V3 /F " . $ddffilename . " 2\>\&1 |" . "\n");
216677600b0SAndre Fischer    return \@cabfilelist;
217cdf0e10cSrcweir}
218cdf0e10cSrcweir
219cdf0e10cSrcweir
220cdf0e10cSrcweir
221cdf0e10cSrcweir#################################################################
222cdf0e10cSrcweir# Returning the name of the msi database
223cdf0e10cSrcweir#################################################################
224cdf0e10cSrcweir
225cdf0e10cSrcweirsub get_msidatabasename
226cdf0e10cSrcweir{
227cdf0e10cSrcweir    my ($allvariableshashref, $language) = @_;
228cdf0e10cSrcweir
229cdf0e10cSrcweir    my $databasename = $allvariableshashref->{'PRODUCTNAME'} . $allvariableshashref->{'PRODUCTVERSION'};
230cdf0e10cSrcweir    $databasename = lc($databasename);
231cdf0e10cSrcweir    $databasename =~ s/\.//g;
232cdf0e10cSrcweir    $databasename =~ s/\-//g;
233cdf0e10cSrcweir    $databasename =~ s/\s//g;
234cdf0e10cSrcweir
235cdf0e10cSrcweir    # possibility to overwrite the name with variable DATABASENAME
236cdf0e10cSrcweir    if ( $allvariableshashref->{'DATABASENAME'} )
237cdf0e10cSrcweir    {
238cdf0e10cSrcweir        $databasename = $allvariableshashref->{'DATABASENAME'};
239cdf0e10cSrcweir    }
240cdf0e10cSrcweir
241cdf0e10cSrcweir    if ( $language )
242cdf0e10cSrcweir    {
243cdf0e10cSrcweir        if (!($language eq ""))
244cdf0e10cSrcweir        {
245cdf0e10cSrcweir            $databasename .= "_$language";
246cdf0e10cSrcweir        }
247cdf0e10cSrcweir    }
248cdf0e10cSrcweir
249cdf0e10cSrcweir    $databasename .= ".msi";
250cdf0e10cSrcweir
251cdf0e10cSrcweir    return $databasename;
252cdf0e10cSrcweir}
253cdf0e10cSrcweir
254cdf0e10cSrcweir#################################################################
255cdf0e10cSrcweir# Creating the msi database
256cdf0e10cSrcweir# This works only on Windows
257cdf0e10cSrcweir#################################################################
258cdf0e10cSrcweir
259cdf0e10cSrcweirsub create_msi_database
260cdf0e10cSrcweir{
261cdf0e10cSrcweir    my ($idtdirbase ,$msifilename) = @_;
262cdf0e10cSrcweir
263cdf0e10cSrcweir    # -f : path containing the idt files
264cdf0e10cSrcweir    # -d : msi database, including path
265cdf0e10cSrcweir    # -c : create database
266cdf0e10cSrcweir    # -i : include the following tables ("*" includes all available tables)
267cdf0e10cSrcweir
268cdf0e10cSrcweir    my $msidb = "msidb.exe";    # Has to be in the path
269cdf0e10cSrcweir    my $extraslash = "";        # Has to be set for non-ActiveState perl
270cdf0e10cSrcweir
271cdf0e10cSrcweir    installer::logger::include_header_into_logfile("Creating msi database");
272cdf0e10cSrcweir
273cdf0e10cSrcweir    $idtdirbase = installer::converter::make_path_conform($idtdirbase);
274cdf0e10cSrcweir
275cdf0e10cSrcweir    $msifilename = installer::converter::make_path_conform($msifilename);
276cdf0e10cSrcweir
277cdf0e10cSrcweir    if ( $^O =~ /cygwin/i ) {
278cdf0e10cSrcweir        # msidb.exe really wants backslashes. (And double escaping because system() expands the string.)
279cdf0e10cSrcweir        $idtdirbase =~ s/\//\\\\/g;
280cdf0e10cSrcweir        $msifilename =~ s/\//\\\\/g;
281cdf0e10cSrcweir        $extraslash = "\\";
282cdf0e10cSrcweir    }
283cdf0e10cSrcweir    my $systemcall = $msidb . " -f " . $idtdirbase . " -d " . $msifilename . " -c " . "-i " . $extraslash . "*";
284cdf0e10cSrcweir
285cdf0e10cSrcweir    my $returnvalue = system($systemcall);
286cdf0e10cSrcweir
287cdf0e10cSrcweir    my $infoline = "Systemcall: $systemcall\n";
288b274bc22SAndre Fischer    $installer::logger::Lang->print($infoline);
289cdf0e10cSrcweir
290cdf0e10cSrcweir    if ($returnvalue)
291cdf0e10cSrcweir    {
292cdf0e10cSrcweir        $infoline = "ERROR: Could not execute $msidb!\n";
293b274bc22SAndre Fischer        $installer::logger::Lang->print($infoline);
294cdf0e10cSrcweir    }
295cdf0e10cSrcweir    else
296cdf0e10cSrcweir    {
297cdf0e10cSrcweir        $infoline = "Success: Executed $msidb successfully!\n";
298b274bc22SAndre Fischer        $installer::logger::Lang->print($infoline);
299cdf0e10cSrcweir    }
300cdf0e10cSrcweir}
301cdf0e10cSrcweir
302cdf0e10cSrcweir#####################################################################
303cdf0e10cSrcweir# Returning the value from sis.mlf for Summary Information Stream
304cdf0e10cSrcweir#####################################################################
305cdf0e10cSrcweir
306cdf0e10cSrcweirsub get_value_from_sis_lng
307cdf0e10cSrcweir{
308cdf0e10cSrcweir    my ($language, $languagefile, $searchstring) = @_;
309cdf0e10cSrcweir
310cdf0e10cSrcweir    my $language_block = installer::windows::idtglobal::get_language_block_from_language_file($searchstring, $languagefile);
311cdf0e10cSrcweir    my $newstring = installer::windows::idtglobal::get_language_string_from_language_block($language_block, $language, $searchstring);
312cdf0e10cSrcweir    $newstring = "\"" . $newstring . "\"";
313cdf0e10cSrcweir
314cdf0e10cSrcweir    return $newstring;
315cdf0e10cSrcweir}
316cdf0e10cSrcweir
317cdf0e10cSrcweir#################################################################
318cdf0e10cSrcweir# Returning the msi version for the Summary Information Stream
319cdf0e10cSrcweir#################################################################
320cdf0e10cSrcweir
321cdf0e10cSrcweirsub get_msiversion_for_sis
322cdf0e10cSrcweir{
323cdf0e10cSrcweir    my $msiversion = "200";
324cdf0e10cSrcweir    return $msiversion;
325cdf0e10cSrcweir}
326cdf0e10cSrcweir
327cdf0e10cSrcweir#################################################################
328cdf0e10cSrcweir# Returning the word count for the Summary Information Stream
329cdf0e10cSrcweir#################################################################
330cdf0e10cSrcweir
331cdf0e10cSrcweirsub get_wordcount_for_sis
332cdf0e10cSrcweir{
333cdf0e10cSrcweir    my $wordcount = "0";
334cdf0e10cSrcweir    return $wordcount;
335cdf0e10cSrcweir}
336cdf0e10cSrcweir
337cdf0e10cSrcweir#################################################################
338cdf0e10cSrcweir# Returning the codepage for the Summary Information Stream
339cdf0e10cSrcweir#################################################################
340cdf0e10cSrcweir
341cdf0e10cSrcweirsub get_codepage_for_sis
342cdf0e10cSrcweir{
343cdf0e10cSrcweir    my ( $language ) = @_;
344cdf0e10cSrcweir
345cdf0e10cSrcweir    my $codepage = installer::windows::language::get_windows_encoding($language);
346cdf0e10cSrcweir
347cdf0e10cSrcweir    # Codepage 65001 does not work in Summary Information Stream
348cdf0e10cSrcweir    if ( $codepage == 65001 ) { $codepage = 0; }
349cdf0e10cSrcweir
350cdf0e10cSrcweir    # my $codepage = "1252";    # determine dynamically in a function
351cdf0e10cSrcweir    # my $codepage = "65001";       # UTF-8
352cdf0e10cSrcweir    return $codepage;
353cdf0e10cSrcweir}
354cdf0e10cSrcweir
355cdf0e10cSrcweir#################################################################
356cdf0e10cSrcweir# Returning the template for the Summary Information Stream
357cdf0e10cSrcweir#################################################################
358cdf0e10cSrcweir
359cdf0e10cSrcweirsub get_template_for_sis
360cdf0e10cSrcweir{
361cdf0e10cSrcweir    my ( $language, $allvariables ) = @_;
362cdf0e10cSrcweir
363cdf0e10cSrcweir    my $windowslanguage = installer::windows::language::get_windows_language($language);
364cdf0e10cSrcweir
365cdf0e10cSrcweir    my $architecture = "Intel";
366cdf0e10cSrcweir
367cdf0e10cSrcweir    # Adding 256, if this is a 64 bit installation set.
368cdf0e10cSrcweir    if (( $allvariables->{'64BITPRODUCT'} ) && ( $allvariables->{'64BITPRODUCT'} == 1 )) { $architecture = "x64"; }
369cdf0e10cSrcweir
370cdf0e10cSrcweir    my $value = "\"" . $architecture . ";" . $windowslanguage;  # adding the Windows language
371cdf0e10cSrcweir
372cdf0e10cSrcweir    $value = $value . "\"";                     # adding ending '"'
373cdf0e10cSrcweir
374cdf0e10cSrcweir    return $value ;
375cdf0e10cSrcweir}
376cdf0e10cSrcweir
377cdf0e10cSrcweir#################################################################
378cdf0e10cSrcweir# Returning the PackageCode for the Summary Information Stream
379cdf0e10cSrcweir#################################################################
380cdf0e10cSrcweir
381cdf0e10cSrcweirsub get_packagecode_for_sis
382cdf0e10cSrcweir{
383cdf0e10cSrcweir    # always generating a new package code for each package
384cdf0e10cSrcweir
3859f91b7e3SAndre Fischer    my $guid = "\{" . create_guid() . "\}";
386cdf0e10cSrcweir
387cdf0e10cSrcweir    my $infoline = "PackageCode: $guid\n";
388b274bc22SAndre Fischer    $installer::logger::Lang->print($infoline);
389cdf0e10cSrcweir
390cdf0e10cSrcweir    return $guid;
391cdf0e10cSrcweir}
392cdf0e10cSrcweir
393cdf0e10cSrcweir#################################################################
394cdf0e10cSrcweir# Returning the title for the Summary Information Stream
395cdf0e10cSrcweir#################################################################
396cdf0e10cSrcweir
397cdf0e10cSrcweirsub get_title_for_sis
398cdf0e10cSrcweir{
399cdf0e10cSrcweir    my ( $language, $languagefile, $searchstring ) = @_;
400cdf0e10cSrcweir
401cdf0e10cSrcweir    my $title = get_value_from_sis_lng($language, $languagefile, $searchstring );
402cdf0e10cSrcweir
403cdf0e10cSrcweir    return $title;
404cdf0e10cSrcweir}
405cdf0e10cSrcweir
406cdf0e10cSrcweir#################################################################
407cdf0e10cSrcweir# Returning the author for the Summary Information Stream
408cdf0e10cSrcweir#################################################################
409cdf0e10cSrcweir
410cdf0e10cSrcweirsub get_author_for_sis
411cdf0e10cSrcweir{
412cdf0e10cSrcweir    my $author = $installer::globals::longmanufacturer;
413cdf0e10cSrcweir
414cdf0e10cSrcweir    $author = "\"" . $author . "\"";
415cdf0e10cSrcweir
416cdf0e10cSrcweir    return $author;
417cdf0e10cSrcweir}
418cdf0e10cSrcweir
419cdf0e10cSrcweir#################################################################
420cdf0e10cSrcweir# Returning the subject for the Summary Information Stream
421cdf0e10cSrcweir#################################################################
422cdf0e10cSrcweir
423cdf0e10cSrcweirsub get_subject_for_sis
424cdf0e10cSrcweir{
425cdf0e10cSrcweir    my ( $allvariableshashref ) = @_;
426cdf0e10cSrcweir
427cdf0e10cSrcweir    my $subject = $allvariableshashref->{'PRODUCTNAME'} . " " . $allvariableshashref->{'PRODUCTVERSION'};
428cdf0e10cSrcweir
429cdf0e10cSrcweir    $subject = "\"" . $subject . "\"";
430cdf0e10cSrcweir
431cdf0e10cSrcweir    return $subject;
432cdf0e10cSrcweir}
433cdf0e10cSrcweir
434cdf0e10cSrcweir#################################################################
435cdf0e10cSrcweir# Returning the comment for the Summary Information Stream
436cdf0e10cSrcweir#################################################################
437cdf0e10cSrcweir
438cdf0e10cSrcweirsub get_comment_for_sis
439cdf0e10cSrcweir{
440cdf0e10cSrcweir    my ( $language, $languagefile, $searchstring ) = @_;
441cdf0e10cSrcweir
442cdf0e10cSrcweir    my $comment = get_value_from_sis_lng($language, $languagefile, $searchstring );
443cdf0e10cSrcweir
444cdf0e10cSrcweir    return $comment;
445cdf0e10cSrcweir}
446cdf0e10cSrcweir
447cdf0e10cSrcweir#################################################################
448cdf0e10cSrcweir# Returning the keywords for the Summary Information Stream
449cdf0e10cSrcweir#################################################################
450cdf0e10cSrcweir
451cdf0e10cSrcweirsub get_keywords_for_sis
452cdf0e10cSrcweir{
453cdf0e10cSrcweir    my ( $language, $languagefile, $searchstring ) = @_;
454cdf0e10cSrcweir
455cdf0e10cSrcweir    my $keywords = get_value_from_sis_lng($language, $languagefile, $searchstring );
456cdf0e10cSrcweir
457cdf0e10cSrcweir    return $keywords;
458cdf0e10cSrcweir}
459cdf0e10cSrcweir
460cdf0e10cSrcweir######################################################################
461cdf0e10cSrcweir# Returning the application name for the Summary Information Stream
462cdf0e10cSrcweir######################################################################
463cdf0e10cSrcweir
464cdf0e10cSrcweirsub get_appname_for_sis
465cdf0e10cSrcweir{
466cdf0e10cSrcweir    my ( $language, $languagefile, $searchstring ) = @_;
467cdf0e10cSrcweir
468cdf0e10cSrcweir    my $appname = get_value_from_sis_lng($language, $languagefile, $searchstring );
469cdf0e10cSrcweir
470cdf0e10cSrcweir    return $appname;
471cdf0e10cSrcweir}
472cdf0e10cSrcweir
473cdf0e10cSrcweir######################################################################
474cdf0e10cSrcweir# Returning the security for the Summary Information Stream
475cdf0e10cSrcweir######################################################################
476cdf0e10cSrcweir
477cdf0e10cSrcweirsub get_security_for_sis
478cdf0e10cSrcweir{
479cdf0e10cSrcweir    my $security = "0";
480cdf0e10cSrcweir    return $security;
481cdf0e10cSrcweir}
482cdf0e10cSrcweir
483cdf0e10cSrcweir#################################################################
484cdf0e10cSrcweir# Writing the Summary information stream into the msi database
485cdf0e10cSrcweir# This works only on Windows
486cdf0e10cSrcweir#################################################################
487cdf0e10cSrcweir
488cdf0e10cSrcweirsub write_summary_into_msi_database
489cdf0e10cSrcweir{
490cdf0e10cSrcweir    my ($msifilename, $language, $languagefile, $allvariableshashref) = @_;
491cdf0e10cSrcweir
492*8ac570c6Smseidel    # -g : required msi version
493cdf0e10cSrcweir    # -c : codepage
494cdf0e10cSrcweir    # -p : template
495cdf0e10cSrcweir
496cdf0e10cSrcweir    installer::logger::include_header_into_logfile("Writing summary information stream");
497cdf0e10cSrcweir
498cdf0e10cSrcweir    my $msiinfo = "msiinfo.exe";    # Has to be in the path
499cdf0e10cSrcweir
500*8ac570c6Smseidel    my $sislanguage = "en-US";  # title, comment, keyword and appname always in English
501cdf0e10cSrcweir
502cdf0e10cSrcweir    my $msiversion = get_msiversion_for_sis();
503cdf0e10cSrcweir    my $codepage = get_codepage_for_sis($language);
504cdf0e10cSrcweir    my $template = get_template_for_sis($language, $allvariableshashref);
505cdf0e10cSrcweir    my $guid = get_packagecode_for_sis();
506cdf0e10cSrcweir    my $title = get_title_for_sis($sislanguage,$languagefile, "OOO_SIS_TITLE");
507cdf0e10cSrcweir    my $author = get_author_for_sis();
508cdf0e10cSrcweir    my $subject = get_subject_for_sis($allvariableshashref);
509cdf0e10cSrcweir    my $comment = get_comment_for_sis($sislanguage,$languagefile, "OOO_SIS_COMMENT");
510cdf0e10cSrcweir    my $keywords = get_keywords_for_sis($sislanguage,$languagefile, "OOO_SIS_KEYWORDS");
511cdf0e10cSrcweir    my $appname = get_appname_for_sis($sislanguage,$languagefile, "OOO_SIS_APPNAME");
512cdf0e10cSrcweir    my $security = get_security_for_sis();
513cdf0e10cSrcweir    my $wordcount = get_wordcount_for_sis();
514cdf0e10cSrcweir
515cdf0e10cSrcweir    $msifilename = installer::converter::make_path_conform($msifilename);
516cdf0e10cSrcweir
517cdf0e10cSrcweir    my $systemcall = $msiinfo . " " . $msifilename . " -g " . $msiversion . " -c " . $codepage
518cdf0e10cSrcweir                    . " -p " . $template . " -v " . $guid . " -t " . $title . " -a " . $author
519cdf0e10cSrcweir                    . " -j " . $subject . " -o " . $comment . " -k " . $keywords . " -n " . $appname
520cdf0e10cSrcweir                    . " -u " . $security . " -w " . $wordcount;
521cdf0e10cSrcweir
522cdf0e10cSrcweir    my $returnvalue = system($systemcall);
523cdf0e10cSrcweir
524cdf0e10cSrcweir    my $infoline = "Systemcall: $systemcall\n";
525b274bc22SAndre Fischer    $installer::logger::Lang->print($infoline);
526cdf0e10cSrcweir
527cdf0e10cSrcweir    if ($returnvalue)
528cdf0e10cSrcweir    {
529cdf0e10cSrcweir        $infoline = "ERROR: Could not execute $msiinfo!\n";
530b274bc22SAndre Fischer        $installer::logger::Lang->print($infoline);
531cdf0e10cSrcweir    }
532cdf0e10cSrcweir    else
533cdf0e10cSrcweir    {
534cdf0e10cSrcweir        $infoline = "Success: Executed $msiinfo successfully!\n";
535b274bc22SAndre Fischer        $installer::logger::Lang->print($infoline);
536cdf0e10cSrcweir    }
537cdf0e10cSrcweir}
538cdf0e10cSrcweir
539cdf0e10cSrcweir#########################################################################
540cdf0e10cSrcweir# For more than one language in the installation set:
541cdf0e10cSrcweir# Use one database and create Transformations for all other languages
542cdf0e10cSrcweir#########################################################################
543cdf0e10cSrcweir
544cdf0e10cSrcweirsub create_transforms
545cdf0e10cSrcweir{
546cdf0e10cSrcweir    my ($languagesarray, $defaultlanguage, $installdir, $allvariableshashref) = @_;
547cdf0e10cSrcweir
548cdf0e10cSrcweir    installer::logger::include_header_into_logfile("Creating Transforms");
549cdf0e10cSrcweir
550cdf0e10cSrcweir    my $msitran = "msitran.exe";    # Has to be in the path
551cdf0e10cSrcweir
552cdf0e10cSrcweir    $installdir = installer::converter::make_path_conform($installdir);
553cdf0e10cSrcweir
554cdf0e10cSrcweir    # Syntax for creating a transformation
555cdf0e10cSrcweir    # msitran.exe -g <baseDB> <referenceDB> <transformfile> [<errorhandling>}
556cdf0e10cSrcweir
557cdf0e10cSrcweir    my $basedbname = get_msidatabasename($allvariableshashref, $defaultlanguage);
558cdf0e10cSrcweir    $basedbname = $installdir . $installer::globals::separator . $basedbname;
559cdf0e10cSrcweir
560cdf0e10cSrcweir    my $errorhandling = "f";    # Suppress "change codepage" error
561cdf0e10cSrcweir
562cdf0e10cSrcweir    # Iterating over all files
563cdf0e10cSrcweir
564cdf0e10cSrcweir    foreach ( @{$languagesarray} )
565cdf0e10cSrcweir    {
566cdf0e10cSrcweir        my $onelanguage = $_;
567cdf0e10cSrcweir
568cdf0e10cSrcweir        if ( $onelanguage eq $defaultlanguage ) { next; }
569cdf0e10cSrcweir
570cdf0e10cSrcweir        my $referencedbname = get_msidatabasename($allvariableshashref, $onelanguage);
571cdf0e10cSrcweir        $referencedbname = $installdir . $installer::globals::separator . $referencedbname;
572cdf0e10cSrcweir
573cdf0e10cSrcweir        my $transformfile = $installdir . $installer::globals::separator . "trans_" . $onelanguage . ".mst";
574cdf0e10cSrcweir
575cdf0e10cSrcweir        my $systemcall = $msitran . " " . " -g " . $basedbname . " " . $referencedbname . " " . $transformfile . " " . $errorhandling;
576cdf0e10cSrcweir
577cdf0e10cSrcweir        my $returnvalue = system($systemcall);
578cdf0e10cSrcweir
579cdf0e10cSrcweir        my $infoline = "Systemcall: $systemcall\n";
580b274bc22SAndre Fischer        $installer::logger::Lang->print($infoline);
581cdf0e10cSrcweir
58286e1cf34SPedro Giffuni        # Problem: msitran.exe in version 4.0 always returns "1", even if no failure occurred.
583cdf0e10cSrcweir        # Therefore it has to be checked, if this is version 4.0. If yes, if the mst file
58486e1cf34SPedro Giffuni        # exists and if it is larger than 0 bytes. If this is true, then no error occurred.
585cdf0e10cSrcweir        # File Version of msitran.exe: 4.0.6000.16384 has checksum: "b66190a70145a57773ec769e16777b29".
586cdf0e10cSrcweir        # Same for msitran.exe from wntmsci12: "aa25d3445b94ffde8ef0c1efb77a56b8"
587cdf0e10cSrcweir
588cdf0e10cSrcweir        if ($returnvalue)
589cdf0e10cSrcweir        {
590cdf0e10cSrcweir            $infoline = "WARNING: Returnvalue of $msitran is not 0. Checking version of $msitran!\n";
591b274bc22SAndre Fischer            $installer::logger::Lang->print($infoline);
592cdf0e10cSrcweir
593cdf0e10cSrcweir            open(FILE, "<$installer::globals::msitranpath") or die "ERROR: Can't open $installer::globals::msitranpath for creating file hash";
594cdf0e10cSrcweir            binmode(FILE);
595cdf0e10cSrcweir            my $digest = Digest::MD5->new->addfile(*FILE)->hexdigest;
596cdf0e10cSrcweir            close(FILE);
597cdf0e10cSrcweir
598cdf0e10cSrcweir            my @problemchecksums = ("b66190a70145a57773ec769e16777b29", "aa25d3445b94ffde8ef0c1efb77a56b8");
599cdf0e10cSrcweir            my $isproblemchecksum = 0;
600cdf0e10cSrcweir
601cdf0e10cSrcweir            foreach my $problemchecksum ( @problemchecksums )
602cdf0e10cSrcweir            {
603cdf0e10cSrcweir                $infoline = "Checksum of problematic MsiTran.exe: $problemchecksum\n";
604b274bc22SAndre Fischer                $installer::logger::Lang->print($infoline);
605cdf0e10cSrcweir                $infoline = "Checksum of used MsiTran.exe: $digest\n";
606b274bc22SAndre Fischer                $installer::logger::Lang->print($infoline);
607cdf0e10cSrcweir                if ( $digest eq $problemchecksum ) { $isproblemchecksum = 1; }
608cdf0e10cSrcweir            }
609cdf0e10cSrcweir
610cdf0e10cSrcweir            if ( $isproblemchecksum )
611cdf0e10cSrcweir            {
612cdf0e10cSrcweir                # Check existence of mst
613cdf0e10cSrcweir                if ( -f $transformfile )
614cdf0e10cSrcweir                {
615cdf0e10cSrcweir                    $infoline = "File $transformfile exists.\n";
616b274bc22SAndre Fischer                    $installer::logger::Lang->print($infoline);
617cdf0e10cSrcweir                    my $filesize = ( -s $transformfile );
618cdf0e10cSrcweir                    $infoline = "Size of $transformfile: $filesize\n";
619b274bc22SAndre Fischer                    $installer::logger::Lang->print($infoline);
620cdf0e10cSrcweir
621cdf0e10cSrcweir                    if ( $filesize > 0 )
622cdf0e10cSrcweir                    {
623cdf0e10cSrcweir                        $infoline = "Info: Returnvalue $returnvalue of $msitran is no problem :-) .\n";
624b274bc22SAndre Fischer                        $installer::logger::Lang->print($infoline);
625cdf0e10cSrcweir                        $returnvalue = 0; # reset the error
626cdf0e10cSrcweir                    }
627cdf0e10cSrcweir                    else
628cdf0e10cSrcweir                    {
62986e1cf34SPedro Giffuni                        $infoline = "Filesize indicates that an error occurred.\n";
630b274bc22SAndre Fischer                        $installer::logger::Lang->print($infoline);
631cdf0e10cSrcweir                    }
632cdf0e10cSrcweir                }
633cdf0e10cSrcweir                else
634cdf0e10cSrcweir                {
63586e1cf34SPedro Giffuni                    $infoline = "File $transformfile does not exist -> An error occurred.\n";
636b274bc22SAndre Fischer                    $installer::logger::Lang->print($infoline);
637cdf0e10cSrcweir                }
638cdf0e10cSrcweir            }
639cdf0e10cSrcweir            else
640cdf0e10cSrcweir            {
641cdf0e10cSrcweir                $infoline = "This is not a problematic version of msitran.exe. Therefore the error is not caused by problematic msitran.exe.\n";
642b274bc22SAndre Fischer                $installer::logger::Lang->print($infoline);
643cdf0e10cSrcweir            }
644cdf0e10cSrcweir        }
645cdf0e10cSrcweir
646cdf0e10cSrcweir        if ($returnvalue)
647cdf0e10cSrcweir        {
648cdf0e10cSrcweir            $infoline = "ERROR: Could not execute $msitran!\n";
649b274bc22SAndre Fischer            $installer::logger::Lang->print($infoline);
650cdf0e10cSrcweir        }
651cdf0e10cSrcweir        else
652cdf0e10cSrcweir        {
653cdf0e10cSrcweir            $infoline = "Success: Executed $msitran successfully!\n";
654b274bc22SAndre Fischer            $installer::logger::Lang->print($infoline);
655cdf0e10cSrcweir        }
656cdf0e10cSrcweir
657cdf0e10cSrcweir        # The reference database can be deleted
658cdf0e10cSrcweir
659cdf0e10cSrcweir        my $result = unlink($referencedbname);
660cdf0e10cSrcweir        # $result contains the number of deleted files
661cdf0e10cSrcweir
662cdf0e10cSrcweir        if ( $result == 0 )
663cdf0e10cSrcweir        {
664cdf0e10cSrcweir            $infoline = "ERROR: Could not remove file $$referencedbname !\n";
665b274bc22SAndre Fischer            $installer::logger::Lang->print($infoline);
666cdf0e10cSrcweir            installer::exiter::exit_program($infoline, "create_transforms");
667cdf0e10cSrcweir        }
668cdf0e10cSrcweir    }
669cdf0e10cSrcweir}
670cdf0e10cSrcweir
671cdf0e10cSrcweir#########################################################################
672cdf0e10cSrcweir# The default language msi database does not need to contain
673cdf0e10cSrcweir# the language in the database name. Therefore the file
674cdf0e10cSrcweir# is renamed. Example: "openofficeorg20_01.msi" to "openofficeorg20.msi"
675cdf0e10cSrcweir#########################################################################
676cdf0e10cSrcweir
677cdf0e10cSrcweirsub rename_msi_database_in_installset
678cdf0e10cSrcweir{
679cdf0e10cSrcweir    my ($defaultlanguage, $installdir, $allvariableshashref) = @_;
680cdf0e10cSrcweir
681cdf0e10cSrcweir    installer::logger::include_header_into_logfile("Renaming msi database");
682cdf0e10cSrcweir
683cdf0e10cSrcweir    my $olddatabasename = get_msidatabasename($allvariableshashref, $defaultlanguage);
684cdf0e10cSrcweir    $olddatabasename = $installdir . $installer::globals::separator . $olddatabasename;
685cdf0e10cSrcweir
686cdf0e10cSrcweir    my $newdatabasename = get_msidatabasename($allvariableshashref);
687cdf0e10cSrcweir
688cdf0e10cSrcweir    $installer::globals::shortmsidatabasename = $newdatabasename;
689cdf0e10cSrcweir
690cdf0e10cSrcweir    $newdatabasename = $installdir . $installer::globals::separator . $newdatabasename;
691cdf0e10cSrcweir
692cdf0e10cSrcweir    installer::systemactions::rename_one_file($olddatabasename, $newdatabasename);
693cdf0e10cSrcweir
694cdf0e10cSrcweir    $installer::globals::msidatabasename = $newdatabasename;
695cdf0e10cSrcweir}
696cdf0e10cSrcweir
697cdf0e10cSrcweir#########################################################################
698cdf0e10cSrcweir# Adding the language to the name of the msi databasename,
699cdf0e10cSrcweir# if this is required (ADDLANGUAGEINDATABASENAME)
700cdf0e10cSrcweir#########################################################################
701cdf0e10cSrcweir
702cdf0e10cSrcweirsub add_language_to_msi_database
703cdf0e10cSrcweir{
704cdf0e10cSrcweir    my ($defaultlanguage, $installdir, $allvariables) = @_;
705cdf0e10cSrcweir
706cdf0e10cSrcweir    my $languagestring = $defaultlanguage;
707cdf0e10cSrcweir    if ( $allvariables->{'USELANGUAGECODE'} ) { $languagestring = installer::windows::language::get_windows_language($defaultlanguage); }
708cdf0e10cSrcweir    my $newdatabasename = $installer::globals::shortmsidatabasename;
709cdf0e10cSrcweir    $newdatabasename =~ s/\.msi\s*$/_$languagestring\.msi/;
710cdf0e10cSrcweir    $installer::globals::shortmsidatabasename = $newdatabasename;
711cdf0e10cSrcweir    $newdatabasename = $installdir . $installer::globals::separator . $newdatabasename;
712cdf0e10cSrcweir
713cdf0e10cSrcweir    my $olddatabasename = $installer::globals::msidatabasename;
714cdf0e10cSrcweir
715cdf0e10cSrcweir    installer::systemactions::rename_one_file($olddatabasename, $newdatabasename);
716cdf0e10cSrcweir
717cdf0e10cSrcweir    $installer::globals::msidatabasename = $newdatabasename;
718cdf0e10cSrcweir}
719cdf0e10cSrcweir
720cdf0e10cSrcweir##########################################################################
721cdf0e10cSrcweir# Writing the databasename into the setup.ini.
722cdf0e10cSrcweir##########################################################################
723cdf0e10cSrcweir
724cdf0e10cSrcweirsub put_databasename_into_setupini
725cdf0e10cSrcweir{
726cdf0e10cSrcweir    my ($setupinifile, $allvariableshashref) = @_;
727cdf0e10cSrcweir
728cdf0e10cSrcweir    my $databasename = get_msidatabasename($allvariableshashref);
729cdf0e10cSrcweir    my $line = "database=" . $databasename . "\n";
730cdf0e10cSrcweir
731cdf0e10cSrcweir    push(@{$setupinifile}, $line);
732cdf0e10cSrcweir}
733cdf0e10cSrcweir
734cdf0e10cSrcweir##########################################################################
735cdf0e10cSrcweir# Writing the required msi version into setup.ini
736cdf0e10cSrcweir##########################################################################
737cdf0e10cSrcweir
738cdf0e10cSrcweirsub put_msiversion_into_setupini
739cdf0e10cSrcweir{
740cdf0e10cSrcweir    my ($setupinifile) = @_;
741cdf0e10cSrcweir
742cdf0e10cSrcweir    my $msiversion = "2.0";
743cdf0e10cSrcweir    my $line = "msiversion=" . $msiversion . "\n";
744cdf0e10cSrcweir
745cdf0e10cSrcweir    push(@{$setupinifile}, $line);
746cdf0e10cSrcweir}
747cdf0e10cSrcweir
748cdf0e10cSrcweir##########################################################################
749cdf0e10cSrcweir# Writing the productname into setup.ini
750cdf0e10cSrcweir##########################################################################
751cdf0e10cSrcweir
752cdf0e10cSrcweirsub put_productname_into_setupini
753cdf0e10cSrcweir{
754cdf0e10cSrcweir    my ($setupinifile, $allvariableshashref) = @_;
755cdf0e10cSrcweir
756cdf0e10cSrcweir    my $productname = $allvariableshashref->{'PRODUCTNAME'};
757cdf0e10cSrcweir    my $line = "productname=" . $productname . "\n";
758cdf0e10cSrcweir
759cdf0e10cSrcweir    push(@{$setupinifile}, $line);
760cdf0e10cSrcweir}
761cdf0e10cSrcweir
762cdf0e10cSrcweir##########################################################################
763cdf0e10cSrcweir# Writing the productcode into setup.ini
764cdf0e10cSrcweir##########################################################################
765cdf0e10cSrcweir
766cdf0e10cSrcweirsub put_productcode_into_setupini
767cdf0e10cSrcweir{
768cdf0e10cSrcweir    my ($setupinifile) = @_;
769cdf0e10cSrcweir
770cdf0e10cSrcweir    my $productcode = $installer::globals::productcode;
771cdf0e10cSrcweir    my $line = "productcode=" . $productcode . "\n";
772cdf0e10cSrcweir
773cdf0e10cSrcweir    push(@{$setupinifile}, $line);
774cdf0e10cSrcweir}
775cdf0e10cSrcweir
776cdf0e10cSrcweir##########################################################################
777cdf0e10cSrcweir# Writing the ProductVersion from Property table into setup.ini
778cdf0e10cSrcweir##########################################################################
779cdf0e10cSrcweir
780cdf0e10cSrcweirsub put_productversion_into_setupini
781cdf0e10cSrcweir{
782cdf0e10cSrcweir    my ($setupinifile) = @_;
783cdf0e10cSrcweir
784cdf0e10cSrcweir    my $line = "productversion=" . $installer::globals::msiproductversion . "\n";
785cdf0e10cSrcweir    push(@{$setupinifile}, $line);
786cdf0e10cSrcweir}
787cdf0e10cSrcweir
788cdf0e10cSrcweir##########################################################################
789cdf0e10cSrcweir# Writing the key for Minor Upgrades into setup.ini
790cdf0e10cSrcweir##########################################################################
791cdf0e10cSrcweir
792cdf0e10cSrcweirsub put_upgradekey_into_setupini
793cdf0e10cSrcweir{
794cdf0e10cSrcweir    my ($setupinifile) = @_;
795cdf0e10cSrcweir
796cdf0e10cSrcweir    if ( $installer::globals::minorupgradekey ne "" )
797cdf0e10cSrcweir    {
798cdf0e10cSrcweir        my $line = "upgradekey=" . $installer::globals::minorupgradekey . "\n";
799cdf0e10cSrcweir        push(@{$setupinifile}, $line);
800cdf0e10cSrcweir    }
801cdf0e10cSrcweir}
802cdf0e10cSrcweir
803cdf0e10cSrcweir##########################################################################
804cdf0e10cSrcweir# Writing the number of languages into setup.ini
805cdf0e10cSrcweir##########################################################################
806cdf0e10cSrcweir
807cdf0e10cSrcweirsub put_languagecount_into_setupini
808cdf0e10cSrcweir{
809cdf0e10cSrcweir    my ($setupinifile, $languagesarray) = @_;
810cdf0e10cSrcweir
811cdf0e10cSrcweir    my $languagecount = $#{$languagesarray} + 1;
812cdf0e10cSrcweir    my $line = "count=" . $languagecount . "\n";
813cdf0e10cSrcweir
814cdf0e10cSrcweir    push(@{$setupinifile}, $line);
815cdf0e10cSrcweir}
816cdf0e10cSrcweir
817cdf0e10cSrcweir##########################################################################
818cdf0e10cSrcweir# Writing the defaultlanguage into setup.ini
819cdf0e10cSrcweir##########################################################################
820cdf0e10cSrcweir
821cdf0e10cSrcweirsub put_defaultlanguage_into_setupini
822cdf0e10cSrcweir{
823cdf0e10cSrcweir    my ($setupinifile, $defaultlanguage) = @_;
824cdf0e10cSrcweir
825cdf0e10cSrcweir    my $windowslanguage = installer::windows::language::get_windows_language($defaultlanguage);
826cdf0e10cSrcweir    my $line = "default=" . $windowslanguage . "\n";
827cdf0e10cSrcweir    push(@{$setupinifile}, $line);
828cdf0e10cSrcweir}
829cdf0e10cSrcweir
830cdf0e10cSrcweir##########################################################################
831cdf0e10cSrcweir# Writing the information about transformations into setup.ini
832cdf0e10cSrcweir##########################################################################
833cdf0e10cSrcweir
834cdf0e10cSrcweirsub put_transforms_into_setupini
835cdf0e10cSrcweir{
836cdf0e10cSrcweir    my ($setupinifile, $onelanguage, $counter) = @_;
837cdf0e10cSrcweir
838cdf0e10cSrcweir    my $windowslanguage = installer::windows::language::get_windows_language($onelanguage);
839cdf0e10cSrcweir    my $transformfilename = "trans_" . $onelanguage . ".mst";
840cdf0e10cSrcweir
841cdf0e10cSrcweir    my $line = "lang" . $counter . "=" . $windowslanguage . "," . $transformfilename . "\n";
842cdf0e10cSrcweir
843cdf0e10cSrcweir    push(@{$setupinifile}, $line);
844cdf0e10cSrcweir}
845cdf0e10cSrcweir
846cdf0e10cSrcweir###################################################
847cdf0e10cSrcweir# Including Windows line ends in ini files
848cdf0e10cSrcweir# Profiles on Windows shall have \r\n line ends
849cdf0e10cSrcweir###################################################
850cdf0e10cSrcweir
851cdf0e10cSrcweirsub include_windows_lineends
852cdf0e10cSrcweir{
853cdf0e10cSrcweir    my ($onefile) = @_;
854cdf0e10cSrcweir
855cdf0e10cSrcweir    for ( my $i = 0; $i <= $#{$onefile}; $i++ )
856cdf0e10cSrcweir    {
857cdf0e10cSrcweir        ${$onefile}[$i] =~ s/\r?\n$/\r\n/;
858cdf0e10cSrcweir    }
859cdf0e10cSrcweir}
860cdf0e10cSrcweir
861cdf0e10cSrcweir##########################################################################
862*8ac570c6Smseidel# Generating the file setup.ini, that is used by the loader setup.exe.
863cdf0e10cSrcweir##########################################################################
864cdf0e10cSrcweir
865cdf0e10cSrcweirsub create_setup_ini
866cdf0e10cSrcweir{
867cdf0e10cSrcweir    my ($languagesarray, $defaultlanguage, $installdir, $allvariableshashref) = @_;
868cdf0e10cSrcweir
869cdf0e10cSrcweir    installer::logger::include_header_into_logfile("Creating setup.ini");
870cdf0e10cSrcweir
871cdf0e10cSrcweir    my $setupinifilename = $installdir . $installer::globals::separator . "setup.ini";
872cdf0e10cSrcweir
873cdf0e10cSrcweir    my @setupinifile = ();
874cdf0e10cSrcweir    my $setupinifile = \@setupinifile;
875cdf0e10cSrcweir
876cdf0e10cSrcweir    my $line = "\[setup\]\n";
877cdf0e10cSrcweir    push(@setupinifile, $line);
878cdf0e10cSrcweir
879cdf0e10cSrcweir    put_databasename_into_setupini($setupinifile, $allvariableshashref);
880cdf0e10cSrcweir    put_msiversion_into_setupini($setupinifile);
881cdf0e10cSrcweir    put_productname_into_setupini($setupinifile, $allvariableshashref);
882cdf0e10cSrcweir    put_productcode_into_setupini($setupinifile);
883cdf0e10cSrcweir    put_productversion_into_setupini($setupinifile);
884cdf0e10cSrcweir    put_upgradekey_into_setupini($setupinifile);
885cdf0e10cSrcweir
886cdf0e10cSrcweir    $line = "\[languages\]\n";
887cdf0e10cSrcweir    push(@setupinifile, $line);
888cdf0e10cSrcweir
889cdf0e10cSrcweir    put_languagecount_into_setupini($setupinifile, $languagesarray);
890cdf0e10cSrcweir    put_defaultlanguage_into_setupini($setupinifile, $defaultlanguage);
891cdf0e10cSrcweir
892cdf0e10cSrcweir    if ( $#{$languagesarray} > 0 )  # writing the transforms information
893cdf0e10cSrcweir    {
894cdf0e10cSrcweir        my $counter = 1;
895cdf0e10cSrcweir
896cdf0e10cSrcweir        for ( my $i = 0; $i <= $#{$languagesarray}; $i++ )
897cdf0e10cSrcweir        {
898cdf0e10cSrcweir            if ( ${$languagesarray}[$i] eq $defaultlanguage ) { next; }
899cdf0e10cSrcweir
900cdf0e10cSrcweir            put_transforms_into_setupini($setupinifile, ${$languagesarray}[$i], $counter);
901cdf0e10cSrcweir            $counter++;
902cdf0e10cSrcweir        }
903cdf0e10cSrcweir    }
904cdf0e10cSrcweir
905cdf0e10cSrcweir    if ( $installer::globals::iswin && $installer::globals::plat =~ /cygwin/i)      # Windows line ends only for Cygwin
906cdf0e10cSrcweir    {
907cdf0e10cSrcweir        include_windows_lineends($setupinifile);
908cdf0e10cSrcweir    }
909cdf0e10cSrcweir
910cdf0e10cSrcweir    installer::files::save_file($setupinifilename, $setupinifile);
911cdf0e10cSrcweir
9121ba1fd99SAndre Fischer    $installer::logger::Lang->printf("Generated file %s\n", $setupinifilename);
913cdf0e10cSrcweir}
914cdf0e10cSrcweir
915cdf0e10cSrcweir#################################################################
916cdf0e10cSrcweir# Copying the files defined as ScpActions into the
917cdf0e10cSrcweir# installation set.
918cdf0e10cSrcweir#################################################################
919cdf0e10cSrcweir
920cdf0e10cSrcweirsub copy_scpactions_into_installset
921cdf0e10cSrcweir{
922cdf0e10cSrcweir    my ($defaultlanguage, $installdir, $allscpactions) = @_;
923cdf0e10cSrcweir
924cdf0e10cSrcweir    installer::logger::include_header_into_logfile("Copying ScpAction files into installation set");
925cdf0e10cSrcweir
926cdf0e10cSrcweir    for ( my $i = 0; $i <= $#{$allscpactions}; $i++ )
927cdf0e10cSrcweir    {
928cdf0e10cSrcweir        my $onescpaction = ${$allscpactions}[$i];
929cdf0e10cSrcweir
930cdf0e10cSrcweir        if ( $onescpaction->{'Name'} eq "loader.exe" ) { next; }    # do not copy this ScpAction loader
931cdf0e10cSrcweir
932cdf0e10cSrcweir        # only copying language independent files or files with the correct language (the defaultlanguage)
933cdf0e10cSrcweir
934cdf0e10cSrcweir        my $filelanguage = $onescpaction->{'specificlanguage'};
935cdf0e10cSrcweir
936cdf0e10cSrcweir        if ( ($filelanguage eq $defaultlanguage) || ($filelanguage eq "") )
937cdf0e10cSrcweir        {
938cdf0e10cSrcweir            my $sourcefile = $onescpaction->{'sourcepath'};
939cdf0e10cSrcweir            my $destfile = $installdir . $installer::globals::separator . $onescpaction->{'DestinationName'};
940cdf0e10cSrcweir
941cdf0e10cSrcweir            installer::systemactions::copy_one_file($sourcefile, $destfile);
942cdf0e10cSrcweir        }
943cdf0e10cSrcweir    }
944cdf0e10cSrcweir}
945cdf0e10cSrcweir
946cdf0e10cSrcweir#################################################################
947cdf0e10cSrcweir# Copying the files for the Windows installer into the
948cdf0e10cSrcweir# installation set (setup.exe).
949cdf0e10cSrcweir#################################################################
950cdf0e10cSrcweir
951cdf0e10cSrcweirsub copy_windows_installer_files_into_installset
952cdf0e10cSrcweir{
953cdf0e10cSrcweir    my ($installdir, $includepatharrayref, $allvariables) = @_;
954cdf0e10cSrcweir
955cdf0e10cSrcweir    installer::logger::include_header_into_logfile("Copying Windows installer files into installation set");
956cdf0e10cSrcweir
9571ba1fd99SAndre Fischer    my @copyfile = ();
958cdf0e10cSrcweir    push(@copyfile, "loader2.exe");
959cdf0e10cSrcweir
960cdf0e10cSrcweir    if ( $allvariables->{'NOLOADERREQUIRED'} ) { @copyfile = (); }
961cdf0e10cSrcweir
962cdf0e10cSrcweir    for ( my $i = 0; $i <= $#copyfile; $i++ )
963cdf0e10cSrcweir    {
964cdf0e10cSrcweir        my $filename = $copyfile[$i];
965cdf0e10cSrcweir        my $sourcefileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$filename, $includepatharrayref, 1);
966cdf0e10cSrcweir
967cdf0e10cSrcweir        if ( ! -f $$sourcefileref ) { installer::exiter::exit_program("ERROR: msi file not found: $$sourcefileref !", "copy_windows_installer_files_into_installset"); }
968cdf0e10cSrcweir
969cdf0e10cSrcweir        my $destfile;
970cdf0e10cSrcweir        if ( $copyfile[$i] eq "loader2.exe" ) { $destfile = "setup.exe"; }  # renaming the loader
971cdf0e10cSrcweir        else { $destfile = $copyfile[$i]; }
972cdf0e10cSrcweir
973cdf0e10cSrcweir        $destfile = $installdir . $installer::globals::separator . $destfile;
974cdf0e10cSrcweir
975cdf0e10cSrcweir        installer::systemactions::copy_one_file($$sourcefileref, $destfile);
976cdf0e10cSrcweir    }
977cdf0e10cSrcweir}
978cdf0e10cSrcweir
979cdf0e10cSrcweir#################################################################
980cdf0e10cSrcweir# Copying the child projects into the
981cdf0e10cSrcweir# installation set
982cdf0e10cSrcweir#################################################################
983cdf0e10cSrcweir
984cdf0e10cSrcweirsub copy_child_projects_into_installset
985cdf0e10cSrcweir{
986cdf0e10cSrcweir    my ($installdir, $allvariables) = @_;
987cdf0e10cSrcweir
988cdf0e10cSrcweir    my $sourcefile = "";
989cdf0e10cSrcweir    my $destdir = "";
990cdf0e10cSrcweir
991cdf0e10cSrcweir    # adding Java
992cdf0e10cSrcweir
993cdf0e10cSrcweir    if ( $allvariables->{'JAVAPRODUCT'} )
994cdf0e10cSrcweir    {
995cdf0e10cSrcweir        $sourcefile = $installer::globals::javafile->{'sourcepath'};
996cdf0e10cSrcweir        $destdir = $installdir . $installer::globals::separator . $installer::globals::javafile->{'Subdir'};
997cdf0e10cSrcweir        if ( ! -d $destdir) { installer::systemactions::create_directory($destdir); }
998cdf0e10cSrcweir        installer::systemactions::copy_one_file($sourcefile, $destdir);
999cdf0e10cSrcweir    }
1000cdf0e10cSrcweir
1001cdf0e10cSrcweir    if ( $allvariables->{'UREPRODUCT'} )
1002cdf0e10cSrcweir    {
1003cdf0e10cSrcweir        $sourcefile = $installer::globals::urefile->{'sourcepath'};
1004cdf0e10cSrcweir        $destdir = $installdir . $installer::globals::separator . $installer::globals::urefile->{'Subdir'};
1005cdf0e10cSrcweir        if ( ! -d $destdir) { installer::systemactions::create_directory($destdir); }
1006cdf0e10cSrcweir        installer::systemactions::copy_one_file($sourcefile, $destdir);
1007cdf0e10cSrcweir    }
1008cdf0e10cSrcweir}
1009cdf0e10cSrcweir
1010cdf0e10cSrcweir
10119f91b7e3SAndre Fischer
10129f91b7e3SAndre Fischer=head2 create_guid ()
10139f91b7e3SAndre Fischer
10149f91b7e3SAndre Fischer    Create a single UUID aka GUID via calling the external executable 'uuidgen'.
10159f91b7e3SAndre Fischer    There are Perl modules for that, but do they exist on the build bots?
10169f91b7e3SAndre Fischer
10179f91b7e3SAndre Fischer=cut
10189f91b7e3SAndre Fischersub create_guid ()
1019cdf0e10cSrcweir{
10209f91b7e3SAndre Fischer    my $uuid = qx("uuidgen");
10219f91b7e3SAndre Fischer    $uuid =~ s/\s*$//;
10229f91b7e3SAndre Fischer    return uc($uuid);
1023cdf0e10cSrcweir}
1024cdf0e10cSrcweir
1025cdf0e10cSrcweir#################################################################
1026cdf0e10cSrcweir# Calculating a GUID with a string using md5.
1027cdf0e10cSrcweir#################################################################
1028cdf0e10cSrcweir
1029cdf0e10cSrcweirsub calculate_guid
1030cdf0e10cSrcweir{
1031cdf0e10cSrcweir    my ( $string ) = @_;
1032cdf0e10cSrcweir
1033cdf0e10cSrcweir    my $guid = "";
1034cdf0e10cSrcweir
1035cdf0e10cSrcweir    my $md5 = Digest::MD5->new;
1036cdf0e10cSrcweir    $md5->add($string);
1037cdf0e10cSrcweir    my $digest = $md5->hexdigest;
1038cdf0e10cSrcweir    $digest = uc($digest);
1039cdf0e10cSrcweir
1040cdf0e10cSrcweir    # my $id = pack("A32", $digest);
1041cdf0e10cSrcweir    my ($first, $second, $third, $fourth, $fifth) = unpack ('A8 A4 A4 A4 A12', $digest);
1042cdf0e10cSrcweir    $guid = "$first-$second-$third-$fourth-$fifth";
1043cdf0e10cSrcweir
10449f91b7e3SAndre Fischer    $installer::logger::Lang->printf("guid for '%s' is %s\n",
10459f91b7e3SAndre Fischer        $string, $guid);
10469f91b7e3SAndre Fischer
1047cdf0e10cSrcweir    return $guid;
1048cdf0e10cSrcweir}
1049cdf0e10cSrcweir
1050cdf0e10cSrcweir#################################################################
105119d58b3aSEike Rathke# Calculating a ID with a string using md5 (very fast).
105219d58b3aSEike Rathke#################################################################
105319d58b3aSEike Rathke
105419d58b3aSEike Rathkesub calculate_id
105519d58b3aSEike Rathke{
105619d58b3aSEike Rathke    my ( $string, $length ) = @_;
105719d58b3aSEike Rathke
105819d58b3aSEike Rathke    my $id = "";
105919d58b3aSEike Rathke
106019d58b3aSEike Rathke    my $md5 = Digest::MD5->new;
106119d58b3aSEike Rathke    $md5->add($string);
106219d58b3aSEike Rathke    my $digest = lc($md5->hexdigest);
106319d58b3aSEike Rathke    $id = substr($digest, 0, $length);
106419d58b3aSEike Rathke
106519d58b3aSEike Rathke    return $id;
106619d58b3aSEike Rathke}
106719d58b3aSEike Rathke
106819d58b3aSEike Rathke#################################################################
1069cdf0e10cSrcweir# Filling the component hash with the values of the
1070cdf0e10cSrcweir# component file.
1071cdf0e10cSrcweir#################################################################
1072cdf0e10cSrcweir
1073cdf0e10cSrcweirsub fill_component_hash
1074cdf0e10cSrcweir{
1075cdf0e10cSrcweir    my ($componentfile) = @_;
1076cdf0e10cSrcweir
1077cdf0e10cSrcweir    my %components = ();
1078cdf0e10cSrcweir
1079cdf0e10cSrcweir    for ( my $i = 0; $i <= $#{$componentfile}; $i++ )
1080cdf0e10cSrcweir    {
1081cdf0e10cSrcweir        my $line = ${$componentfile}[$i];
1082cdf0e10cSrcweir
1083cdf0e10cSrcweir        if ( $line =~ /^\s*(.*?)\t(.*?)\s*$/ )
1084cdf0e10cSrcweir        {
1085cdf0e10cSrcweir            my $key = $1;
1086cdf0e10cSrcweir            my $value = $2;
1087cdf0e10cSrcweir
1088cdf0e10cSrcweir            $components{$key} = $value;
1089cdf0e10cSrcweir        }
1090cdf0e10cSrcweir    }
1091cdf0e10cSrcweir
1092cdf0e10cSrcweir    return \%components;
1093cdf0e10cSrcweir}
1094cdf0e10cSrcweir
1095cdf0e10cSrcweir#################################################################
1096cdf0e10cSrcweir# Creating a new component file, if new guids were generated.
1097cdf0e10cSrcweir#################################################################
1098cdf0e10cSrcweir
1099cdf0e10cSrcweirsub create_new_component_file
1100cdf0e10cSrcweir{
1101cdf0e10cSrcweir    my ($componenthash) = @_;
1102cdf0e10cSrcweir
1103cdf0e10cSrcweir    my @componentfile = ();
1104cdf0e10cSrcweir
1105cdf0e10cSrcweir    my $key;
1106cdf0e10cSrcweir
1107cdf0e10cSrcweir    foreach $key (keys %{$componenthash})
1108cdf0e10cSrcweir    {
1109cdf0e10cSrcweir        my $value = $componenthash->{$key};
1110cdf0e10cSrcweir        my $input = "$key\t$value\n";
1111cdf0e10cSrcweir        push(@componentfile ,$input);
1112cdf0e10cSrcweir    }
1113cdf0e10cSrcweir
1114cdf0e10cSrcweir    return \@componentfile;
1115cdf0e10cSrcweir}
1116cdf0e10cSrcweir
1117cdf0e10cSrcweir#################################################################
1118cdf0e10cSrcweir# Filling real component GUID into the component table.
1119cdf0e10cSrcweir# This works only on Windows
1120cdf0e10cSrcweir#################################################################
1121cdf0e10cSrcweir
11229f91b7e3SAndre Fischersub __set_uuid_into_component_table
1123cdf0e10cSrcweir{
1124cdf0e10cSrcweir    my ($idtdirbase, $allvariables) = @_;
1125cdf0e10cSrcweir
1126cdf0e10cSrcweir    my $componenttablename = $idtdirbase . $installer::globals::separator . "Componen.idt";
1127cdf0e10cSrcweir
1128cdf0e10cSrcweir    my $componenttable = installer::files::read_file($componenttablename);
1129cdf0e10cSrcweir
1130cdf0e10cSrcweir    # For update and patch reasons (small update) the GUID of an existing component must not change!
1131cdf0e10cSrcweir    # The collection of component GUIDs is saved in the directory $installer::globals::idttemplatepath in the file "components.txt"
1132cdf0e10cSrcweir
1133cdf0e10cSrcweir    my $infoline = "";
1134cdf0e10cSrcweir    my $counter = 0;
1135cdf0e10cSrcweir    # my $componentfile = installer::files::read_file($installer::globals::componentfilename);
1136cdf0e10cSrcweir    # my $componenthash = fill_component_hash($componentfile);
1137cdf0e10cSrcweir
1138cdf0e10cSrcweir    for ( my $i = 3; $i <= $#{$componenttable}; $i++ )  # ignoring the first three lines
1139cdf0e10cSrcweir    {
1140cdf0e10cSrcweir        my $oneline = ${$componenttable}[$i];
1141cdf0e10cSrcweir        my $componentname = "";
1142cdf0e10cSrcweir        if ( $oneline =~ /^\s*(\S+?)\t/ ) { $componentname = $1; }
1143cdf0e10cSrcweir
1144cdf0e10cSrcweir        my $uuid = "";
1145cdf0e10cSrcweir
1146cdf0e10cSrcweir    #   if ( $componenthash->{$componentname} )
1147cdf0e10cSrcweir    #   {
1148cdf0e10cSrcweir    #       $uuid = $componenthash->{$componentname};
1149cdf0e10cSrcweir    #   }
1150cdf0e10cSrcweir    #   else
1151cdf0e10cSrcweir    #   {
1152cdf0e10cSrcweir
1153cdf0e10cSrcweir            if ( exists($installer::globals::calculated_component_guids{$componentname}))
1154cdf0e10cSrcweir            {
1155cdf0e10cSrcweir                $uuid = $installer::globals::calculated_component_guids{$componentname};
1156cdf0e10cSrcweir            }
1157cdf0e10cSrcweir            else
1158cdf0e10cSrcweir            {
1159cdf0e10cSrcweir                # Calculating new GUID with the help of the component name.
1160cdf0e10cSrcweir                my $useooobaseversion = 1;
11619f91b7e3SAndre Fischer                if ( exists($installer::globals::base_independent_components{$componentname}))
11629f91b7e3SAndre Fischer                {
11639f91b7e3SAndre Fischer                    $useooobaseversion = 0;
11649f91b7e3SAndre Fischer                }
1165cdf0e10cSrcweir                my $sourcestring = $componentname;
1166cdf0e10cSrcweir
1167cdf0e10cSrcweir                if ( $useooobaseversion )
1168cdf0e10cSrcweir                {
11699f91b7e3SAndre Fischer                    if ( ! exists($allvariables->{'OOOBASEVERSION'}) )
11709f91b7e3SAndre Fischer                    {
11719f91b7e3SAndre Fischer                        installer::exiter::exit_program(
11729f91b7e3SAndre Fischer                            "ERROR: Could not find variable \"OOOBASEVERSION\" (required value for GUID creation)!",
11739f91b7e3SAndre Fischer                            "set_uuid_into_component_table");
11749f91b7e3SAndre Fischer                    }
1175cdf0e10cSrcweir                    $sourcestring = $sourcestring . "_" . $allvariables->{'OOOBASEVERSION'};
1176cdf0e10cSrcweir                }
1177cdf0e10cSrcweir                $uuid = calculate_guid($sourcestring);
1178cdf0e10cSrcweir                $counter++;
1179cdf0e10cSrcweir
1180cdf0e10cSrcweir                # checking, if there is a conflict with an already created guid
11819f91b7e3SAndre Fischer                if ( exists($installer::globals::allcalculated_guids{$uuid}) )
11829f91b7e3SAndre Fischer                {
11839f91b7e3SAndre Fischer                    installer::exiter::exit_program(
11849f91b7e3SAndre Fischer                        "ERROR: \"$uuid\" was already created before!",
11859f91b7e3SAndre Fischer                        "set_uuid_into_component_table");
11869f91b7e3SAndre Fischer                }
1187cdf0e10cSrcweir                $installer::globals::allcalculated_guids{$uuid} = 1;
1188cdf0e10cSrcweir                $installer::globals::calculated_component_guids{$componentname} = $uuid;
1189cdf0e10cSrcweir
1190cdf0e10cSrcweir                # Setting new uuid
1191cdf0e10cSrcweir                # $componenthash->{$componentname} = $uuid;
1192cdf0e10cSrcweir
1193cdf0e10cSrcweir                # Setting flag
1194cdf0e10cSrcweir                # $installer::globals::created_new_component_guid = 1;  # this is very important!
1195cdf0e10cSrcweir            }
1196cdf0e10cSrcweir    #   }
1197cdf0e10cSrcweir
1198cdf0e10cSrcweir        ${$componenttable}[$i] =~ s/COMPONENTGUID/$uuid/;
1199cdf0e10cSrcweir    }
1200cdf0e10cSrcweir
1201cdf0e10cSrcweir    installer::files::save_file($componenttablename, $componenttable);
1202cdf0e10cSrcweir
1203cdf0e10cSrcweir#   if ( $installer::globals::created_new_component_guid )
1204cdf0e10cSrcweir#   {
1205cdf0e10cSrcweir#       # create new component file!
1206cdf0e10cSrcweir#       $componentfile = create_new_component_file($componenthash);
1207cdf0e10cSrcweir#       installer::worker::sort_array($componentfile);
1208cdf0e10cSrcweir#
1209cdf0e10cSrcweir#       # To avoid conflict the components file cannot be saved at the same place
1210cdf0e10cSrcweir#       # All important data have to be saved in the directory: $installer::globals::infodirectory
1211cdf0e10cSrcweir#       my $localcomponentfilename = $installer::globals::componentfilename;
1212cdf0e10cSrcweir#       installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$localcomponentfilename);
1213cdf0e10cSrcweir#       $localcomponentfilename = $installer::globals::infodirectory . $installer::globals::separator . $localcomponentfilename;
1214cdf0e10cSrcweir#       installer::files::save_file($localcomponentfilename, $componentfile);
1215cdf0e10cSrcweir#
1216cdf0e10cSrcweir#       # installer::files::save_file($installer::globals::componentfilename, $componentfile);  # version using new file in solver
1217cdf0e10cSrcweir#
1218cdf0e10cSrcweir#       $infoline = "COMPONENTCODES: Created $counter new GUIDs for components ! \n";
1219b274bc22SAndre Fischer#       $installer::logger::Lang->print($infoline);
1220cdf0e10cSrcweir#   }
1221cdf0e10cSrcweir#   else
1222cdf0e10cSrcweir#   {
1223cdf0e10cSrcweir#       $infoline = "SUCCESS COMPONENTCODES: All component codes exist! \n";
1224b274bc22SAndre Fischer#       $installer::logger::Lang->print($infoline);
1225cdf0e10cSrcweir#   }
1226cdf0e10cSrcweir
1227cdf0e10cSrcweir}
1228cdf0e10cSrcweir
1229cdf0e10cSrcweir#########################################################################
1230cdf0e10cSrcweir# Adding final 64 properties into msi database, if required.
1231cdf0e10cSrcweir# RegLocator : +16 in type column to search in 64 bit registry.
1232cdf0e10cSrcweir# All conditions: "VersionNT" -> "VersionNT64" (several tables).
1233cdf0e10cSrcweir# Already done: "+256" in Attributes column of table "Component".
1234cdf0e10cSrcweir# Still following: Setting "x64" instead of "Intel" in Summary
1235cdf0e10cSrcweir# Information Stream of msi database in "get_template_for_sis".
1236cdf0e10cSrcweir#########################################################################
1237cdf0e10cSrcweir
1238cdf0e10cSrcweirsub prepare_64bit_database
1239cdf0e10cSrcweir{
1240cdf0e10cSrcweir    my ($basedir, $allvariables) = @_;
1241cdf0e10cSrcweir
1242cdf0e10cSrcweir    my $infoline = "";
1243cdf0e10cSrcweir
1244cdf0e10cSrcweir    if (( $allvariables->{'64BITPRODUCT'} ) && ( $allvariables->{'64BITPRODUCT'} == 1 ))
1245cdf0e10cSrcweir    {
1246cdf0e10cSrcweir        # 1. Beginning with table "RegLocat.idt". Adding "16" to the type.
1247cdf0e10cSrcweir
1248cdf0e10cSrcweir        my $reglocatfile = "";
1249cdf0e10cSrcweir        my $reglocatfilename = $basedir . $installer::globals::separator . "RegLocat.idt";
1250cdf0e10cSrcweir
1251cdf0e10cSrcweir        if ( -f $reglocatfilename )
1252cdf0e10cSrcweir        {
1253cdf0e10cSrcweir            my $saving_required = 0;
1254cdf0e10cSrcweir            $reglocatfile = installer::files::read_file($reglocatfilename);
1255cdf0e10cSrcweir
1256cdf0e10cSrcweir            for ( my $i = 3; $i <= $#{$reglocatfile}; $i++ )    # ignoring the first three lines
1257cdf0e10cSrcweir            {
1258cdf0e10cSrcweir                my $oneline = ${$reglocatfile}[$i];
1259cdf0e10cSrcweir
1260cdf0e10cSrcweir                if ( $oneline =~ /^\s*\#/ ) { next; }   # this is a comment line
1261cdf0e10cSrcweir                if ( $oneline =~ /^\s*$/ ) { next; }
1262cdf0e10cSrcweir
1263cdf0e10cSrcweir                if ( $oneline =~ /^\s*(.*?)\t(.*?)\t(.*?)\t(.*?)\t(\d+)\s*$/ )
1264cdf0e10cSrcweir                {
1265cdf0e10cSrcweir                    # Syntax: Signature_ Root Key Name Type
1266cdf0e10cSrcweir                    my $sig = $1;
1267cdf0e10cSrcweir                    my $root = $2;
1268cdf0e10cSrcweir                    my $key = $3;
1269cdf0e10cSrcweir                    my $name = $4;
1270cdf0e10cSrcweir                    my $type = $5;
1271cdf0e10cSrcweir
1272cdf0e10cSrcweir                    $type = $type + 16;
1273cdf0e10cSrcweir
1274cdf0e10cSrcweir                    my $newline = $sig . "\t" . $root . "\t" . $key . "\t" . $name . "\t" . $type . "\n";
1275cdf0e10cSrcweir                    ${$reglocatfile}[$i] = $newline;
1276cdf0e10cSrcweir
1277cdf0e10cSrcweir                    $saving_required = 1;
1278cdf0e10cSrcweir                }
1279cdf0e10cSrcweir            }
1280cdf0e10cSrcweir
1281cdf0e10cSrcweir            if ( $saving_required )
1282cdf0e10cSrcweir            {
1283cdf0e10cSrcweir                # Saving the files
1284cdf0e10cSrcweir                installer::files::save_file($reglocatfilename ,$reglocatfile);
1285cdf0e10cSrcweir                $infoline = "Making idt file 64 bit conform: $reglocatfilename\n";
1286b274bc22SAndre Fischer                $installer::logger::Lang->print($infoline);
1287cdf0e10cSrcweir            }
1288cdf0e10cSrcweir        }
1289cdf0e10cSrcweir
129086e1cf34SPedro Giffuni        # 2. Replacing all occurrences of "VersionNT" by "VersionNT64"
1291cdf0e10cSrcweir
1292cdf0e10cSrcweir        my @versionnt_files = ("Componen.idt", "InstallE.idt", "InstallU.idt", "LaunchCo.idt");
1293cdf0e10cSrcweir
1294cdf0e10cSrcweir        foreach my $onefile ( @versionnt_files )
1295cdf0e10cSrcweir        {
1296cdf0e10cSrcweir            my $fullfilename = $basedir . $installer::globals::separator . $onefile;
1297cdf0e10cSrcweir
1298cdf0e10cSrcweir            if ( -f $fullfilename )
1299cdf0e10cSrcweir            {
1300cdf0e10cSrcweir                my $saving_required = 0;
13011ba1fd99SAndre Fischer                my $filecontent = installer::files::read_file($fullfilename);
1302cdf0e10cSrcweir
1303cdf0e10cSrcweir                for ( my $i = 3; $i <= $#{$filecontent}; $i++ )     # ignoring the first three lines
1304cdf0e10cSrcweir                {
1305cdf0e10cSrcweir                    my $oneline = ${$filecontent}[$i];
1306cdf0e10cSrcweir
1307cdf0e10cSrcweir                    if ( $oneline =~ /\bVersionNT\b/ )
1308cdf0e10cSrcweir                    {
1309cdf0e10cSrcweir                        ${$filecontent}[$i] =~ s/\bVersionNT\b/VersionNT64/g;
1310cdf0e10cSrcweir                        $saving_required = 1;
1311cdf0e10cSrcweir                    }
1312cdf0e10cSrcweir                }
1313cdf0e10cSrcweir
1314cdf0e10cSrcweir                if ( $saving_required )
1315cdf0e10cSrcweir                {
1316cdf0e10cSrcweir                    # Saving the files
1317cdf0e10cSrcweir                    installer::files::save_file($fullfilename ,$filecontent);
1318cdf0e10cSrcweir                    $infoline = "Making idt file 64 bit conform: $fullfilename\n";
1319b274bc22SAndre Fischer                    $installer::logger::Lang->print($infoline);
1320cdf0e10cSrcweir                }
1321cdf0e10cSrcweir            }
1322cdf0e10cSrcweir        }
1323cdf0e10cSrcweir    }
1324cdf0e10cSrcweir
1325cdf0e10cSrcweir}
1326cdf0e10cSrcweir
1327cdf0e10cSrcweir#################################################################
1328cdf0e10cSrcweir# Include all cab files into the msi database.
1329cdf0e10cSrcweir# This works only on Windows
1330cdf0e10cSrcweir#################################################################
1331cdf0e10cSrcweir
1332cdf0e10cSrcweirsub include_cabs_into_msi
1333cdf0e10cSrcweir{
1334cdf0e10cSrcweir    my ($installdir) = @_;
1335cdf0e10cSrcweir
1336cdf0e10cSrcweir    installer::logger::include_header_into_logfile("Including cabs into msi database");
1337cdf0e10cSrcweir
1338cdf0e10cSrcweir    my $from = cwd();
1339cdf0e10cSrcweir    my $to = $installdir;
1340cdf0e10cSrcweir
1341cdf0e10cSrcweir    chdir($to);
1342cdf0e10cSrcweir
1343cdf0e10cSrcweir    my $infoline = "Changing into directory: $to";
1344b274bc22SAndre Fischer    $installer::logger::Lang->print($infoline);
1345cdf0e10cSrcweir
1346cdf0e10cSrcweir    my $msidb = "msidb.exe";    # Has to be in the path
1347cdf0e10cSrcweir    my $extraslash = "";        # Has to be set for non-ActiveState perl
1348cdf0e10cSrcweir
1349cdf0e10cSrcweir    my $msifilename = $installer::globals::msidatabasename;
1350cdf0e10cSrcweir
1351cdf0e10cSrcweir    $msifilename = installer::converter::make_path_conform($msifilename);
1352cdf0e10cSrcweir
1353cdf0e10cSrcweir    # msidb.exe really wants backslashes. (And double escaping because system() expands the string.)
1354cdf0e10cSrcweir    $msifilename =~ s/\//\\\\/g;
1355cdf0e10cSrcweir    $extraslash = "\\";
1356cdf0e10cSrcweir
1357cdf0e10cSrcweir    my $allcabfiles = installer::systemactions::find_file_with_file_extension("cab", $installdir);
1358cdf0e10cSrcweir
1359cdf0e10cSrcweir    for ( my $i = 0; $i <= $#{$allcabfiles}; $i++ )
1360cdf0e10cSrcweir    {
1361cdf0e10cSrcweir        my $systemcall = $msidb . " -d " . $msifilename . " -a " . ${$allcabfiles}[$i];
1362cdf0e10cSrcweir
1363cdf0e10cSrcweir        my $returnvalue = system($systemcall);
1364cdf0e10cSrcweir
1365cdf0e10cSrcweir        $infoline = "Systemcall: $systemcall\n";
1366b274bc22SAndre Fischer        $installer::logger::Lang->print($infoline);
1367cdf0e10cSrcweir
1368cdf0e10cSrcweir        if ($returnvalue)
1369cdf0e10cSrcweir        {
1370cdf0e10cSrcweir            $infoline = "ERROR: Could not execute $systemcall !\n";
1371b274bc22SAndre Fischer            $installer::logger::Lang->print($infoline);
1372cdf0e10cSrcweir        }
1373cdf0e10cSrcweir        else
1374cdf0e10cSrcweir        {
1375cdf0e10cSrcweir            $infoline = "Success: Executed $systemcall successfully!\n";
1376b274bc22SAndre Fischer            $installer::logger::Lang->print($infoline);
1377cdf0e10cSrcweir        }
1378cdf0e10cSrcweir
1379cdf0e10cSrcweir        # deleting the cab file
1380cdf0e10cSrcweir
1381cdf0e10cSrcweir        unlink(${$allcabfiles}[$i]);
1382cdf0e10cSrcweir
1383cdf0e10cSrcweir        $infoline = "Deleted cab file: ${$allcabfiles}[$i]\n";
1384b274bc22SAndre Fischer        $installer::logger::Lang->print($infoline);
1385cdf0e10cSrcweir    }
1386cdf0e10cSrcweir
1387cdf0e10cSrcweir    $infoline = "Changing back into directory: $from";
1388b274bc22SAndre Fischer    $installer::logger::Lang->print($infoline);
1389cdf0e10cSrcweir
1390cdf0e10cSrcweir    chdir($from);
1391cdf0e10cSrcweir}
1392cdf0e10cSrcweir
1393cdf0e10cSrcweir#################################################################
1394cdf0e10cSrcweir# Executing the created batch file to pack all files.
1395cdf0e10cSrcweir# This works only on Windows
1396cdf0e10cSrcweir#################################################################
1397cdf0e10cSrcweir
1398cdf0e10cSrcweirsub execute_packaging
1399cdf0e10cSrcweir{
1400cdf0e10cSrcweir    my ($localpackjobref, $loggingdir, $allvariables) = @_;
1401cdf0e10cSrcweir
1402cdf0e10cSrcweir    installer::logger::include_header_into_logfile("Packaging process");
1403cdf0e10cSrcweir
1404b274bc22SAndre Fischer    $installer::logger::Lang->add_timestamp("Performance Info: Execute packaging start");
1405cdf0e10cSrcweir
1406cdf0e10cSrcweir    my $infoline = "";
1407cdf0e10cSrcweir    my $from = cwd();
1408cdf0e10cSrcweir    my $to = $loggingdir;
1409cdf0e10cSrcweir
1410cdf0e10cSrcweir    chdir($to);
1411cdf0e10cSrcweir    $infoline = "chdir: $to \n";
1412b274bc22SAndre Fischer    $installer::logger::Lang->print($infoline);
1413cdf0e10cSrcweir
141486e1cf34SPedro Giffuni    # if the ddf file contains relative paths, it is necessary to change into the temp directory
1415cdf0e10cSrcweir    if ( $allvariables->{'RELATIVE_PATHES_IN_DDF'} )
1416cdf0e10cSrcweir    {
1417cdf0e10cSrcweir        $to = $installer::globals::temppath;
1418cdf0e10cSrcweir        chdir($to);
1419cdf0e10cSrcweir        $infoline = "chdir: $to \n";
1420b274bc22SAndre Fischer        $installer::logger::Lang->print($infoline);
1421cdf0e10cSrcweir    }
1422cdf0e10cSrcweir
1423cdf0e10cSrcweir    # changing the tmp directory, because makecab.exe generates temporary cab files
1424cdf0e10cSrcweir    my $origtemppath = "";
1425cdf0e10cSrcweir    if ( $ENV{'TMP'} ) { $origtemppath = $ENV{'TMP'}; }
1426cdf0e10cSrcweir    $ENV{'TMP'} = $installer::globals::temppath;    # setting TMP to the new unique directory!
1427cdf0e10cSrcweir
1428cdf0e10cSrcweir    my $maxmakecabcalls = 3;
1429cdf0e10cSrcweir    my $allmakecabcalls = $#{$localpackjobref} + 1;
1430cdf0e10cSrcweir
1431cdf0e10cSrcweir    for ( my $i = 0; $i <= $#{$localpackjobref}; $i++ )
1432cdf0e10cSrcweir    {
1433cdf0e10cSrcweir        my $systemcall = ${$localpackjobref}[$i];
1434cdf0e10cSrcweir
1435cdf0e10cSrcweir        my $callscounter = $i + 1;
1436cdf0e10cSrcweir
1437b274bc22SAndre Fischer        $installer::logger::Info->printf("... makecab.exe (%s/%s) ... \n", $callscounter, $allmakecabcalls);
1438cdf0e10cSrcweir
1439cdf0e10cSrcweir        # my $returnvalue = system($systemcall);
1440cdf0e10cSrcweir
1441cdf0e10cSrcweir        for ( my $n = 1; $n <= $maxmakecabcalls; $n++ )
1442cdf0e10cSrcweir        {
1443cdf0e10cSrcweir            my @ddfoutput = ();
1444cdf0e10cSrcweir
1445cdf0e10cSrcweir            $infoline = "Systemcall: $systemcall";
1446b274bc22SAndre Fischer            $installer::logger::Lang->print($infoline);
1447cdf0e10cSrcweir
1448cdf0e10cSrcweir            open (DDF, "$systemcall");
1449cdf0e10cSrcweir            while (<DDF>) {push(@ddfoutput, $_); }
1450cdf0e10cSrcweir            close (DDF);
1451cdf0e10cSrcweir
1452cdf0e10cSrcweir            my $returnvalue = $?;   # $? contains the return value of the systemcall
1453cdf0e10cSrcweir
1454cdf0e10cSrcweir            if ($returnvalue)
1455cdf0e10cSrcweir            {
1456cdf0e10cSrcweir                if ( $n < $maxmakecabcalls )
1457cdf0e10cSrcweir                {
1458b274bc22SAndre Fischer                    $installer::logger::Info->printf("makecab_error (Try %s): Trying again\n", $n);
1459b274bc22SAndre Fischer                    $installer::logger::Lang->printf("makecab_error (Try %s): Trying again\n", $n);
1460cdf0e10cSrcweir                }
1461cdf0e10cSrcweir                else
1462cdf0e10cSrcweir                {
1463b274bc22SAndre Fischer                    $installer::logger::Info->printf("ERROR (Try %s): Abort packing \n", $n);
1464b274bc22SAndre Fischer                    $installer::logger::Lang->printf("ERROR (Try %s): Abort packing \n", $n);
1465cdf0e10cSrcweir                }
1466cdf0e10cSrcweir
1467cdf0e10cSrcweir                for ( my $m = 0; $m <= $#ddfoutput; $m++ )
1468cdf0e10cSrcweir                {
1469cdf0e10cSrcweir                    if ( $ddfoutput[$m] =~ /(ERROR\:.*?)\s*$/ )
1470cdf0e10cSrcweir                    {
1471cdf0e10cSrcweir                        $infoline = $1 . "\n";
1472b274bc22SAndre Fischer                        if ( $n < $maxmakecabcalls )
1473b274bc22SAndre Fischer                        {
1474b274bc22SAndre Fischer                            $infoline =~ s/ERROR\:/makecab_error\:/i;
1475b274bc22SAndre Fischer                        }
1476b274bc22SAndre Fischer                        $installer::logger::Info->print($infoline);
1477b274bc22SAndre Fischer                        $installer::logger::Lang->print($infoline);
1478cdf0e10cSrcweir                    }
1479cdf0e10cSrcweir                }
1480cdf0e10cSrcweir
1481cdf0e10cSrcweir                if ( $n == $maxmakecabcalls ) { installer::exiter::exit_program("ERROR: \"$systemcall\"!", "execute_packaging"); }
1482cdf0e10cSrcweir            }
1483cdf0e10cSrcweir            else
1484cdf0e10cSrcweir            {
1485cdf0e10cSrcweir                $infoline = "Success (Try $n): $systemcall";
1486b274bc22SAndre Fischer                $installer::logger::Lang->print($infoline);
1487cdf0e10cSrcweir                last;
1488cdf0e10cSrcweir            }
1489cdf0e10cSrcweir        }
1490cdf0e10cSrcweir    }
1491cdf0e10cSrcweir
1492b274bc22SAndre Fischer    $installer::logger::Lang->add_timestamp("Performance Info: Execute packaging end");
1493cdf0e10cSrcweir
1494cdf0e10cSrcweir    # setting back to the original tmp directory
1495cdf0e10cSrcweir    $ENV{'TMP'} = $origtemppath;
1496cdf0e10cSrcweir
1497cdf0e10cSrcweir    chdir($from);
1498cdf0e10cSrcweir    $infoline = "chdir: $from \n";
1499b274bc22SAndre Fischer    $installer::logger::Lang->print($infoline);
1500cdf0e10cSrcweir}
1501cdf0e10cSrcweir
1502cdf0e10cSrcweir
15039f91b7e3SAndre Fischer=head2 get_source_codes($languagesref)
15049f91b7e3SAndre Fischer
15059f91b7e3SAndre Fischer    Return product code and upgrade code from the source version.
15069f91b7e3SAndre Fischer    When no source version is defined then return undef for both.
15079f91b7e3SAndre Fischer
15089f91b7e3SAndre Fischer=cut
15099f91b7e3SAndre Fischersub get_source_codes ($)
15109f91b7e3SAndre Fischer{
15119f91b7e3SAndre Fischer    my ($languagesref) = @_;
15129f91b7e3SAndre Fischer
1513ba69edf5SAndre Fischer    if ( ! $installer::globals::is_release)
1514ba69edf5SAndre Fischer    {
1515ba69edf5SAndre Fischer        return (undef, undef);
1516ba69edf5SAndre Fischer    }
1517ba69edf5SAndre Fischer    elsif ( ! defined $installer::globals::source_version)
15189f91b7e3SAndre Fischer    {
1519f5a0c083SAndre Fischer        $installer::logger::Lang->printf("no source version defined\n");
1520f5a0c083SAndre Fischer        return (undef, undef);
15219f91b7e3SAndre Fischer    }
15229f91b7e3SAndre Fischer
15239f91b7e3SAndre Fischer    my $onelanguage = installer::languages::get_key_language($languagesref);
15249f91b7e3SAndre Fischer
15259f91b7e3SAndre Fischer    my $release_data = installer::patch::ReleasesList::Instance()
15269f91b7e3SAndre Fischer        ->{$installer::globals::source_version}
15279f91b7e3SAndre Fischer        ->{$installer::globals::packageformat};
15289f91b7e3SAndre Fischer    if (defined $release_data)
15299f91b7e3SAndre Fischer    {
1530f5a0c083SAndre Fischer        my $normalized_language = installer::languages::get_normalized_language($languagesref);
1531f5a0c083SAndre Fischer        my $language_data = $release_data->{$normalized_language};
15329f91b7e3SAndre Fischer        if (defined $language_data)
15339f91b7e3SAndre Fischer        {
15349f91b7e3SAndre Fischer            $installer::logger::Lang->printf("source product code is %s\n", $language_data->{'product-code'});
15359f91b7e3SAndre Fischer            $installer::logger::Lang->printf("source upgrade code is %s\n", $release_data->{'upgrade-code'});
15369f91b7e3SAndre Fischer
15379f91b7e3SAndre Fischer            return (
15389f91b7e3SAndre Fischer                $language_data->{'product-code'},
15399f91b7e3SAndre Fischer                $release_data->{'upgrade-code'}
15409f91b7e3SAndre Fischer                );
15419f91b7e3SAndre Fischer        }
15429f91b7e3SAndre Fischer        else
15439f91b7e3SAndre Fischer        {
15449f91b7e3SAndre Fischer            $installer::logger::Info->printf(
1545f5a0c083SAndre Fischer                "Warning: can not access information about previous version %s and language %s/%s/%s\n",
15469f91b7e3SAndre Fischer                $installer::globals::source_version,
1547f5a0c083SAndre Fischer                $onelanguage,
1548f5a0c083SAndre Fischer                join(", ",@$languagesref),
1549f5a0c083SAndre Fischer                $normalized_language);
15509f91b7e3SAndre Fischer            return (undef,undef);
15519f91b7e3SAndre Fischer        }
15529f91b7e3SAndre Fischer    }
15539f91b7e3SAndre Fischer    else
15549f91b7e3SAndre Fischer    {
15559f91b7e3SAndre Fischer        $installer::logger::Info->printf("Warning: can not access information about previous version %s\n",
15569f91b7e3SAndre Fischer            $installer::globals::source_version);
15579f91b7e3SAndre Fischer        return (undef,undef);
15589f91b7e3SAndre Fischer    }
15599f91b7e3SAndre Fischer}
15609f91b7e3SAndre Fischer
15619f91b7e3SAndre Fischer
15629f91b7e3SAndre Fischer
15639f91b7e3SAndre Fischer
15649f91b7e3SAndre Fischer=head2 set_global_code_variables ($languagesref, $allvariableshashref)
15659f91b7e3SAndre Fischer
15669f91b7e3SAndre Fischer    Determine values for the product code and upgrade code of the target version.
15679f91b7e3SAndre Fischer
156877bec208SAndre Fischer    As preparation for building a Windows patch, certain conditions have to be fulfilled.
156977bec208SAndre Fischer    - The upgrade code remains the same
15709f91b7e3SAndre Fischer    - The product code remains the same
157177bec208SAndre Fischer        [this is still to be determined. For patches to work we need the same product codes but
157277bec208SAndre Fischer        the install sets install only when the product codes differ.]
157377bec208SAndre Fischer    In order to enforce that we have to access information about the source version.
15749f91b7e3SAndre Fischer
15759f91b7e3SAndre Fischer    The resulting values are stored as global variables
15769f91b7e3SAndre Fischer        $installer::globals::productcode
15779f91b7e3SAndre Fischer        $installer::globals::upgradecode
15789f91b7e3SAndre Fischer    and as variables in the given hash
15799f91b7e3SAndre Fischer        $allvariableshashref->{'PRODUCTCODE'}
15809f91b7e3SAndre Fischer        $allvariableshashref->{'UPGRADECODE'}
15819f91b7e3SAndre Fischer
15829f91b7e3SAndre Fischer=cut
1583dca4887fSAndre Fischersub set_global_code_variables ($$)
1584cdf0e10cSrcweir{
1585dca4887fSAndre Fischer    my ($languagesref, $allvariableshashref) = @_;
1586cdf0e10cSrcweir
15879f91b7e3SAndre Fischer    my ($source_product_code, $source_upgrade_code) = get_source_codes($languagesref);
15889f91b7e3SAndre Fischer    my ($target_product_code, $target_upgrade_code) = (undef, undef);
1589cdf0e10cSrcweir
15909f91b7e3SAndre Fischer    if (defined $source_product_code && defined $source_upgrade_code)
1591cdf0e10cSrcweir    {
15929f91b7e3SAndre Fischer        if ($installer::globals::is_major_release)
15939f91b7e3SAndre Fischer        {
15949f91b7e3SAndre Fischer            # For a major release we have to change the product code.
15959f91b7e3SAndre Fischer            $target_product_code = "{" . create_guid() . "}";
15969f91b7e3SAndre Fischer            $installer::logger::Lang->printf("building a major release, created new product code %s\n",
15979f91b7e3SAndre Fischer                $target_product_code);
15989f91b7e3SAndre Fischer
15999f91b7e3SAndre Fischer            # Let's do a paranoia check that the new and the old guids are
16009f91b7e3SAndre Fischer            # different. In reality the new guid really has to be
16019f91b7e3SAndre Fischer            # different from all other guids used for * codes, components,
16029f91b7e3SAndre Fischer            # etc.
16039f91b7e3SAndre Fischer            if ($target_product_code eq $source_product_code)
16049f91b7e3SAndre Fischer            {
16059f91b7e3SAndre Fischer                installer::logger::PrintError(
16069f91b7e3SAndre Fischer                    "new GUID for product code is the same as the old product code but should be different.");
1607cdf0e10cSrcweir            }
1608cdf0e10cSrcweir        }
1609cdf0e10cSrcweir        else
1610cdf0e10cSrcweir        {
1611*8ac570c6Smseidel            # For minor or micro releases we have to keep the old product code.
16129f91b7e3SAndre Fischer            $target_product_code = "{" . $source_product_code . "}";
16139f91b7e3SAndre Fischer            $installer::logger::Lang->printf("building a minor or micro release, reusing product code %s\n",
16149f91b7e3SAndre Fischer                $target_product_code);
16159f91b7e3SAndre Fischer        }
16169f91b7e3SAndre Fischer
16179f91b7e3SAndre Fischer        $target_upgrade_code = "{" . create_guid() . "}";
16189f91b7e3SAndre Fischer        # Again, just one test for paranoia.
16199f91b7e3SAndre Fischer        if ($target_upgrade_code eq $source_upgrade_code)
1620cdf0e10cSrcweir        {
16219f91b7e3SAndre Fischer            installer::logger::PrintError(
16229f91b7e3SAndre Fischer                "new GUID for upgrade code is the same as the old upgrade code but should be different.");
16239f91b7e3SAndre Fischer        }
1624cdf0e10cSrcweir    }
1625cdf0e10cSrcweir    else
1626cdf0e10cSrcweir    {
16279f91b7e3SAndre Fischer        # There is no previous version with which to compare the product code.
16289f91b7e3SAndre Fischer        # Just create two new uuids.
16299f91b7e3SAndre Fischer        $target_product_code = "{" . create_guid() . "}";
16309f91b7e3SAndre Fischer        $target_upgrade_code = "{" . create_guid() . "}";
1631f5a0c083SAndre Fischer        $installer::logger::Lang->printf("there is no source version => created new guids\n");
1632cdf0e10cSrcweir    }
1633cdf0e10cSrcweir
163477bec208SAndre Fischer    # Keep the upgrade code constant between versions. Read it from the codes.txt file.
163577bec208SAndre Fischer    # Note that this handles regular installation sets and language packs.
163677bec208SAndre Fischer    my $onelanguage = ${$languagesref}[0];
163777bec208SAndre Fischer    $installer::logger::Lang->printf("reading upgrade code for language %s from %s\n",
163877bec208SAndre Fischer        $onelanguage,
163977bec208SAndre Fischer        $installer::globals::codefilename);
164077bec208SAndre Fischer    if (defined $installer::globals::codefilename)
164177bec208SAndre Fischer    {
164277bec208SAndre Fischer        my $code_filename = $installer::globals::codefilename;
164377bec208SAndre Fischer        installer::files::check_file($code_filename);
164477bec208SAndre Fischer        my $codefile = installer::files::read_file($code_filename);
164577bec208SAndre Fischer        my $searchstring = "UPGRADECODE";
164677bec208SAndre Fischer        my $codeblock = installer::windows::idtglobal::get_language_block_from_language_file(
164777bec208SAndre Fischer            $searchstring,
164877bec208SAndre Fischer            $codefile);
164977bec208SAndre Fischer        $target_upgrade_code = installer::windows::idtglobal::get_language_string_from_language_block(
165077bec208SAndre Fischer            $codeblock,
165177bec208SAndre Fischer            $onelanguage,
165277bec208SAndre Fischer            "");
165377bec208SAndre Fischer    }
165477bec208SAndre Fischer    # else use the previously generated upgrade code.
165577bec208SAndre Fischer
16569f91b7e3SAndre Fischer    $installer::globals::productcode = $target_product_code;
16579f91b7e3SAndre Fischer    $installer::globals::upgradecode = $target_upgrade_code;
16589f91b7e3SAndre Fischer    $allvariableshashref->{'PRODUCTCODE'} = $target_product_code;
16599f91b7e3SAndre Fischer    $allvariableshashref->{'UPGRADECODE'} = $target_upgrade_code;
16609f91b7e3SAndre Fischer
16619f91b7e3SAndre Fischer    $installer::logger::Lang->printf("target product code is %s\n", $target_product_code);
16629f91b7e3SAndre Fischer    $installer::logger::Lang->printf("target upgrade code is %s\n", $target_upgrade_code);
1663cdf0e10cSrcweir}
1664cdf0e10cSrcweir
1665cdf0e10cSrcweir
1666cdf0e10cSrcweir
1667cdf0e10cSrcweir
1668cdf0e10cSrcweir###############################################################
1669cdf0e10cSrcweir# Setting the product version used in property table and
1670cdf0e10cSrcweir# upgrade table. Saving in global variable $msiproductversion
1671cdf0e10cSrcweir###############################################################
1672cdf0e10cSrcweir
1673cdf0e10cSrcweirsub set_msiproductversion
1674cdf0e10cSrcweir{
1675cdf0e10cSrcweir    my ( $allvariables ) = @_;
1676cdf0e10cSrcweir
1677cdf0e10cSrcweir    my $productversion = $allvariables->{'PRODUCTVERSION'};
1678c1467797Smseidel    my $productmajor;
1679c1467797Smseidel    my $productminor; # It must be 3 digits long
1680cdf0e10cSrcweir
1681cdf0e10cSrcweir    if (( $productversion =~ /^\s*\d+\s*$/ ) && ( $productversion > 255 )) { $productversion = $productversion%256; }
1682cdf0e10cSrcweir
1683cdf0e10cSrcweir    if ( $productversion =~ /^\s*(\d+)\.(\d+)\.(\d+)\s*$/ )
1684cdf0e10cSrcweir    {
1685c1467797Smseidel        my $productmicro = $3;
1686c1467797Smseidel        $productmajor = $1;
1687c1467797Smseidel        $productminor = $2;
1688c1467797Smseidel        $productmicro = "0" . $productmicro while ( length ( $productminor . $productmicro ) < 3 );
1689c1467797Smseidel        $productminor .= $productmicro;
1690cdf0e10cSrcweir    }
1691cdf0e10cSrcweir    elsif ( $productversion =~ /^\s*(\d+)\.(\d+)\s*$/ )
1692cdf0e10cSrcweir    {
1693c1467797Smseidel        $productmajor = $1;
1694c1467797Smseidel        $productminor = $2;
1695cdf0e10cSrcweir    }
1696cdf0e10cSrcweir    else
1697cdf0e10cSrcweir    {
1698cdf0e10cSrcweir        if (( $allvariables->{'PACKAGEVERSION'} ) && ( $allvariables->{'PACKAGEVERSION'} ne "" ))
1699cdf0e10cSrcweir        {
1700cdf0e10cSrcweir            if ( $allvariables->{'PACKAGEVERSION'} =~ /^\s*(\d+)\.(\d+)\.(\d+)\s*$/ ) { $productminor = $2; }
1701cdf0e10cSrcweir        }
1702cdf0e10cSrcweir
1703c1467797Smseidel        $productmajor = $productversion;
1704cdf0e10cSrcweir    }
1705c1467797Smseidel    $productminor .= "0" while ( length( $productminor ) < 3);
1706c1467797Smseidel    $productversion = $productmajor . "\." . $productminor . "\." . $installer::globals::buildid;
1707cdf0e10cSrcweir
1708cdf0e10cSrcweir    $installer::globals::msiproductversion = $productversion;
1709cdf0e10cSrcweir
1710cdf0e10cSrcweir    # Setting $installer::globals::msimajorproductversion, to differ between old version in upgrade table
1711cdf0e10cSrcweir
1712cdf0e10cSrcweir    if ( $installer::globals::msiproductversion =~ /^\s*(\d+)\./ )
1713cdf0e10cSrcweir    {
1714cdf0e10cSrcweir        my $major = $1;
1715cdf0e10cSrcweir        $installer::globals::msimajorproductversion = $major . "\.0\.0";
1716cdf0e10cSrcweir    }
1717cdf0e10cSrcweir}
1718cdf0e10cSrcweir
1719cdf0e10cSrcweir#################################################################################
1720cdf0e10cSrcweir# Including the msi product version into the bootstrap.ini, Windows only
1721cdf0e10cSrcweir#################################################################################
1722cdf0e10cSrcweir
1723cdf0e10cSrcweirsub put_msiproductversion_into_bootstrapfile
1724cdf0e10cSrcweir{
1725cdf0e10cSrcweir    my ($filesref) = @_;
1726cdf0e10cSrcweir
1727cdf0e10cSrcweir    for ( my $i = 0; $i <= $#{$filesref}; $i++ )
1728cdf0e10cSrcweir    {
1729cdf0e10cSrcweir        my $onefile = ${$filesref}[$i];
1730cdf0e10cSrcweir
1731cdf0e10cSrcweir        if ( $onefile->{'gid'} eq "gid_Profile_Version_Ini" )
1732cdf0e10cSrcweir        {
1733cdf0e10cSrcweir            my $file = installer::files::read_file($onefile->{'sourcepath'});
1734cdf0e10cSrcweir
1735cdf0e10cSrcweir            for ( my $j = 0; $j <= $#{$file}; $j++ )
1736cdf0e10cSrcweir            {
1737cdf0e10cSrcweir                ${$file}[$j] =~ s/\<msiproductversion\>/$installer::globals::msiproductversion/;
1738cdf0e10cSrcweir            }
1739cdf0e10cSrcweir
1740cdf0e10cSrcweir            installer::files::save_file($onefile->{'sourcepath'}, $file);
1741cdf0e10cSrcweir
1742cdf0e10cSrcweir            last;
1743cdf0e10cSrcweir        }
1744cdf0e10cSrcweir    }
1745cdf0e10cSrcweir}
1746cdf0e10cSrcweir
1747cdf0e10cSrcweir####################################################################################
1748cdf0e10cSrcweir# Updating the file Property.idt dynamically
1749cdf0e10cSrcweir# Content:
1750cdf0e10cSrcweir# Property Value
1751cdf0e10cSrcweir####################################################################################
1752cdf0e10cSrcweir
1753cdf0e10cSrcweirsub update_reglocat_table
1754cdf0e10cSrcweir{
1755cdf0e10cSrcweir    my ($basedir, $allvariables) = @_;
1756cdf0e10cSrcweir
1757cdf0e10cSrcweir    my $reglocatfilename = $basedir . $installer::globals::separator . "RegLocat.idt";
1758cdf0e10cSrcweir
1759cdf0e10cSrcweir    # Only do something, if this file exists
1760cdf0e10cSrcweir
1761cdf0e10cSrcweir    if ( -f $reglocatfilename )
1762cdf0e10cSrcweir    {
1763cdf0e10cSrcweir        my $reglocatfile = installer::files::read_file($reglocatfilename);
1764cdf0e10cSrcweir
1765cdf0e10cSrcweir        my $layername = "";
1766cdf0e10cSrcweir        if ( $allvariables->{'REGISTRYLAYERNAME'} )
1767cdf0e10cSrcweir        {
1768cdf0e10cSrcweir            $layername = $allvariables->{'REGISTRYLAYERNAME'};
1769cdf0e10cSrcweir        }
1770cdf0e10cSrcweir        else
1771cdf0e10cSrcweir        {
1772cdf0e10cSrcweir            for ( my $i = 0; $i <= $#{$reglocatfile}; $i++ )
1773cdf0e10cSrcweir            {
1774cdf0e10cSrcweir                if ( ${$reglocatfile}[$i] =~ /\bLAYERNAMETEMPLATE\b/ )
1775cdf0e10cSrcweir                {
1776cdf0e10cSrcweir                    installer::exiter::exit_program("ERROR: Variable \"REGISTRYLAYERNAME\" has to be defined", "update_reglocat_table");
1777cdf0e10cSrcweir                }
1778cdf0e10cSrcweir            }
1779cdf0e10cSrcweir        }
1780cdf0e10cSrcweir
1781cdf0e10cSrcweir        if ( $layername ne "" )
1782cdf0e10cSrcweir        {
1783cdf0e10cSrcweir            # Updating the layername in
1784cdf0e10cSrcweir
1785cdf0e10cSrcweir            for ( my $i = 0; $i <= $#{$reglocatfile}; $i++ )
1786cdf0e10cSrcweir            {
1787cdf0e10cSrcweir                ${$reglocatfile}[$i] =~ s/\bLAYERNAMETEMPLATE\b/$layername/;
1788cdf0e10cSrcweir            }
1789cdf0e10cSrcweir
1790cdf0e10cSrcweir            # Saving the file
1791cdf0e10cSrcweir            installer::files::save_file($reglocatfilename ,$reglocatfile);
1792cdf0e10cSrcweir            my $infoline = "Updated idt file: $reglocatfilename\n";
1793b274bc22SAndre Fischer            $installer::logger::Lang->print($infoline);
1794cdf0e10cSrcweir        }
1795cdf0e10cSrcweir    }
1796cdf0e10cSrcweir}
1797cdf0e10cSrcweir
1798cdf0e10cSrcweir
1799cdf0e10cSrcweir
1800cdf0e10cSrcweir####################################################################################
1801cdf0e10cSrcweir# Updating the file RemoveRe.idt dynamically (RemoveRegistry.idt)
1802cdf0e10cSrcweir# The name of the component has to be replaced.
1803cdf0e10cSrcweir####################################################################################
1804cdf0e10cSrcweir
1805cdf0e10cSrcweirsub update_removere_table
1806cdf0e10cSrcweir{
1807cdf0e10cSrcweir    my ($basedir) = @_;
1808cdf0e10cSrcweir
1809cdf0e10cSrcweir    my $removeregistryfilename = $basedir . $installer::globals::separator . "RemoveRe.idt";
1810cdf0e10cSrcweir
1811cdf0e10cSrcweir    # Only do something, if this file exists
1812cdf0e10cSrcweir
1813cdf0e10cSrcweir    if ( -f $removeregistryfilename )
1814cdf0e10cSrcweir    {
1815cdf0e10cSrcweir        my $removeregistryfile = installer::files::read_file($removeregistryfilename);
1816cdf0e10cSrcweir
1817cdf0e10cSrcweir        for ( my $i = 0; $i <= $#{$removeregistryfile}; $i++ )
1818cdf0e10cSrcweir        {
1819cdf0e10cSrcweir            for ( my $i = 0; $i <= $#{$removeregistryfile}; $i++ )
1820cdf0e10cSrcweir            {
1821cdf0e10cSrcweir                ${$removeregistryfile}[$i] =~ s/\bREGISTRYROOTCOMPONENT\b/$installer::globals::registryrootcomponent/;
1822cdf0e10cSrcweir            }
1823cdf0e10cSrcweir        }
1824cdf0e10cSrcweir
1825cdf0e10cSrcweir        # Saving the file
1826cdf0e10cSrcweir        installer::files::save_file($removeregistryfilename ,$removeregistryfile);
1827cdf0e10cSrcweir        my $infoline = "Updated idt file: $removeregistryfilename \n";
1828b274bc22SAndre Fischer        $installer::logger::Lang->print($infoline);
1829cdf0e10cSrcweir    }
1830cdf0e10cSrcweir}
1831cdf0e10cSrcweir
1832cdf0e10cSrcweir1;
1833