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