2 # This file is part of the LibreOffice project.
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 # This file incorporates work covered by the following license notice:
10 # Licensed to the Apache Software Foundation (ASF) under one or more
11 # contributor license agreements. See the NOTICE file distributed
12 # with this work for additional information regarding copyright
13 # ownership. The ASF licenses this file to you under the Apache
14 # License, Version 2.0 (the "License"); you may not use this file
15 # except in compliance with the License. You may obtain a copy of
16 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package installer
::windows
::file
;
25 use installer
::exiter
;
27 use installer
::globals
;
28 use installer
::logger
;
29 use installer
::pathanalyzer
;
30 use installer
::worker
;
31 use installer
::windows
::font
;
32 use installer
::windows
::idtglobal
;
33 use installer
::windows
::msiglobal
;
34 use installer
::windows
::language
;
35 use installer
::windows
::component
;
37 ##########################################################################
38 # Assigning one cabinet file to each file. This is required,
39 # if cabinet files shall be equivalent to packages.
40 ##########################################################################
42 sub assign_cab_to_files
44 my ( $filesref ) = @_;
48 for ( my $i = 0; $i <= $#{$filesref}; $i++ )
50 if ( ! exists(${$filesref}[$i]->{'modules'}) ) { installer
::exiter
::exit_program
("ERROR: No module assignment found for ${$filesref}[$i]->{'gid'} !", "assign_cab_to_files"); }
51 my $module = ${$filesref}[$i]->{'modules'};
52 # If modules contains a list of modules, only taking the first one.
53 if ( $module =~ /^\s*(.*?)\,/ ) { $module = $1; }
55 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"); }
56 ${$filesref}[$i]->{'assignedcabinetfile'} = $installer::globals
::allcabinetassigns
{$module};
58 # Counting the files in each cabinet file
59 if ( ! exists($installer::globals
::cabfilecounter
{${$filesref}[$i]->{'assignedcabinetfile'}}) )
61 $installer::globals
::cabfilecounter
{${$filesref}[$i]->{'assignedcabinetfile'}} = 1;
65 $installer::globals
::cabfilecounter
{${$filesref}[$i]->{'assignedcabinetfile'}}++;
69 # logging the number of files in each cabinet file
71 $infoline = "\nCabinet file content:\n";
72 push(@installer::globals
::logfileinfo
, $infoline);
74 foreach $cabfile ( sort keys %installer::globals
::cabfilecounter
)
76 $infoline = "$cabfile : $installer::globals::cabfilecounter{$cabfile} files\n";
77 push(@installer::globals
::logfileinfo
, $infoline);
80 # assigning startsequencenumbers for each cab file
83 foreach $cabfile ( sort keys %installer::globals
::cabfilecounter
)
85 my $filecount = $installer::globals
::cabfilecounter
{$cabfile};
86 $installer::globals
::cabfilecounter
{$cabfile} = $offset;
87 $offset = $offset + $filecount;
89 $installer::globals
::lastsequence
{$cabfile} = $offset - 1;
92 # logging the start sequence numbers
94 $infoline = "\nCabinet file start sequences:\n";
95 push(@installer::globals
::logfileinfo
, $infoline);
96 foreach $cabfile ( sort keys %installer::globals
::cabfilecounter
)
98 $infoline = "$cabfile : $installer::globals::cabfilecounter{$cabfile}\n";
99 push(@installer::globals
::logfileinfo
, $infoline);
102 # logging the last sequence numbers
104 $infoline = "\nCabinet file last sequences:\n";
105 push(@installer::globals
::logfileinfo
, $infoline);
106 foreach $cabfile ( sort keys %installer::globals
::lastsequence
)
108 $infoline = "$cabfile : $installer::globals::lastsequence{$cabfile}\n";
109 push(@installer::globals
::logfileinfo
, $infoline);
113 ##########################################################################
114 # Assigning sequencenumbers to files. This is required,
115 # if cabinet files shall be equivalent to packages.
116 ##########################################################################
118 sub assign_sequencenumbers_to_files
120 my ( $filesref ) = @_;
122 my %directaccess = ();
125 for ( my $i = 0; $i <= $#{$filesref}; $i++ )
127 my $onefile = ${$filesref}[$i];
129 # Keeping order in cabinet files
130 # -> collecting all files in one cabinet file
131 # -> sorting files and assigning numbers
133 # Saving counter $i for direct access into files array
134 # "destination" of the file is a unique identifier ('Name' is not unique!)
135 if ( exists($directaccess{$onefile->{'destination'}}) ) { installer
::exiter
::exit_program
("ERROR: 'destination' at file not unique: $onefile->{'destination'}", "assign_sequencenumbers_to_files"); }
136 $directaccess{$onefile->{'destination'}} = $i;
138 my $cabfilename = $onefile->{'assignedcabinetfile'};
139 # collecting files in cabinet files
140 if ( ! exists($allassigns{$cabfilename}) )
143 $onecabfile{$onefile->{'destination'}} = 1;
144 $allassigns{$cabfilename} = \
%onecabfile;
148 $allassigns{$cabfilename}->{$onefile->{'destination'}} = 1;
152 # Sorting each hash and assigning numbers
153 # The destination of the file determines the sort order, not the filename!
155 foreach $cabfile ( sort keys %allassigns )
157 my $counter = $installer::globals
::cabfilecounter
{$cabfile};
159 foreach $dest ( sort keys %{$allassigns{$cabfile}} ) # <- sorting the destination!
161 my $directaccessnumber = $directaccess{$dest};
162 ${$filesref}[$directaccessnumber]->{'assignedsequencenumber'} = $counter;
168 #########################################################
169 # Create a shorter version of a long component name,
170 # because maximum length in msi database is 72.
171 # Attention: In multi msi installation sets, the short
172 # names have to be unique over all packages, because
173 # this string is used to create the globally unique id
175 # %installer::globals::allshortcomponents
176 # after a package was created.
177 # Using no counter because of reproducibility.
178 #########################################################
180 sub generate_new_short_componentname
182 my ($componentname) = @_;
184 my $startversion = substr($componentname, 0, 60); # taking only the first 60 characters
185 my $subid = installer
::windows
::msiglobal
::calculate_id
($componentname, 9); # taking only the first 9 digits
186 my $shortcomponentname = $startversion . "_" . $subid;
188 if ( exists($installer::globals
::allshortcomponents
{$shortcomponentname}) ) { installer
::exiter
::exit_program
("Failed to create unique component name: \"$shortcomponentname\"", "generate_new_short_componentname"); }
190 $installer::globals
::allshortcomponents
{$shortcomponentname} = 1;
192 return $shortcomponentname;
195 ###############################################
196 # Generating the component name from a file
197 ###############################################
199 sub get_file_component_name
201 my ($fileref, $filesref) = @_;
203 my $componentname = "";
205 # Special handling for files with ASSIGNCOMPONENT
208 if ( $fileref->{'Styles'} ) { $styles = $fileref->{'Styles'}; }
209 if ( $styles =~ /\bASSIGNCOMPONENT\b/ )
211 $componentname = get_component_from_assigned_file
($fileref->{'AssignComponent'}, $filesref);
215 # In this function exists the rule to create components from files
217 # Two files get the same componentid, if:
218 # both have the same destination directory.
219 # both have the same "gid" -> both were packed in the same zip file
220 # All other files are included into different components!
222 # my $componentname = $fileref->{'gid'} . "_" . $fileref->{'Dir'};
224 # $fileref->{'Dir'} is not sufficient! All files in a zip file have the same $fileref->{'Dir'},
225 # but can be in different subdirectories.
226 # Solution: destination=share\Scripts\beanshell\Capitalise\capitalise.bsh
227 # in which the filename (capitalise.bsh) has to be removed and all backslashes (slashes) are
228 # converted into underline.
230 my $destination = $fileref->{'destination'};
231 installer
::pathanalyzer
::get_path_from_fullqualifiedname
(\
$destination);
232 $destination =~ s/\s//g;
233 $destination =~ s/\\/\_/g;
234 $destination =~ s/\//\_
/g
;
235 $destination =~ s/\_\s*$//g; # removing ending underline
237 $componentname = $fileref->{'gid'} . "__" . $destination;
239 # Files with different languages, need to be packed into different components.
240 # Then the installation of the language specific component is determined by a language condition.
242 if ( $fileref->{'ismultilingual'} )
244 my $officelanguage = $fileref->{'specificlanguage'};
245 $componentname = $componentname . "_" . $officelanguage;
248 $componentname = lc($componentname); # componentnames always lowercase
250 $componentname =~ s/\-/\_/g; # converting "-" to "_"
251 $componentname =~ s/\./\_/g; # converting "." to "_"
252 $componentname =~ s/\@/\_/g; # converting "@" to "_"
254 # Attention: Maximum length for the componentname is 72
255 # %installer::globals::allcomponents_in_this_database : reset for each database
256 # %installer::globals::allcomponents : not reset for each database
257 # Component strings must be unique for the complete product, because they are used for
258 # the creation of the globally unique identifier.
260 my $fullname = $componentname; # This can be longer than 72
262 if (( exists($installer::globals
::allcomponents
{$fullname}) ) && ( ! exists($installer::globals
::allcomponents_in_this_database
{$fullname}) ))
264 # This is not allowed: One component cannot be installed with different packages.
265 installer
::exiter
::exit_program
("ERROR: Component \"$fullname\" is already included into another package. This is not allowed.", "get_file_component_name");
268 if ( exists($installer::globals
::allcomponents
{$fullname}) )
270 $componentname = $installer::globals
::allcomponents
{$fullname};
274 if ( length($componentname) > 70 )
276 $componentname = generate_new_short_componentname
($componentname); # This has to be unique for the complete product, not only one package
279 $installer::globals
::allcomponents
{$fullname} = $componentname;
280 $installer::globals
::allcomponents_in_this_database
{$fullname} = 1;
283 # $componentname =~ s/gid_file_/g_f_/g;
284 # $componentname =~ s/_extra_/_e_/g;
285 # $componentname =~ s/_config_/_c_/g;
286 # $componentname =~ s/_org_openoffice_/_o_o_/g;
287 # $componentname =~ s/_program_/_p_/g;
288 # $componentname =~ s/_typedetection_/_td_/g;
289 # $componentname =~ s/_linguistic_/_l_/g;
290 # $componentname =~ s/_module_/_m_/g;
291 # $componentname =~ s/_optional_/_opt_/g;
292 # $componentname =~ s/_packages/_pack/g;
293 # $componentname =~ s/_menubar/_mb/g;
294 # $componentname =~ s/_common_/_cm_/g;
295 # $componentname =~ s/_export_/_exp_/g;
296 # $componentname =~ s/_table_/_tb_/g;
297 # $componentname =~ s/_sofficecfg_/_sc_/g;
298 # $componentname =~ s/_soffice_cfg_/_sc_/g;
299 # $componentname =~ s/_startmodulecommands_/_smc_/g;
300 # $componentname =~ s/_drawimpresscommands_/_dic_/g;
301 # $componentname =~ s/_basiccommands_/_bac_/g;
302 # $componentname =~ s/_basicidecommands_/_baic_/g;
303 # $componentname =~ s/_genericcommands_/_genc_/g;
304 # $componentname =~ s/_bibliographycommands_/_bibc_/g;
305 # $componentname =~ s/_gentiumbookbasicbolditalic_/_gbbbi_/g;
306 # $componentname =~ s/_share_/_s_/g;
307 # $componentname =~ s/_extension_/_ext_/g;
308 # $componentname =~ s/_extensions_/_exs_/g;
309 # $componentname =~ s/_modules_/_ms_/g;
310 # $componentname =~ s/_uiconfig_zip_/_ucz_/g;
311 # $componentname =~ s/_productivity_/_pr_/g;
312 # $componentname =~ s/_wizard_/_wz_/g;
313 # $componentname =~ s/_import_/_im_/g;
314 # $componentname =~ s/_javascript_/_js_/g;
315 # $componentname =~ s/_template_/_tpl_/g;
316 # $componentname =~ s/_tplwizletter_/_twl_/g;
317 # $componentname =~ s/_beanshell_/_bs_/g;
318 # $componentname =~ s/_presentation_/_bs_/g;
319 # $componentname =~ s/_columns_/_cls_/g;
320 # $componentname =~ s/_python_/_py_/g;
322 # $componentname =~ s/_tools/_ts/g;
323 # $componentname =~ s/_transitions/_trs/g;
324 # $componentname =~ s/_scriptbinding/_scrb/g;
325 # $componentname =~ s/_spreadsheet/_ssh/g;
326 # $componentname =~ s/_publisher/_pub/g;
327 # $componentname =~ s/_presenter/_pre/g;
328 # $componentname =~ s/_registry/_reg/g;
330 # $componentname =~ s/screen/sc/g;
331 # $componentname =~ s/wordml/wm/g;
332 # $componentname =~ s/openoffice/oo/g;
335 return $componentname;
338 ####################################################################
339 # Returning the component name for a defined file gid.
340 # This is necessary for files with flag ASSIGNCOMPONENT
341 ####################################################################
343 sub get_component_from_assigned_file
345 my ($gid, $filesref) = @_;
347 my ($onefile) = grep {$_->{gid
} eq $gid} @
{$filesref};
348 if (! defined $onefile) {
349 installer
::exiter
::exit_program
("ERROR: Could not find file $gid in list of files!", "get_component_from_assigned_file");
352 my $componentname = "";
353 if ( $onefile->{'componentname'} ) { $componentname = $onefile->{'componentname'}; }
354 else { installer
::exiter
::exit_program
("ERROR: No component defined for file: $gid", "get_component_from_assigned_file"); }
356 return $componentname;
359 ####################################################################
360 # Generating the special filename for the database file File.idt
361 # Sample: CONTEXTS, CONTEXTS1
362 # This name has to be unique.
363 # In most cases this is simply the filename.
364 ####################################################################
366 sub generate_unique_filename_for_filetable
368 my ($fileref, $component, $uniquefilenamehashref) = @_;
370 # This new filename has to be saved into $fileref, because this is needed to find the source.
371 # The filename sbasic.idx/OFFSETS is changed to OFFSETS, but OFFSETS is not unique.
372 # In this procedure names like OFFSETS5 are produced. And exactly this string has to be added to
373 # the array of all files.
375 my $uniquefilename = "";
378 if ( $fileref->{'Name'} ) { $uniquefilename = $fileref->{'Name'}; }
380 installer
::pathanalyzer
::make_absolute_filename_to_relative_filename
(\
$uniquefilename); # making /registry/schema/org/openoffice/VCL.xcs to VCL.xcs
382 # Reading unique filename with help of "Component_" in File table from old database
383 if (( $installer::globals
::updatedatabase
) && ( exists($uniquefilenamehashref->{"$component/$uniquefilename"}) ))
385 $uniquefilename = $uniquefilenamehashref->{"$component/$uniquefilename"}; # syntax of $value: ($uniquename;$shortname)
386 if ( $uniquefilename =~ /^\s*(.*?)\;\s*(.*?)\s*$/ ) { $uniquefilename = $1; }
387 my $lcuniquefilename = lc($uniquefilename);
388 $installer::globals
::alluniquefilenames
{$uniquefilename} = 1;
389 $installer::globals
::alllcuniquefilenames
{$lcuniquefilename} = 1;
390 return $uniquefilename;
392 elsif (( $installer::globals
::prepare_winpatch
) && ( exists($installer::globals
::savedmapping
{"$component/$uniquefilename"}) ))
394 # If we have a FTK mapping for this component/file, use it.
395 $installer::globals
::savedmapping
{"$component/$uniquefilename"} =~ m
/^(.*);/;
396 $uniquefilename = $1;
397 my $lcuniquefilename = lc($uniquefilename);
398 $installer::globals
::alluniquefilenames
{$uniquefilename} = 1;
399 $installer::globals
::alllcuniquefilenames
{$lcuniquefilename} = 1;
400 return $uniquefilename;
403 $uniquefilename =~ s/\-/\_/g; # no "-" allowed
404 $uniquefilename =~ s/\@/\_/g; # no "@" allowed
405 $uniquefilename =~ s/\$/\_/g; # no "$" allowed
406 $uniquefilename =~ s/^\s*\./\_/g; # no "." at the beginning allowed
407 $uniquefilename =~ s/^\s*\d/\_d/g; # no number at the beginning allowed (even file "0.gif", replacing to "_d.gif")
408 $uniquefilename =~ s/org_openoffice_/ooo_/g; # shorten the unique file name
410 my $lcuniquefilename = lc($uniquefilename); # only lowercase names
414 if ( ! exists($installer::globals
::alllcuniquefilenames
{$lcuniquefilename}) &&
415 ! exists($installer::globals
::savedrevmapping
{$lcuniquefilename}) )
417 $installer::globals
::alluniquefilenames
{$uniquefilename} = 1;
418 $installer::globals
::alllcuniquefilenames
{$lcuniquefilename} = 1;
424 # adding a number until the name is really unique: OFFSETS, OFFSETS1, OFFSETS2, ...
425 # But attention: Making "abc.xcu" to "abc1.xcu"
427 my $uniquefilenamebase = $uniquefilename;
433 if ( $uniquefilenamebase =~ /\./ )
435 $uniquefilename = $uniquefilenamebase;
436 $uniquefilename =~ s/\./$counter\./;
440 $uniquefilename = $uniquefilenamebase . $counter;
444 $lcuniquefilename = lc($uniquefilename); # only lowercase names
446 if ( ! exists($installer::globals
::alllcuniquefilenames
{$lcuniquefilename}) &&
447 ! exists($installer::globals
::savedrevmapping
{$lcuniquefilename}) )
449 $installer::globals
::alluniquefilenames
{$uniquefilename} = 1;
450 $installer::globals
::alllcuniquefilenames
{$lcuniquefilename} = 1;
457 return $uniquefilename;
460 ####################################################################
461 # Generating the special file column for the database file File.idt
462 # Sample: NAMETR~1.TAB|.nametranslation.table
463 # The first part has to be 8.3 conform.
464 ####################################################################
466 sub generate_filename_for_filetable
468 my ($fileref, $shortnamesref, $uniquefilenamehashref) = @_;
470 my $returnstring = "";
472 my $filename = $fileref->{'Name'};
474 installer
::pathanalyzer
::make_absolute_filename_to_relative_filename
(\
$filename); # making /registry/schema/org/openoffice/VCL.xcs to VCL.xcs
478 # Reading short string with help of "FileName" in File table from old database
479 if (( $installer::globals
::updatedatabase
) && ( exists($uniquefilenamehashref->{"$fileref->{'componentname'}/$filename"}) ))
481 my $value = $uniquefilenamehashref->{"$fileref->{'componentname'}/$filename"}; # syntax of $value: ($uniquename;$shortname)
482 if ( $value =~ /^\s*(.*?)\;\s*(.*?)\s*$/ ) { $shortstring = $2; } # already collected in function "collect_shortnames_from_old_database"
483 else { $shortstring = $filename; }
485 elsif (( $installer::globals
::prepare_winpatch
) && ( exists($installer::globals
::savedmapping
{"$fileref->{'componentname'}/$filename"}) ))
487 $installer::globals
::savedmapping
{"$fileref->{'componentname'}/$filename"} =~ m
/.*;(.*)/;
494 $shortstring = installer
::windows
::idtglobal
::make_eight_three_conform_with_hash
($filename, "file", $shortnamesref);
499 $shortstring = installer
::windows
::idtglobal
::make_eight_three_conform_with_hash
($filename, "file", $shortnamesref);
502 if ( $shortstring eq $filename ) { $returnstring = $filename; } # nothing changed
503 else {$returnstring = $shortstring . "\|" . $filename; }
505 return $returnstring;
508 #########################################
509 # Returning the filesize of a file
510 #########################################
516 my $file = $fileref->{'sourcepath'};
520 if ( -f
$file ) # test of existence. For instance services.rdb does not always exist
522 $filesize = ( -s
$file ); # file size can be "0"
532 #############################################
533 # Returning the file version, if required
534 # Sample: "8.0.1.8976";
535 #############################################
539 my ($onefile, $allvariables, $styles) = @_;
541 my $fileversion = "";
543 if ( $onefile->{'Name'} =~ /\.bin$|\.com$|\.dll$|\.exe$|\.pyd$/ )
545 open (EXE
, "<$onefile->{'sourcepath'}");
548 {local $/ = undef; $exedata = <EXE
>;}
551 my $binaryfileversion = "(V\x00S\x00_\x00V\x00E\x00R\x00S\x00I\x00O\x00N\x00_\x00I\x00N\x00F\x00O\x00\x00\x00\x00\x00\xbd\x04\xef\xfe\x00\x00\x01\x00)(........)";
553 if ($exedata =~ /$binaryfileversion/ms)
555 my ($header, $subversion, $version, $vervariant, $microversion) = ($1,unpack( "vvvv", $2));
556 $fileversion = $version . "." . $subversion . "." . $microversion . "." . $vervariant;
559 # file version for font files (tdf#76239)
560 if ( $onefile->{'Name'} =~ /\.(otf|ttf|ttc)$/i )
562 require Font
::TTF
::Font
;
563 Font
::TTF
::Font
->import;
564 my $fnt = Font
::TTF
::Font
->open("<$onefile->{'sourcepath'}");
565 # 5 is pre-defined name ID for version string - see
566 # https://docs.microsoft.com/en-us/typography/opentype/spec/name
567 my $ttfdata = $fnt->{'name'}->read->find_name(5);
570 if ($ttfdata =~ /(Version )?([0-9]+(\.[0-9]+)*)/i)
572 my ($version, $subversion, $microversion, $vervariant) = split(/\./,$2);
573 $subversion = 0 if not defined $subversion;
574 $microversion = 0 if not defined $microversion;
575 $vervariant = 0 if not defined $vervariant;
576 $fileversion = int($version) . "." . int($subversion) . "." . int($microversion) . "." . int($vervariant);
580 $fileversion = "1.0.0.0";
587 #############################################
588 # Returning the sequence for a file
589 #############################################
591 sub get_sequence_for_file
593 my ($number, $onefile, $fileentry, $allupdatesequenceshashref, $allupdatecomponentshashref, $allupdatefileorderhashref, $allfilecomponents) = @_;
597 my $pffcomponentname = $onefile->{'componentname'} . "_pff";
599 if ( $installer::globals
::updatedatabase
)
601 if (( exists($allupdatesequenceshashref->{$onefile->{'uniquename'}}) ) &&
602 (( $onefile->{'componentname'} eq $allupdatecomponentshashref->{$onefile->{'uniquename'}} ) ||
603 ( $pffcomponentname eq $allupdatecomponentshashref->{$onefile->{'uniquename'}} )))
605 # The second condition is necessary to find shifted files, that have same "uniquename", but are now
606 # located in another directory. This can be seen at the component name.
607 $sequence = $allupdatesequenceshashref->{$onefile->{'uniquename'}};
608 $onefile->{'assignedsequencenumber'} = $sequence;
609 # Collecting all used sequences, to guarantee, that no number is unused
610 $installer::globals
::allusedupdatesequences
{$sequence} = 1;
611 # Special help for files, that already have a "pff" component name (for example after ServicePack 1)
612 if ( $pffcomponentname eq $allupdatecomponentshashref->{$onefile->{'uniquename'}} )
614 $infoline = "Warning: Special handling for component \"$pffcomponentname\". This file was added after the final, but before this ServicePack.\n";
615 push(@installer::globals
::logfileinfo
, $infoline);
616 $onefile->{'componentname'} = $pffcomponentname; # pff for "post final file"
617 $fileentry->{'Component_'} = $onefile->{'componentname'};
618 if ( ! exists($allfilecomponents->{$fileentry->{'Component_'}}) ) { $allfilecomponents->{$fileentry->{'Component_'}} = 1; }
623 $installer::globals
::updatesequencecounter
++;
624 $sequence = $installer::globals
::updatesequencecounter
;
625 $onefile->{'assignedsequencenumber'} = $sequence;
626 # $onefile->{'assignedcabinetfile'} = $installer::globals::pffcabfilename; # assigning to cabinet file for "post final files"
627 # Collecting all new files
628 $installer::globals
::newupdatefiles
{$sequence} = $onefile;
629 # Saving in sequence hash
630 $allupdatefileorderhashref->{$sequence} = $onefile->{'uniquename'};
632 # If the new file is part of an existing component, this must be changed now. All files
633 # of one component have to be included in one cabinet file. But because the order must
634 # not change, all new files have to be added to new components.
635 # $onefile->{'componentname'} = $file{'Component_'};
637 $onefile->{'componentname'} = $onefile->{'componentname'} . "_pff"; # pff for "post final file"
638 $fileentry->{'Component_'} = $onefile->{'componentname'};
639 if ( ! exists($allfilecomponents->{$fileentry->{'Component_'}}) ) { $allfilecomponents->{$fileentry->{'Component_'}} = 1; }
640 $onefile->{'PostFinalFile'} = 1;
641 # The sequence for this file has changed. It has to be inserted at the end of the files collector.
642 $installer::globals
::insert_file_at_end
= 1;
643 $installer::globals
::newfilescollector
{$sequence} = $onefile; # Adding new files to the end of the filescollector
644 $installer::globals
::newfilesexist
= 1;
650 # my $sequence = $number + 1;
652 # Idea: Each component is packed into a cab file.
653 # This requires that all files in one cab file have sequences directly following each other,
654 # for instance from 1456 to 1466. Then in the media table the LastSequence for this cab file
656 # Because all files belonging to one component are directly behind each other in the file
657 # collector, it is possible to use simply an increasing number as sequence value.
658 # If files belonging to one component are not directly behind each other in the files collector
659 # this mechanism will no longer work.
665 #############################################
666 # Returning the Windows language of a file
667 #############################################
669 sub get_language_for_file
675 if ( $fileref->{'specificlanguage'} ) { $language = $fileref->{'specificlanguage'}; }
677 if ( $language eq "" )
679 $language = 0; # language independent
680 # If this is not a font, the return value should be "0" (Check ICE 60)
682 if ( $fileref->{'Styles'} ) { $styles = $fileref->{'Styles'}; }
683 if ( $styles =~ /\bFONT\b/ ) { $language = ""; }
687 $language = installer
::windows
::language
::get_windows_language
($language);
693 ####################################################################
694 # Creating a new KeyPath for components in TemplatesFolder.
695 ####################################################################
697 sub generate_registry_keypath
701 my $keypath = $onefile->{'Name'};
703 $keypath = lc($keypath);
704 $keypath = "userreg_" . $keypath;
709 ####################################################################
710 # Check, if in an update process files are missing. No removal
711 # of files allowed for Windows Patch creation.
712 # Also logging all new files, that have to be included in extra
713 # components and cab files.
714 ####################################################################
716 sub check_file_sequences
718 my ($allupdatefileorderhashref, $allupdatecomponentorderhashref) = @_;
720 # All used sequences stored in %installer::globals::allusedupdatesequences
721 # Maximum sequence number of old database stored in $installer::globals::updatelastsequence
722 # All new files stored in %installer::globals::newupdatefiles
726 my @missing_sequences = ();
727 my @really_missing_sequences = ();
729 for ( my $i = 1; $i <= $installer::globals
::updatelastsequence
; $i++ )
731 if ( ! exists($installer::globals
::allusedupdatesequences
{$i}) ) { push(@missing_sequences, $i); }
734 if ( $#missing_sequences > -1 )
736 # Missing sequences can also be caused by files included in merge modules. This files are added later into the file table.
737 # Therefore now it is time to check the content of the merge modules.
739 for ( my $j = 0; $j <= $#missing_sequences; $j++ )
741 my $filename = $allupdatefileorderhashref->{$missing_sequences[$j]};
743 # Is this a file from a merge module? Then this is no error.
744 if ( ! exists($installer::globals
::mergemodulefiles
{$filename}) )
746 push(@really_missing_sequences, $missing_sequences[$j]);
751 if ( $#really_missing_sequences > -1 )
753 my $errorstring = "";
754 for ( my $j = 0; $j <= $#really_missing_sequences; $j++ )
756 my $filename = $allupdatefileorderhashref->{$really_missing_sequences[$j]};
757 my $comp = $allupdatecomponentorderhashref->{$really_missing_sequences[$j]};
758 $errorstring = "$errorstring$filename (Sequence: $really_missing_sequences[$j], Component: \"$comp\")\n";
761 $infoline = "ERROR: Files are removed compared with update database.\nThe following files are missing:\n$errorstring";
762 push(@installer::globals
::logfileinfo
, $infoline);
763 installer
::exiter
::exit_program
($infoline, "check_file_sequences");
766 # Searching for new files
770 foreach my $key ( keys %installer::globals
::newupdatefiles
)
772 my $onefile = $installer::globals
::newupdatefiles
{$key};
776 $infoline = "\nNew files compared to the update database:\n";
777 push(@installer::globals
::logfileinfo
, $infoline);
780 $infoline = "$onefile->{'Name'} ($onefile->{'gid'}) Sequence: $onefile->{'assignedsequencenumber'}\n";
781 push(@installer::globals
::logfileinfo
, $infoline);
786 $infoline = "Info: No new file compared with update database!\n";
787 push(@installer::globals
::logfileinfo
, $infoline);
792 ###################################################################
793 # Collecting further conditions for the component table.
794 # This is used by multilayer products, to enable installation
795 # of separate layers.
796 ###################################################################
798 sub get_tree_condition_for_component
800 my ($onefile, $componentname) = @_;
802 if ( $onefile->{'destination'} )
804 my $dest = $onefile->{'destination'};
806 # Comparing the destination path with
807 # $installer::globals::hostnametreestyles{$hostname} = $treestyle;
808 # (-> hostname is the key, the style the value!)
810 foreach my $hostname ( keys %installer::globals
::hostnametreestyles
)
812 if (( $dest eq $hostname ) || ( $dest =~ /^\s*\Q$hostname\E\\/ ))
814 # the value is the style
815 my $style = $installer::globals
::hostnametreestyles
{$hostname};
816 # the condition is saved in %installer::globals::treestyles
817 my $condition = $installer::globals
::treestyles
{$style};
818 # Saving condition to be added in table Property
819 $installer::globals
::usedtreeconditions
{$condition} = 1;
820 $condition = $condition . "=1";
821 # saving this condition
822 $installer::globals
::treeconditions
{$componentname} = $condition;
824 # saving also at the file, for usage in fileinfo
825 $onefile->{'layer'} = $installer::globals
::treelayername
{$style};
831 ############################################
832 # Collecting all short names, that are
833 # already used by the old database
834 ############################################
836 sub collect_shortnames_from_old_database
838 my ($uniquefilenamehashref, $shortnameshashref) = @_;
840 foreach my $key ( keys %{$uniquefilenamehashref} )
842 my $value = $uniquefilenamehashref->{$key}; # syntax of $value: ($uniquename;$shortname)
844 if ( $value =~ /^\s*(.*?)\;\s*(.*?)\s*$/ )
846 my $shortstring = $2;
847 $shortnameshashref->{$shortstring} = 1; # adding the shortname to the array of all shortnames
852 ############################################
853 # Creating the file File.idt dynamically
854 ############################################
856 sub create_files_table
858 my ($filesref, $dirref, $allfilecomponentsref, $basedir, $allvariables, $uniquefilenamehashref, $allupdatesequenceshashref, $allupdatecomponentshashref, $allupdatefileorderhashref) = @_;
860 installer
::logger
::include_timestamp_into_logfile
("Performance Info: File Table start");
862 # Structure of the files table:
863 # File Component_ FileName FileSize Version Language Attributes Sequence
864 # In this function, all components are created.
866 # $allfilecomponentsref is empty at the beginning
872 my @filehashtable = ();
873 my %allfilecomponents = ();
876 if ( $^O
=~ /cygwin/i ) { installer
::worker
::generate_cygwin_paths
($filesref); }
878 # The filenames must be collected because of uniqueness
879 # 01-44-~1.DAT, 01-44-~2.DAT, ...
882 if ( $installer::globals
::updatedatabase
) { collect_shortnames_from_old_database
($uniquefilenamehashref, \
%shortnames); }
884 installer
::windows
::idtglobal
::write_idt_header
(\
@filetable, "file");
885 installer
::windows
::idtglobal
::write_idt_header
(\
@filehashtable, "filehash");
886 installer
::windows
::idtglobal
::write_idt_header
(\
@installer::globals
::removefiletable
, "removefile");
888 for ( my $i = 0; $i <= $#{$filesref}; $i++ )
892 my $onefile = ${$filesref}[$i];
895 if ( $onefile->{'Styles'} ) { $styles = $onefile->{'Styles'}; }
897 $file{'Component_'} = get_file_component_name
($onefile, $filesref);
898 $file{'File'} = generate_unique_filename_for_filetable
($onefile, $file{'Component_'}, $uniquefilenamehashref);
900 $onefile->{'uniquename'} = $file{'File'};
901 $onefile->{'componentname'} = $file{'Component_'};
903 # Collecting all components
905 if ( ! exists($allfilecomponents{$file{'Component_'}}) ) { $allfilecomponents{$file{'Component_'}} = 1; }
907 $file{'FileName'} = generate_filename_for_filetable
($onefile, \
%shortnames, $uniquefilenamehashref);
909 $file{'FileSize'} = get_filesize
($onefile);
911 $file{'Version'} = get_fileversion
($onefile, $allvariables, $styles);
913 $file{'Language'} = get_language_for_file
($onefile);
915 if ( $styles =~ /\bDONT_PACK\b/ ) { $file{'Attributes'} = "8192"; }
916 else { $file{'Attributes'} = "16384"; }
918 # $file{'Attributes'} = "16384"; # Sourcefile is packed
919 # $file{'Attributes'} = "8192"; # Sourcefile is unpacked
921 $installer::globals
::insert_file_at_end
= 0;
923 $file{'Sequence'} = get_sequence_for_file
($counter, $onefile, \
%file, $allupdatesequenceshashref, $allupdatecomponentshashref, $allupdatefileorderhashref, \
%allfilecomponents);
925 $onefile->{'sequencenumber'} = $file{'Sequence'};
927 my $oneline = $file{'File'} . "\t" . $file{'Component_'} . "\t" . $file{'FileName'} . "\t"
928 . $file{'FileSize'} . "\t" . $file{'Version'} . "\t" . $file{'Language'} . "\t"
929 . $file{'Attributes'} . "\t" . $file{'Sequence'} . "\n";
931 push(@filetable, $oneline);
933 if ( $file{'File'} =~ /\.py$/ )
937 $removefile{'FileKey'} = "remove_" . $file{'File'} . "c";
938 $removefile{'Component_'} = $file{'Component_'};
939 $removefile{'FileName'} = $file{'FileName'};
940 $removefile{'FileName'} =~ s/\.py$/.pyc/;
941 $removefile{'FileName'} =~ s/\.PY\|/.PYC|/;
942 $removefile{'DirProperty'} = installer
::windows
::component
::get_file_component_directory
($file{'Component_'}, $filesref, $dirref);
943 $removefile{'InstallMode'} = 2; # msiInstallStateAbsent
944 $oneline = $removefile{'FileKey'} . "\t" . $removefile{'Component_'} . "\t" . $removefile{'FileName'} . "\t"
945 . $removefile{'DirProperty'} . "\t" . $removefile{'InstallMode'} . "\n";
947 push(@installer::globals
::removefiletable
, $oneline);
950 if ( ! $installer::globals
::insert_file_at_end
) { push(@allfiles, $onefile); }
952 # Collecting all component conditions
953 if ( $onefile->{'ComponentCondition'} )
955 if ( ! exists($installer::globals
::componentcondition
{$file{'Component_'}}))
957 $installer::globals
::componentcondition
{$file{'Component_'}} = $onefile->{'ComponentCondition'};
961 # Collecting also all tree conditions for multilayer products
962 get_tree_condition_for_component
($onefile, $file{'Component_'});
964 unless ( $file{'Version'} )
966 my $path = $onefile->{'sourcepath'};
967 if ( $^O
=~ /cygwin/i ) { $path = $onefile->{'cyg_sourcepath'}; }
969 open(FILE
, $path) or die "ERROR: Can't open $path for creating file hash";
971 my $hashinfo = pack("l", 20);
972 $hashinfo .= Digest
::MD5
->new->addfile(*FILE
)->digest;
974 my @i = unpack ('x[l]l4', $hashinfo);
975 $oneline = $file{'File'} . "\t" .
981 push (@filehashtable, $oneline);
984 # Saving the sequence number in a hash with uniquefilename as key.
985 # This is used for better performance in "save_packorder"
986 $installer::globals
::uniquefilenamesequence
{$onefile->{'uniquename'}} = $onefile->{'sequencenumber'};
989 if ( $onefile->{'Dir'} ) { $destdir = $onefile->{'Dir'}; }
991 if ( $onefile->{'needs_user_registry_key'} )
993 my $keypath = generate_registry_keypath
($onefile);
994 $onefile->{'userregkeypath'} = $keypath;
995 push(@installer::globals
::userregistrycollector
, $onefile);
996 $installer::globals
::addeduserregitrykeys
= 1;
1000 # putting content from %allfilecomponents to $allfilecomponentsref for later usage
1001 foreach my $localkey (keys %allfilecomponents ) { push( @
{$allfilecomponentsref}, $localkey); }
1003 my $filetablename = $basedir . $installer::globals
::separator
. "File.idt";
1004 installer
::files
::save_file
($filetablename ,\
@filetable);
1005 $infoline = "\nCreated idt file: $filetablename\n";
1006 push(@installer::globals
::logfileinfo
, $infoline);
1008 installer
::logger
::include_timestamp_into_logfile
("Performance Info: File Table end");
1010 my $filehashtablename = $basedir . $installer::globals
::separator
. "MsiFileHash.idt";
1011 installer
::files
::save_file
($filehashtablename ,\
@filehashtable);
1012 $infoline = "\nCreated idt file: $filehashtablename\n";
1013 push(@installer::globals
::logfileinfo
, $infoline);
1015 # Now the new files can be added to the files collector (only in update packaging processes)
1016 if ( $installer::globals
::newfilesexist
)
1018 foreach my $seq (sort keys %installer::globals
::newfilescollector
) { push(@allfiles, $installer::globals
::newfilescollector
{$seq}) }