| 1 |
# |
| 2 |
# This file is part of the LibreOffice project. |
| 3 |
# |
| 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/. |
| 7 |
# |
| 8 |
# This file incorporates work covered by the following license notice: |
| 9 |
# |
| 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 . |
| 17 |
# |
| 18 |
|
| 19 |
package installer::windows::mergemodule; |
| 20 |
|
| 21 |
use strict; |
| 22 |
use warnings; |
| 23 |
|
| 24 |
use Cwd; |
| 25 |
use Digest::MD5; |
| 26 |
use installer::converter; |
| 27 |
use installer::exiter; |
| 28 |
use installer::files; |
| 29 |
use installer::globals; |
| 30 |
use installer::logger; |
| 31 |
use installer::pathanalyzer; |
| 32 |
use installer::remover; |
| 33 |
use installer::scriptitems; |
| 34 |
use installer::systemactions; |
| 35 |
use installer::worker; |
| 36 |
use installer::windows::idtglobal; |
| 37 |
use installer::windows::language; |
| 38 |
|
| 39 |
################################################################# |
| 40 |
# Merging the Windows MergeModules into the msi database. |
| 41 |
################################################################# |
| 42 |
|
| 43 |
sub merge_mergemodules_into_msi_database |
| 44 |
{ |
| 45 |
my ($mergemodules, $filesref, $msifilename, $languagestringref, $allvariables, $includepatharrayref, $allupdatesequences, $allupdatelastsequences, $allupdatediskids) = @_; |
| 46 |
|
| 47 |
my $domerge = 0; |
| 48 |
if (( $#{$mergemodules} > -1 ) && ( ! $installer::globals::languagepack ) && ( ! $installer::globals::helppack )) { $domerge = 1; } |
| 49 |
|
| 50 |
if ( $domerge ) |
| 51 |
{ |
| 52 |
installer::logger::include_header_into_logfile("Merging merge modules into msi database"); |
| 53 |
installer::logger::print_message( "... merging msm files into msi database ... \n" ); |
| 54 |
installer::logger::include_timestamp_into_logfile("\nPerformance Info: MergeModule into msi database, start"); |
| 55 |
|
| 56 |
my $msidb = "msidb.exe"; # Has to be in the path |
| 57 |
my $cabinetfile = "MergeModule.CABinet"; # the name of each cabinet file in a merge file |
| 58 |
my $infoline = ""; |
| 59 |
my $systemcall = ""; |
| 60 |
my $systemcall_output = ""; |
| 61 |
my $returnvalue = ""; |
| 62 |
# in cygwin the * glob needs to be escaped when passing it to msidb |
| 63 |
my $globescape = ""; |
| 64 |
$globescape = "\\" if ( $^O =~ /cygwin/i ); |
| 65 |
|
| 66 |
# 1. Analyzing the MergeModule (has only to be done once) |
| 67 |
# a. -> Extracting cabinet file: msidb.exe -d <msmfile> -x MergeModule.CABinet |
| 68 |
# b. -> Number of files in cabinet file: msidb.exe -d <msmfile> -f <directory> -e File |
| 69 |
# c. -> List of components: msidb.exe -d <msmfile> -f <directory> -e Component |
| 70 |
|
| 71 |
if ( ! $installer::globals::mergemodules_analyzed ) |
| 72 |
{ |
| 73 |
installer::logger::include_timestamp_into_logfile("\nPerformance Info: Analyzing MergeModules, start"); |
| 74 |
$infoline = "Analyzing all Merge Modules\n\n"; |
| 75 |
push( @installer::globals::logfileinfo, $infoline); |
| 76 |
|
| 77 |
%installer::globals::mergemodules = (); |
| 78 |
|
| 79 |
my $mergemoduledir = installer::systemactions::create_directories("mergefiles", $languagestringref); |
| 80 |
|
| 81 |
my $mergemodule; |
| 82 |
foreach $mergemodule ( @{$mergemodules} ) |
| 83 |
{ |
| 84 |
my $filename = $mergemodule->{'Name'}; |
| 85 |
my $mergefile = $ENV{'MSM_PATH'} . $filename; |
| 86 |
|
| 87 |
if ( ! -f $mergefile ) { installer::exiter::exit_program("ERROR: msm file not found: $filename ($mergefile)!", "merge_mergemodules_into_msi_database"); } |
| 88 |
my $completesource = $mergefile; |
| 89 |
|
| 90 |
my $mergegid = $mergemodule->{'gid'}; |
| 91 |
my $workdir = $mergemoduledir . $installer::globals::separator . $mergegid; |
| 92 |
if ( ! -d $workdir ) { installer::systemactions::create_directory($workdir); } |
| 93 |
|
| 94 |
$infoline = "Analyzing Merge Module: $filename\n"; |
| 95 |
push( @installer::globals::logfileinfo, $infoline); |
| 96 |
|
| 97 |
# copy msm file into working directory |
| 98 |
my $completedest = $workdir . $installer::globals::separator . $filename; |
| 99 |
installer::systemactions::copy_one_file($completesource, $completedest); |
| 100 |
if ( ! -f $completedest ) { installer::exiter::exit_program("ERROR: msm file not found: $completedest !", "merge_mergemodules_into_msi_database"); } |
| 101 |
|
| 102 |
# changing directory |
| 103 |
my $from = cwd(); |
| 104 |
my $to = $workdir; |
| 105 |
chdir($to); |
| 106 |
|
| 107 |
# remove an existing cabinet file |
| 108 |
if ( -f $cabinetfile ) { unlink($cabinetfile); } |
| 109 |
|
| 110 |
# export cabinet file |
| 111 |
$systemcall = $msidb . " -d " . $filename . " -x " . $cabinetfile; |
| 112 |
$systemcall_output = `$systemcall`; |
| 113 |
$returnvalue = $? >> 8; |
| 114 |
|
| 115 |
if ($returnvalue) |
| 116 |
{ |
| 117 |
$infoline = "ERROR: Could not execute $systemcall - returncode: $returnvalue - output: $systemcall_output\n"; |
| 118 |
push( @installer::globals::logfileinfo, $infoline); |
| 119 |
installer::exiter::exit_program("ERROR: Could not extract cabinet file from merge file: $completedest !", "merge_mergemodules_into_msi_database"); |
| 120 |
} |
| 121 |
else |
| 122 |
{ |
| 123 |
$infoline = "Success: Executed $systemcall successfully!\n"; |
| 124 |
push( @installer::globals::logfileinfo, $infoline); |
| 125 |
} |
| 126 |
|
| 127 |
# export tables from mergefile |
| 128 |
# Attention: All listed tables have to exist in the database. If they not exist, an error window pops up |
| 129 |
# and the return value of msidb.exe is not zero. The error window makes it impossible to check the existence |
| 130 |
# of a table with the help of the return value. |
| 131 |
# Solution: Export of all tables by using "*" . Some tables must exist (File Component Directory), other |
| 132 |
# tables do not need to exist (MsiAssembly). |
| 133 |
|
| 134 |
$systemcall = $msidb . " -d " . $filename . " -f " . $workdir . " -e $globescape*"; |
| 135 |
# msidb.exe really wants backslashes |
| 136 |
$systemcall =~ s/\//\\\\/g; |
| 137 |
|
| 138 |
$systemcall_output = `$systemcall`; |
| 139 |
$returnvalue = $? >> 8; |
| 140 |
|
| 141 |
if ($returnvalue) |
| 142 |
{ |
| 143 |
$infoline = "ERROR: Could not execute $systemcall - returncode: $returnvalue - output: $systemcall_output\n"; |
| 144 |
push( @installer::globals::logfileinfo, $infoline); |
| 145 |
installer::exiter::exit_program("ERROR: Could not export tables from merge file: $completedest !", "merge_mergemodules_into_msi_database"); |
| 146 |
} |
| 147 |
else |
| 148 |
{ |
| 149 |
$infoline = "Success: Executed $systemcall successfully!\n"; |
| 150 |
push( @installer::globals::logfileinfo, $infoline); |
| 151 |
} |
| 152 |
|
| 153 |
# Determining files |
| 154 |
my $idtfilename = "File.idt"; # must exist |
| 155 |
if ( ! -f $idtfilename ) { installer::exiter::exit_program("ERROR: File \"$idtfilename\" not found in directory \"$workdir\" !", "merge_mergemodules_into_msi_database"); } |
| 156 |
my $filecontent = installer::files::read_file($idtfilename); |
| 157 |
my @file_idt_content = (); |
| 158 |
my $filecounter = 0; |
| 159 |
my %mergefilesequence = (); |
| 160 |
for ( my $i = 0; $i <= $#{$filecontent}; $i++ ) |
| 161 |
{ |
| 162 |
if ( $i <= 2 ) { next; } # ignoring first three lines |
| 163 |
if ( ${$filecontent}[$i] =~ /^\s*$/ ) { next; } # ignoring empty lines |
| 164 |
$filecounter++; |
| 165 |
push(@file_idt_content, ${$filecontent}[$i]); |
| 166 |
if ( ${$filecontent}[$i] =~ /^\s*(.+?)\t(.+?)\t(.+?)\t(.+?)\t(.*?)\t(.*?)\t(.*?)\t(\d+?)\s*$/ ) |
| 167 |
{ |
| 168 |
my $filename = $1; |
| 169 |
my $filesequence = $8; |
| 170 |
$mergefilesequence{$filename} = $filesequence; |
| 171 |
} |
| 172 |
else |
| 173 |
{ |
| 174 |
my $linecount = $i + 1; |
| 175 |
installer::exiter::exit_program("ERROR: Unknown line format in table \"$idtfilename\" (line $linecount) !", "merge_mergemodules_into_msi_database"); |
| 176 |
} |
| 177 |
} |
| 178 |
|
| 179 |
# Determining components |
| 180 |
$idtfilename = "Component.idt"; # must exist |
| 181 |
if ( ! -f $idtfilename ) { installer::exiter::exit_program("ERROR: File \"$idtfilename\" not found in directory \"$workdir\" !", "merge_mergemodules_into_msi_database"); } |
| 182 |
$filecontent = installer::files::read_file($idtfilename); |
| 183 |
my %componentnames = (); |
| 184 |
for ( my $i = 0; $i <= $#{$filecontent}; $i++ ) |
| 185 |
{ |
| 186 |
if ( $i <= 2 ) { next; } # ignoring first three lines |
| 187 |
if ( ${$filecontent}[$i] =~ /^\s*$/ ) { next; } # ignoring empty lines |
| 188 |
if ( ${$filecontent}[$i] =~ /^\s*(\S+)\s+/ ) { $componentnames{$1} = 1; } |
| 189 |
} |
| 190 |
|
| 191 |
# Determining directories |
| 192 |
$idtfilename = "Directory.idt"; # must exist |
| 193 |
if ( ! -f $idtfilename ) { installer::exiter::exit_program("ERROR: File \"$idtfilename\" not found in directory \"$workdir\" !", "merge_mergemodules_into_msi_database"); } |
| 194 |
$filecontent = installer::files::read_file($idtfilename); |
| 195 |
my %mergedirectories = (); |
| 196 |
for ( my $i = 0; $i <= $#{$filecontent}; $i++ ) |
| 197 |
{ |
| 198 |
if ( $i <= 2 ) { next; } # ignoring first three lines |
| 199 |
if ( ${$filecontent}[$i] =~ /^\s*$/ ) { next; } # ignoring empty lines |
| 200 |
if ( ${$filecontent}[$i] =~ /^\s*(\S+)\s+/ ) { $mergedirectories{$1} = 1; } |
| 201 |
} |
| 202 |
|
| 203 |
# Determining assemblies |
| 204 |
$idtfilename = "MsiAssembly.idt"; # does not need to exist |
| 205 |
my $hasmsiassemblies = 0; |
| 206 |
my %mergeassemblies = (); |
| 207 |
if ( -f $idtfilename ) |
| 208 |
{ |
| 209 |
$filecontent = installer::files::read_file($idtfilename); |
| 210 |
$hasmsiassemblies = 1; |
| 211 |
for ( my $i = 0; $i <= $#{$filecontent}; $i++ ) |
| 212 |
{ |
| 213 |
if ( $i <= 2 ) { next; } # ignoring first three lines |
| 214 |
if ( ${$filecontent}[$i] =~ /^\s*$/ ) { next; } # ignoring empty lines |
| 215 |
if ( ${$filecontent}[$i] =~ /^\s*(\S+)\s+/ ) { $mergeassemblies{$1} = 1; } |
| 216 |
} |
| 217 |
} |
| 218 |
|
| 219 |
# It is possible, that other tables have to be checked here. This happens, if tables in the |
| 220 |
# merge module have to know the "Feature" or the "Directory", under which the content of the |
| 221 |
# msm file is integrated into the msi database. |
| 222 |
|
| 223 |
# Determining name of cabinet file in installation set |
| 224 |
my $cabfilename = $mergemodule->{'Cabfilename'}; |
| 225 |
if ( $cabfilename ) { installer::packagelist::resolve_packagevariables(\$cabfilename, $allvariables, 0); } |
| 226 |
|
| 227 |
# Analyzing styles |
| 228 |
# Flag REMOVE_FILE_TABLE is required for msvc9 Merge-Module, because otherwise msidb.exe |
| 229 |
# fails during integration of msm file into msi database. |
| 230 |
|
| 231 |
my $styles = ""; |
| 232 |
my $removefiletable = 0; |
| 233 |
if ( $mergemodule->{'Styles'} ) { $styles = $mergemodule->{'Styles'}; } |
| 234 |
if ( $styles =~ /\bREMOVE_FILE_TABLE\b/ ) { $removefiletable = 1; } |
| 235 |
|
| 236 |
if ( $removefiletable ) |
| 237 |
{ |
| 238 |
my $removeworkdir = $workdir . $installer::globals::separator . "remove_file_idt"; |
| 239 |
if ( ! -d $removeworkdir ) { installer::systemactions::create_directory($removeworkdir); } |
| 240 |
my $completeremovedest = $removeworkdir . $installer::globals::separator . $filename; |
| 241 |
installer::systemactions::copy_one_file($completedest, $completeremovedest); |
| 242 |
if ( ! -f $completeremovedest ) { installer::exiter::exit_program("ERROR: msm file not found: $completeremovedest !", "merge_mergemodules_into_msi_database"); } |
| 243 |
|
| 244 |
# Unpacking msm file |
| 245 |
$systemcall = $msidb . " -d " . $completeremovedest . " -f " . $removeworkdir . " -e $globescape*"; |
| 246 |
# msidb.exe really wants backslashes |
| 247 |
$systemcall =~ s/\//\\\\/g; |
| 248 |
|
| 249 |
$systemcall_output = `$systemcall`; |
| 250 |
$returnvalue = $? >> 8; |
| 251 |
|
| 252 |
if ($returnvalue) { |
| 253 |
$infoline = "ERROR: Could not execute $systemcall - returncode: $returnvalue - output: $systemcall_output\n"; |
| 254 |
push( @installer::globals::logfileinfo, $infoline); |
| 255 |
installer::exiter::exit_program("ERROR: $systemcall failed!", "merge_mergemodules_into_msi_database"); |
| 256 |
} else { |
| 257 |
$infoline = "Success: Executed $systemcall successfully!\n"; |
| 258 |
push(@installer::globals::logfileinfo, $infoline); |
| 259 |
} |
| 260 |
|
| 261 |
my $idtfilename = $removeworkdir . $installer::globals::separator . "File.idt"; |
| 262 |
if ( -f $idtfilename ) { unlink $idtfilename; } |
| 263 |
unlink $completeremovedest; |
| 264 |
|
| 265 |
# Packing msm file without "File.idt" |
| 266 |
$systemcall = $msidb . " -c -d " . $completeremovedest . " -f " . $removeworkdir . " -i $globescape*"; |
| 267 |
# msidb.exe really wants backslashes |
| 268 |
$systemcall =~ s/\//\\\\/g; |
| 269 |
|
| 270 |
$systemcall_output = `$systemcall`; |
| 271 |
$returnvalue = $? >> 8; |
| 272 |
|
| 273 |
if ($returnvalue) { |
| 274 |
$infoline = "ERROR: Could not execute $systemcall - returncode: $returnvalue - output: $systemcall_output\n"; |
| 275 |
push( @installer::globals::logfileinfo, $infoline); |
| 276 |
installer::exiter::exit_program("ERROR: $systemcall failed!", "merge_mergemodules_into_msi_database"); |
| 277 |
} else { |
| 278 |
$infoline = "Success: Executed $systemcall successfully!\n"; |
| 279 |
push( @installer::globals::logfileinfo, $infoline); |
| 280 |
} |
| 281 |
|
| 282 |
# Using this msm file for merging |
| 283 |
if ( -f $completeremovedest ) { $completedest = $completeremovedest; } |
| 284 |
else { installer::exiter::exit_program("ERROR: Could not find msm file without File.idt: $completeremovedest !", "merge_mergemodules_into_msi_database"); } |
| 285 |
} |
| 286 |
|
| 287 |
# Saving MergeModule info |
| 288 |
|
| 289 |
my %onemergemodulehash = (); |
| 290 |
$onemergemodulehash{'mergefilepath'} = $completedest; |
| 291 |
$onemergemodulehash{'workdir'} = $workdir; |
| 292 |
$onemergemodulehash{'cabinetfile'} = $workdir . $installer::globals::separator . $cabinetfile; |
| 293 |
$onemergemodulehash{'filenumber'} = $filecounter; |
| 294 |
$onemergemodulehash{'componentnames'} = \%componentnames; |
| 295 |
$onemergemodulehash{'componentcondition'} = $mergemodule->{'ComponentCondition'}; |
| 296 |
$onemergemodulehash{'attributes_add'} = $mergemodule->{'Attributes_Add'}; |
| 297 |
$onemergemodulehash{'cabfilename'} = $cabfilename; |
| 298 |
$onemergemodulehash{'feature'} = $mergemodule->{'Feature'}; |
| 299 |
$onemergemodulehash{'rootdir'} = $mergemodule->{'RootDir'}; |
| 300 |
$onemergemodulehash{'name'} = $mergemodule->{'Name'}; |
| 301 |
$onemergemodulehash{'mergefilesequence'} = \%mergefilesequence; |
| 302 |
$onemergemodulehash{'mergeassemblies'} = \%mergeassemblies; |
| 303 |
$onemergemodulehash{'mergedirectories'} = \%mergedirectories; |
| 304 |
$onemergemodulehash{'hasmsiassemblies'} = $hasmsiassemblies; |
| 305 |
$onemergemodulehash{'removefiletable'} = $removefiletable; |
| 306 |
$onemergemodulehash{'fileidtcontent'} = \@file_idt_content; |
| 307 |
|
| 308 |
$installer::globals::mergemodules{$mergegid} = \%onemergemodulehash; |
| 309 |
|
| 310 |
# Collecting all cab files, to copy them into installation set |
| 311 |
if ( $cabfilename ) { $installer::globals::copy_msm_files{$cabfilename} = $onemergemodulehash{'cabinetfile'}; } |
| 312 |
|
| 313 |
chdir($from); |
| 314 |
} |
| 315 |
|
| 316 |
$infoline = "All Merge Modules successfully analyzed\n"; |
| 317 |
push( @installer::globals::logfileinfo, $infoline); |
| 318 |
|
| 319 |
$installer::globals::mergemodules_analyzed = 1; |
| 320 |
installer::logger::include_timestamp_into_logfile("\nPerformance Info: Analyzing MergeModules, stop"); |
| 321 |
|
| 322 |
$infoline = "\n"; |
| 323 |
push( @installer::globals::logfileinfo, $infoline); |
| 324 |
} |
| 325 |
|
| 326 |
# 2. Change msi database (has to be done for every msi database -> for every language) |
| 327 |
# a. Merge msm file into msi database: msidb.exe -d <msifile> -m <mergefile> |
| 328 |
# b. Extracting tables from msi database: msidb.exe -d <msifile> -f <directory> -e File Media, ... |
| 329 |
# c. Changing content of msi database in tables: File, Media, Directory, FeatureComponent |
| 330 |
# d. Including tables into msi database: msidb.exe -d <msifile> -f <directory> -i File Media, ... |
| 331 |
# e. Copying cabinet file into installation set (later) |
| 332 |
|
| 333 |
my $counter = 0; |
| 334 |
my $mergemodulegid; |
| 335 |
foreach $mergemodulegid (keys %installer::globals::mergemodules) |
| 336 |
{ |
| 337 |
my $mergemodulehash = $installer::globals::mergemodules{$mergemodulegid}; |
| 338 |
$counter++; |
| 339 |
|
| 340 |
installer::logger::include_header_into_logfile("Merging Module: $mergemodulehash->{'name'}"); |
| 341 |
installer::logger::print_message( "\t... $mergemodulehash->{'name'} ... \n" ); |
| 342 |
|
| 343 |
$msifilename = installer::converter::make_path_conform($msifilename); |
| 344 |
my $workdir = $msifilename; |
| 345 |
installer::pathanalyzer::get_path_from_fullqualifiedname(\$workdir); |
| 346 |
|
| 347 |
# changing directory |
| 348 |
my $from = cwd(); |
| 349 |
my $to = $workdir; |
| 350 |
chdir($to); |
| 351 |
|
| 352 |
# Saving original msi database |
| 353 |
installer::systemactions::copy_one_file($msifilename, "$msifilename\.$counter"); |
| 354 |
|
| 355 |
# Merging msm file, this is the "real" merge command |
| 356 |
|
| 357 |
installer::logger::include_timestamp_into_logfile("\nPerformance Info: Before merging database"); |
| 358 |
|
| 359 |
$systemcall = $msidb . " -d " . $msifilename . " -m " . $mergemodulehash->{'mergefilepath'}; |
| 360 |
# msidb.exe really wants backslashes |
| 361 |
$systemcall =~ s/\//\\\\/g; |
| 362 |
|
| 363 |
$systemcall_output = `$systemcall`; |
| 364 |
$returnvalue = $? >> 8; |
| 365 |
|
| 366 |
if ($returnvalue) |
| 367 |
{ |
| 368 |
$infoline = "ERROR: Could not execute $systemcall - returncode: $returnvalue - output: $systemcall_output\n"; |
| 369 |
push( @installer::globals::logfileinfo, $infoline); |
| 370 |
installer::exiter::exit_program("Could not merge msm file into database: $mergemodulehash->{'mergefilepath'}\n$infoline", "merge_mergemodules_into_msi_database"); |
| 371 |
} |
| 372 |
else |
| 373 |
{ |
| 374 |
$infoline = "Success: Executed $systemcall successfully!\n"; |
| 375 |
push( @installer::globals::logfileinfo, $infoline); |
| 376 |
} |
| 377 |
|
| 378 |
installer::logger::include_timestamp_into_logfile("\nPerformance Info: After merging database"); |
| 379 |
|
| 380 |
# Saving original idt files |
| 381 |
if ( -f "File.idt" ) { installer::systemactions::rename_one_file("File.idt", "old.File.idt.$counter"); } |
| 382 |
if ( -f "Media.idt" ) { installer::systemactions::rename_one_file("Media.idt", "old.Media.idt.$counter"); } |
| 383 |
if ( -f "Directory.idt" ) { installer::systemactions::rename_one_file("Directory.idt", "old.Directory.idt.$counter"); } |
| 384 |
if ( -f "Director.idt" ) { installer::systemactions::rename_one_file("Director.idt", "old.Director.idt.$counter"); } |
| 385 |
if ( -f "FeatureComponents.idt" ) { installer::systemactions::rename_one_file("FeatureComponents.idt", "old.FeatureComponents.idt.$counter"); } |
| 386 |
if ( -f "FeatureC.idt" ) { installer::systemactions::rename_one_file("FeatureC.idt", "old.FeatureC.idt.$counter"); } |
| 387 |
if ( -f "MsiAssembly.idt" ) { installer::systemactions::rename_one_file("MsiAssembly.idt", "old.MsiAssembly.idt.$counter"); } |
| 388 |
if ( -f "MsiAssem.idt" ) { installer::systemactions::rename_one_file("MsiAssem.idt", "old.MsiAssem.idt.$counter"); } |
| 389 |
if ( -f "Componen.idt" ) { installer::systemactions::rename_one_file("Componen.idt", "old.Componen.idt.$counter"); } |
| 390 |
|
| 391 |
# Extracting tables |
| 392 |
|
| 393 |
installer::logger::include_timestamp_into_logfile("\nPerformance Info: Before extracting tables"); |
| 394 |
|
| 395 |
my $workingtables = "File Media Directory FeatureComponents"; # required tables |
| 396 |
# Optional tables can be added now |
| 397 |
if ( $mergemodulehash->{'hasmsiassemblies'} ) { $workingtables = $workingtables . " MsiAssembly"; } |
| 398 |
if ( ( $mergemodulehash->{'componentcondition'} ) || ( $mergemodulehash->{'attributes_add'} ) ) { $workingtables = $workingtables . " Component"; } |
| 399 |
|
| 400 |
# Table "Feature" has to be exported, but it is not necessary to import it. |
| 401 |
$systemcall = $msidb . " -d " . $msifilename . " -f " . $workdir . " -e " . "Feature " . $workingtables; |
| 402 |
# msidb.exe really wants backslashes |
| 403 |
$systemcall =~ s/\//\\\\/g; |
| 404 |
|
| 405 |
$systemcall_output = `$systemcall`; |
| 406 |
$returnvalue = $? >> 8; |
| 407 |
|
| 408 |
if ($returnvalue) |
| 409 |
{ |
| 410 |
$infoline = "ERROR: Could not execute $systemcall - returncode: $returnvalue - output: $systemcall_output\n"; |
| 411 |
push( @installer::globals::logfileinfo, $infoline); |
| 412 |
installer::exiter::exit_program("ERROR: Could not exclude tables from msi database: $msifilename !", "merge_mergemodules_into_msi_database"); |
| 413 |
} |
| 414 |
else |
| 415 |
{ |
| 416 |
$infoline = "Success: Executed $systemcall successfully!\n"; |
| 417 |
push( @installer::globals::logfileinfo, $infoline); |
| 418 |
} |
| 419 |
|
| 420 |
installer::logger::include_timestamp_into_logfile("\nPerformance Info: After extracting tables"); |
| 421 |
|
| 422 |
# Using 8+3 table names, that are used, when tables are integrated into database. The export of tables |
| 423 |
# creates idt-files, that have long names. |
| 424 |
|
| 425 |
if ( -f "Directory.idt" ) { installer::systemactions::rename_one_file("Directory.idt", "Director.idt"); } |
| 426 |
if ( -f "FeatureComponents.idt" ) { installer::systemactions::rename_one_file("FeatureComponents.idt", "FeatureC.idt"); } |
| 427 |
if ( -f "MsiAssembly.idt" ) { installer::systemactions::rename_one_file("MsiAssembly.idt", "MsiAssem.idt"); } |
| 428 |
if ( -f "Component.idt" ) { installer::systemactions::rename_one_file("Component.idt", "Componen.idt"); } |
| 429 |
|
| 430 |
# Changing content of tables: File, Media, Directory, FeatureComponent, MsiAssembly, Component |
| 431 |
installer::logger::include_timestamp_into_logfile("\nPerformance Info: Changing Media table"); |
| 432 |
change_media_table($mergemodulehash, $workdir, $mergemodulegid, $allupdatelastsequences, $allupdatediskids); |
| 433 |
installer::logger::include_timestamp_into_logfile("\nPerformance Info: Changing File table"); |
| 434 |
$filesref = change_file_table($mergemodulehash, $workdir, $allupdatesequences, $includepatharrayref, $filesref, $mergemodulegid); |
| 435 |
installer::logger::include_timestamp_into_logfile("\nPerformance Info: Changing FeatureComponent table"); |
| 436 |
change_featurecomponent_table($mergemodulehash, $workdir); |
| 437 |
installer::logger::include_timestamp_into_logfile("\nPerformance Info: Changing Directory table"); |
| 438 |
change_directory_table($mergemodulehash, $workdir); |
| 439 |
if ( $mergemodulehash->{'hasmsiassemblies'} ) |
| 440 |
{ |
| 441 |
installer::logger::include_timestamp_into_logfile("\nPerformance Info: Changing MsiAssembly table"); |
| 442 |
change_msiassembly_table($mergemodulehash, $workdir); |
| 443 |
} |
| 444 |
|
| 445 |
if ( ( $mergemodulehash->{'componentcondition'} ) || ( $mergemodulehash->{'attributes_add'} ) ) |
| 446 |
{ |
| 447 |
installer::logger::include_timestamp_into_logfile("\nPerformance Info: Changing Component table"); |
| 448 |
change_component_table($mergemodulehash, $workdir); |
| 449 |
} |
| 450 |
|
| 451 |
# msidb.exe does not merge InstallExecuteSequence, AdminExecuteSequence and AdvtExecuteSequence. Instead it creates |
| 452 |
# new tables ModuleInstallExecuteSequence, ModuleAdminExecuteSequence and ModuleAdvtExecuteSequence that need to be |
| 453 |
# merged into the three ExecuteSequences with the following process (also into InstallUISequence.idt). |
| 454 |
|
| 455 |
# Saving original idt files |
| 456 |
if ( -f "InstallE.idt" ) { installer::systemactions::rename_one_file("InstallE.idt", "old.InstallE.idt.$counter"); } |
| 457 |
if ( -f "InstallU.idt" ) { installer::systemactions::rename_one_file("InstallU.idt", "old.InstallU.idt.$counter"); } |
| 458 |
if ( -f "AdminExe.idt" ) { installer::systemactions::rename_one_file("AdminExe.idt", "old.AdminExe.idt.$counter"); } |
| 459 |
if ( -f "AdvtExec.idt" ) { installer::systemactions::rename_one_file("AdvtExec.idt", "old.AdvtExec.idt.$counter"); } |
| 460 |
if ( -f "ModuleInstallExecuteSequence.idt" ) { installer::systemactions::rename_one_file("ModuleInstallExecuteSequence.idt", "old.ModuleInstallExecuteSequence.idt.$counter"); } |
| 461 |
if ( -f "ModuleAdminExecuteSequence.idt" ) { installer::systemactions::rename_one_file("ModuleAdminExecuteSequence.idt", "old.ModuleAdminExecuteSequence.idt.$counter"); } |
| 462 |
if ( -f "ModuleAdvtExecuteSequence.idt" ) { installer::systemactions::rename_one_file("ModuleAdvtExecuteSequence.idt", "old.ModuleAdvtExecuteSequence.idt.$counter"); } |
| 463 |
|
| 464 |
# Extracting tables |
| 465 |
my $moduleexecutetables = "ModuleInstallExecuteSequence ModuleAdminExecuteSequence ModuleAdvtExecuteSequence"; # new tables |
| 466 |
my $executetables = "InstallExecuteSequence InstallUISequence AdminExecuteSequence AdvtExecuteSequence"; # tables to be merged |
| 467 |
|
| 468 |
$systemcall = $msidb . " -d " . $msifilename . " -f " . $workdir . " -e " . "Feature " . $moduleexecutetables; |
| 469 |
# msidb.exe really wants backslashes |
| 470 |
$systemcall =~ s/\//\\\\/g; |
| 471 |
|
| 472 |
$systemcall_output = `$systemcall`; |
| 473 |
$returnvalue = $? >> 8; |
| 474 |
|
| 475 |
if ($returnvalue) { |
| 476 |
# the exit status of this command had not been checked in the past, it fails because |
| 477 |
# there is no ModuleAdminExecuteSequence table |
| 478 |
$infoline = "IGNORING: Could not execute $systemcall - returncode: $returnvalue - output: $systemcall_output\n"; |
| 479 |
push( @installer::globals::logfileinfo, $infoline); |
| 480 |
#installer::exiter::exit_program("ERROR: $infoline", "merge_mergemodules_into_msi_database"); |
| 481 |
} else { |
| 482 |
$infoline = "Success: Executed $systemcall successfully\n"; |
| 483 |
push( @installer::globals::logfileinfo, $infoline); |
| 484 |
} |
| 485 |
|
| 486 |
$systemcall = $msidb . " -d " . $msifilename . " -f " . $workdir . " -e " . "Feature " . $executetables; |
| 487 |
# msidb.exe really wants backslashes |
| 488 |
$systemcall =~ s/\//\\\\/g; |
| 489 |
|
| 490 |
$systemcall_output = `$systemcall`; |
| 491 |
$returnvalue = $? >> 8; |
| 492 |
|
| 493 |
if ($returnvalue) { |
| 494 |
$infoline = "ERROR: Could not execute $systemcall - returncode: $returnvalue - output: $systemcall_output\n"; |
| 495 |
push( @installer::globals::logfileinfo, $infoline); |
| 496 |
installer::exiter::exit_program("$infoline", "merge_mergemodules_into_msi_database"); |
| 497 |
} else { |
| 498 |
$infoline = "Success: Executed $systemcall successfully\n"; |
| 499 |
push( @installer::globals::logfileinfo, $infoline); |
| 500 |
} |
| 501 |
|
| 502 |
# Using 8+3 table names, that are used, when tables are integrated into database. The export of tables |
| 503 |
# creates idt-files, that have long names. |
| 504 |
|
| 505 |
if ( -f "InstallExecuteSequence.idt" ) { installer::systemactions::rename_one_file("InstallExecuteSequence.idt", "InstallE.idt"); } |
| 506 |
if ( -f "InstallUISequence.idt" ) { installer::systemactions::rename_one_file("InstallUISequence.idt", "InstallU.idt"); } |
| 507 |
if ( -f "AdminExecuteSequence.idt" ) { installer::systemactions::rename_one_file("AdminExecuteSequence.idt", "AdminExe.idt"); } |
| 508 |
if ( -f "AdvtExecuteSequence.idt" ) { installer::systemactions::rename_one_file("AdvtExecuteSequence.idt", "AdvtExec.idt"); } |
| 509 |
|
| 510 |
# Merging content of tables ModuleInstallExecuteSequence, ModuleAdminExecuteSequence and ModuleAdvtExecuteSequence |
| 511 |
# into tables InstallExecuteSequence, AdminExecuteSequence and AdvtExecuteSequence |
| 512 |
if ( -f "ModuleInstallExecuteSequence.idt" ) |
| 513 |
{ |
| 514 |
installer::logger::include_timestamp_into_logfile("\nPerformance Info: Changing InstallExecuteSequence table"); |
| 515 |
change_executesequence_table($mergemodulehash, $workdir, "InstallE.idt", "ModuleInstallExecuteSequence.idt"); |
| 516 |
installer::logger::include_timestamp_into_logfile("\nPerformance Info: Changing InstallUISequence table"); |
| 517 |
change_executesequence_table($mergemodulehash, $workdir, "InstallU.idt", "ModuleInstallExecuteSequence.idt"); |
| 518 |
} |
| 519 |
|
| 520 |
if ( -f "ModuleAdminExecuteSequence.idt" ) |
| 521 |
{ |
| 522 |
installer::logger::include_timestamp_into_logfile("\nPerformance Info: Changing AdminExecuteSequence table"); |
| 523 |
change_executesequence_table($mergemodulehash, $workdir, "AdminExe.idt", "ModuleAdminExecuteSequence.idt"); |
| 524 |
} |
| 525 |
|
| 526 |
if ( -f "ModuleAdvtExecuteSequence.idt" ) |
| 527 |
{ |
| 528 |
installer::logger::include_timestamp_into_logfile("\nPerformance Info: Changing AdvtExecuteSequence table"); |
| 529 |
change_executesequence_table($mergemodulehash, $workdir, "AdvtExec.idt", "ModuleAdvtExecuteSequence.idt"); |
| 530 |
} |
| 531 |
|
| 532 |
installer::logger::include_timestamp_into_logfile("\nPerformance Info: All tables edited"); |
| 533 |
|
| 534 |
# Including tables into msi database |
| 535 |
|
| 536 |
installer::logger::include_timestamp_into_logfile("\nPerformance Info: Before including tables"); |
| 537 |
|
| 538 |
# trying to import all tables at once seems to work fine, but creates a broken installer tdf#165149 |
| 539 |
foreach my $table (split / /, $workingtables . ' ' . $executetables) { |
| 540 |
$systemcall = $msidb . " -d " . $msifilename . " -f " . $workdir . " -i " . $table; |
| 541 |
# msidb.exe really wants backslashes |
| 542 |
$systemcall =~ s/\//\\\\/g; |
| 543 |
|
| 544 |
$systemcall_output = `$systemcall`; |
| 545 |
$returnvalue = $? >> 8; |
| 546 |
|
| 547 |
if ($returnvalue) |
| 548 |
{ |
| 549 |
$infoline = "ERROR: Could not execute $systemcall - returncode: $returnvalue - output: $systemcall_output\n"; |
| 550 |
push( @installer::globals::logfileinfo, $infoline); |
| 551 |
installer::exiter::exit_program("ERROR: Could not include tables into msi database: $msifilename !", "merge_mergemodules_into_msi_database"); |
| 552 |
} |
| 553 |
else |
| 554 |
{ |
| 555 |
$infoline = "Success: Executed $systemcall successfully!\n"; |
| 556 |
push( @installer::globals::logfileinfo, $infoline); |
| 557 |
} |
| 558 |
} |
| 559 |
|
| 560 |
installer::logger::include_timestamp_into_logfile("\nPerformance Info: After including tables"); |
| 561 |
|
| 562 |
chdir($from); |
| 563 |
} |
| 564 |
|
| 565 |
if ( ! $installer::globals::mergefiles_added_into_collector ) { $installer::globals::mergefiles_added_into_collector = 1; } # Now all mergemodules are merged for one language. |
| 566 |
|
| 567 |
installer::logger::include_timestamp_into_logfile("\nPerformance Info: MergeModule into msi database, stop"); |
| 568 |
} |
| 569 |
|
| 570 |
return $filesref; |
| 571 |
} |
| 572 |
|
| 573 |
######################################################################### |
| 574 |
# Analyzing the content of the media table. |
| 575 |
######################################################################### |
| 576 |
|
| 577 |
sub analyze_media_file |
| 578 |
{ |
| 579 |
my ($filecontent, $workdir) = @_; |
| 580 |
|
| 581 |
my %filehash = (); |
| 582 |
my $linecount = 0; |
| 583 |
my $counter = 0; |
| 584 |
my $filename = "Media.idt"; |
| 585 |
|
| 586 |
for ( my $i = 0; $i <= $#{$filecontent}; $i++ ) |
| 587 |
{ |
| 588 |
if ( $i <= 2 ) { next; } # ignoring first three lines |
| 589 |
if ( ${$filecontent}[$i] =~ /^\s*$/ ) { next; } # ignoring empty lines |
| 590 |
if ( ${$filecontent}[$i] =~ /^\s*(.+?)\t(.+?)\t(.+?)\t(.+?)\t(.+?)\t(.*?)\s*$/ ) |
| 591 |
{ |
| 592 |
my %line = (); |
| 593 |
# Format: DiskId LastSequence DiskPrompt Cabinet VolumeLabel Source |
| 594 |
$line{'DiskId'} = $1; |
| 595 |
$line{'LastSequence'} = $2; |
| 596 |
$line{'DiskPrompt'} = $3; |
| 597 |
$line{'Cabinet'} = $4; |
| 598 |
$line{'VolumeLabel'} = $5; |
| 599 |
$line{'Source'} = $6; |
| 600 |
|
| 601 |
$counter++; |
| 602 |
$filehash{$counter} = \%line; |
| 603 |
} |
| 604 |
else |
| 605 |
{ |
| 606 |
$linecount = $i + 1; |
| 607 |
installer::exiter::exit_program("ERROR: Unknown line format in table \"$filename\" in \"$workdir\" (line $linecount) !", "analyze_media_file"); |
| 608 |
} |
| 609 |
} |
| 610 |
|
| 611 |
return \%filehash; |
| 612 |
} |
| 613 |
|
| 614 |
######################################################################### |
| 615 |
# Setting the DiskID for the new cabinet file |
| 616 |
######################################################################### |
| 617 |
|
| 618 |
sub get_diskid |
| 619 |
{ |
| 620 |
my ($mediafile, $allupdatediskids, $cabfilename) = @_; |
| 621 |
|
| 622 |
my $diskid = 0; |
| 623 |
my $line; |
| 624 |
|
| 625 |
if (( $installer::globals::updatedatabase ) && ( exists($allupdatediskids->{$cabfilename}) )) |
| 626 |
{ |
| 627 |
$diskid = $allupdatediskids->{$cabfilename}; |
| 628 |
} |
| 629 |
else |
| 630 |
{ |
| 631 |
foreach $line ( keys %{$mediafile} ) |
| 632 |
{ |
| 633 |
if ( $mediafile->{$line}->{'DiskId'} > $diskid ) { $diskid = $mediafile->{$line}->{'DiskId'}; } |
| 634 |
} |
| 635 |
|
| 636 |
$diskid++; |
| 637 |
} |
| 638 |
|
| 639 |
return $diskid; |
| 640 |
} |
| 641 |
|
| 642 |
######################################################################### |
| 643 |
# Setting the global LastSequence variable |
| 644 |
######################################################################### |
| 645 |
|
| 646 |
sub set_current_last_sequence |
| 647 |
{ |
| 648 |
my ($mediafile) = @_; |
| 649 |
|
| 650 |
my $lastsequence = 0; |
| 651 |
my $line; |
| 652 |
foreach $line ( keys %{$mediafile} ) |
| 653 |
{ |
| 654 |
if ( $mediafile->{$line}->{'LastSequence'} > $lastsequence ) { $lastsequence = $mediafile->{$line}->{'LastSequence'}; } |
| 655 |
} |
| 656 |
|
| 657 |
$installer::globals::lastsequence_before_merge = $lastsequence; |
| 658 |
} |
| 659 |
|
| 660 |
######################################################################### |
| 661 |
# Setting the LastSequence for the new cabinet file |
| 662 |
######################################################################### |
| 663 |
|
| 664 |
sub get_lastsequence |
| 665 |
{ |
| 666 |
my ($mergemodulehash, $allupdatelastsequences) = @_; |
| 667 |
|
| 668 |
my $lastsequence = 0; |
| 669 |
|
| 670 |
if (( $installer::globals::updatedatabase ) && ( exists($allupdatelastsequences->{$mergemodulehash->{'cabfilename'}}) )) |
| 671 |
{ |
| 672 |
$lastsequence = $allupdatelastsequences->{$mergemodulehash->{'cabfilename'}}; |
| 673 |
} |
| 674 |
else |
| 675 |
{ |
| 676 |
$lastsequence = $installer::globals::lastsequence_before_merge + $mergemodulehash->{'filenumber'}; |
| 677 |
} |
| 678 |
|
| 679 |
return $lastsequence; |
| 680 |
} |
| 681 |
|
| 682 |
######################################################################### |
| 683 |
# Setting the DiskPrompt for the new cabinet file |
| 684 |
######################################################################### |
| 685 |
|
| 686 |
sub get_diskprompt |
| 687 |
{ |
| 688 |
my ($mediafile) = @_; |
| 689 |
|
| 690 |
my $diskprompt = ""; |
| 691 |
my $line; |
| 692 |
foreach $line ( keys %{$mediafile} ) |
| 693 |
{ |
| 694 |
if ( exists($mediafile->{$line}->{'DiskPrompt'}) ) |
| 695 |
{ |
| 696 |
$diskprompt = $mediafile->{$line}->{'DiskPrompt'}; |
| 697 |
last; |
| 698 |
} |
| 699 |
} |
| 700 |
|
| 701 |
return $diskprompt; |
| 702 |
} |
| 703 |
|
| 704 |
######################################################################### |
| 705 |
# Setting the VolumeLabel for the new cabinet file |
| 706 |
######################################################################### |
| 707 |
|
| 708 |
sub get_volumelabel |
| 709 |
{ |
| 710 |
my ($mediafile) = @_; |
| 711 |
|
| 712 |
my $volumelabel = ""; |
| 713 |
my $line; |
| 714 |
foreach $line ( keys %{$mediafile} ) |
| 715 |
{ |
| 716 |
if ( exists($mediafile->{$line}->{'VolumeLabel'}) ) |
| 717 |
{ |
| 718 |
$volumelabel = $mediafile->{$line}->{'VolumeLabel'}; |
| 719 |
last; |
| 720 |
} |
| 721 |
} |
| 722 |
|
| 723 |
return $volumelabel; |
| 724 |
} |
| 725 |
|
| 726 |
######################################################################### |
| 727 |
# Setting the Source for the new cabinet file |
| 728 |
######################################################################### |
| 729 |
|
| 730 |
sub get_source |
| 731 |
{ |
| 732 |
my ($mediafile) = @_; |
| 733 |
|
| 734 |
my $source = ""; |
| 735 |
my $line; |
| 736 |
foreach $line ( keys %{$mediafile} ) |
| 737 |
{ |
| 738 |
if ( exists($mediafile->{$line}->{'Source'}) ) |
| 739 |
{ |
| 740 |
$source = $mediafile->{$line}->{'Source'}; |
| 741 |
last; |
| 742 |
} |
| 743 |
} |
| 744 |
|
| 745 |
return $source; |
| 746 |
} |
| 747 |
|
| 748 |
######################################################################### |
| 749 |
# For each Merge Module one new line has to be included into the |
| 750 |
# media table. |
| 751 |
######################################################################### |
| 752 |
|
| 753 |
sub create_new_media_line |
| 754 |
{ |
| 755 |
my ($mergemodulehash, $mediafile, $allupdatelastsequences, $allupdatediskids) = @_; |
| 756 |
|
| 757 |
my $diskid = get_diskid($mediafile, $allupdatediskids, $mergemodulehash->{'cabfilename'}); |
| 758 |
my $lastsequence = get_lastsequence($mergemodulehash, $allupdatelastsequences); |
| 759 |
my $diskprompt = get_diskprompt($mediafile); |
| 760 |
my $cabinet = $mergemodulehash->{'cabfilename'}; |
| 761 |
my $volumelabel = get_volumelabel($mediafile); |
| 762 |
my $source = get_source($mediafile); |
| 763 |
|
| 764 |
if ( $installer::globals::include_cab_in_msi ) { $cabinet = "\#" . $cabinet; } |
| 765 |
|
| 766 |
my $newline = "$diskid\t$lastsequence\t$diskprompt\t$cabinet\t$volumelabel\t$source\n"; |
| 767 |
|
| 768 |
return $newline; |
| 769 |
} |
| 770 |
|
| 771 |
######################################################################### |
| 772 |
# Setting the last diskid in media table. |
| 773 |
######################################################################### |
| 774 |
|
| 775 |
sub get_last_diskid |
| 776 |
{ |
| 777 |
my ($mediafile) = @_; |
| 778 |
|
| 779 |
my $lastdiskid = 0; |
| 780 |
my $line; |
| 781 |
foreach $line ( keys %{$mediafile} ) |
| 782 |
{ |
| 783 |
if ( $mediafile->{$line}->{'DiskId'} > $lastdiskid ) { $lastdiskid = $mediafile->{$line}->{'DiskId'}; } |
| 784 |
} |
| 785 |
|
| 786 |
return $lastdiskid; |
| 787 |
} |
| 788 |
|
| 789 |
######################################################################### |
| 790 |
# Setting global variable for last cab file name. |
| 791 |
######################################################################### |
| 792 |
|
| 793 |
sub set_last_cabfile_name |
| 794 |
{ |
| 795 |
my ($mediafile, $lastdiskid) = @_; |
| 796 |
|
| 797 |
my $line; |
| 798 |
foreach $line ( keys %{$mediafile} ) |
| 799 |
{ |
| 800 |
if ( $mediafile->{$line}->{'DiskId'} == $lastdiskid ) { $installer::globals::lastcabfilename = $mediafile->{$line}->{'Cabinet'}; } |
| 801 |
} |
| 802 |
my $infoline = "Setting last cabinet file: $installer::globals::lastcabfilename\n"; |
| 803 |
push( @installer::globals::logfileinfo, $infoline); |
| 804 |
} |
| 805 |
|
| 806 |
######################################################################### |
| 807 |
# In the media table the new cabinet file has to be added or the |
| 808 |
# number of the last cabinet file has to be increased. |
| 809 |
######################################################################### |
| 810 |
|
| 811 |
sub change_media_table |
| 812 |
{ |
| 813 |
my ( $mergemodulehash, $workdir, $mergemodulegid, $allupdatelastsequences, $allupdatediskids ) = @_; |
| 814 |
|
| 815 |
my $infoline = "Changing content of table \"Media\"\n"; |
| 816 |
push( @installer::globals::logfileinfo, $infoline); |
| 817 |
|
| 818 |
my $filename = "Media.idt"; |
| 819 |
if ( ! -f $filename ) { installer::exiter::exit_program("ERROR: Could not find file \"$filename\" in \"$workdir\" !", "change_media_table"); } |
| 820 |
|
| 821 |
my $filecontent = installer::files::read_file($filename); |
| 822 |
my $mediafile = analyze_media_file($filecontent, $workdir); |
| 823 |
set_current_last_sequence($mediafile); |
| 824 |
|
| 825 |
if ( $installer::globals::fix_number_of_cab_files ) |
| 826 |
{ |
| 827 |
# Determining the line with the highest sequencenumber. That file needs to be updated. |
| 828 |
my $lastdiskid = get_last_diskid($mediafile); |
| 829 |
if ( $installer::globals::lastcabfilename eq "" ) { set_last_cabfile_name($mediafile, $lastdiskid); } |
| 830 |
my $newmaxsequencenumber = $installer::globals::lastsequence_before_merge + $mergemodulehash->{'filenumber'}; |
| 831 |
|
| 832 |
for ( my $i = 0; $i <= $#{$filecontent}; $i++ ) |
| 833 |
{ |
| 834 |
if ( $i <= 2 ) { next; } # ignoring first three lines |
| 835 |
if ( ${$filecontent}[$i] =~ /^\s*$/ ) { next; } # ignoring empty lines |
| 836 |
if ( ${$filecontent}[$i] =~ /^\s*(\Q$lastdiskid\E\t)\Q$installer::globals::lastsequence_before_merge\E(\t.*)$/ ) |
| 837 |
{ |
| 838 |
my $start = $1; |
| 839 |
my $final = $2; |
| 840 |
$infoline = "Merge: Old line in media table: ${$filecontent}[$i]\n"; |
| 841 |
push( @installer::globals::logfileinfo, $infoline); |
| 842 |
my $newline = $start . $newmaxsequencenumber . $final . "\n"; |
| 843 |
${$filecontent}[$i] = $newline; |
| 844 |
$infoline = "Merge: Changed line in media table: ${$filecontent}[$i]\n"; |
| 845 |
push( @installer::globals::logfileinfo, $infoline); |
| 846 |
} |
| 847 |
} |
| 848 |
} |
| 849 |
else |
| 850 |
{ |
| 851 |
# the new line is identical for all localized databases, but has to be created for each MergeModule ($mergemodulegid) |
| 852 |
if ( ! exists($installer::globals::merge_media_line{$mergemodulegid}) ) |
| 853 |
{ |
| 854 |
$installer::globals::merge_media_line{$mergemodulegid} = create_new_media_line($mergemodulehash, $mediafile, $allupdatelastsequences, $allupdatediskids); |
| 855 |
} |
| 856 |
|
| 857 |
$infoline = "Adding line: $installer::globals::merge_media_line{$mergemodulegid}\n"; |
| 858 |
push( @installer::globals::logfileinfo, $infoline); |
| 859 |
|
| 860 |
# adding new line |
| 861 |
push(@{$filecontent}, $installer::globals::merge_media_line{$mergemodulegid}); |
| 862 |
} |
| 863 |
|
| 864 |
# saving file |
| 865 |
installer::files::save_file($filename, $filecontent); |
| 866 |
} |
| 867 |
|
| 868 |
######################################################################### |
| 869 |
# Putting the directory table content into a hash. |
| 870 |
######################################################################### |
| 871 |
|
| 872 |
sub analyze_directorytable_file |
| 873 |
{ |
| 874 |
my ($filecontent, $idtfilename) = @_; |
| 875 |
|
| 876 |
my %dirhash = (); |
| 877 |
# Iterating over the file content |
| 878 |
for ( my $i = 0; $i <= $#{$filecontent}; $i++ ) |
| 879 |
{ |
| 880 |
if ( $i <= 2 ) { next; } # ignoring first three lines |
| 881 |
if ( ${$filecontent}[$i] =~ /^\s*$/ ) { next; } # ignoring empty lines |
| 882 |
if ( ${$filecontent}[$i] =~ /^\s*(.+?)\t(.*?)\t(.*?)\s*$/ ) |
| 883 |
{ |
| 884 |
my %line = (); |
| 885 |
# Format: Directory Directory_Parent DefaultDir |
| 886 |
$line{'Directory'} = $1; |
| 887 |
$line{'Directory_Parent'} = $2; |
| 888 |
$line{'DefaultDir'} = $3; |
| 889 |
$line{'linenumber'} = $i; # saving also the line number for direct access |
| 890 |
|
| 891 |
my $uniquekey = $line{'Directory'}; |
| 892 |
$dirhash{$uniquekey} = \%line; |
| 893 |
} |
| 894 |
else |
| 895 |
{ |
| 896 |
my $linecount = $i + 1; |
| 897 |
installer::exiter::exit_program("ERROR: Unknown line format in table \"$idtfilename\" (line $linecount) !", "analyze_directorytable_file"); |
| 898 |
} |
| 899 |
} |
| 900 |
|
| 901 |
return \%dirhash; |
| 902 |
} |
| 903 |
|
| 904 |
######################################################################### |
| 905 |
# Putting the msi assembly table content into a hash. |
| 906 |
######################################################################### |
| 907 |
|
| 908 |
sub analyze_msiassemblytable_file |
| 909 |
{ |
| 910 |
my ($filecontent, $idtfilename) = @_; |
| 911 |
|
| 912 |
my %assemblyhash = (); |
| 913 |
# Iterating over the file content |
| 914 |
for ( my $i = 0; $i <= $#{$filecontent}; $i++ ) |
| 915 |
{ |
| 916 |
if ( $i <= 2 ) { next; } # ignoring first three lines |
| 917 |
if ( ${$filecontent}[$i] =~ /^\s*$/ ) { next; } # ignoring empty lines |
| 918 |
if ( ${$filecontent}[$i] =~ /^\s*(.+?)\t(.+?)\t(.+?)\t(.*?)\t(.*?)\s*$/ ) |
| 919 |
{ |
| 920 |
my %line = (); |
| 921 |
# Format: Component_ Feature_ File_Manifest File_Application Attributes |
| 922 |
$line{'Component'} = $1; |
| 923 |
$line{'Feature'} = $2; |
| 924 |
$line{'File_Manifest'} = $3; |
| 925 |
$line{'File_Application'} = $4; |
| 926 |
$line{'Attributes'} = $5; |
| 927 |
$line{'linenumber'} = $i; # saving also the line number for direct access |
| 928 |
|
| 929 |
my $uniquekey = $line{'Component'}; |
| 930 |
$assemblyhash{$uniquekey} = \%line; |
| 931 |
} |
| 932 |
else |
| 933 |
{ |
| 934 |
my $linecount = $i + 1; |
| 935 |
installer::exiter::exit_program("ERROR: Unknown line format in table \"$idtfilename\" (line $linecount) !", "analyze_msiassemblytable_file"); |
| 936 |
} |
| 937 |
} |
| 938 |
|
| 939 |
return \%assemblyhash; |
| 940 |
} |
| 941 |
|
| 942 |
######################################################################### |
| 943 |
# Putting the file table content into a hash. |
| 944 |
######################################################################### |
| 945 |
|
| 946 |
sub analyze_filetable_file |
| 947 |
{ |
| 948 |
my ( $filecontent, $idtfilename ) = @_; |
| 949 |
|
| 950 |
my %filehash = (); |
| 951 |
# Iterating over the file content |
| 952 |
for ( my $i = 0; $i <= $#{$filecontent}; $i++ ) |
| 953 |
{ |
| 954 |
if ( $i <= 2 ) { next; } # ignoring first three lines |
| 955 |
if ( ${$filecontent}[$i] =~ /^\s*$/ ) { next; } # ignoring empty lines |
| 956 |
if ( ${$filecontent}[$i] =~ /^\s*(.+?)\t(.+?)\t(.+?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.+?)\s*$/ ) |
| 957 |
{ |
| 958 |
my %line = (); |
| 959 |
# Format: File Component_ FileName FileSize Version Language Attributes Sequence |
| 960 |
$line{'File'} = $1; |
| 961 |
$line{'Component'} = $2; |
| 962 |
$line{'FileName'} = $3; |
| 963 |
$line{'FileSize'} = $4; |
| 964 |
$line{'Version'} = $5; |
| 965 |
$line{'Language'} = $6; |
| 966 |
$line{'Attributes'} = $7; |
| 967 |
$line{'Sequence'} = $8; |
| 968 |
$line{'linenumber'} = $i; # saving also the line number for direct access |
| 969 |
|
| 970 |
my $uniquekey = $line{'File'}; |
| 971 |
$filehash{$uniquekey} = \%line; |
| 972 |
} |
| 973 |
else |
| 974 |
{ |
| 975 |
my $linecount = $i + 1; |
| 976 |
installer::exiter::exit_program("ERROR: Unknown line format in table \"$idtfilename\" (line $linecount) !", "analyze_filetable_file"); |
| 977 |
} |
| 978 |
} |
| 979 |
|
| 980 |
return \%filehash; |
| 981 |
} |
| 982 |
|
| 983 |
######################################################################### |
| 984 |
# Creating a new line for the directory table. |
| 985 |
######################################################################### |
| 986 |
|
| 987 |
sub get_new_line_for_directory_table |
| 988 |
{ |
| 989 |
my ($dir) = @_; |
| 990 |
|
| 991 |
my $newline = "$dir->{'Directory'}\t$dir->{'Directory_Parent'}\t$dir->{'DefaultDir'}\n"; |
| 992 |
|
| 993 |
return $newline; |
| 994 |
} |
| 995 |
|
| 996 |
######################################################################### |
| 997 |
# Creating a new line for the file table. |
| 998 |
######################################################################### |
| 999 |
|
| 1000 |
sub get_new_line_for_file_table |
| 1001 |
{ |
| 1002 |
my ($file) = @_; |
| 1003 |
|
| 1004 |
my $newline = "$file->{'File'}\t$file->{'Component'}\t$file->{'FileName'}\t$file->{'FileSize'}\t$file->{'Version'}\t$file->{'Language'}\t$file->{'Attributes'}\t$file->{'Sequence'}\n"; |
| 1005 |
|
| 1006 |
return $newline; |
| 1007 |
} |
| 1008 |
|
| 1009 |
######################################################################### |
| 1010 |
# Creating a new line for the msiassembly table. |
| 1011 |
######################################################################### |
| 1012 |
|
| 1013 |
sub get_new_line_for_msiassembly_table |
| 1014 |
{ |
| 1015 |
my ($assembly) = @_; |
| 1016 |
|
| 1017 |
my $newline = "$assembly->{'Component'}\t$assembly->{'Feature'}\t$assembly->{'File_Manifest'}\t$assembly->{'File_Application'}\t$assembly->{'Attributes'}\n"; |
| 1018 |
|
| 1019 |
return $newline; |
| 1020 |
} |
| 1021 |
|
| 1022 |
######################################################################### |
| 1023 |
# Sorting the files collector, if there are files, following |
| 1024 |
# the merge module files. |
| 1025 |
######################################################################### |
| 1026 |
|
| 1027 |
sub sort_files_collector_for_sequence |
| 1028 |
{ |
| 1029 |
my ($filesref) = @_; |
| 1030 |
|
| 1031 |
my @sortarray = (); |
| 1032 |
my %helphash = (); |
| 1033 |
|
| 1034 |
for ( my $i = 0; $i <= $#{$filesref}; $i++ ) |
| 1035 |
{ |
| 1036 |
my $onefile = ${$filesref}[$i]; |
| 1037 |
if ( ! exists($onefile->{'sequencenumber'}) ) { installer::exiter::exit_program("ERROR: Could not find sequencenumber for file: $onefile->{'uniquename'} !", "sort_files_collector_for_sequence"); } |
| 1038 |
my $sequence = $onefile->{'sequencenumber'}; |
| 1039 |
$helphash{$sequence} = $onefile; |
| 1040 |
} |
| 1041 |
|
| 1042 |
foreach my $seq ( sort { $a <=> $b } keys %helphash ) { push(@sortarray, $helphash{$seq}); } |
| 1043 |
|
| 1044 |
return \@sortarray; |
| 1045 |
} |
| 1046 |
|
| 1047 |
######################################################################### |
| 1048 |
# In the file table "Sequence" and "Attributes" have to be changed. |
| 1049 |
######################################################################### |
| 1050 |
|
| 1051 |
sub change_file_table |
| 1052 |
{ |
| 1053 |
my ($mergemodulehash, $workdir, $allupdatesequenceshashref, $includepatharrayref, $filesref, $mergemodulegid) = @_; |
| 1054 |
|
| 1055 |
my $infoline = "Changing content of table \"File\"\n"; |
| 1056 |
push( @installer::globals::logfileinfo, $infoline); |
| 1057 |
|
| 1058 |
my $globescape = ""; |
| 1059 |
$globescape = "\\" if ( $^O =~ /cygwin/i ); |
| 1060 |
|
| 1061 |
my $idtfilename = "File.idt"; |
| 1062 |
if ( ! -f $idtfilename ) { installer::exiter::exit_program("ERROR: Could not find file \"$idtfilename\" in \"$workdir\" !", "change_file_table"); } |
| 1063 |
|
| 1064 |
my $filecontent = installer::files::read_file($idtfilename); |
| 1065 |
|
| 1066 |
# If File.idt needed to be removed before the msm database was merged into the msi database, |
| 1067 |
# now it is time to add the content into File.idt |
| 1068 |
if ( $mergemodulehash->{'removefiletable'} ) |
| 1069 |
{ |
| 1070 |
for ( my $i = 0; $i <= $#{$mergemodulehash->{'fileidtcontent'}}; $i++ ) |
| 1071 |
{ |
| 1072 |
push(@{$filecontent}, ${$mergemodulehash->{'fileidtcontent'}}[$i]); |
| 1073 |
} |
| 1074 |
} |
| 1075 |
|
| 1076 |
# Unpacking the MergeModule.CABinet (only once) |
| 1077 |
# Unpacking into temp directory. Warning: expand.exe has problems with very long unpack directories. |
| 1078 |
|
| 1079 |
my $empty = ""; |
| 1080 |
my $unpackdir = installer::systemactions::create_directories("cab", \$empty); |
| 1081 |
$unpackdir = qx(cygpath -m "$unpackdir"); |
| 1082 |
chomp $unpackdir; |
| 1083 |
push(@installer::globals::removedirs, $unpackdir); |
| 1084 |
$unpackdir = $unpackdir . $installer::globals::separator . $mergemodulegid; |
| 1085 |
|
| 1086 |
my %newfileshash = (); |
| 1087 |
if (( $installer::globals::fix_number_of_cab_files ) && ( ! $installer::globals::mergefiles_added_into_collector )) |
| 1088 |
{ |
| 1089 |
if ( ! -d $unpackdir ) { installer::systemactions::create_directory($unpackdir); } |
| 1090 |
|
| 1091 |
# changing directory |
| 1092 |
my $from = cwd(); |
| 1093 |
my $to = $mergemodulehash->{'workdir'}; |
| 1094 |
if ( $^O =~ /cygwin/i ) { |
| 1095 |
$to = qx(cygpath -u "$to"); |
| 1096 |
chomp $to; |
| 1097 |
} |
| 1098 |
|
| 1099 |
chdir($to) || die "Could not chdir to \"$to\"\n"; |
| 1100 |
|
| 1101 |
# Unpack the cab file, so that in can be included into the last office cabinet file. |
| 1102 |
# Not using cabarc.exe from cabsdk for unpacking cabinet files, but "expand.exe" that |
| 1103 |
# should be available on every Windows system. |
| 1104 |
|
| 1105 |
$infoline = "Unpacking cabinet file: $mergemodulehash->{'cabinetfile'}\n"; |
| 1106 |
push( @installer::globals::logfileinfo, $infoline); |
| 1107 |
|
| 1108 |
# Avoid the Cygwin expand command |
| 1109 |
my $expandfile = qx(cygpath -m "$ENV{WINDIR}"/System32/expand.exe); |
| 1110 |
chomp $expandfile; |
| 1111 |
|
| 1112 |
my $cabfilename = "MergeModule.CABinet"; |
| 1113 |
|
| 1114 |
my $systemcall = $expandfile . " " . $cabfilename . " -F:$globescape* " . $unpackdir . " 2\>\&1"; |
| 1115 |
|
| 1116 |
my $systemcall_output = `$systemcall`; |
| 1117 |
my $returnvalue = $? >> 8; |
| 1118 |
|
| 1119 |
if ($returnvalue) |
| 1120 |
{ |
| 1121 |
$infoline = "ERROR: Could not execute $systemcall - returncode: $returnvalue - output: $systemcall_output\n"; |
| 1122 |
push( @installer::globals::logfileinfo, $infoline); |
| 1123 |
installer::exiter::exit_program("ERROR: extracting $cabfilename failed using $systemcall", "change_file_table"); |
| 1124 |
} |
| 1125 |
else |
| 1126 |
{ |
| 1127 |
$infoline = "Success: Executed $systemcall successfully!\n"; |
| 1128 |
push( @installer::globals::logfileinfo, $infoline); |
| 1129 |
} |
| 1130 |
|
| 1131 |
chdir($from); |
| 1132 |
} |
| 1133 |
|
| 1134 |
# For performance reasons creating a hash with file names and rows |
| 1135 |
# The content of File.idt is changed after every merge -> content cannot be saved in global hash |
| 1136 |
my $merge_filetablehashref = analyze_filetable_file($filecontent, $idtfilename); |
| 1137 |
|
| 1138 |
my $attributes = "16384"; # Always |
| 1139 |
|
| 1140 |
my $filename; |
| 1141 |
foreach $filename (keys %{$mergemodulehash->{'mergefilesequence'}} ) |
| 1142 |
{ |
| 1143 |
my $mergefilesequence = $mergemodulehash->{'mergefilesequence'}->{$filename}; |
| 1144 |
|
| 1145 |
if ( ! exists($merge_filetablehashref->{$filename}) ) { installer::exiter::exit_program("ERROR: Could not find file \"$filename\" in \"$idtfilename\" !", "change_file_table"); } |
| 1146 |
my $filehash = $merge_filetablehashref->{$filename}; |
| 1147 |
my $linenumber = $filehash->{'linenumber'}; |
| 1148 |
|
| 1149 |
# <- this line has to be changed concerning "Sequence" and "Attributes" |
| 1150 |
$filehash->{'Attributes'} = $attributes; |
| 1151 |
|
| 1152 |
# If this is an update process, the sequence numbers have to be reused. |
| 1153 |
if ( $installer::globals::updatedatabase ) |
| 1154 |
{ |
| 1155 |
if ( ! exists($allupdatesequenceshashref->{$filehash->{'File'}}) ) { installer::exiter::exit_program("ERROR: Sequence not defined for file \"$filehash->{'File'}\" !", "change_file_table"); } |
| 1156 |
$filehash->{'Sequence'} = $allupdatesequenceshashref->{$filehash->{'File'}}; |
| 1157 |
# Saving all mergemodule sequence numbers. This is important for creating ddf files |
| 1158 |
$installer::globals::allmergemodulefilesequences{$filehash->{'Sequence'}} = 1; |
| 1159 |
} |
| 1160 |
else |
| 1161 |
{ |
| 1162 |
# Important saved data: $installer::globals::lastsequence_before_merge. |
| 1163 |
# This mechanism keeps the correct order inside the new cabinet file. |
| 1164 |
$filehash->{'Sequence'} = $filehash->{'Sequence'} + $installer::globals::lastsequence_before_merge; |
| 1165 |
} |
| 1166 |
|
| 1167 |
my $oldline = ${$filecontent}[$linenumber]; |
| 1168 |
my $newline = get_new_line_for_file_table($filehash); |
| 1169 |
${$filecontent}[$linenumber] = $newline; |
| 1170 |
|
| 1171 |
$infoline = "Merge, replacing line:\n"; |
| 1172 |
push( @installer::globals::logfileinfo, $infoline); |
| 1173 |
$infoline = "Old: $oldline\n"; |
| 1174 |
push( @installer::globals::logfileinfo, $infoline); |
| 1175 |
$infoline = "New: $newline\n"; |
| 1176 |
push( @installer::globals::logfileinfo, $infoline); |
| 1177 |
|
| 1178 |
# Adding files to the files collector (but only once) |
| 1179 |
if (( $installer::globals::fix_number_of_cab_files ) && ( ! $installer::globals::mergefiles_added_into_collector )) |
| 1180 |
{ |
| 1181 |
# If the number of cabinet files is kept constant, |
| 1182 |
# all files from the mergemodule cabinet files will |
| 1183 |
# be integrated into the last office cabinet file |
| 1184 |
# (installer::globals::lastcabfilename). |
| 1185 |
# Therefore the files must now be added to the filescollector, |
| 1186 |
# so that they will be integrated into the ddf files. |
| 1187 |
|
| 1188 |
# Problem with very long filenames -> copying to shorter filenames |
| 1189 |
my $newfilename = "f" . $filehash->{'Sequence'}; |
| 1190 |
my $completesource = $unpackdir . $installer::globals::separator . $filehash->{'File'}; |
| 1191 |
my $completedest = $unpackdir . $installer::globals::separator . $newfilename; |
| 1192 |
installer::systemactions::copy_one_file($completesource, $completedest); |
| 1193 |
|
| 1194 |
my $locallastcabfilename = $installer::globals::lastcabfilename; |
| 1195 |
if ( $locallastcabfilename =~ /^\s*\#/ ) { $locallastcabfilename =~ s/^\s*\#//; } # removing beginning hashes |
| 1196 |
|
| 1197 |
# Create new file hash for file collector |
| 1198 |
my %newfile = (); |
| 1199 |
$newfile{'sequencenumber'} = $filehash->{'Sequence'}; |
| 1200 |
$newfile{'assignedsequencenumber'} = $filehash->{'Sequence'}; |
| 1201 |
$newfile{'cabinet'} = $locallastcabfilename; |
| 1202 |
$newfile{'sourcepath'} = $completedest; |
| 1203 |
$newfile{'componentname'} = $filehash->{'Component'}; |
| 1204 |
$newfile{'uniquename'} = $filehash->{'File'}; |
| 1205 |
$newfile{'Name'} = $filehash->{'File'}; |
| 1206 |
|
| 1207 |
# Saving in globals sequence hash |
| 1208 |
$installer::globals::uniquefilenamesequence{$filehash->{'File'}} = $filehash->{'Sequence'}; |
| 1209 |
|
| 1210 |
if ( ! -f $newfile{'sourcepath'} ) { installer::exiter::exit_program("ERROR: File \"$newfile{'sourcepath'}\" must exist!", "change_file_table"); } |
| 1211 |
|
| 1212 |
# Collecting all new files. Attention: This files must be included into files collector in correct order! |
| 1213 |
$newfileshash{$filehash->{'Sequence'}} = \%newfile; |
| 1214 |
# push(@{$filesref}, \%newfile); -> this is not the correct order |
| 1215 |
} |
| 1216 |
} |
| 1217 |
|
| 1218 |
# Now the files can be added to the files collector |
| 1219 |
# In the case of an update process, there can be new files, that have to be added after the merge module files. |
| 1220 |
# Warning: In multilingual installation sets, the files only have to be added once to the files collector! |
| 1221 |
|
| 1222 |
if ( ! $installer::globals::mergefiles_added_into_collector ) |
| 1223 |
{ |
| 1224 |
foreach my $localsequence ( sort { $a <=> $b } keys %newfileshash ) { push(@{$filesref}, $newfileshash{$localsequence}); } |
| 1225 |
if ( $installer::globals::newfilesexist ) { $filesref = sort_files_collector_for_sequence($filesref); } |
| 1226 |
# $installer::globals::mergefiles_added_into_collector = 1; -> Not yet. Only if all mergemodules are merged for one language. |
| 1227 |
} |
| 1228 |
|
| 1229 |
# Saving the idt file (for every language) |
| 1230 |
installer::files::save_file($idtfilename, $filecontent); |
| 1231 |
|
| 1232 |
return $filesref; |
| 1233 |
} |
| 1234 |
|
| 1235 |
######################################################################### |
| 1236 |
# Reading the file "Director.idt". The Directory, that is defined in scp |
| 1237 |
# has to be defined in this table. |
| 1238 |
######################################################################### |
| 1239 |
|
| 1240 |
sub collect_directories |
| 1241 |
{ |
| 1242 |
my $idtfilename = "Director.idt"; |
| 1243 |
my $filecontent = installer::files::read_file($idtfilename); |
| 1244 |
|
| 1245 |
for ( my $i = 0; $i <= $#{$filecontent}; $i++ ) |
| 1246 |
{ |
| 1247 |
if ( $i <= 2 ) { next; } # ignoring first three lines |
| 1248 |
if ( ${$filecontent}[$i] =~ /^\s*$/ ) { next; } # ignoring empty lines |
| 1249 |
# Format: Directory Directory_Parent DefaultDir |
| 1250 |
if ( ${$filecontent}[$i] =~ /^\s*(.+?)\t(.*?)\t(.*?)\s*$/ ) |
| 1251 |
{ |
| 1252 |
$installer::globals::merge_alldirectory_hash{$1} = 1; |
| 1253 |
} |
| 1254 |
else |
| 1255 |
{ |
| 1256 |
my $linecount = $i + 1; |
| 1257 |
installer::exiter::exit_program("ERROR: Unknown line format in table \"$idtfilename\" (line $linecount) !", "collect_directories"); |
| 1258 |
} |
| 1259 |
} |
| 1260 |
} |
| 1261 |
|
| 1262 |
######################################################################### |
| 1263 |
# Reading the file "Feature.idt". The Feature, that is defined in scp |
| 1264 |
# has to be defined in this table. |
| 1265 |
######################################################################### |
| 1266 |
|
| 1267 |
sub collect_feature |
| 1268 |
{ |
| 1269 |
my ($workdir) = @_; |
| 1270 |
my $idtfilename = "Feature.idt"; |
| 1271 |
if ( ! -f $idtfilename ) { installer::exiter::exit_program("ERROR: Could not find file \"$idtfilename\" in \"$workdir\" !", "collect_feature"); } |
| 1272 |
my $filecontent = installer::files::read_file($idtfilename); |
| 1273 |
|
| 1274 |
for ( my $i = 0; $i <= $#{$filecontent}; $i++ ) |
| 1275 |
{ |
| 1276 |
if ( $i <= 2 ) { next; } # ignoring first three lines |
| 1277 |
if ( ${$filecontent}[$i] =~ /^\s*$/ ) { next; } # ignoring empty lines |
| 1278 |
# Format: Feature Feature_Parent Title Description Display Level Directory_ Attributes |
| 1279 |
if ( ${$filecontent}[$i] =~ /^\s*(.+?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\s*$/ ) |
| 1280 |
{ |
| 1281 |
$installer::globals::merge_allfeature_hash{$1} = 1; |
| 1282 |
} |
| 1283 |
else |
| 1284 |
{ |
| 1285 |
my $linecount = $i + 1; |
| 1286 |
installer::exiter::exit_program("ERROR: Unknown line format in table \"$idtfilename\" (line $linecount) !", "collect_feature"); |
| 1287 |
} |
| 1288 |
} |
| 1289 |
} |
| 1290 |
|
| 1291 |
######################################################################### |
| 1292 |
# In the featurecomponent table, the new connections have to be added. |
| 1293 |
######################################################################### |
| 1294 |
|
| 1295 |
sub change_featurecomponent_table |
| 1296 |
{ |
| 1297 |
my ($mergemodulehash, $workdir) = @_; |
| 1298 |
|
| 1299 |
my $infoline = "Changing content of table \"FeatureComponents\"\n"; |
| 1300 |
push( @installer::globals::logfileinfo, $infoline); |
| 1301 |
|
| 1302 |
my $idtfilename = "FeatureC.idt"; |
| 1303 |
if ( ! -f $idtfilename ) { installer::exiter::exit_program("ERROR: Could not find file \"$idtfilename\" in \"$workdir\" !", "change_featurecomponent_table"); } |
| 1304 |
|
| 1305 |
my $filecontent = installer::files::read_file($idtfilename); |
| 1306 |
|
| 1307 |
# Simply adding for each new component one line. The Feature has to be defined in scp project. |
| 1308 |
my $feature = $mergemodulehash->{'feature'}; |
| 1309 |
|
| 1310 |
if ( ! $installer::globals::mergefeaturecollected ) |
| 1311 |
{ |
| 1312 |
collect_feature($workdir); # putting content into hash %installer::globals::merge_allfeature_hash |
| 1313 |
$installer::globals::mergefeaturecollected = 1; |
| 1314 |
} |
| 1315 |
|
| 1316 |
if ( ! exists($installer::globals::merge_allfeature_hash{$feature}) ) |
| 1317 |
{ |
| 1318 |
installer::exiter::exit_program("ERROR: Unknown feature defined in scp: \"$feature\" . Not defined in table \"Feature\" !", "change_featurecomponent_table"); |
| 1319 |
} |
| 1320 |
|
| 1321 |
my $component; |
| 1322 |
foreach $component ( keys %{$mergemodulehash->{'componentnames'}} ) |
| 1323 |
{ |
| 1324 |
my $line = "$feature\t$component\n"; |
| 1325 |
push(@{$filecontent}, $line); |
| 1326 |
$infoline = "Adding line: $line\n"; |
| 1327 |
push( @installer::globals::logfileinfo, $infoline); |
| 1328 |
} |
| 1329 |
|
| 1330 |
# saving file |
| 1331 |
installer::files::save_file($idtfilename, $filecontent); |
| 1332 |
} |
| 1333 |
|
| 1334 |
############################################################################### |
| 1335 |
# In the components table, the conditions or attributes of merge modules should be updated |
| 1336 |
############################################################################### |
| 1337 |
|
| 1338 |
sub change_component_table |
| 1339 |
{ |
| 1340 |
my ($mergemodulehash, $workdir) = @_; |
| 1341 |
|
| 1342 |
my $infoline = "Changing content of table \"Component\"\n"; |
| 1343 |
push( @installer::globals::logfileinfo, $infoline); |
| 1344 |
|
| 1345 |
my $idtfilename = "Componen.idt"; |
| 1346 |
if ( ! -f $idtfilename ) { installer::exiter::exit_program("ERROR: Could not find file \"$idtfilename\" in \"$workdir\" !", "change_component_table"); } |
| 1347 |
|
| 1348 |
my $filecontent = installer::files::read_file($idtfilename); |
| 1349 |
|
| 1350 |
for ( my $i = 0; $i <= $#{$filecontent}; $i++ ) |
| 1351 |
{ |
| 1352 |
my $component; |
| 1353 |
foreach $component ( keys %{$mergemodulehash->{'componentnames'}} ) |
| 1354 |
{ |
| 1355 |
if ( my ( $comp_, $compid_, $dir_, $attr_, $cond_, $keyp_ ) = ${$filecontent}[$i] =~ /^\s*($component)\t(.*?)\t(.+?)\t(.+?)\t(.*?)\t(.*?)\s*$/) |
| 1356 |
{ |
| 1357 |
my $newattr_ = ( $attr_ =~ /^\s*0x/ ) ? hex($attr_) : $attr_; |
| 1358 |
if ( $mergemodulehash->{'attributes_add'} ) |
| 1359 |
{ |
| 1360 |
$infoline = "Adding attribute(s) ($mergemodulehash->{'attributes_add'}) from scp2 to component $comp_\n"; |
| 1361 |
push( @installer::globals::logfileinfo, $infoline); |
| 1362 |
if ( $mergemodulehash->{'attributes_add'} =~ /^\s*0x/ ) |
| 1363 |
{ |
| 1364 |
$newattr_ = $newattr_ | hex($mergemodulehash->{'attributes_add'}); |
| 1365 |
} |
| 1366 |
else |
| 1367 |
{ |
| 1368 |
$newattr_ = $newattr_ | $mergemodulehash->{'attributes_add'}; |
| 1369 |
} |
| 1370 |
$infoline = "Old attribute(s): $attr_\nNew attribute(s): $newattr_\n"; |
| 1371 |
push( @installer::globals::logfileinfo, $infoline); |
| 1372 |
} |
| 1373 |
my $newcond_ = $cond_; |
| 1374 |
if ( $mergemodulehash->{'componentcondition'} ) |
| 1375 |
{ |
| 1376 |
$infoline = "Adding condition ($mergemodulehash->{'componentcondition'}) from scp2 to component $comp_\n"; |
| 1377 |
push( @installer::globals::logfileinfo, $infoline); |
| 1378 |
if ($cond_) |
| 1379 |
{ |
| 1380 |
$newcond_ = "($cond_) AND ($mergemodulehash->{'componentcondition'})"; |
| 1381 |
} |
| 1382 |
else |
| 1383 |
{ |
| 1384 |
$newcond_ = "$mergemodulehash->{'componentcondition'}"; |
| 1385 |
} |
| 1386 |
$infoline = "Old condition: $cond_\nNew condition: $newcond_\n"; |
| 1387 |
push( @installer::globals::logfileinfo, $infoline); |
| 1388 |
} |
| 1389 |
${$filecontent}[$i] = "$comp_\t$compid_\t$dir_\t$newattr_\t$newcond_\t$keyp_\n"; |
| 1390 |
} |
| 1391 |
} |
| 1392 |
} |
| 1393 |
|
| 1394 |
# saving file |
| 1395 |
installer::files::save_file($idtfilename, $filecontent); |
| 1396 |
} |
| 1397 |
|
| 1398 |
######################################################################### |
| 1399 |
# In the directory table, the directory parent has to be changed, |
| 1400 |
# if it is not TARGETDIR. |
| 1401 |
######################################################################### |
| 1402 |
|
| 1403 |
sub change_directory_table |
| 1404 |
{ |
| 1405 |
my ($mergemodulehash, $workdir) = @_; |
| 1406 |
|
| 1407 |
# directory for MergeModule has to be defined in scp project |
| 1408 |
my $scpdirectory = $mergemodulehash->{'rootdir'}; |
| 1409 |
|
| 1410 |
if ( $scpdirectory ne "TARGETDIR" ) # TARGETDIR works fine, when using msidb.exe |
| 1411 |
{ |
| 1412 |
my $infoline = "Changing content of table \"Directory\"\n"; |
| 1413 |
push( @installer::globals::logfileinfo, $infoline); |
| 1414 |
|
| 1415 |
my $idtfilename = "Director.idt"; |
| 1416 |
if ( ! -f $idtfilename ) { installer::exiter::exit_program("ERROR: Could not find file \"$idtfilename\" in \"$workdir\" !", "change_directory_table"); } |
| 1417 |
|
| 1418 |
my $filecontent = installer::files::read_file($idtfilename); |
| 1419 |
|
| 1420 |
if ( ! $installer::globals::mergedirectoriescollected ) |
| 1421 |
{ |
| 1422 |
collect_directories(); # putting content into %installer::globals::merge_alldirectory_hash, only first column! |
| 1423 |
$installer::globals::mergedirectoriescollected = 1; |
| 1424 |
} |
| 1425 |
|
| 1426 |
if ( ! exists($installer::globals::merge_alldirectory_hash{$scpdirectory}) ) |
| 1427 |
{ |
| 1428 |
installer::exiter::exit_program("ERROR: Unknown directory defined in scp: \"$scpdirectory\" . Not defined in table \"Directory\" !", "change_directory_table"); |
| 1429 |
} |
| 1430 |
|
| 1431 |
# If the definition in scp is okay, now the complete content of "Director.idt" can be analyzed |
| 1432 |
my $merge_directorytablehashref = analyze_directorytable_file($filecontent, $idtfilename); |
| 1433 |
|
| 1434 |
my $directory; |
| 1435 |
foreach $directory (keys %{$mergemodulehash->{'mergedirectories'}} ) |
| 1436 |
{ |
| 1437 |
if ( ! exists($merge_directorytablehashref->{$directory}) ) { installer::exiter::exit_program("ERROR: Could not find directory \"$directory\" in \"$idtfilename\" !", "change_directory_table"); } |
| 1438 |
my $dirhash = $merge_directorytablehashref->{$directory}; |
| 1439 |
my $linenumber = $dirhash->{'linenumber'}; |
| 1440 |
|
| 1441 |
# <- this line has to be changed concerning "Directory_Parent", |
| 1442 |
# if the current value is "TARGETDIR", which is the default value from msidb.exe |
| 1443 |
|
| 1444 |
if ( $dirhash->{'Directory_Parent'} eq "TARGETDIR" ) |
| 1445 |
{ |
| 1446 |
$dirhash->{'Directory_Parent'} = $scpdirectory; |
| 1447 |
|
| 1448 |
my $oldline = ${$filecontent}[$linenumber]; |
| 1449 |
my $newline = get_new_line_for_directory_table($dirhash); |
| 1450 |
${$filecontent}[$linenumber] = $newline; |
| 1451 |
|
| 1452 |
$infoline = "Merge, replacing line:\n"; |
| 1453 |
push( @installer::globals::logfileinfo, $infoline); |
| 1454 |
$infoline = "Old: $oldline\n"; |
| 1455 |
push( @installer::globals::logfileinfo, $infoline); |
| 1456 |
$infoline = "New: $newline\n"; |
| 1457 |
push( @installer::globals::logfileinfo, $infoline); |
| 1458 |
} |
| 1459 |
} |
| 1460 |
|
| 1461 |
# saving file |
| 1462 |
installer::files::save_file($idtfilename, $filecontent); |
| 1463 |
} |
| 1464 |
} |
| 1465 |
|
| 1466 |
######################################################################### |
| 1467 |
# In the msiassembly table, the feature has to be changed. |
| 1468 |
######################################################################### |
| 1469 |
|
| 1470 |
sub change_msiassembly_table |
| 1471 |
{ |
| 1472 |
my ($mergemodulehash, $workdir) = @_; |
| 1473 |
|
| 1474 |
my $infoline = "Changing content of table \"MsiAssembly\"\n"; |
| 1475 |
push( @installer::globals::logfileinfo, $infoline); |
| 1476 |
|
| 1477 |
my $idtfilename = "MsiAssem.idt"; |
| 1478 |
if ( ! -f $idtfilename ) { installer::exiter::exit_program("ERROR: Could not find file \"$idtfilename\" in \"$workdir\" !", "change_msiassembly_table"); } |
| 1479 |
|
| 1480 |
my $filecontent = installer::files::read_file($idtfilename); |
| 1481 |
|
| 1482 |
# feature has to be defined in scp project |
| 1483 |
my $feature = $mergemodulehash->{'feature'}; |
| 1484 |
|
| 1485 |
if ( ! $installer::globals::mergefeaturecollected ) |
| 1486 |
{ |
| 1487 |
collect_feature($workdir); # putting content into hash %installer::globals::merge_allfeature_hash |
| 1488 |
$installer::globals::mergefeaturecollected = 1; |
| 1489 |
} |
| 1490 |
|
| 1491 |
if ( ! exists($installer::globals::merge_allfeature_hash{$feature}) ) |
| 1492 |
{ |
| 1493 |
installer::exiter::exit_program("ERROR: Unknown feature defined in scp: \"$feature\" . Not defined in table \"Feature\" !", "change_msiassembly_table"); |
| 1494 |
} |
| 1495 |
|
| 1496 |
my $merge_msiassemblytablehashref = analyze_msiassemblytable_file($filecontent, $idtfilename); |
| 1497 |
|
| 1498 |
my $component; |
| 1499 |
foreach $component (keys %{$mergemodulehash->{'mergeassemblies'}} ) |
| 1500 |
{ |
| 1501 |
if ( ! exists($merge_msiassemblytablehashref->{$component}) ) { installer::exiter::exit_program("ERROR: Could not find component \"$component\" in \"$idtfilename\" !", "change_msiassembly_table"); } |
| 1502 |
my $assemblyhash = $merge_msiassemblytablehashref->{$component}; |
| 1503 |
my $linenumber = $assemblyhash->{'linenumber'}; |
| 1504 |
|
| 1505 |
# <- this line has to be changed concerning "Feature" |
| 1506 |
$assemblyhash->{'Feature'} = $feature; |
| 1507 |
|
| 1508 |
my $oldline = ${$filecontent}[$linenumber]; |
| 1509 |
my $newline = get_new_line_for_msiassembly_table($assemblyhash); |
| 1510 |
${$filecontent}[$linenumber] = $newline; |
| 1511 |
|
| 1512 |
$infoline = "Merge, replacing line:\n"; |
| 1513 |
push( @installer::globals::logfileinfo, $infoline); |
| 1514 |
$infoline = "Old: $oldline\n"; |
| 1515 |
push( @installer::globals::logfileinfo, $infoline); |
| 1516 |
$infoline = "New: $newline\n"; |
| 1517 |
push( @installer::globals::logfileinfo, $infoline); |
| 1518 |
} |
| 1519 |
|
| 1520 |
# saving file |
| 1521 |
installer::files::save_file($idtfilename, $filecontent); |
| 1522 |
} |
| 1523 |
|
| 1524 |
######################################################################### |
| 1525 |
# Creating file content hash |
| 1526 |
######################################################################### |
| 1527 |
|
| 1528 |
sub make_executeidtcontent_hash |
| 1529 |
{ |
| 1530 |
my ($filecontent, $idtfilename) = @_; |
| 1531 |
|
| 1532 |
my %newhash = (); |
| 1533 |
|
| 1534 |
for ( my $i = 0; $i <= $#{$filecontent}; $i++ ) |
| 1535 |
{ |
| 1536 |
if ( $i <= 2 ) { next; } # ignoring first three lines |
| 1537 |
if ( ${$filecontent}[$i] =~ /^\s*$/ ) { next; } # ignoring empty lines |
| 1538 |
# Format for all sequence tables: Action Condition Sequence |
| 1539 |
if ( ${$filecontent}[$i] =~ /^\s*(.+?)\t(.*?)\t(.*?)\s*$/ ) |
| 1540 |
{ |
| 1541 |
my %onehash = (); |
| 1542 |
$onehash{'Action'} = $1; |
| 1543 |
$onehash{'Condition'} = $2; |
| 1544 |
$onehash{'Sequence'} = $3; |
| 1545 |
$newhash{$onehash{'Action'}} = \%onehash; |
| 1546 |
} |
| 1547 |
else |
| 1548 |
{ |
| 1549 |
my $linecount = $i + 1; |
| 1550 |
installer::exiter::exit_program("ERROR: Unknown line format in table \"$idtfilename\" (line $linecount) !", "make_executeidtcontent_hash"); |
| 1551 |
} |
| 1552 |
} |
| 1553 |
|
| 1554 |
return \%newhash; |
| 1555 |
} |
| 1556 |
|
| 1557 |
######################################################################### |
| 1558 |
# Creating file content hash |
| 1559 |
######################################################################### |
| 1560 |
|
| 1561 |
sub make_moduleexecuteidtcontent_hash |
| 1562 |
{ |
| 1563 |
my ($filecontent, $idtfilename) = @_; |
| 1564 |
|
| 1565 |
my %newhash = (); |
| 1566 |
|
| 1567 |
for ( my $i = 0; $i <= $#{$filecontent}; $i++ ) |
| 1568 |
{ |
| 1569 |
if ( $i <= 2 ) { next; } # ignoring first three lines |
| 1570 |
if ( ${$filecontent}[$i] =~ /^\s*$/ ) { next; } # ignoring empty lines |
| 1571 |
# Format for all module sequence tables: Action Sequence BaseAction After Condition |
| 1572 |
if ( ${$filecontent}[$i] =~ /^\s*(.+?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\s*$/ ) |
| 1573 |
{ |
| 1574 |
my %onehash = (); |
| 1575 |
$onehash{'Action'} = $1; |
| 1576 |
$onehash{'Sequence'} = $2; |
| 1577 |
$onehash{'BaseAction'} = $3; |
| 1578 |
$onehash{'After'} = $4; |
| 1579 |
$onehash{'Condition'} = $5; |
| 1580 |
$newhash{$onehash{'Action'}} = \%onehash; |
| 1581 |
} |
| 1582 |
else |
| 1583 |
{ |
| 1584 |
my $linecount = $i + 1; |
| 1585 |
installer::exiter::exit_program("ERROR: Unknown line format in table \"$idtfilename\" (line $linecount) !", "make_executeidtcontent_hash"); |
| 1586 |
} |
| 1587 |
} |
| 1588 |
|
| 1589 |
return \%newhash; |
| 1590 |
} |
| 1591 |
|
| 1592 |
######################################################################### |
| 1593 |
# ExecuteSequence tables need to be merged with |
| 1594 |
# ModuleExecuteSequence tables created by msidb.exe. |
| 1595 |
######################################################################### |
| 1596 |
|
| 1597 |
sub change_executesequence_table |
| 1598 |
{ |
| 1599 |
my ($mergemodulehash, $workdir, $idtfilename, $moduleidtfilename) = @_; |
| 1600 |
|
| 1601 |
my $infoline = "Changing content of table \"$idtfilename\"\n"; |
| 1602 |
push( @installer::globals::logfileinfo, $infoline); |
| 1603 |
|
| 1604 |
if ( ! -f $idtfilename ) { installer::exiter::exit_program("ERROR: Could not find file \"$idtfilename\" in \"$workdir\" !", "change_executesequence_table"); } |
| 1605 |
if ( ! -f $moduleidtfilename ) { installer::exiter::exit_program("ERROR: Could not find file \"$moduleidtfilename\" in \"$workdir\" !", "change_executesequence_table"); } |
| 1606 |
|
| 1607 |
# Reading file content |
| 1608 |
my $idtfilecontent = installer::files::read_file($idtfilename); |
| 1609 |
my $moduleidtfilecontent = installer::files::read_file($moduleidtfilename); |
| 1610 |
|
| 1611 |
# Converting to hash |
| 1612 |
my $idtcontenthash = make_executeidtcontent_hash($idtfilecontent, $idtfilename); |
| 1613 |
my $moduleidtcontenthash = make_moduleexecuteidtcontent_hash($moduleidtfilecontent, $moduleidtfilename); |
| 1614 |
|
| 1615 |
# Merging |
| 1616 |
foreach my $action ( keys %{$moduleidtcontenthash} ) |
| 1617 |
{ |
| 1618 |
if ( exists($idtcontenthash->{$action}) ) { next; } # Action already exists, can be ignored |
| 1619 |
|
| 1620 |
if (( $idtfilename eq "InstallU.idt" ) && ( ! ( $action =~ /^\s*WindowsFolder\./ ))) { next; } # Only "WindowsFolder.*" CustomActions for UI Sequence table |
| 1621 |
|
| 1622 |
my $actionhashref = $moduleidtcontenthash->{$action}; |
| 1623 |
if ( $actionhashref->{'Sequence'} ne "" ) |
| 1624 |
{ |
| 1625 |
# Format for all sequence tables: Action Condition Sequence |
| 1626 |
my $newline = $actionhashref->{'Action'} . "\t" . $actionhashref->{'Condition'} . "\t" . $actionhashref->{'Sequence'} . "\n"; |
| 1627 |
# Adding to table |
| 1628 |
push(@{$idtfilecontent}, $newline); |
| 1629 |
# Also adding to hash |
| 1630 |
my %idttablehash = (); |
| 1631 |
$idttablehash{'Action'} = $actionhashref->{'Action'}; |
| 1632 |
$idttablehash{'Condition'} = $actionhashref->{'Condition'}; |
| 1633 |
$idttablehash{'Sequence'} = $actionhashref->{'Sequence'}; |
| 1634 |
$idtcontenthash->{$action} = \%idttablehash; |
| 1635 |
|
| 1636 |
} |
| 1637 |
else # no sequence defined, using syntax "BaseAction" and "After" |
| 1638 |
{ |
| 1639 |
my $baseactionname = $actionhashref->{'BaseAction'}; |
| 1640 |
# If this baseactionname is not defined in execute idt file, it is not possible to merge |
| 1641 |
if ( ! exists($idtcontenthash->{$baseactionname}) ) { installer::exiter::exit_program("ERROR: Merge problem: Could not find action \"$baseactionname\" in file \"$idtfilename\" !", "change_executesequence_table"); } |
| 1642 |
|
| 1643 |
my $baseaction = $idtcontenthash->{$baseactionname}; |
| 1644 |
my $sequencenumber = $baseaction->{'Sequence'}; |
| 1645 |
if ( $actionhashref->{'After'} == 1 ) { $sequencenumber = $sequencenumber + 1; } |
| 1646 |
else { $sequencenumber = $sequencenumber - 1; } |
| 1647 |
|
| 1648 |
# Format for all sequence tables: Action Condition Sequence |
| 1649 |
my $newline = $actionhashref->{'Action'} . "\t" . $actionhashref->{'Condition'} . "\t" . $sequencenumber . "\n"; |
| 1650 |
# Adding to table |
| 1651 |
push(@{$idtfilecontent}, $newline); |
| 1652 |
# Also adding to hash |
| 1653 |
my %idttablehash = (); |
| 1654 |
$idttablehash{'Action'} = $actionhashref->{'Action'}; |
| 1655 |
$idttablehash{'Condition'} = $actionhashref->{'Condition'}; |
| 1656 |
$idttablehash{'Sequence'} = $sequencenumber; |
| 1657 |
$idtcontenthash->{$action} = \%idttablehash; |
| 1658 |
} |
| 1659 |
} |
| 1660 |
|
| 1661 |
# saving file |
| 1662 |
installer::files::save_file($idtfilename, $idtfilecontent); |
| 1663 |
} |
| 1664 |
|
| 1665 |
|
| 1666 |
1; |