| 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::component; |
| 20 |
|
| 21 |
use strict; |
| 22 |
use warnings; |
| 23 |
|
| 24 |
use installer::exiter; |
| 25 |
use installer::files; |
| 26 |
use installer::globals; |
| 27 |
use installer::windows::idtglobal; |
| 28 |
use installer::windows::language; |
| 29 |
|
| 30 |
############################################################## |
| 31 |
# Returning a globally unique ID (GUID) for a component |
| 32 |
# If the component is new, a unique guid has to be created. |
| 33 |
# If the component already exists, the guid has to be |
| 34 |
# taken from a list component <-> guid |
| 35 |
# Sample for a guid: {B68FD953-3CEF-4489-8269-8726848056E8} |
| 36 |
############################################################## |
| 37 |
|
| 38 |
sub get_component_guid |
| 39 |
{ |
| 40 |
my ( $componentname, $componentidhashref ) = @_; |
| 41 |
|
| 42 |
# At this time only a template |
| 43 |
my $returnvalue = "\{COMPONENTGUID\}"; |
| 44 |
|
| 45 |
if (( $installer::globals::updatedatabase ) && ( exists($componentidhashref->{$componentname}) )) |
| 46 |
{ |
| 47 |
$returnvalue = $componentidhashref->{$componentname}; |
| 48 |
} |
| 49 |
|
| 50 |
# Returning a ComponentID, that is assigned in scp project |
| 51 |
if ( exists($installer::globals::componentid{$componentname}) ) |
| 52 |
{ |
| 53 |
$returnvalue = "\{" . $installer::globals::componentid{$componentname} . "\}"; |
| 54 |
} |
| 55 |
|
| 56 |
return $returnvalue; |
| 57 |
} |
| 58 |
|
| 59 |
############################################################## |
| 60 |
# Returning the directory for a file component. |
| 61 |
############################################################## |
| 62 |
|
| 63 |
sub get_file_component_directory |
| 64 |
{ |
| 65 |
my ($componentname, $filesref, $dirref) = @_; |
| 66 |
|
| 67 |
my ($onefile, $component, $onedir, $hostname, $uniquedir); |
| 68 |
my $found = 0; |
| 69 |
|
| 70 |
for ( my $i = 0; $i <= $#{$filesref}; $i++ ) |
| 71 |
{ |
| 72 |
$onefile = ${$filesref}[$i]; |
| 73 |
$component = $onefile->{'componentname'}; |
| 74 |
|
| 75 |
if ( $component eq $componentname ) |
| 76 |
{ |
| 77 |
$found = 1; |
| 78 |
last; |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
if (!($found)) |
| 83 |
{ |
| 84 |
# This component can be ignored, if it exists in a version with extension "_pff" (this was renamed in file::get_sequence_for_file() ) |
| 85 |
my $ignore_this_component = 0; |
| 86 |
my $origcomponentname = $componentname; |
| 87 |
my $componentname = $componentname . "_pff"; |
| 88 |
|
| 89 |
for ( my $j = 0; $j <= $#{$filesref}; $j++ ) |
| 90 |
{ |
| 91 |
$onefile = ${$filesref}[$j]; |
| 92 |
$component = $onefile->{'componentname'}; |
| 93 |
|
| 94 |
if ( $component eq $componentname ) |
| 95 |
{ |
| 96 |
$ignore_this_component = 1; |
| 97 |
last; |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
if ( $ignore_this_component ) { return "IGNORE_COMP"; } |
| 102 |
else { installer::exiter::exit_program("ERROR: Did not find component \"$origcomponentname\" in file collection", "get_file_component_directory"); } |
| 103 |
} |
| 104 |
|
| 105 |
my $localstyles = ""; |
| 106 |
|
| 107 |
if ( $onefile->{'Styles'} ) { $localstyles = $onefile->{'Styles'}; } |
| 108 |
|
| 109 |
if ( $localstyles =~ /\bFONT\b/ ) # special handling for font files |
| 110 |
{ |
| 111 |
return $installer::globals::fontsfolder; |
| 112 |
} |
| 113 |
|
| 114 |
my $destdir = ""; |
| 115 |
|
| 116 |
if ( $onefile->{'Dir'} ) { $destdir = $onefile->{'Dir'}; } |
| 117 |
|
| 118 |
my $destination = $onefile->{'destination'}; |
| 119 |
|
| 120 |
installer::pathanalyzer::get_path_from_fullqualifiedname(\$destination); |
| 121 |
|
| 122 |
$destination =~ s/\Q$installer::globals::separator\E\s*$//; |
| 123 |
|
| 124 |
# This path has to be defined in the directory collection at "HostName" |
| 125 |
|
| 126 |
if ($destination eq "") # files in the installation root |
| 127 |
{ |
| 128 |
$uniquedir = "INSTALLLOCATION"; |
| 129 |
} |
| 130 |
else |
| 131 |
{ |
| 132 |
$found = 0; |
| 133 |
|
| 134 |
for ( my $i = 0; $i <= $#{$dirref}; $i++ ) |
| 135 |
{ |
| 136 |
$onedir = ${$dirref}[$i]; |
| 137 |
$hostname = $onedir->{'HostName'}; |
| 138 |
|
| 139 |
if ( $hostname eq $destination ) |
| 140 |
{ |
| 141 |
$found = 1; |
| 142 |
last; |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
if (!($found)) |
| 147 |
{ |
| 148 |
installer::exiter::exit_program("ERROR: Did not find destination $destination in directory collection", "get_file_component_directory"); |
| 149 |
} |
| 150 |
|
| 151 |
$uniquedir = $onedir->{'uniquename'}; |
| 152 |
|
| 153 |
if ( $uniquedir eq $installer::globals::officeinstalldirectory ) |
| 154 |
{ |
| 155 |
$uniquedir = "INSTALLLOCATION"; |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
$onefile->{'uniquedirname'} = $uniquedir; # saving it in the file collection |
| 160 |
|
| 161 |
return $uniquedir |
| 162 |
} |
| 163 |
|
| 164 |
############################################################## |
| 165 |
# Returning the directory for a registry component. |
| 166 |
# This cannot be a useful value |
| 167 |
############################################################## |
| 168 |
|
| 169 |
sub get_registry_component_directory |
| 170 |
{ |
| 171 |
my $componentdir = "INSTALLLOCATION"; |
| 172 |
|
| 173 |
return $componentdir; |
| 174 |
} |
| 175 |
|
| 176 |
############################################################## |
| 177 |
# Returning the attributes for a file component. |
| 178 |
############################################################## |
| 179 |
|
| 180 |
sub get_file_component_attributes |
| 181 |
{ |
| 182 |
my ($componentname, $filesref, $allvariables) = @_; |
| 183 |
|
| 184 |
my $attributes; |
| 185 |
|
| 186 |
$attributes = 2; |
| 187 |
|
| 188 |
# special handling for font files |
| 189 |
|
| 190 |
my $onefile; |
| 191 |
my $found = 0; |
| 192 |
|
| 193 |
for ( my $i = 0; $i <= $#{$filesref}; $i++ ) |
| 194 |
{ |
| 195 |
$onefile = ${$filesref}[$i]; |
| 196 |
my $component = $onefile->{'componentname'}; |
| 197 |
|
| 198 |
if ( $component eq $componentname ) |
| 199 |
{ |
| 200 |
$found = 1; |
| 201 |
last; |
| 202 |
} |
| 203 |
} |
| 204 |
|
| 205 |
if (!($found)) |
| 206 |
{ |
| 207 |
installer::exiter::exit_program("ERROR: Did not find component in file collection", "get_file_component_attributes"); |
| 208 |
} |
| 209 |
|
| 210 |
my $localstyles = ""; |
| 211 |
|
| 212 |
if ( $onefile->{'Styles'} ) { $localstyles = $onefile->{'Styles'}; } |
| 213 |
|
| 214 |
if ( $localstyles =~ /\bFONT\b/ ) |
| 215 |
{ |
| 216 |
$attributes = 8; # font files will be deinstalled if the ref count is 0 |
| 217 |
} |
| 218 |
|
| 219 |
if ( $localstyles =~ /\bASSEMBLY\b/ ) |
| 220 |
{ |
| 221 |
$attributes = 0; # Assembly files cannot run from source |
| 222 |
} |
| 223 |
|
| 224 |
if ( $onefile->{'needs_user_registry_key'} ) |
| 225 |
{ |
| 226 |
$attributes = 4; # Files in non advertised startmenu entries must have user registry key as KeyPath |
| 227 |
} |
| 228 |
|
| 229 |
# Setting msidbComponentAttributes64bit, if this is a 64 bit installation set. |
| 230 |
if (( $allvariables->{'64BITPRODUCT'} ) && ( $allvariables->{'64BITPRODUCT'} == 1 )) { $attributes |= 256; } |
| 231 |
|
| 232 |
return $attributes; |
| 233 |
} |
| 234 |
|
| 235 |
############################################################## |
| 236 |
# Returning the attributes for a registry component. |
| 237 |
# Always 4, indicating, the keypath is a defined in |
| 238 |
# table registry |
| 239 |
############################################################## |
| 240 |
|
| 241 |
sub get_registry_component_attributes |
| 242 |
{ |
| 243 |
my ($componentname, $allvariables) = @_; |
| 244 |
|
| 245 |
my $attributes; |
| 246 |
|
| 247 |
$attributes = 4; |
| 248 |
|
| 249 |
# Setting msidbComponentAttributes64bit, if this is a 64 bit installation set. |
| 250 |
if (( $allvariables->{'64BITPRODUCT'} ) && ( $allvariables->{'64BITPRODUCT'} == 1 )) { $attributes |= 256; } |
| 251 |
|
| 252 |
# Setting msidbComponentAttributes64bit for 64 bit shell extension in 32 bit installer, too |
| 253 |
if ( $componentname =~ m/winexplorerext_x64/ ) { $attributes |= 256; } |
| 254 |
|
| 255 |
return $attributes; |
| 256 |
} |
| 257 |
|
| 258 |
############################################################## |
| 259 |
# Returning the conditions for a component. |
| 260 |
# This is important for language dependent components |
| 261 |
# in multilingual installation sets. |
| 262 |
############################################################## |
| 263 |
|
| 264 |
sub get_file_component_condition |
| 265 |
{ |
| 266 |
my ($componentname, $filesref) = @_; |
| 267 |
|
| 268 |
my $condition = ""; |
| 269 |
|
| 270 |
if (exists($installer::globals::componentcondition{$componentname})) |
| 271 |
{ |
| 272 |
$condition = $installer::globals::componentcondition{$componentname}; |
| 273 |
} |
| 274 |
|
| 275 |
# there can be also tree conditions for multilayer products |
| 276 |
if (exists($installer::globals::treeconditions{$componentname})) |
| 277 |
{ |
| 278 |
if ( $condition eq "" ) |
| 279 |
{ |
| 280 |
$condition = $installer::globals::treeconditions{$componentname}; |
| 281 |
} |
| 282 |
else |
| 283 |
{ |
| 284 |
$condition = "($condition) And ($installer::globals::treeconditions{$componentname})"; |
| 285 |
} |
| 286 |
} |
| 287 |
|
| 288 |
return $condition |
| 289 |
} |
| 290 |
|
| 291 |
############################################################## |
| 292 |
# Returning the conditions for a registry component. |
| 293 |
############################################################## |
| 294 |
|
| 295 |
sub get_component_condition |
| 296 |
{ |
| 297 |
my ($componentname) = @_; |
| 298 |
|
| 299 |
my $condition; |
| 300 |
|
| 301 |
$condition = ""; # Always ? |
| 302 |
|
| 303 |
if (exists($installer::globals::componentcondition{$componentname})) |
| 304 |
{ |
| 305 |
$condition = $installer::globals::componentcondition{$componentname}; |
| 306 |
} |
| 307 |
|
| 308 |
return $condition |
| 309 |
} |
| 310 |
|
| 311 |
#################################################################### |
| 312 |
# Returning the keypath for a component. |
| 313 |
# This will be the name of the first file/registry, found in the |
| 314 |
# collection $itemsref |
| 315 |
# Attention: This has to be the unique (file)name, not the |
| 316 |
# real filename! |
| 317 |
#################################################################### |
| 318 |
|
| 319 |
sub get_component_keypath |
| 320 |
{ |
| 321 |
my ($componentname, $itemsref, $componentidkeypathhashref) = @_; |
| 322 |
|
| 323 |
my $oneitem; |
| 324 |
my $found = 0; |
| 325 |
my $infoline = ""; |
| 326 |
|
| 327 |
for ( my $i = 0; $i <= $#{$itemsref}; $i++ ) |
| 328 |
{ |
| 329 |
$oneitem = ${$itemsref}[$i]; |
| 330 |
my $component = $oneitem->{'componentname'}; |
| 331 |
|
| 332 |
if ( $component eq $componentname ) |
| 333 |
{ |
| 334 |
$found = 1; |
| 335 |
last; |
| 336 |
} |
| 337 |
} |
| 338 |
|
| 339 |
if (!($found)) |
| 340 |
{ |
| 341 |
installer::exiter::exit_program("ERROR: Did not find component in file/registry collection, function get_component_keypath", "get_component_keypath"); |
| 342 |
} |
| 343 |
|
| 344 |
my $keypath = $oneitem->{'uniquename'}; # "uniquename", not "Name" |
| 345 |
|
| 346 |
# Special handling for updates from existing databases, because KeyPath must not change |
| 347 |
if (( $installer::globals::updatedatabase ) && ( exists($componentidkeypathhashref->{$componentname}) )) |
| 348 |
{ |
| 349 |
$keypath = $componentidkeypathhashref->{$componentname}; |
| 350 |
# -> check, if this is a valid key path?! |
| 351 |
if ( $keypath ne $oneitem->{'uniquename'} ) |
| 352 |
{ |
| 353 |
# Warning: This keypath was changed because of info from old database |
| 354 |
$infoline = "WARNING: The KeyPath for component \"$componentname\" was changed from \"$oneitem->{'uniquename'}\" to \"$keypath\" because of information from update database"; |
| 355 |
push(@installer::globals::logfileinfo, $infoline); |
| 356 |
} |
| 357 |
} |
| 358 |
|
| 359 |
if ( $oneitem->{'userregkeypath'} ) { $keypath = $oneitem->{'userregkeypath'}; } |
| 360 |
|
| 361 |
# saving it in the file and registry collection |
| 362 |
$oneitem->{'keypath'} = $keypath; |
| 363 |
|
| 364 |
return $keypath |
| 365 |
} |
| 366 |
|
| 367 |
################################################################### |
| 368 |
# Creating the file Componen.idt dynamically |
| 369 |
# Content: |
| 370 |
# Component ComponentId Directory_ Attributes Condition KeyPath |
| 371 |
################################################################### |
| 372 |
|
| 373 |
sub create_component_table |
| 374 |
{ |
| 375 |
my ($filesref, $registryref, $dirref, $allfilecomponentsref, $allregistrycomponents, $basedir, $componentidhashref, $componentidkeypathhashref, $allvariables) = @_; |
| 376 |
|
| 377 |
my @componenttable = (); |
| 378 |
|
| 379 |
my ($oneline, $infoline); |
| 380 |
|
| 381 |
installer::windows::idtglobal::write_idt_header(\@componenttable, "component"); |
| 382 |
|
| 383 |
# File components |
| 384 |
|
| 385 |
for ( my $i = 0; $i <= $#{$allfilecomponentsref}; $i++ ) |
| 386 |
{ |
| 387 |
my %onecomponent = (); |
| 388 |
|
| 389 |
$onecomponent{'name'} = ${$allfilecomponentsref}[$i]; |
| 390 |
$onecomponent{'guid'} = get_component_guid($onecomponent{'name'}, $componentidhashref); |
| 391 |
$onecomponent{'directory'} = get_file_component_directory($onecomponent{'name'}, $filesref, $dirref); |
| 392 |
if ( $onecomponent{'directory'} eq "IGNORE_COMP" ) { next; } |
| 393 |
$onecomponent{'attributes'} = get_file_component_attributes($onecomponent{'name'}, $filesref, $allvariables); |
| 394 |
$onecomponent{'condition'} = get_file_component_condition($onecomponent{'name'}, $filesref); |
| 395 |
$onecomponent{'keypath'} = get_component_keypath($onecomponent{'name'}, $filesref, $componentidkeypathhashref); |
| 396 |
|
| 397 |
$oneline = $onecomponent{'name'} . "\t" . $onecomponent{'guid'} . "\t" . $onecomponent{'directory'} . "\t" |
| 398 |
. $onecomponent{'attributes'} . "\t" . $onecomponent{'condition'} . "\t" . $onecomponent{'keypath'} . "\n"; |
| 399 |
|
| 400 |
push(@componenttable, $oneline); |
| 401 |
} |
| 402 |
|
| 403 |
# Registry components |
| 404 |
|
| 405 |
for ( my $i = 0; $i <= $#{$allregistrycomponents}; $i++ ) |
| 406 |
{ |
| 407 |
my %onecomponent = (); |
| 408 |
|
| 409 |
$onecomponent{'name'} = ${$allregistrycomponents}[$i]; |
| 410 |
$onecomponent{'guid'} = get_component_guid($onecomponent{'name'}, $componentidhashref); |
| 411 |
$onecomponent{'directory'} = get_registry_component_directory(); |
| 412 |
$onecomponent{'attributes'} = get_registry_component_attributes($onecomponent{'name'}, $allvariables); |
| 413 |
$onecomponent{'condition'} = get_component_condition($onecomponent{'name'}); |
| 414 |
$onecomponent{'keypath'} = get_component_keypath($onecomponent{'name'}, $registryref, $componentidkeypathhashref); |
| 415 |
|
| 416 |
$oneline = $onecomponent{'name'} . "\t" . $onecomponent{'guid'} . "\t" . $onecomponent{'directory'} . "\t" |
| 417 |
. $onecomponent{'attributes'} . "\t" . $onecomponent{'condition'} . "\t" . $onecomponent{'keypath'} . "\n"; |
| 418 |
|
| 419 |
push(@componenttable, $oneline); |
| 420 |
} |
| 421 |
|
| 422 |
# Saving the file |
| 423 |
|
| 424 |
my $componenttablename = $basedir . $installer::globals::separator . "Componen.idt"; |
| 425 |
installer::files::save_file($componenttablename ,\@componenttable); |
| 426 |
$infoline = "Created idt file: $componenttablename\n"; |
| 427 |
push(@installer::globals::logfileinfo, $infoline); |
| 428 |
} |
| 429 |
|
| 430 |
#################################################################################### |
| 431 |
# Returning a component for a scp module gid. |
| 432 |
# Pairs are saved in the files collector. |
| 433 |
#################################################################################### |
| 434 |
|
| 435 |
sub get_component_name_from_modulegid |
| 436 |
{ |
| 437 |
my ($modulegid, $filesref) = @_; |
| 438 |
|
| 439 |
my $componentname = ""; |
| 440 |
|
| 441 |
for my $file ( @{$filesref} ) |
| 442 |
{ |
| 443 |
next if ( ! $file->{'modules'} ); |
| 444 |
|
| 445 |
my @filemodules = split /,\s*/, $file->{'modules'}; |
| 446 |
|
| 447 |
if (grep {$_ eq $modulegid} @filemodules) |
| 448 |
{ |
| 449 |
$componentname = $file->{'componentname'}; |
| 450 |
last; |
| 451 |
} |
| 452 |
} |
| 453 |
|
| 454 |
return $componentname; |
| 455 |
} |
| 456 |
|
| 457 |
#################################################################################### |
| 458 |
# Updating the file Environm.idt dynamically |
| 459 |
# Content: |
| 460 |
# Environment Name Value Component_ |
| 461 |
#################################################################################### |
| 462 |
|
| 463 |
sub set_component_in_environment_table |
| 464 |
{ |
| 465 |
my ($basedir, $filesref) = @_; |
| 466 |
|
| 467 |
my $infoline = ""; |
| 468 |
|
| 469 |
my $environmentfilename = $basedir . $installer::globals::separator . "Environm.idt"; |
| 470 |
|
| 471 |
if ( -f $environmentfilename ) # only do something, if file exists |
| 472 |
{ |
| 473 |
my $environmentfile = installer::files::read_file($environmentfilename); |
| 474 |
|
| 475 |
for ( my $i = 3; $i <= $#{$environmentfile}; $i++ ) # starting in line 4 of Environm.idt |
| 476 |
{ |
| 477 |
if ( ${$environmentfile}[$i] =~ /^\s*(.*?)\t(.*?)\t(.*?)\t(.*?)\s*$/ ) |
| 478 |
{ |
| 479 |
my $modulegid = $4; # in Environment table a scp module gid can be used as component replacement |
| 480 |
|
| 481 |
my $componentname = get_component_name_from_modulegid($modulegid, $filesref); |
| 482 |
|
| 483 |
if ( $componentname ) # only do something if a component could be found |
| 484 |
{ |
| 485 |
$infoline = "Updated Environment table:\n"; |
| 486 |
push(@installer::globals::logfileinfo, $infoline); |
| 487 |
$infoline = "Old line: ${$environmentfile}[$i]\n"; |
| 488 |
push(@installer::globals::logfileinfo, $infoline); |
| 489 |
|
| 490 |
${$environmentfile}[$i] =~ s/$modulegid/$componentname/; |
| 491 |
|
| 492 |
$infoline = "New line: ${$environmentfile}[$i]\n"; |
| 493 |
push(@installer::globals::logfileinfo, $infoline); |
| 494 |
|
| 495 |
} |
| 496 |
} |
| 497 |
} |
| 498 |
|
| 499 |
# Saving the file |
| 500 |
|
| 501 |
installer::files::save_file($environmentfilename ,$environmentfile); |
| 502 |
$infoline = "Updated idt file: $environmentfilename\n"; |
| 503 |
push(@installer::globals::logfileinfo, $infoline); |
| 504 |
|
| 505 |
} |
| 506 |
} |
| 507 |
|
| 508 |
1; |