| 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::registry; |
| 20 |
|
| 21 |
use strict; |
| 22 |
use warnings; |
| 23 |
|
| 24 |
use installer::files; |
| 25 |
use installer::globals; |
| 26 |
use installer::worker; |
| 27 |
use installer::windows::msiglobal; |
| 28 |
use installer::windows::idtglobal; |
| 29 |
|
| 30 |
##################################################### |
| 31 |
# Generating the component name from a registryitem |
| 32 |
##################################################### |
| 33 |
|
| 34 |
sub get_registry_component_name |
| 35 |
{ |
| 36 |
my ($registryref, $allvariables) = @_; |
| 37 |
|
| 38 |
# In this function exists the rule to create components from registryitems |
| 39 |
# Rule: |
| 40 |
# The componentname can be directly taken from the ModuleID. |
| 41 |
# All registryitems belonging to one module can get the same component. |
| 42 |
|
| 43 |
my $componentname = ""; |
| 44 |
my $isrootmodule = 0; |
| 45 |
|
| 46 |
if ( $registryref->{'ModuleID'} ) { $componentname = $registryref->{'ModuleID'}; } |
| 47 |
|
| 48 |
$componentname =~ s/\\/\_/g; |
| 49 |
$componentname =~ s/\//\_/g; |
| 50 |
$componentname =~ s/\-/\_/g; |
| 51 |
$componentname =~ s/\_\s*$//g; |
| 52 |
|
| 53 |
$componentname = lc($componentname); # componentnames always lowercase |
| 54 |
|
| 55 |
if ( $componentname eq "gid_module_root" ) { $isrootmodule = 1; } |
| 56 |
|
| 57 |
# Attention: Maximum length for the componentname is 72 |
| 58 |
|
| 59 |
# identifying this component as registryitem component |
| 60 |
$componentname = "registry_" . $componentname; |
| 61 |
|
| 62 |
$componentname =~ s/gid_module_/g_m_/g; |
| 63 |
$componentname =~ s/_optional_/_o_/g; |
| 64 |
|
| 65 |
# This componentname must be more specific |
| 66 |
my $addon = "_"; |
| 67 |
if ( $allvariables->{'PRODUCTNAME'} ) { $addon = $addon . $allvariables->{'PRODUCTNAME'}; } |
| 68 |
if ( $allvariables->{'PRODUCTVERSION'} ) { $addon = $addon . $allvariables->{'PRODUCTVERSION'}; } |
| 69 |
$addon = lc($addon); |
| 70 |
$addon =~ s/ //g; |
| 71 |
$addon =~ s/-//g; |
| 72 |
$addon =~ s/\.//g; |
| 73 |
|
| 74 |
my $styles = ""; |
| 75 |
if ( $registryref->{'Styles'} ) { $styles = $registryref->{'Styles'}; } |
| 76 |
|
| 77 |
# Layer links must have unique Component GUID for all products. This is necessary, because only the |
| 78 |
# uninstallation of the last product has to delete registry keys. |
| 79 |
if ( $styles =~ /\bLAYER_REGISTRY\b/ ) |
| 80 |
{ |
| 81 |
$componentname = "g_m_root_registry_layer_ooo_reglayer"; |
| 82 |
# Styles USE_URELAYERVERSION, USE_PRODUCTVERSION |
| 83 |
if ( $styles =~ /\bUSE_URELAYERVERSION\b/ ) { $addon = "_ure_" . $allvariables->{'URELAYERVERSION'}; } |
| 84 |
if ( $styles =~ /\bUSE_PRODUCTVERSION\b/ ) { $addon = "_basis_" . $allvariables->{'PRODUCTVERSION'}; } |
| 85 |
$addon =~ s/\.//g; |
| 86 |
} |
| 87 |
|
| 88 |
$componentname = $componentname . $addon; |
| 89 |
|
| 90 |
if (( $styles =~ /\bLANGUAGEPACK\b/ ) && ( $installer::globals::languagepack )) { $componentname = $componentname . "_lang"; } |
| 91 |
elsif (( $styles =~ /\bHELPPACK\b/ ) && ( $installer::globals::helppack )) { $componentname = $componentname . "_help"; } |
| 92 |
if ( $styles =~ /\bALWAYS_REQUIRED\b/ ) { $componentname = $componentname . "_forced"; } |
| 93 |
|
| 94 |
# Attention: Maximum length for the componentname is 72 |
| 95 |
# %installer::globals::allregistrycomponents_in_this_database_ : resetted for each database |
| 96 |
# %installer::globals::allregistrycomponents_ : not resetted for each database |
| 97 |
# Component strings must be unique for the complete product, because they are used for |
| 98 |
# the creation of the globally unique identifier. |
| 99 |
|
| 100 |
my $fullname = $componentname; # This can be longer than 72 |
| 101 |
|
| 102 |
if (( exists($installer::globals::allregistrycomponents_{$fullname}) ) && ( ! exists($installer::globals::allregistrycomponents_in_this_database_{$fullname}) )) |
| 103 |
{ |
| 104 |
# This is not allowed: One component cannot be installed with different packages. |
| 105 |
installer::exiter::exit_program("ERROR: Windows registry component \"$fullname\" is already included into another package. This is not allowed.", "get_registry_component_name"); |
| 106 |
} |
| 107 |
|
| 108 |
if ( exists($installer::globals::allregistrycomponents_{$fullname}) ) |
| 109 |
{ |
| 110 |
$componentname = $installer::globals::allregistrycomponents_{$fullname}; |
| 111 |
} |
| 112 |
else |
| 113 |
{ |
| 114 |
if ( length($componentname) > 70 ) |
| 115 |
{ |
| 116 |
$componentname = generate_new_short_registrycomponentname($componentname); # This has to be unique for the complete product, not only one package |
| 117 |
} |
| 118 |
|
| 119 |
$installer::globals::allregistrycomponents_{$fullname} = $componentname; |
| 120 |
$installer::globals::allregistrycomponents_in_this_database_{$fullname} = 1; |
| 121 |
} |
| 122 |
|
| 123 |
if ( $isrootmodule ) { $installer::globals::registryrootcomponent = $componentname; } |
| 124 |
|
| 125 |
return $componentname; |
| 126 |
} |
| 127 |
|
| 128 |
######################################################### |
| 129 |
# Create a shorter version of a long component name, |
| 130 |
# because maximum length in msi database is 72. |
| 131 |
# Attention: In multi msi installation sets, the short |
| 132 |
# names have to be unique over all packages, because |
| 133 |
# this string is used to create the globally unique id |
| 134 |
# -> no resetting of |
| 135 |
# %installer::globals::allshortregistrycomponents |
| 136 |
# after a package was created. |
| 137 |
######################################################### |
| 138 |
|
| 139 |
sub generate_new_short_registrycomponentname |
| 140 |
{ |
| 141 |
my ($componentname) = @_; |
| 142 |
|
| 143 |
my $startversion = substr($componentname, 0, 60); # taking only the first 60 characters |
| 144 |
my $subid = installer::windows::msiglobal::calculate_id($componentname, 9); # taking only the first 9 digits |
| 145 |
my $shortcomponentname = $startversion . "_" . $subid; |
| 146 |
|
| 147 |
if ( exists($installer::globals::allshortregistrycomponents{$shortcomponentname}) ) { installer::exiter::exit_program("Failed to create unique component name: \"$shortcomponentname\"", "generate_new_short_registrycomponentname"); } |
| 148 |
|
| 149 |
$installer::globals::allshortregistrycomponents{$shortcomponentname} = 1; |
| 150 |
|
| 151 |
return $shortcomponentname; |
| 152 |
} |
| 153 |
|
| 154 |
############################################################## |
| 155 |
# Returning identifier for registry table. |
| 156 |
############################################################## |
| 157 |
|
| 158 |
sub get_registry_identifier |
| 159 |
{ |
| 160 |
my ($registry) = @_; |
| 161 |
|
| 162 |
my $identifier = ""; |
| 163 |
|
| 164 |
if ( $registry->{'gid'} ) { $identifier = $registry->{'gid'}; } |
| 165 |
|
| 166 |
$identifier = lc($identifier); # always lower case |
| 167 |
|
| 168 |
# Attention: Maximum length is 72 |
| 169 |
|
| 170 |
$identifier =~ s/gid_regitem_/g_r_/; |
| 171 |
$identifier =~ s/_soffice_/_s_/; |
| 172 |
$identifier =~ s/_clsid_/_c_/; |
| 173 |
$identifier =~ s/_currentversion_/_cv_/; |
| 174 |
$identifier =~ s/_microsoft_/_ms_/; |
| 175 |
$identifier =~ s/_manufacturer_/_mf_/; |
| 176 |
$identifier =~ s/_productname_/_pn_/; |
| 177 |
$identifier =~ s/_productversion_/_pv_/; |
| 178 |
$identifier =~ s/_staroffice_/_so_/; |
| 179 |
$identifier =~ s/_software_/_sw_/; |
| 180 |
$identifier =~ s/_capabilities_/_cap_/; |
| 181 |
$identifier =~ s/_classpath_/_cp_/; |
| 182 |
$identifier =~ s/_extension_/_ex_/; |
| 183 |
$identifier =~ s/_fileassociations_/_fa_/; |
| 184 |
$identifier =~ s/_propertysheethandlers_/_psh_/; |
| 185 |
$identifier =~ s/__/_/g; |
| 186 |
|
| 187 |
# Saving this in the registry collector |
| 188 |
|
| 189 |
$registry->{'uniquename'} = $identifier; |
| 190 |
|
| 191 |
return $identifier; |
| 192 |
} |
| 193 |
|
| 194 |
################################################################## |
| 195 |
# Returning root value for registry table. |
| 196 |
################################################################## |
| 197 |
|
| 198 |
sub get_registry_root |
| 199 |
{ |
| 200 |
my ($registry) = @_; |
| 201 |
|
| 202 |
my $rootvalue = 0; # Default: Parent is KKEY_CLASSES_ROOT |
| 203 |
my $scproot = ""; |
| 204 |
|
| 205 |
if ( $registry->{'ParentID'} ) { $scproot = $registry->{'ParentID'}; } |
| 206 |
|
| 207 |
if ( $scproot eq "PREDEFINED_HKEY_LOCAL_MACHINE" ) { $rootvalue = -1; } |
| 208 |
|
| 209 |
if ( $scproot eq "PREDEFINED_HKEY_CLASSES_ROOT" ) { $rootvalue = 0; } |
| 210 |
|
| 211 |
if ( $scproot eq "PREDEFINED_HKEY_CURRENT_USER_ONLY" ) { $rootvalue = 1; } |
| 212 |
|
| 213 |
if ( $scproot eq "PREDEFINED_HKEY_LOCAL_MACHINE_ONLY" ) { $rootvalue = 2; } |
| 214 |
|
| 215 |
return $rootvalue; |
| 216 |
} |
| 217 |
|
| 218 |
############################################################## |
| 219 |
# Returning key for registry table. |
| 220 |
############################################################## |
| 221 |
|
| 222 |
sub get_registry_key |
| 223 |
{ |
| 224 |
my ($registry, $allvariableshashref) = @_; |
| 225 |
|
| 226 |
my $key = ""; |
| 227 |
|
| 228 |
if ( $registry->{'Subkey'} ) { $key = $registry->{'Subkey'}; } |
| 229 |
|
| 230 |
if ( $key =~ /\%/ ) { $key = installer::worker::replace_variables_in_string($key, $allvariableshashref); } |
| 231 |
|
| 232 |
return $key; |
| 233 |
} |
| 234 |
|
| 235 |
############################################################## |
| 236 |
# Returning name for registry table. |
| 237 |
############################################################## |
| 238 |
|
| 239 |
sub get_registry_name |
| 240 |
{ |
| 241 |
my ($registry, $allvariableshashref) = @_; |
| 242 |
|
| 243 |
my $name = ""; |
| 244 |
|
| 245 |
if ( $registry->{'Name'} ) { $name = $registry->{'Name'}; } |
| 246 |
|
| 247 |
if ( $name =~ /\%/ ) { $name = installer::worker::replace_variables_in_string($name, $allvariableshashref); } |
| 248 |
|
| 249 |
return $name; |
| 250 |
} |
| 251 |
|
| 252 |
############################################################## |
| 253 |
# Returning value for registry table. |
| 254 |
############################################################## |
| 255 |
|
| 256 |
sub get_registry_value |
| 257 |
{ |
| 258 |
my ($registry, $allvariableshashref) = @_; |
| 259 |
|
| 260 |
my $value = ""; |
| 261 |
|
| 262 |
if ( $registry->{'Value'} ) { $value = $registry->{'Value'}; } |
| 263 |
|
| 264 |
$value =~ s/\\\"/\"/g; # no more masquerading of '"' |
| 265 |
$value =~ s/\\\\\s*$/\\/g; # making "\\" at end of value to "\" |
| 266 |
$value =~ s/\<progpath\>/\[INSTALLLOCATION\]/; |
| 267 |
$value =~ s/\[INSTALLLOCATION\]\\/\[INSTALLLOCATION\]/; # removing "\" after "[INSTALLLOCATION]" |
| 268 |
|
| 269 |
if ( $value =~ /\%/ ) { $value = installer::worker::replace_variables_in_string($value, $allvariableshashref); } |
| 270 |
|
| 271 |
return $value; |
| 272 |
} |
| 273 |
|
| 274 |
############################################################## |
| 275 |
# Returning component for registry table. |
| 276 |
############################################################## |
| 277 |
|
| 278 |
sub get_registry_component |
| 279 |
{ |
| 280 |
my ($registry, $allvariables) = @_; |
| 281 |
|
| 282 |
# All registry items belonging to one module can |
| 283 |
# be included into one component |
| 284 |
|
| 285 |
my $componentname = get_registry_component_name($registry, $allvariables); |
| 286 |
|
| 287 |
# saving componentname in the registryitem collector |
| 288 |
|
| 289 |
$registry->{'componentname'} = $componentname; |
| 290 |
|
| 291 |
return $componentname; |
| 292 |
} |
| 293 |
|
| 294 |
###################################################### |
| 295 |
# Adding the content of |
| 296 |
# @installer::globals::userregistrycollector |
| 297 |
# to the registry table. The content was collected |
| 298 |
# in create_files_table() in file.pm. |
| 299 |
###################################################### |
| 300 |
|
| 301 |
sub add_userregs_to_registry_table |
| 302 |
{ |
| 303 |
my ( $registrytable, $allvariables ) = @_; |
| 304 |
|
| 305 |
for ( my $i = 0; $i <= $#installer::globals::userregistrycollector; $i++ ) |
| 306 |
{ |
| 307 |
my $onefile = $installer::globals::userregistrycollector[$i]; |
| 308 |
|
| 309 |
my %registry = (); |
| 310 |
|
| 311 |
$registry{'Registry'} = $onefile->{'userregkeypath'}; |
| 312 |
$registry{'Root'} = "1"; # always HKCU |
| 313 |
$registry{'Key'} = "Software\\$allvariables->{'MANUFACTURER'}\\$allvariables->{'PRODUCTNAME'} $allvariables->{'PRODUCTVERSION'}\\"; |
| 314 |
if ( $onefile->{'needs_user_registry_key'} ) { $registry{'Key'} = $registry{'Key'} . "StartMenu"; } |
| 315 |
$registry{'Name'} = $onefile->{'Name'}; |
| 316 |
$registry{'Value'} = "1"; |
| 317 |
$registry{'Component_'} = $onefile->{'componentname'}; |
| 318 |
|
| 319 |
my $oneline = $registry{'Registry'} . "\t" . $registry{'Root'} . "\t" . $registry{'Key'} . "\t" |
| 320 |
. $registry{'Name'} . "\t" . $registry{'Value'} . "\t" . $registry{'Component_'} . "\n"; |
| 321 |
|
| 322 |
push(@{$registrytable}, $oneline); |
| 323 |
} |
| 324 |
} |
| 325 |
|
| 326 |
###################################################### |
| 327 |
# Creating the file Registry.idt dynamically |
| 328 |
# Content: |
| 329 |
# Registry Root Key Name Value Component_ |
| 330 |
###################################################### |
| 331 |
|
| 332 |
sub create_registry_table |
| 333 |
{ |
| 334 |
my ($registryref, $allregistrycomponentsref, $basedir, $languagesarrayref, $allvariableshashref) = @_; |
| 335 |
|
| 336 |
for ( my $m = 0; $m <= $#{$languagesarrayref}; $m++ ) |
| 337 |
{ |
| 338 |
my $onelanguage = ${$languagesarrayref}[$m]; |
| 339 |
|
| 340 |
my @registrytable = (); |
| 341 |
|
| 342 |
installer::windows::idtglobal::write_idt_header(\@registrytable, "registry"); |
| 343 |
|
| 344 |
for ( my $i = 0; $i <= $#{$registryref}; $i++ ) |
| 345 |
{ |
| 346 |
my $oneregistry = ${$registryref}[$i]; |
| 347 |
|
| 348 |
# Controlling the language! |
| 349 |
# Only language independent folderitems or folderitems with the correct language |
| 350 |
# will be included into the table |
| 351 |
|
| 352 |
if (! (!(( $oneregistry->{'ismultilingual'} )) || ( $oneregistry->{'specificlanguage'} eq $onelanguage )) ) { next; } |
| 353 |
|
| 354 |
my %registry = (); |
| 355 |
|
| 356 |
$registry{'Registry'} = get_registry_identifier($oneregistry); |
| 357 |
$registry{'Root'} = get_registry_root($oneregistry); |
| 358 |
$registry{'Key'} = get_registry_key($oneregistry, $allvariableshashref); |
| 359 |
$registry{'Name'} = get_registry_name($oneregistry, $allvariableshashref); |
| 360 |
$registry{'Value'} = get_registry_value($oneregistry, $allvariableshashref); |
| 361 |
$registry{'Component_'} = get_registry_component($oneregistry, $allvariableshashref); |
| 362 |
|
| 363 |
# Collecting all components |
| 364 |
if (! grep {$_ eq $registry{'Component_'}} @{$allregistrycomponentsref}) |
| 365 |
{ |
| 366 |
push(@{$allregistrycomponentsref}, $registry{'Component_'}); |
| 367 |
} |
| 368 |
|
| 369 |
my $style = ""; |
| 370 |
if ( $oneregistry->{'Styles'} ) { $style = $oneregistry->{'Styles'}; } |
| 371 |
# Collecting all registry components with ALWAYS_REQUIRED style |
| 372 |
if ( ! ( $style =~ /\bALWAYS_REQUIRED\b/ )) |
| 373 |
{ |
| 374 |
# Setting a component condition for unforced registry components! |
| 375 |
# Only write into registry, if WRITE_REGISTRY is set. |
| 376 |
if ( $oneregistry->{'ComponentCondition'} ) { $oneregistry->{'ComponentCondition'} = "(" . $oneregistry->{'ComponentCondition'} . ") AND (WRITE_REGISTRY=1)"; } |
| 377 |
else { $oneregistry->{'ComponentCondition'} = "WRITE_REGISTRY=1"; } |
| 378 |
} |
| 379 |
|
| 380 |
# Collecting all component conditions |
| 381 |
if ( $oneregistry->{'ComponentCondition'} ) |
| 382 |
{ |
| 383 |
if ( ! exists($installer::globals::componentcondition{$registry{'Component_'}})) |
| 384 |
{ |
| 385 |
$installer::globals::componentcondition{$registry{'Component_'}} = $oneregistry->{'ComponentCondition'}; |
| 386 |
} |
| 387 |
} |
| 388 |
|
| 389 |
my $oneline = $registry{'Registry'} . "\t" . $registry{'Root'} . "\t" . $registry{'Key'} . "\t" |
| 390 |
. $registry{'Name'} . "\t" . $registry{'Value'} . "\t" . $registry{'Component_'} . "\n"; |
| 391 |
|
| 392 |
push(@registrytable, $oneline); |
| 393 |
} |
| 394 |
|
| 395 |
# If there are added user registry keys for files collected in |
| 396 |
# @installer::globals::userregistrycollector (file.pm), then |
| 397 |
# this registry keys have to be added now. |
| 398 |
|
| 399 |
if ( $installer::globals::addeduserregitrykeys ) { add_userregs_to_registry_table(\@registrytable, $allvariableshashref); } |
| 400 |
|
| 401 |
# Saving the file |
| 402 |
|
| 403 |
my $registrytablename = $basedir . $installer::globals::separator . "Registry.idt" . "." . $onelanguage; |
| 404 |
installer::files::save_file($registrytablename ,\@registrytable); |
| 405 |
my $infoline = "Created idt file: $registrytablename\n"; |
| 406 |
push(@installer::globals::logfileinfo, $infoline); |
| 407 |
} |
| 408 |
} |
| 409 |
|
| 410 |
1; |