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 $installer::logger::Lang->print("\n"); 74 $installer::logger::Lang->print("Cabinet file content:\n"); 75 my $cabfile; 76 foreach $cabfile ( sort keys %installer::globals::cabfilecounter ) 77 { 78 $infoline = "$cabfile : $installer::globals::cabfilecounter{$cabfile} files\n"; 79 $installer::logger::Lang->print($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 $installer::logger::Lang->print("\n"); 97 $installer::logger::Lang->print("Cabinet file start sequences:\n"); 98 foreach $cabfile ( sort keys %installer::globals::cabfilecounter ) 99 { 100 $infoline = "$cabfile : $installer::globals::cabfilecounter{$cabfile}\n"; 101 $installer::logger::Lang->print($infoline); 102 } 103 104 # logging the last sequence numbers 105 106 $installer::logger::Lang->print("\n"); 107 $installer::logger::Lang->print("Cabinet file last sequences:\n"); 108 foreach $cabfile ( sort keys %installer::globals::lastsequence ) 109 { 110 $infoline = "$cabfile : $installer::globals::lastsequence{$cabfile}\n"; 111 $installer::logger::Lang->print($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 $installer::logger::Lang->print($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 else 631 { 632 $sequence = $number; 633 # my $sequence = $number + 1; 634 635 # Idea: Each component is packed into a cab file. 636 # This requires that all files in one cab file have sequences directly follwing each other, 637 # for instance from 1456 to 1466. Then in the media table the LastSequence for this cab file 638 # is 1466. 639 # Because all files belonging to one component are directly behind each other in the file 640 # collector, it is possible to use simply an increasing number as sequence value. 641 # If files belonging to one component are not directly behind each other in the files collector 642 # this mechanism will no longer work. 643 } 644 645 return $sequence; 646} 647 648############################################# 649# Returning the Windows language of a file 650############################################# 651 652sub get_language_for_file 653{ 654 my ($fileref) = @_; 655 656 my $language = ""; 657 658 if ( $fileref->{'specificlanguage'} ) { $language = $fileref->{'specificlanguage'}; } 659 660 if ( $language eq "" ) 661 { 662 $language = 0; # language independent 663 # If this is not a font, the return value should be "0" (Check ICE 60) 664 my $styles = ""; 665 if ( $fileref->{'Styles'} ) { $styles = $fileref->{'Styles'}; } 666 if ( $styles =~ /\bFONT\b/ ) { $language = ""; } 667 } 668 else 669 { 670 $language = installer::windows::language::get_windows_language($language); 671 } 672 673 return $language; 674} 675 676#################################################################### 677# Creating a new KeyPath for components in TemplatesFolder. 678#################################################################### 679 680sub generate_registry_keypath 681{ 682 my ($onefile) = @_; 683 684 my $keypath = $onefile->{'Name'}; 685 $keypath =~ s/\.//g; 686 $keypath = lc($keypath); 687 $keypath = "userreg_" . $keypath; 688 689 return $keypath; 690} 691 692#################################################################### 693# Check, if in an update process files are missing. No removal 694# of files allowed for Windows Patch creation. 695# Also logging all new files, that have to be included in extra 696# components and cab files. 697#################################################################### 698 699sub check_file_sequences 700{ 701 my ($allupdatefileorderhashref, $allupdatecomponentorderhashref) = @_; 702 703 # All used sequences stored in %installer::globals::allusedupdatesequences 704 # Maximum sequence number of old database stored in $installer::globals::updatelastsequence 705 # All new files stored in %installer::globals::newupdatefiles 706 707 my $infoline = ""; 708 709 my @missing_sequences = (); 710 711 for ( my $i = 1; $i <= $installer::globals::updatelastsequence; $i++ ) 712 { 713 if ( ! exists($installer::globals::allusedupdatesequences{$i}) ) { push(@missing_sequences, $i); } 714 } 715 716 if ( $#missing_sequences > -1 ) 717 { 718 my $errorstring = ""; 719 for ( my $j = 0; $j <= $#missing_sequences; $j++ ) 720 { 721 my $filename = $allupdatefileorderhashref->{$missing_sequences[$j]}; 722 my $comp = $allupdatecomponentorderhashref->{$missing_sequences[$j]}; 723 $errorstring = "$errorstring$filename (Sequence: $missing_sequences[$j], Component: \"$comp\")\n"; 724 } 725 726 $infoline = "ERROR: Files are removed compared with update database.\nThe following files are missing:\n$errorstring"; 727 $installer::logger::Lang->print($infoline); 728 installer::exiter::exit_program($infoline, "check_file_sequences"); 729 } 730 731 # Searching for new files 732 733 my $counter = 0; 734 735 foreach my $key ( keys %installer::globals::newupdatefiles ) 736 { 737 my $onefile = $installer::globals::newupdatefiles{$key}; 738 $counter++; 739 if ( $counter == 1 ) 740 { 741 $installer::logger::Lang->print("\n"); 742 $installer::logger::Lang->print("New files compared to the update database:\n"); 743 } 744 745 $installer::logger::Lang->printf("%s (%s) Sequence: %s\n", 746 $onefile->{'Name'}, 747 $onefile->{'gid'}, 748 $onefile->{'assignedsequencenumber'}); 749 } 750 751 if ( $counter == 0 ) 752 { 753 $infoline = "Info: No new file compared with update database!\n"; 754 $installer::logger::Lang->print($infoline); 755 } 756 757} 758 759################################################################### 760# Collecting further conditions for the component table. 761# This is used by multilayer products, to enable installation 762# of separate layers. 763################################################################### 764 765sub get_tree_condition_for_component 766{ 767 my ($onefile, $componentname) = @_; 768 769 if ( $onefile->{'destination'} ) 770 { 771 my $dest = $onefile->{'destination'}; 772 773 # Comparing the destination path with 774 # $installer::globals::hostnametreestyles{$hostname} = $treestyle; 775 # (-> hostname is the key, the style the value!) 776 777 foreach my $hostname ( keys %installer::globals::hostnametreestyles ) 778 { 779 if (( $dest eq $hostname ) || ( $dest =~ /^\s*\Q$hostname\E\\/ )) 780 { 781 # the value is the style 782 my $style = $installer::globals::hostnametreestyles{$hostname}; 783 # the condition is saved in %installer::globals::treestyles 784 my $condition = $installer::globals::treestyles{$style}; 785 # Saving condition to be added in table Property 786 $installer::globals::usedtreeconditions{$condition} = 1; 787 $condition = $condition . "=1"; 788 # saving this condition 789 $installer::globals::treeconditions{$componentname} = $condition; 790 791 # saving also at the file, for usage in fileinfo 792 $onefile->{'layer'} = $installer::globals::treelayername{$style}; 793 } 794 } 795 } 796} 797 798############################################ 799# Collecting all short names, that are 800# already used by the old database 801############################################ 802 803sub collect_shortnames_from_old_database 804{ 805 my ($uniquefilenamehashref, $shortnameshashref) = @_; 806 807 foreach my $key ( keys %{$uniquefilenamehashref} ) 808 { 809 my $value = $uniquefilenamehashref->{$key}; # syntax of $value: ($uniquename;$shortname) 810 811 if ( $value =~ /^\s*(.*?)\;\s*(.*?)\s*$/ ) 812 { 813 my $shortstring = $2; 814 $shortnameshashref->{$shortstring} = 1; # adding the shortname to the array of all shortnames 815 } 816 } 817} 818 819############################################ 820# Creating the file File.idt dynamically 821############################################ 822 823sub create_files_table 824{ 825 my ($filesref, $allfilecomponentsref, $basedir, $allvariables, $uniquefilenamehashref, $allupdatesequenceshashref, $allupdatecomponentshashref, $allupdatefileorderhashref) = @_; 826 827 $installer::logger::Lang->add_timestamp("Performance Info: File Table start"); 828 829 # Structure of the files table: 830 # File Component_ FileName FileSize Version Language Attributes Sequence 831 # In this function, all components are created. 832 # 833 # $allfilecomponentsref is empty at the beginning 834 835 my $infoline; 836 837 my @allfiles = (); 838 my @filetable = (); 839 my @filehashtable = (); 840 my %allfilecomponents = (); 841 my $counter = 0; 842 843 if ( $^O =~ /cygwin/i ) { installer::worker::generate_cygwin_pathes($filesref); } 844 845 # The filenames must be collected because of uniqueness 846 # 01-44-~1.DAT, 01-44-~2.DAT, ... 847 # my @shortnames = (); 848 my %shortnames = (); 849 850 if ( $installer::globals::updatedatabase ) { collect_shortnames_from_old_database($uniquefilenamehashref, \%shortnames); } 851 852 installer::windows::idtglobal::write_idt_header(\@filetable, "file"); 853 installer::windows::idtglobal::write_idt_header(\@filehashtable, "filehash"); 854 855 for ( my $i = 0; $i <= $#{$filesref}; $i++ ) 856 { 857 my %file = (); 858 859 my $onefile = ${$filesref}[$i]; 860 861 my $styles = ""; 862 if ( $onefile->{'Styles'} ) { $styles = $onefile->{'Styles'}; } 863 if (( $styles =~ /\bJAVAFILE\b/ ) && ( ! ($allvariables->{'JAVAPRODUCT'} ))) { next; } 864 865 $file{'Component_'} = get_file_component_name($onefile, $filesref); 866 $file{'File'} = generate_unique_filename_for_filetable($onefile, $file{'Component_'}, $uniquefilenamehashref); 867 868 $onefile->{'uniquename'} = $file{'File'}; 869 $onefile->{'componentname'} = $file{'Component_'}; 870 871 # Collecting all components 872 # if (!(installer::existence::exists_in_array($file{'Component_'}, $allfilecomponentsref))) { push(@{$allfilecomponentsref}, $file{'Component_'}); } 873 874 if ( ! exists($allfilecomponents{$file{'Component_'}}) ) { $allfilecomponents{$file{'Component_'}} = 1; } 875 876 $file{'FileName'} = generate_filename_for_filetable($onefile, \%shortnames, $uniquefilenamehashref); 877 878 $file{'FileSize'} = get_filesize($onefile); 879 880 $file{'Version'} = get_fileversion($onefile, $allvariables, $styles); 881 882 $file{'Language'} = get_language_for_file($onefile); 883 884 if ( $styles =~ /\bDONT_PACK\b/ ) { $file{'Attributes'} = "8192"; } 885 else { $file{'Attributes'} = "16384"; } 886 887 # $file{'Attributes'} = "16384"; # Sourcefile is packed 888 # $file{'Attributes'} = "8192"; # Sourcefile is unpacked 889 890 $installer::globals::insert_file_at_end = 0; 891 $counter++; 892 $file{'Sequence'} = get_sequence_for_file($counter, $onefile, \%file, $allupdatesequenceshashref, $allupdatecomponentshashref, $allupdatefileorderhashref, \%allfilecomponents); 893 894 $onefile->{'sequencenumber'} = $file{'Sequence'}; 895 896 my $oneline = $file{'File'} . "\t" . $file{'Component_'} . "\t" . $file{'FileName'} . "\t" 897 . $file{'FileSize'} . "\t" . $file{'Version'} . "\t" . $file{'Language'} . "\t" 898 . $file{'Attributes'} . "\t" . $file{'Sequence'} . "\n"; 899 900 push(@filetable, $oneline); 901 902 if ( ! $installer::globals::insert_file_at_end ) { push(@allfiles, $onefile); } 903 904 # Collecting all component conditions 905 if ( $onefile->{'ComponentCondition'} ) 906 { 907 if ( ! exists($installer::globals::componentcondition{$file{'Component_'}})) 908 { 909 $installer::globals::componentcondition{$file{'Component_'}} = $onefile->{'ComponentCondition'}; 910 } 911 } 912 913 # Collecting also all tree conditions for multilayer products 914 get_tree_condition_for_component($onefile, $file{'Component_'}); 915 916 # Collecting all component names, that have flag VERSION_INDEPENDENT_COMP_ID 917 # This should be all components with constant API, for example URE 918 if ( $styles =~ /\bVERSION_INDEPENDENT_COMP_ID\b/ ) 919 { 920 $installer::globals::base_independent_components{$onefile->{'componentname'}} = 1; 921 } 922 923 # Collecting all component ids, that are defined at files in scp project (should not be used anymore) 924 if ( $onefile->{'CompID'} ) 925 { 926 if ( ! exists($installer::globals::componentid{$onefile->{'componentname'}})) 927 { 928 $installer::globals::componentid{$onefile->{'componentname'}} = $onefile->{'CompID'}; 929 } 930 else 931 { 932 if ( $installer::globals::componentid{$onefile->{'componentname'}} ne $onefile->{'CompID'} ) 933 { 934 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"); 935 } 936 } 937 938 # Also checking vice versa. Is this ComponentID already used? If yes, is the componentname the same? 939 940 if ( ! exists($installer::globals::comparecomponentname{$onefile->{'CompID'}})) 941 { 942 $installer::globals::comparecomponentname{$onefile->{'CompID'}} = $onefile->{'componentname'}; 943 } 944 else 945 { 946 if ( $installer::globals::comparecomponentname{$onefile->{'CompID'}} ne $onefile->{'componentname'} ) 947 { 948 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"); 949 } 950 } 951 } 952 953 # Collecting all language specific conditions 954 # if ( $onefile->{'haslanguagemodule'} ) 955 if ( $onefile->{'ismultilingual'} ) 956 { 957 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"); } 958 959 if ( $onefile->{'specificlanguage'} eq "" ) { installer::exiter::exit_program("ERROR: There is no specific language for file at language module: $onefile->{'gid'} !", "create_files_table"); } 960 my $locallanguage = $onefile->{'specificlanguage'}; 961 my $property = "IS" . $file{'Language'}; 962 my $value = 1; 963 my $condition = $property . "=" . $value; 964 965 $onefile->{'ComponentCondition'} = $condition; 966 967 if ( exists($installer::globals::componentcondition{$file{'Component_'}})) 968 { 969 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"); } 970 } 971 else 972 { 973 $installer::globals::componentcondition{$file{'Component_'}} = $condition; 974 } 975 976 # collecting all properties for table Property 977 if ( ! exists($installer::globals::languageproperties{$property}) ) { $installer::globals::languageproperties{$property} = $value; } 978 } 979 980 if ( $installer::globals::prepare_winpatch ) 981 { 982 my $path = $onefile->{'sourcepath'}; 983 if ( $^O =~ /cygwin/i ) { $path = $onefile->{'cyg_sourcepath'}; } 984 985 open(FILE, $path) or die "ERROR: Can't open $path for creating file hash"; 986 binmode(FILE); 987 my $hashinfo = pack("l", 20); 988 $hashinfo .= Digest::MD5->new->addfile(*FILE)->digest; 989 990 my @i = unpack ('x[l]l4', $hashinfo); 991 $oneline = $file{'File'} . "\t" . 992 "0" . "\t" . 993 $i[0] . "\t" . 994 $i[1] . "\t" . 995 $i[2] . "\t" . 996 $i[3] . "\n"; 997 push (@filehashtable, $oneline); 998 } 999 1000 # Saving the sequence number in a hash with uniquefilename as key. 1001 # This is used for better performance in "save_packorder" 1002 $installer::globals::uniquefilenamesequence{$onefile->{'uniquename'}} = $onefile->{'sequencenumber'}; 1003 1004 # Special handling for files in PREDEFINED_OSSHELLNEWDIR. These components 1005 # need as KeyPath a RegistryItem in HKCU 1006 my $destdir = ""; 1007 if ( $onefile->{'Dir'} ) { $destdir = $onefile->{'Dir'}; } 1008 1009 if (( $destdir =~ /\bPREDEFINED_OSSHELLNEWDIR\b/ ) || ( $onefile->{'needs_user_registry_key'} )) 1010 { 1011 my $keypath = generate_registry_keypath($onefile); 1012 $onefile->{'userregkeypath'} = $keypath; 1013 push(@installer::globals::userregistrycollector, $onefile); 1014 $installer::globals::addeduserregitrykeys = 1; 1015 } 1016 } 1017 1018 # putting content from %allfilecomponents to $allfilecomponentsref for later usage 1019 foreach $localkey (keys %allfilecomponents ) { push( @{$allfilecomponentsref}, $localkey); } 1020 1021 my $filetablename = $basedir . $installer::globals::separator . "File.idt"; 1022 installer::files::save_file($filetablename ,\@filetable); 1023 $installer::logger::Lang->print("\n"); 1024 $installer::logger::Lang->printf("Created idt file: %s\n", $filetablename); 1025 1026 $installer::logger::Lang->add_timestamp("Performance Info: File Table end"); 1027 1028 my $filehashtablename = $basedir . $installer::globals::separator . "MsiFileHash.idt"; 1029 installer::files::save_file($filehashtablename ,\@filehashtable); 1030 $installer::logger::Lang->print("\n"); 1031 $installer::logger::Lang->printf("Created idt file: %s\n", $filehashtablename); 1032 1033 # Now the new files can be added to the files collector (only in update packaging processes) 1034 if ( $installer::globals::newfilesexist ) 1035 { 1036 foreach my $seq (sort keys %installer::globals::newfilescollector) { push(@allfiles, $installer::globals::newfilescollector{$seq}) } 1037 } 1038 1039 return \@allfiles; 1040} 1041 10421; 1043