xref: /AOO41X/main/solenv/bin/modules/installer/windows/file.pm (revision 707fc0d4d52eb4f69d89a98ffec6918ca5de6326)
1#**************************************************************
2#
3#  Licensed to the Apache Software Foundation (ASF) under one
4#  or more contributor license agreements.  See the NOTICE file
5#  distributed with this work for additional information
6#  regarding copyright ownership.  The ASF licenses this file
7#  to you under the Apache License, Version 2.0 (the
8#  "License"); you may not use this file except in compliance
9#  with the License.  You may obtain a copy of the License at
10#
11#    http://www.apache.org/licenses/LICENSE-2.0
12#
13#  Unless required by applicable law or agreed to in writing,
14#  software distributed under the License is distributed on an
15#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16#  KIND, either express or implied.  See the License for the
17#  specific language governing permissions and limitations
18#  under the License.
19#
20#**************************************************************
21
22
23
24package installer::windows::file;
25
26use Digest::MD5;
27use installer::existence;
28use installer::exiter;
29use installer::files;
30use installer::globals;
31use installer::logger;
32use installer::pathanalyzer;
33use installer::worker;
34use installer::windows::font;
35use installer::windows::idtglobal;
36use installer::windows::msiglobal;
37use installer::windows::language;
38
39##########################################################################
40# Assigning one cabinet file to each file. This is requrired,
41# if cabinet files shall be equivalent to packages.
42##########################################################################
43
44sub assign_cab_to_files
45{
46    my ( $filesref ) = @_;
47
48    my $infoline = "";
49
50    for ( my $i = 0; $i <= $#{$filesref}; $i++ )
51    {
52        if ( ! exists(${$filesref}[$i]->{'modules'}) ) { installer::exiter::exit_program("ERROR: No module assignment found for ${$filesref}[$i]->{'gid'} !", "assign_cab_to_files"); }
53        my $module = ${$filesref}[$i]->{'modules'};
54        # If modules contains a list of modules, only taking the first one.
55        if ( $module =~ /^\s*(.*?)\,/ ) { $module = $1; }
56
57        if ( ! exists($installer::globals::allcabinetassigns{$module}) ) { installer::exiter::exit_program("ERROR: No cabinet file assigned to module \"$module\" (${$filesref}[$i]->{'gid'}) !", "assign_cab_to_files"); }
58        ${$filesref}[$i]->{'assignedcabinetfile'} = $installer::globals::allcabinetassigns{$module};
59
60        # Counting the files in each cabinet file
61        if ( ! exists($installer::globals::cabfilecounter{${$filesref}[$i]->{'assignedcabinetfile'}}) )
62        {
63            $installer::globals::cabfilecounter{${$filesref}[$i]->{'assignedcabinetfile'}} = 1;
64        }
65        else
66        {
67            $installer::globals::cabfilecounter{${$filesref}[$i]->{'assignedcabinetfile'}}++;
68        }
69    }
70
71    # logging the number of files in each cabinet file
72
73    $infoline = "\nCabinet file content:\n";
74    push(@installer::globals::logfileinfo, $infoline);
75    my $cabfile;
76    foreach $cabfile ( sort keys %installer::globals::cabfilecounter )
77    {
78        $infoline = "$cabfile : $installer::globals::cabfilecounter{$cabfile} files\n";
79        push(@installer::globals::logfileinfo, $infoline);
80    }
81
82    # assigning startsequencenumbers for each cab file
83
84    my $offset = 1;
85    foreach $cabfile ( sort keys %installer::globals::cabfilecounter )
86    {
87        my $filecount = $installer::globals::cabfilecounter{$cabfile};
88        $installer::globals::cabfilecounter{$cabfile} = $offset;
89        $offset = $offset + $filecount;
90
91        $installer::globals::lastsequence{$cabfile} = $offset - 1;
92    }
93
94    # logging the start sequence numbers
95
96    $infoline = "\nCabinet file start sequences:\n";
97    push(@installer::globals::logfileinfo, $infoline);
98    foreach $cabfile ( sort keys %installer::globals::cabfilecounter )
99    {
100        $infoline = "$cabfile : $installer::globals::cabfilecounter{$cabfile}\n";
101        push(@installer::globals::logfileinfo, $infoline);
102    }
103
104    # logging the last sequence numbers
105
106    $infoline = "\nCabinet file last sequences:\n";
107    push(@installer::globals::logfileinfo, $infoline);
108    foreach $cabfile ( sort keys %installer::globals::lastsequence )
109    {
110        $infoline = "$cabfile : $installer::globals::lastsequence{$cabfile}\n";
111        push(@installer::globals::logfileinfo, $infoline);
112    }
113}
114
115##########################################################################
116# Assigning sequencenumbers to files. This is requrired,
117# if cabinet files shall be equivalent to packages.
118##########################################################################
119
120sub assign_sequencenumbers_to_files
121{
122    my ( $filesref ) = @_;
123
124    my %directaccess = ();
125    my %allassigns = ();
126
127    for ( my $i = 0; $i <= $#{$filesref}; $i++ )
128    {
129        my $onefile = ${$filesref}[$i];
130
131        # Keeping order in cabinet files
132        # -> collecting all files in one cabinet file
133        # -> sorting files and assigning numbers
134
135        # Saving counter $i for direct access into files array
136        # "destination" of the file is a unique identifier ('Name' is not unique!)
137        if ( exists($directaccess{$onefile->{'destination'}}) ) { installer::exiter::exit_program("ERROR: 'destination' at file not unique: $onefile->{'destination'}", "assign_sequencenumbers_to_files"); }
138        $directaccess{$onefile->{'destination'}} = $i;
139
140        my $cabfilename = $onefile->{'assignedcabinetfile'};
141        # collecting files in cabinet files
142        if ( ! exists($allassigns{$cabfilename}) )
143        {
144            my %onecabfile = ();
145            $onecabfile{$onefile->{'destination'}} = 1;
146            $allassigns{$cabfilename} = \%onecabfile;
147        }
148        else
149        {
150            $allassigns{$cabfilename}->{$onefile->{'destination'}} = 1;
151        }
152    }
153
154    # Sorting each hash and assigning numbers
155    # The destination of the file determines the sort order, not the filename!
156    my $cabfile;
157    foreach $cabfile ( sort keys %allassigns )
158    {
159        my $counter = $installer::globals::cabfilecounter{$cabfile};
160        my $dest;
161        foreach $dest ( sort keys %{$allassigns{$cabfile}} ) # <- sorting the destination!
162        {
163            my $directaccessnumber = $directaccess{$dest};
164            ${$filesref}[$directaccessnumber]->{'assignedsequencenumber'} = $counter;
165            $counter++;
166        }
167    }
168}
169
170#########################################################
171# Create a shorter version of a long component name,
172# because maximum length in msi database is 72.
173# Attention: In multi msi installation sets, the short
174# names have to be unique over all packages, because
175# this string is used to create the globally unique id
176# -> no resetting of
177# %installer::globals::allshortcomponents
178# after a package was created.
179# Using no counter because of reproducibility.
180#########################################################
181
182sub generate_new_short_componentname
183{
184    my ($componentname) = @_;
185
186    my $startversion = substr($componentname, 0, 60); # taking only the first 60 characters
187    my $subid = installer::windows::msiglobal::calculate_id($componentname, 9); # taking only the first 9 digits
188    my $shortcomponentname = $startversion . "_" . $subid;
189
190    if ( exists($installer::globals::allshortcomponents{$shortcomponentname}) ) { installer::exiter::exit_program("Failed to create unique component name: \"$shortcomponentname\"", "generate_new_short_componentname"); }
191
192    $installer::globals::allshortcomponents{$shortcomponentname} = 1;
193
194    return $shortcomponentname;
195}
196
197###############################################
198# Generating the component name from a file
199###############################################
200
201sub get_file_component_name
202{
203    my ($fileref, $filesref) = @_;
204
205    my $componentname = "";
206
207    # Special handling for files with ASSIGNCOMPOMENT
208
209    my $styles = "";
210    if ( $fileref->{'Styles'} ) { $styles = $fileref->{'Styles'}; }
211    if ( $styles =~ /\bASSIGNCOMPOMENT\b/ )
212    {
213        $componentname = get_component_from_assigned_file($fileref->{'AssignComponent'}, $filesref);
214    }
215    else
216    {
217        # In this function exists the rule to create components from files
218        # Rule:
219        # Two files get the same componentid, if:
220        # both have the same destination directory.
221        # both have the same "gid" -> both were packed in the same zip file
222        # All other files are included into different components!
223
224        # my $componentname = $fileref->{'gid'} . "_" . $fileref->{'Dir'};
225
226        # $fileref->{'Dir'} is not sufficient! All files in a zip file have the same $fileref->{'Dir'},
227        # but can be in different subdirectories.
228        # Solution: destination=share\Scripts\beanshell\Capitalise\capitalise.bsh
229        # in which the filename (capitalise.bsh) has to be removed and all backslashes (slashes) are
230        # converted into underline.
231
232        my $destination = $fileref->{'destination'};
233        installer::pathanalyzer::get_path_from_fullqualifiedname(\$destination);
234        $destination =~ s/\s//g;
235        $destination =~ s/\\/\_/g;
236        $destination =~ s/\//\_/g;
237        $destination =~ s/\_\s*$//g;    # removing ending underline
238
239        $componentname = $fileref->{'gid'} . "__" . $destination;
240
241        # Files with different languages, need to be packed into different components.
242        # Then the installation of the language specific component is determined by a language condition.
243
244        if ( $fileref->{'ismultilingual'} )
245        {
246            my $officelanguage = $fileref->{'specificlanguage'};
247            $componentname = $componentname . "_" . $officelanguage;
248        }
249
250        $componentname = lc($componentname);    # componentnames always lowercase
251
252        $componentname =~ s/\-/\_/g;            # converting "-" to "_"
253        $componentname =~ s/\./\_/g;            # converting "-" to "_"
254
255        # Attention: Maximum length for the componentname is 72
256        # %installer::globals::allcomponents_in_this_database : resetted for each database
257        # %installer::globals::allcomponents : not resetted for each database
258        # Component strings must be unique for the complete product, because they are used for
259        # the creation of the globally unique identifier.
260
261        my $fullname = $componentname;  # This can be longer than 72
262
263        if (( exists($installer::globals::allcomponents{$fullname}) ) && ( ! exists($installer::globals::allcomponents_in_this_database{$fullname}) ))
264        {
265            # This is not allowed: One component cannot be installed with different packages.
266            installer::exiter::exit_program("ERROR: Component \"$fullname\" is already included into another package. This is not allowed.", "get_file_component_name");
267        }
268
269        if ( exists($installer::globals::allcomponents{$fullname}) )
270        {
271            $componentname = $installer::globals::allcomponents{$fullname};
272        }
273        else
274        {
275            if ( length($componentname) > 70 )
276            {
277                $componentname = generate_new_short_componentname($componentname); # This has to be unique for the complete product, not only one package
278            }
279
280            $installer::globals::allcomponents{$fullname} = $componentname;
281            $installer::globals::allcomponents_in_this_database{$fullname} = 1;
282        }
283
284        # $componentname =~ s/gid_file_/g_f_/g;
285        # $componentname =~ s/_extra_/_e_/g;
286        # $componentname =~ s/_config_/_c_/g;
287        # $componentname =~ s/_org_openoffice_/_o_o_/g;
288        # $componentname =~ s/_program_/_p_/g;
289        # $componentname =~ s/_typedetection_/_td_/g;
290        # $componentname =~ s/_linguistic_/_l_/g;
291        # $componentname =~ s/_module_/_m_/g;
292        # $componentname =~ s/_optional_/_opt_/g;
293        # $componentname =~ s/_packages/_pack/g;
294        # $componentname =~ s/_menubar/_mb/g;
295        # $componentname =~ s/_common_/_cm_/g;
296        # $componentname =~ s/_export_/_exp_/g;
297        # $componentname =~ s/_table_/_tb_/g;
298        # $componentname =~ s/_sofficecfg_/_sc_/g;
299        # $componentname =~ s/_soffice_cfg_/_sc_/g;
300        # $componentname =~ s/_startmodulecommands_/_smc_/g;
301        # $componentname =~ s/_drawimpresscommands_/_dic_/g;
302        # $componentname =~ s/_basiccommands_/_bac_/g;
303        # $componentname =~ s/_basicidecommands_/_baic_/g;
304        # $componentname =~ s/_genericcommands_/_genc_/g;
305        # $componentname =~ s/_bibliographycommands_/_bibc_/g;
306        # $componentname =~ s/_gentiumbookbasicbolditalic_/_gbbbi_/g;
307        # $componentname =~ s/_share_/_s_/g;
308        # $componentname =~ s/_extension_/_ext_/g;
309        # $componentname =~ s/_extensions_/_exs_/g;
310        # $componentname =~ s/_modules_/_ms_/g;
311        # $componentname =~ s/_uiconfig_zip_/_ucz_/g;
312        # $componentname =~ s/_productivity_/_pr_/g;
313        # $componentname =~ s/_wizard_/_wz_/g;
314        # $componentname =~ s/_import_/_im_/g;
315        # $componentname =~ s/_javascript_/_js_/g;
316        # $componentname =~ s/_template_/_tpl_/g;
317        # $componentname =~ s/_tplwizletter_/_twl_/g;
318        # $componentname =~ s/_beanshell_/_bs_/g;
319        # $componentname =~ s/_presentation_/_bs_/g;
320        # $componentname =~ s/_columns_/_cls_/g;
321        # $componentname =~ s/_python_/_py_/g;
322
323        # $componentname =~ s/_tools/_ts/g;
324        # $componentname =~ s/_transitions/_trs/g;
325        # $componentname =~ s/_scriptbinding/_scrb/g;
326        # $componentname =~ s/_spreadsheet/_ssh/g;
327        # $componentname =~ s/_publisher/_pub/g;
328        # $componentname =~ s/_presenter/_pre/g;
329        # $componentname =~ s/_registry/_reg/g;
330
331        # $componentname =~ s/screen/sc/g;
332        # $componentname =~ s/wordml/wm/g;
333        # $componentname =~ s/openoffice/oo/g;
334    }
335
336    return $componentname;
337}
338
339####################################################################
340# Returning the component name for a defined file gid.
341# This is necessary for files with flag ASSIGNCOMPOMENT
342####################################################################
343
344sub get_component_from_assigned_file
345{
346    my ($gid, $filesref) = @_;
347
348    my $onefile = installer::existence::get_specified_file($filesref, $gid);
349    my $componentname = "";
350    if ( $onefile->{'componentname'} ) { $componentname = $onefile->{'componentname'}; }
351    else { installer::exiter::exit_program("ERROR: No component defined for file: $gid", "get_component_from_assigned_file"); }
352
353    return $componentname;
354}
355
356####################################################################
357# Generating the special filename for the database file File.idt
358# Sample: CONTEXTS, CONTEXTS1
359# This name has to be unique.
360# In most cases this is simply the filename.
361####################################################################
362
363sub generate_unique_filename_for_filetable
364{
365    my ($fileref, $component, $uniquefilenamehashref) = @_;
366
367    # This new filename has to be saved into $fileref, because this is needed to find the source.
368    # The filename sbasic.idx/OFFSETS is changed to OFFSETS, but OFFSETS is not unique.
369    # In this procedure names like OFFSETS5 are produced. And exactly this string has to be added to
370    # the array of all files.
371
372    my $uniquefilename = "";
373    my $counter = 0;
374
375    if ( $fileref->{'Name'} ) { $uniquefilename = $fileref->{'Name'}; }
376
377    installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$uniquefilename); # making /registry/schema/org/openoffice/VCL.xcs to VCL.xcs
378
379    # Reading unique filename with help of "Component_" in File table from old database
380    if (( $installer::globals::updatedatabase ) && ( exists($uniquefilenamehashref->{"$component/$uniquefilename"}) ))
381    {
382        $uniquefilename = $uniquefilenamehashref->{"$component/$uniquefilename"};  # syntax of $value: ($uniquename;$shortname)
383        if ( $uniquefilename =~ /^\s*(.*?)\;\s*(.*?)\s*$/ ) { $uniquefilename = $1; }
384        $lcuniquefilename = lc($uniquefilename);
385        $installer::globals::alluniquefilenames{$uniquefilename} = 1;
386        $installer::globals::alllcuniquefilenames{$lcuniquefilename} = 1;
387        return $uniquefilename;
388    }
389    elsif (( $installer::globals::prepare_winpatch ) && ( exists($installer::globals::savedmapping{"$component/$uniquefilename"}) ))
390    {
391        # If we have a FTK mapping for this component/file, use it.
392        $installer::globals::savedmapping{"$component/$uniquefilename"} =~ m/^(.*);/;
393        $uniquefilename = $1;
394        $lcuniquefilename = lc($uniquefilename);
395        $installer::globals::alluniquefilenames{$uniquefilename} = 1;
396        $installer::globals::alllcuniquefilenames{$lcuniquefilename} = 1;
397        return $uniquefilename;
398    }
399
400    $uniquefilename =~ s/\-/\_/g;       # no "-" allowed
401    $uniquefilename =~ s/\@/\_/g;       # no "@" allowed
402    $uniquefilename =~ s/\$/\_/g;       # no "$" allowed
403    $uniquefilename =~ s/^\s*\./\_/g;       # no "." at the beginning allowed allowed
404    $uniquefilename =~ s/^\s*\d/\_d/g;      # no number at the beginning allowed allowed (even file "0.gif", replacing to "_d.gif")
405    $uniquefilename =~ s/org_openoffice_/ooo_/g;    # shorten the unique file name
406
407    my $lcuniquefilename = lc($uniquefilename); # only lowercase names
408
409    my $newname = 0;
410
411    if ( ! exists($installer::globals::alllcuniquefilenames{$lcuniquefilename}) &&
412         ! exists($installer::globals::savedrevmapping{$lcuniquefilename}) )
413    {
414        $installer::globals::alluniquefilenames{$uniquefilename} = 1;
415        $installer::globals::alllcuniquefilenames{$lcuniquefilename} = 1;
416        $newname = 1;
417    }
418
419    if ( ! $newname )
420    {
421        # adding a number until the name is really unique: OFFSETS, OFFSETS1, OFFSETS2, ...
422        # But attention: Making "abc.xcu" to "abc1.xcu"
423
424        my $uniquefilenamebase = $uniquefilename;
425
426        do
427        {
428            $counter++;
429
430            if ( $uniquefilenamebase =~ /\./ )
431            {
432                $uniquefilename = $uniquefilenamebase;
433                $uniquefilename =~ s/\./$counter\./;
434            }
435            else
436            {
437                $uniquefilename = $uniquefilenamebase . $counter;
438            }
439
440            $newname = 0;
441            $lcuniquefilename = lc($uniquefilename);    # only lowercase names
442
443            if ( ! exists($installer::globals::alllcuniquefilenames{$lcuniquefilename}) &&
444                 ! exists($installer::globals::savedrevmapping{$lcuniquefilename}) )
445            {
446                $installer::globals::alluniquefilenames{$uniquefilename} = 1;
447                $installer::globals::alllcuniquefilenames{$lcuniquefilename} = 1;
448                $newname = 1;
449            }
450        }
451        until ( $newname )
452    }
453
454    return $uniquefilename;
455}
456
457####################################################################
458# Generating the special file column for the database file File.idt
459# Sample: NAMETR~1.TAB|.nametranslation.table
460# The first part has to be 8.3 conform.
461####################################################################
462
463sub generate_filename_for_filetable
464{
465    my ($fileref, $shortnamesref, $uniquefilenamehashref) = @_;
466
467    my $returnstring = "";
468
469    my $filename = $fileref->{'Name'};
470
471    installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$filename);   # making /registry/schema/org/openoffice/VCL.xcs to VCL.xcs
472
473    my $shortstring;
474
475    # Reading short string with help of "FileName" in File table from old database
476    if (( $installer::globals::updatedatabase ) && ( exists($uniquefilenamehashref->{"$fileref->{'componentname'}/$filename"}) ))
477    {
478        my $value = $uniquefilenamehashref->{"$fileref->{'componentname'}/$filename"};  # syntax of $value: ($uniquename;$shortname)
479        if ( $value =~ /^\s*(.*?)\;\s*(.*?)\s*$/ ) { $shortstring = $2; } # already collected in function "collect_shortnames_from_old_database"
480        else { $shortstring = $filename; }
481    }
482    elsif (( $installer::globals::prepare_winpatch ) && ( exists($installer::globals::savedmapping{"$fileref->{'componentname'}/$filename"}) ))
483    {
484        $installer::globals::savedmapping{"$fileref->{'componentname'}/$filename"} =~ m/.*;(.*)/;
485        if ($1 ne '')
486        {
487            $shortstring = $1;
488        }
489        else
490        {
491            $shortstring = installer::windows::idtglobal::make_eight_three_conform_with_hash($filename, "file", $shortnamesref);
492        }
493    }
494    else
495    {
496        $shortstring = installer::windows::idtglobal::make_eight_three_conform_with_hash($filename, "file", $shortnamesref);
497    }
498
499    if ( $shortstring eq $filename ) { $returnstring = $filename; } # nothing changed
500    else {$returnstring = $shortstring . "\|" . $filename; }
501
502    return $returnstring;
503}
504
505#########################################
506# Returning the filesize of a file
507#########################################
508
509sub get_filesize
510{
511    my ($fileref) = @_;
512
513    my $file = $fileref->{'sourcepath'};
514
515    my $filesize;
516
517    if ( -f $file ) # test of existence. For instance services.rdb does not always exist
518    {
519        $filesize = ( -s $file );   # file size can be "0"
520    }
521    else
522    {
523        $filesize = -1;
524    }
525
526    return $filesize;
527}
528
529#############################################
530# Returning the file version, if required
531# Sample: "8.0.1.8976";
532#############################################
533
534sub get_fileversion
535{
536    my ($onefile, $allvariables, $styles) = @_;
537
538    my $fileversion = "";
539
540    if ( $allvariables->{'USE_FILEVERSION'} )
541    {
542        if ( ! $allvariables->{'LIBRARYVERSION'} ) { installer::exiter::exit_program("ERROR: USE_FILEVERSION is set, but not LIBRARYVERSION", "get_fileversion"); }
543        my $libraryversion = $allvariables->{'LIBRARYVERSION'};
544        if ( $libraryversion =~ /^\s*(\d+)\.(\d+)\.(\d+)\s*$/ )
545        {
546            my $major = $1;
547            my $minor = $2;
548            my $micro = $3;
549            my $concat = 100 * $minor + $micro;
550            $libraryversion = $major . "\." . $concat;
551        }
552        my $vendornumber = 0;
553        if ( $allvariables->{'VENDORPATCHVERSION'} ) { $vendornumber = $allvariables->{'VENDORPATCHVERSION'}; }
554        $fileversion = $libraryversion . "\." . $installer::globals::buildid . "\." . $vendornumber;
555        if ( $onefile->{'FileVersion'} ) { $fileversion = $onefile->{'FileVersion'}; } # overriding FileVersion in scp
556
557        # if ( $styles =~ /\bFONT\b/ )
558        # {
559        #   my $newfileversion = installer::windows::font::get_font_version($onefile->{'sourcepath'});
560        #   if ( $newfileversion != 0 ) { $fileversion = $newfileversion; }
561        # }
562    }
563
564    if ( $installer::globals::prepare_winpatch ) { $fileversion = ""; } # Windows patches do not allow this version # -> who says so?
565
566    return $fileversion;
567}
568
569#############################################
570# Returning the sequence for a file
571#############################################
572
573sub get_sequence_for_file
574{
575    my ($number, $onefile, $fileentry, $allupdatesequenceshashref, $allupdatecomponentshashref, $allupdatefileorderhashref, $allfilecomponents) = @_;
576
577    my $sequence = "";
578    my $infoline = "";
579    my $pffcomponentname = $onefile->{'componentname'} . "_pff";
580
581    if ( $installer::globals::updatedatabase )
582    {
583        if (( exists($allupdatesequenceshashref->{$onefile->{'uniquename'}}) ) &&
584            (( $onefile->{'componentname'} eq $allupdatecomponentshashref->{$onefile->{'uniquename'}} ) ||
585             ( $pffcomponentname eq $allupdatecomponentshashref->{$onefile->{'uniquename'}} )))
586        {
587            # The second condition is necessary to find shifted files, that have same "uniquename", but are now
588            # located in another directory. This can be seen at the component name.
589            $sequence = $allupdatesequenceshashref->{$onefile->{'uniquename'}};
590            $onefile->{'assignedsequencenumber'} = $sequence;
591            # Collecting all used sequences, to guarantee, that no number is unused
592            $installer::globals::allusedupdatesequences{$sequence} = 1;
593            # Special help for files, that already have a "pff" component name (for example after ServicePack 1)
594            if ( $pffcomponentname eq $allupdatecomponentshashref->{$onefile->{'uniquename'}} )
595            {
596                $infoline = "Warning: Special handling for component \"$pffcomponentname\". This file was added after the final, but before this ServicePack.\n";
597                push(@installer::globals::logfileinfo, $infoline);
598                $onefile->{'componentname'} = $pffcomponentname; # pff for "post final file"
599                $fileentry->{'Component_'} = $onefile->{'componentname'};
600                if ( ! exists($allfilecomponents->{$fileentry->{'Component_'}}) ) { $allfilecomponents->{$fileentry->{'Component_'}} = 1; }
601            }
602        }
603        else
604        {
605            $installer::globals::updatesequencecounter++;
606            $sequence = $installer::globals::updatesequencecounter;
607            $onefile->{'assignedsequencenumber'} = $sequence;
608            # $onefile->{'assignedcabinetfile'} = $installer::globals::pffcabfilename; # assigning to cabinet file for "post final files"
609            # Collecting all new files
610            $installer::globals::newupdatefiles{$sequence} = $onefile;
611            # Saving in sequence hash
612            $allupdatefileorderhashref->{$sequence} = $onefile->{'uniquename'};
613
614            # If the new file is part of an existing component, this must be changed now. All files
615            # of one component have to be included in one cabinet file. But because the order must
616            # not change, all new files have to be added to new components.
617            # $onefile->{'componentname'} = $file{'Component_'};
618
619            $onefile->{'componentname'} = $onefile->{'componentname'} . "_pff"; # pff for "post final file"
620            $fileentry->{'Component_'} = $onefile->{'componentname'};
621            if ( ! exists($allfilecomponents->{$fileentry->{'Component_'}}) ) { $allfilecomponents->{$fileentry->{'Component_'}} = 1; }
622            $onefile->{'PostFinalFile'} = 1;
623            # $installer::globals::pfffileexists = 1;
624            # The sequence for this file has changed. It has to be inserted at the end of the files collector.
625            $installer::globals::insert_file_at_end = 1;
626            $installer::globals::newfilescollector{$sequence} = $onefile; # Adding new files to the end of the filescollector
627            $installer::globals::newfilesexist = 1;
628        }
629    }
630    elsif (( $onefile->{'assignedsequencenumber'} ) && ( $installer::globals::use_packages_for_cabs ))
631    {
632        $sequence = $onefile->{'assignedsequencenumber'};
633    }
634    else
635    {
636        $sequence = $number;
637        # my $sequence = $number + 1;
638
639        # Idea: Each component is packed into a cab file.
640        # This requires that all files in one cab file have sequences directly follwing each other,
641        # for instance from 1456 to 1466. Then in the media table the LastSequence for this cab file
642        # is 1466.
643        # Because all files belonging to one component are directly behind each other in the file
644        # collector, it is possible to use simply an increasing number as sequence value.
645        # If files belonging to one component are not directly behind each other in the files collector
646        # this mechanism will no longer work.
647    }
648
649    return $sequence;
650}
651
652#############################################
653# Returning the Windows language of a file
654#############################################
655
656sub get_language_for_file
657{
658    my ($fileref) = @_;
659
660    my $language = "";
661
662    if ( $fileref->{'specificlanguage'} ) { $language = $fileref->{'specificlanguage'}; }
663
664    if ( $language eq "" )
665    {
666        $language = 0;  # language independent
667        # If this is not a font, the return value should be "0" (Check ICE 60)
668        my $styles = "";
669        if ( $fileref->{'Styles'} ) { $styles = $fileref->{'Styles'}; }
670        if ( $styles =~ /\bFONT\b/ ) { $language = ""; }
671    }
672    else
673    {
674        $language = installer::windows::language::get_windows_language($language);
675    }
676
677    return $language;
678}
679
680####################################################################
681# Creating a new KeyPath for components in TemplatesFolder.
682####################################################################
683
684sub generate_registry_keypath
685{
686    my ($onefile) = @_;
687
688    my $keypath = $onefile->{'Name'};
689    $keypath =~ s/\.//g;
690    $keypath = lc($keypath);
691    $keypath = "userreg_" . $keypath;
692
693    return $keypath;
694}
695
696####################################################################
697# Check, if in an update process files are missing. No removal
698# of files allowed for Windows Patch creation.
699# Also logging all new files, that have to be included in extra
700# components and cab files.
701####################################################################
702
703sub check_file_sequences
704{
705    my ($allupdatefileorderhashref, $allupdatecomponentorderhashref) = @_;
706
707    # All used sequences stored in %installer::globals::allusedupdatesequences
708    # Maximum sequence number of old database stored in $installer::globals::updatelastsequence
709    # All new files stored in %installer::globals::newupdatefiles
710
711    my $infoline = "";
712
713    my @missing_sequences = ();
714    my @really_missing_sequences = ();
715
716    for ( my $i = 1; $i <= $installer::globals::updatelastsequence; $i++ )
717    {
718        if ( ! exists($installer::globals::allusedupdatesequences{$i}) ) { push(@missing_sequences, $i); }
719    }
720
721    if ( $#missing_sequences > -1 )
722    {
723        # Missing sequences can also be caused by files included in merge modules. This files are added later into the file table.
724        # Therefore now it is time to check the content of the merge modules.
725
726        for ( my $j = 0; $j <= $#missing_sequences; $j++ )
727        {
728            my $filename = $allupdatefileorderhashref->{$missing_sequences[$j]};
729
730            # Is this a file from a merge module? Then this is no error.
731            if ( ! exists($installer::globals::mergemodulefiles{$filename}) )
732            {
733                push(@really_missing_sequences, $missing_sequences[$j]);
734            }
735        }
736    }
737
738    if ( $#really_missing_sequences > -1 )
739    {
740        my $errorstring = "";
741        for ( my $j = 0; $j <= $#really_missing_sequences; $j++ )
742        {
743            my $filename = $allupdatefileorderhashref->{$really_missing_sequences[$j]};
744            my $comp = $allupdatecomponentorderhashref->{$really_missing_sequences[$j]};
745            $errorstring = "$errorstring$filename (Sequence: $really_missing_sequences[$j], Component: \"$comp\")\n";
746        }
747
748        $infoline = "ERROR: Files are removed compared with update database.\nThe following files are missing:\n$errorstring";
749        push(@installer::globals::logfileinfo, $infoline);
750        installer::exiter::exit_program($infoline, "check_file_sequences");
751    }
752
753    # Searching for new files
754
755    my $counter = 0;
756
757    foreach my $key ( keys %installer::globals::newupdatefiles )
758    {
759        my $onefile = $installer::globals::newupdatefiles{$key};
760        $counter++;
761        if ( $counter == 1 )
762        {
763            $infoline = "\nNew files compared to the update database:\n";
764            push(@installer::globals::logfileinfo, $infoline);
765        }
766
767        $infoline = "$onefile->{'Name'} ($onefile->{'gid'}) Sequence: $onefile->{'assignedsequencenumber'}\n";
768        push(@installer::globals::logfileinfo, $infoline);
769    }
770
771    if ( $counter == 0 )
772    {
773        $infoline = "Info: No new file compared with update database!\n";
774        push(@installer::globals::logfileinfo, $infoline);
775    }
776
777}
778
779###################################################################
780# Collecting further conditions for the component table.
781# This is used by multilayer products, to enable installation
782# of separate layers.
783###################################################################
784
785sub get_tree_condition_for_component
786{
787    my ($onefile, $componentname) = @_;
788
789    if ( $onefile->{'destination'} )
790    {
791        my $dest = $onefile->{'destination'};
792
793        # Comparing the destination path with
794        # $installer::globals::hostnametreestyles{$hostname} = $treestyle;
795        # (-> hostname is the key, the style the value!)
796
797        foreach my $hostname ( keys %installer::globals::hostnametreestyles )
798        {
799            if (( $dest eq $hostname ) || ( $dest =~ /^\s*\Q$hostname\E\\/ ))
800            {
801                # the value is the style
802                my $style = $installer::globals::hostnametreestyles{$hostname};
803                # the condition is saved in %installer::globals::treestyles
804                my $condition = $installer::globals::treestyles{$style};
805                # Saving condition to be added in table Property
806                $installer::globals::usedtreeconditions{$condition} = 1;
807                $condition = $condition . "=1";
808                # saving this condition
809                $installer::globals::treeconditions{$componentname} = $condition;
810
811                # saving also at the file, for usage in fileinfo
812                $onefile->{'layer'} = $installer::globals::treelayername{$style};
813            }
814        }
815    }
816}
817
818############################################
819# Collecting all short names, that are
820# already used by the old database
821############################################
822
823sub collect_shortnames_from_old_database
824{
825    my ($uniquefilenamehashref, $shortnameshashref) = @_;
826
827    foreach my $key ( keys %{$uniquefilenamehashref} )
828    {
829        my $value = $uniquefilenamehashref->{$key};  # syntax of $value: ($uniquename;$shortname)
830
831        if ( $value =~ /^\s*(.*?)\;\s*(.*?)\s*$/ )
832        {
833            my $shortstring = $2;
834            $shortnameshashref->{$shortstring} = 1; # adding the shortname to the array of all shortnames
835        }
836    }
837}
838
839############################################
840# Creating the file File.idt dynamically
841############################################
842
843sub create_files_table
844{
845    my ($filesref, $allfilecomponentsref, $basedir, $allvariables, $uniquefilenamehashref, $allupdatesequenceshashref, $allupdatecomponentshashref, $allupdatefileorderhashref) = @_;
846
847    installer::logger::include_timestamp_into_logfile("Performance Info: File Table start");
848
849    # Structure of the files table:
850    # File Component_ FileName FileSize Version Language Attributes Sequence
851    # In this function, all components are created.
852    #
853    # $allfilecomponentsref is empty at the beginning
854
855    my $infoline;
856
857    my @allfiles = ();
858    my @filetable = ();
859    my @filehashtable = ();
860    my %allfilecomponents = ();
861    my $counter = 0;
862
863    if ( $^O =~ /cygwin/i ) { installer::worker::generate_cygwin_pathes($filesref); }
864
865    # The filenames must be collected because of uniqueness
866    # 01-44-~1.DAT, 01-44-~2.DAT, ...
867    # my @shortnames = ();
868    my %shortnames = ();
869
870    if ( $installer::globals::updatedatabase ) { collect_shortnames_from_old_database($uniquefilenamehashref, \%shortnames); }
871
872    installer::windows::idtglobal::write_idt_header(\@filetable, "file");
873    installer::windows::idtglobal::write_idt_header(\@filehashtable, "filehash");
874
875    for ( my $i = 0; $i <= $#{$filesref}; $i++ )
876    {
877        my %file = ();
878
879        my $onefile = ${$filesref}[$i];
880
881        my $styles = "";
882        if ( $onefile->{'Styles'} ) { $styles = $onefile->{'Styles'}; }
883        if (( $styles =~ /\bJAVAFILE\b/ ) && ( ! ($allvariables->{'JAVAPRODUCT'} ))) { next; }
884
885        $file{'Component_'} = get_file_component_name($onefile, $filesref);
886        $file{'File'} = generate_unique_filename_for_filetable($onefile, $file{'Component_'}, $uniquefilenamehashref);
887
888        $onefile->{'uniquename'} = $file{'File'};
889        $onefile->{'componentname'} = $file{'Component_'};
890
891        # Collecting all components
892        # if (!(installer::existence::exists_in_array($file{'Component_'}, $allfilecomponentsref))) { push(@{$allfilecomponentsref}, $file{'Component_'}); }
893
894        if ( ! exists($allfilecomponents{$file{'Component_'}}) ) { $allfilecomponents{$file{'Component_'}} = 1; }
895
896        $file{'FileName'} = generate_filename_for_filetable($onefile, \%shortnames, $uniquefilenamehashref);
897
898        $file{'FileSize'} = get_filesize($onefile);
899
900        $file{'Version'} = get_fileversion($onefile, $allvariables, $styles);
901
902        $file{'Language'} = get_language_for_file($onefile);
903
904        if ( $styles =~ /\bDONT_PACK\b/ ) { $file{'Attributes'} = "8192"; }
905        else { $file{'Attributes'} = "16384"; }
906
907        # $file{'Attributes'} = "16384";    # Sourcefile is packed
908        # $file{'Attributes'} = "8192";     # Sourcefile is unpacked
909
910        $installer::globals::insert_file_at_end = 0;
911        $counter++;
912        $file{'Sequence'} = get_sequence_for_file($counter, $onefile, \%file, $allupdatesequenceshashref, $allupdatecomponentshashref, $allupdatefileorderhashref, \%allfilecomponents);
913
914        $onefile->{'sequencenumber'} = $file{'Sequence'};
915
916        my $oneline = $file{'File'} . "\t" . $file{'Component_'} . "\t" . $file{'FileName'} . "\t"
917                . $file{'FileSize'} . "\t" . $file{'Version'} . "\t" . $file{'Language'} . "\t"
918                . $file{'Attributes'} . "\t" . $file{'Sequence'} . "\n";
919
920        push(@filetable, $oneline);
921
922        if ( ! $installer::globals::insert_file_at_end ) { push(@allfiles, $onefile); }
923
924        # Collecting all component conditions
925        if ( $onefile->{'ComponentCondition'} )
926        {
927            if ( ! exists($installer::globals::componentcondition{$file{'Component_'}}))
928            {
929                $installer::globals::componentcondition{$file{'Component_'}} = $onefile->{'ComponentCondition'};
930            }
931        }
932
933        # Collecting also all tree conditions for multilayer products
934        get_tree_condition_for_component($onefile, $file{'Component_'});
935
936        # Collecting all component names, that have flag VERSION_INDEPENDENT_COMP_ID
937        # This should be all components with constant API, for example URE
938        if ( $styles =~ /\bVERSION_INDEPENDENT_COMP_ID\b/ )
939        {
940            $installer::globals::base_independent_components{$onefile->{'componentname'}} = 1;
941        }
942
943        # Collecting all component ids, that are defined at files in scp project (should not be used anymore)
944        if ( $onefile->{'CompID'} )
945        {
946            if ( ! exists($installer::globals::componentid{$onefile->{'componentname'}}))
947            {
948                $installer::globals::componentid{$onefile->{'componentname'}} = $onefile->{'CompID'};
949            }
950            else
951            {
952                if ( $installer::globals::componentid{$onefile->{'componentname'}} ne $onefile->{'CompID'} )
953                {
954                    installer::exiter::exit_program("ERROR: There is already a ComponentID for component \"$onefile->{'componentname'}\" : \"$installer::globals::componentid{$onefile->{'componentname'}}\" . File \"$onefile->{'gid'}\" uses \"$onefile->{'CompID'}\" !", "create_files_table");
955                }
956            }
957
958            # Also checking vice versa. Is this ComponentID already used? If yes, is the componentname the same?
959
960            if ( ! exists($installer::globals::comparecomponentname{$onefile->{'CompID'}}))
961            {
962                $installer::globals::comparecomponentname{$onefile->{'CompID'}} = $onefile->{'componentname'};
963            }
964            else
965            {
966                if ( $installer::globals::comparecomponentname{$onefile->{'CompID'}} ne $onefile->{'componentname'} )
967                {
968                    installer::exiter::exit_program("ERROR: There is already a component for ComponentID \"$onefile->{'CompID'}\" : \"$installer::globals::comparecomponentname{$onefile->{'CompID'}}\" . File \"$onefile->{'gid'}\" has same component id but is included in component \"$onefile->{'componentname'}\" !", "create_files_table");
969                }
970            }
971        }
972
973        # Collecting all language specific conditions
974        # if ( $onefile->{'haslanguagemodule'} )
975        if ( $onefile->{'ismultilingual'} )
976        {
977            if ( $onefile->{'ComponentCondition'} ) { installer::exiter::exit_program("ERROR: Cannot set language condition. There is already another component condition for file $onefile->{'gid'}: \"$onefile->{'ComponentCondition'}\" !", "create_files_table"); }
978
979            if ( $onefile->{'specificlanguage'} eq "" ) { installer::exiter::exit_program("ERROR: There is no specific language for file at language module: $onefile->{'gid'} !", "create_files_table"); }
980            my $locallanguage = $onefile->{'specificlanguage'};
981            my $property = "IS" . $file{'Language'};
982            my $value = 1;
983            my $condition = $property . "=" . $value;
984
985            $onefile->{'ComponentCondition'} = $condition;
986
987            if ( exists($installer::globals::componentcondition{$file{'Component_'}}))
988            {
989                if ( $installer::globals::componentcondition{$file{'Component_'}} ne $condition ) { installer::exiter::exit_program("ERROR: There is already another component condition for file $onefile->{'gid'}: \"$installer::globals::componentcondition{$file{'Component_'}}\" and \"$condition\" !", "create_files_table"); }
990            }
991            else
992            {
993                $installer::globals::componentcondition{$file{'Component_'}} = $condition;
994            }
995
996            # collecting all properties for table Property
997            if ( ! exists($installer::globals::languageproperties{$property}) ) { $installer::globals::languageproperties{$property} = $value; }
998        }
999
1000        if ( $installer::globals::prepare_winpatch )
1001        {
1002            my $path = $onefile->{'sourcepath'};
1003            if ( $^O =~ /cygwin/i ) { $path = $onefile->{'cyg_sourcepath'}; }
1004
1005            open(FILE, $path) or die "ERROR: Can't open $path for creating file hash";
1006            binmode(FILE);
1007            my $hashinfo = pack("l", 20);
1008            $hashinfo .= Digest::MD5->new->addfile(*FILE)->digest;
1009
1010            my @i = unpack ('x[l]l4', $hashinfo);
1011            $oneline = $file{'File'} . "\t" .
1012                "0" . "\t" .
1013                $i[0] . "\t" .
1014                $i[1] . "\t" .
1015                $i[2] . "\t" .
1016                $i[3] . "\n";
1017            push (@filehashtable, $oneline);
1018        }
1019
1020        # Saving the sequence number in a hash with uniquefilename as key.
1021        # This is used for better performance in "save_packorder"
1022        $installer::globals::uniquefilenamesequence{$onefile->{'uniquename'}} = $onefile->{'sequencenumber'};
1023
1024        # Special handling for files in PREDEFINED_OSSHELLNEWDIR. These components
1025        # need as KeyPath a RegistryItem in HKCU
1026        my $destdir = "";
1027        if ( $onefile->{'Dir'} ) { $destdir = $onefile->{'Dir'}; }
1028
1029        if (( $destdir =~ /\bPREDEFINED_OSSHELLNEWDIR\b/ ) || ( $onefile->{'needs_user_registry_key'} ))
1030        {
1031            my $keypath = generate_registry_keypath($onefile);
1032            $onefile->{'userregkeypath'} = $keypath;
1033            push(@installer::globals::userregistrycollector, $onefile);
1034            $installer::globals::addeduserregitrykeys = 1;
1035        }
1036    }
1037
1038    # putting content from %allfilecomponents to $allfilecomponentsref for later usage
1039    foreach $localkey (keys %allfilecomponents ) { push( @{$allfilecomponentsref}, $localkey); }
1040
1041    my $filetablename = $basedir . $installer::globals::separator . "File.idt";
1042    installer::files::save_file($filetablename ,\@filetable);
1043    $infoline = "\nCreated idt file: $filetablename\n";
1044    push(@installer::globals::logfileinfo, $infoline);
1045
1046    installer::logger::include_timestamp_into_logfile("Performance Info: File Table end");
1047
1048    my $filehashtablename = $basedir . $installer::globals::separator . "MsiFileHash.idt";
1049    installer::files::save_file($filehashtablename ,\@filehashtable);
1050    $infoline = "\nCreated idt file: $filehashtablename\n";
1051    push(@installer::globals::logfileinfo, $infoline);
1052
1053    # Now the new files can be added to the files collector (only in update packaging processes)
1054    if ( $installer::globals::newfilesexist )
1055    {
1056        foreach my $seq (sort keys %installer::globals::newfilescollector) { push(@allfiles, $installer::globals::newfilescollector{$seq}) }
1057    }
1058
1059    return \@allfiles;
1060}
1061
10621;
1063