Branch libreoffice-5-0-4
[LibreOffice.git] / solenv / bin / modules / installer / windows / registry.pm
blob81c4f9a3b26803d26a6963602737ad5b35ab1bde
2 # This file is part of the LibreOffice project.
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/.
8 # This file incorporates work covered by the following license notice:
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 .
19 package installer::windows::registry;
21 use installer::files;
22 use installer::globals;
23 use installer::worker;
24 use installer::windows::msiglobal;
25 use installer::windows::idtglobal;
27 #####################################################
28 # Generating the component name from a registryitem
29 #####################################################
31 sub get_registry_component_name
33 my ($registryref, $allvariables) = @_;
35 # In this function exists the rule to create components from registryitems
36 # Rule:
37 # The componentname can be directly taken from the ModuleID.
38 # All registryitems belonging to one module can get the same component.
40 my $componentname = "";
41 my $isrootmodule = 0;
43 if ( $registryref->{'ModuleID'} ) { $componentname = $registryref->{'ModuleID'}; }
45 $componentname =~ s/\\/\_/g;
46 $componentname =~ s/\//\_/g;
47 $componentname =~ s/\-/\_/g;
48 $componentname =~ s/\_\s*$//g;
50 $componentname = lc($componentname); # componentnames always lowercase
52 if ( $componentname eq "gid_module_root" ) { $isrootmodule = 1; }
54 # Attention: Maximum length for the componentname is 72
56 # identifying this component as registryitem component
57 $componentname = "registry_" . $componentname;
59 $componentname =~ s/gid_module_/g_m_/g;
60 $componentname =~ s/_optional_/_o_/g;
62 # This componentname must be more specific
63 my $addon = "_";
64 if ( $allvariables->{'PRODUCTNAME'} ) { $addon = $addon . $allvariables->{'PRODUCTNAME'}; }
65 if ( $allvariables->{'PRODUCTVERSION'} ) { $addon = $addon . $allvariables->{'PRODUCTVERSION'}; }
66 $addon = lc($addon);
67 $addon =~ s/ //g;
68 $addon =~ s/-//g;
69 $addon =~ s/\.//g;
71 my $styles = "";
72 if ( $registryref->{'Styles'} ) { $styles = $registryref->{'Styles'}; }
74 # Layer links must have unique Component GUID for all products. This is necessary, because only the
75 # uninstallation of the last product has to delete registry keys.
76 if ( $styles =~ /\bLAYER_REGISTRY\b/ )
78 $componentname = "g_m_root_registry_layer_ooo_reglayer";
79 # Styles USE_URELAYERVERSION, USE_PRODUCTVERSION
80 if ( $styles =~ /\bUSE_URELAYERVERSION\b/ ) { $addon = "_ure_" . $allvariables->{'URELAYERVERSION'}; }
81 if ( $styles =~ /\bUSE_PRODUCTVERSION\b/ ) { $addon = "_basis_" . $allvariables->{'PRODUCTVERSION'}; }
82 $addon =~ s/\.//g;
85 $componentname = $componentname . $addon;
87 if (( $styles =~ /\bLANGUAGEPACK\b/ ) && ( $installer::globals::languagepack )) { $componentname = $componentname . "_lang"; }
88 elsif (( $styles =~ /\bHELPPACK\b/ ) && ( $installer::globals::helppack )) { $componentname = $componentname . "_help"; }
89 if ( $styles =~ /\bALWAYS_REQUIRED\b/ ) { $componentname = $componentname . "_forced"; }
91 # Attention: Maximum length for the componentname is 72
92 # %installer::globals::allregistrycomponents_in_this_database_ : resetted for each database
93 # %installer::globals::allregistrycomponents_ : not resetted for each database
94 # Component strings must be unique for the complete product, because they are used for
95 # the creation of the globally unique identifier.
97 my $fullname = $componentname; # This can be longer than 72
99 if (( exists($installer::globals::allregistrycomponents_{$fullname}) ) && ( ! exists($installer::globals::allregistrycomponents_in_this_database_{$fullname}) ))
101 # This is not allowed: One component cannot be installed with different packages.
102 installer::exiter::exit_program("ERROR: Windows registry component \"$fullname\" is already included into another package. This is not allowed.", "get_registry_component_name");
105 if ( exists($installer::globals::allregistrycomponents_{$fullname}) )
107 $componentname = $installer::globals::allregistrycomponents_{$fullname};
109 else
111 if ( length($componentname) > 70 )
113 $componentname = generate_new_short_registrycomponentname($componentname); # This has to be unique for the complete product, not only one package
116 $installer::globals::allregistrycomponents_{$fullname} = $componentname;
117 $installer::globals::allregistrycomponents_in_this_database_{$fullname} = 1;
120 if ( $isrootmodule ) { $installer::globals::registryrootcomponent = $componentname; }
122 return $componentname;
125 #########################################################
126 # Create a shorter version of a long component name,
127 # because maximum length in msi database is 72.
128 # Attention: In multi msi installation sets, the short
129 # names have to be unique over all packages, because
130 # this string is used to create the globally unique id
131 # -> no resetting of
132 # %installer::globals::allshortregistrycomponents
133 # after a package was created.
134 #########################################################
136 sub generate_new_short_registrycomponentname
138 my ($componentname) = @_;
140 my $startversion = substr($componentname, 0, 60); # taking only the first 60 characters
141 my $subid = installer::windows::msiglobal::calculate_id($componentname, 9); # taking only the first 9 digits
142 my $shortcomponentname = $startversion . "_" . $subid;
144 if ( exists($installer::globals::allshortregistrycomponents{$shortcomponentname}) ) { installer::exiter::exit_program("Failed to create unique component name: \"$shortcomponentname\"", "generate_new_short_registrycomponentname"); }
146 $installer::globals::allshortregistrycomponents{$shortcomponentname} = 1;
148 return $shortcomponentname;
151 ##############################################################
152 # Returning identifier for registry table.
153 ##############################################################
155 sub get_registry_identifier
157 my ($registry) = @_;
159 my $identifier = "";
161 if ( $registry->{'gid'} ) { $identifier = $registry->{'gid'}; }
163 $identifier = lc($identifier); # always lower case
165 # Attention: Maximum length is 72
167 $identifier =~ s/gid_regitem_/g_r_/;
168 $identifier =~ s/_soffice_/_s_/;
169 $identifier =~ s/_clsid_/_c_/;
170 $identifier =~ s/_currentversion_/_cv_/;
171 $identifier =~ s/_microsoft_/_ms_/;
172 $identifier =~ s/_manufacturer_/_mf_/;
173 $identifier =~ s/_productname_/_pn_/;
174 $identifier =~ s/_productversion_/_pv_/;
175 $identifier =~ s/_staroffice_/_so_/;
176 $identifier =~ s/_software_/_sw_/;
177 $identifier =~ s/_capabilities_/_cap_/;
178 $identifier =~ s/_classpath_/_cp_/;
179 $identifier =~ s/_extension_/_ex_/;
180 $identifier =~ s/_fileassociations_/_fa_/;
181 $identifier =~ s/_propertysheethandlers_/_psh_/;
182 $identifier =~ s/__/_/g;
184 # Saving this in the registry collector
186 $registry->{'uniquename'} = $identifier;
188 return $identifier;
191 ##################################################################
192 # Returning root value for registry table.
193 ##################################################################
195 sub get_registry_root
197 my ($registry) = @_;
199 my $rootvalue = 0; # Default: Parent is KKEY_CLASSES_ROOT
200 my $scproot = "";
202 if ( $registry->{'ParentID'} ) { $scproot = $registry->{'ParentID'}; }
204 if ( $scproot eq "PREDEFINED_HKEY_LOCAL_MACHINE" ) { $rootvalue = -1; }
206 if ( $scproot eq "PREDEFINED_HKEY_CLASSES_ROOT" ) { $rootvalue = 0; }
208 if ( $scproot eq "PREDEFINED_HKEY_CURRENT_USER_ONLY" ) { $rootvalue = 1; }
210 if ( $scproot eq "PREDEFINED_HKEY_LOCAL_MACHINE_ONLY" ) { $rootvalue = 2; }
212 return $rootvalue;
215 ##############################################################
216 # Returning key for registry table.
217 ##############################################################
219 sub get_registry_key
221 my ($registry, $allvariableshashref) = @_;
223 my $key = "";
225 if ( $registry->{'Subkey'} ) { $key = $registry->{'Subkey'}; }
227 if ( $key =~ /\%/ ) { $key = installer::worker::replace_variables_in_string($key, $allvariableshashref); }
229 return $key;
232 ##############################################################
233 # Returning name for registry table.
234 ##############################################################
236 sub get_registry_name
238 my ($registry, $allvariableshashref) = @_;
240 my $name = "";
242 if ( $registry->{'Name'} ) { $name = $registry->{'Name'}; }
244 if ( $name =~ /\%/ ) { $name = installer::worker::replace_variables_in_string($name, $allvariableshashref); }
246 return $name;
249 ##############################################################
250 # Returning value for registry table.
251 ##############################################################
253 sub get_registry_value
255 my ($registry, $allvariableshashref) = @_;
257 my $value = "";
259 if ( $registry->{'Value'} ) { $value = $registry->{'Value'}; }
261 $value =~ s/\\\"/\"/g; # no more masquerading of '"'
262 $value =~ s/\\\\\s*$/\\/g; # making "\\" at end of value to "\"
263 $value =~ s/\<progpath\>/\[INSTALLLOCATION\]/;
264 $value =~ s/\[INSTALLLOCATION\]\\/\[INSTALLLOCATION\]/; # removing "\" after "[INSTALLLOCATION]"
266 if ( $value =~ /\%/ ) { $value = installer::worker::replace_variables_in_string($value, $allvariableshashref); }
268 return $value;
271 ##############################################################
272 # Returning component for registry table.
273 ##############################################################
275 sub get_registry_component
277 my ($registry, $allvariables) = @_;
279 # All registry items belonging to one module can
280 # be included into one component
282 my $componentname = get_registry_component_name($registry, $allvariables);
284 # saving componentname in the registryitem collector
286 $registry->{'componentname'} = $componentname;
288 return $componentname;
291 ######################################################
292 # Adding the content of
293 # @installer::globals::userregistrycollector
294 # to the registry table. The content was collected
295 # in create_files_table() in file.pm.
296 ######################################################
298 sub add_userregs_to_registry_table
300 my ( $registrytable, $allvariables ) = @_;
302 for ( my $i = 0; $i <= $#installer::globals::userregistrycollector; $i++ )
304 my $onefile = $installer::globals::userregistrycollector[$i];
306 my %registry = ();
308 $registry{'Registry'} = $onefile->{'userregkeypath'};
309 $registry{'Root'} = "1"; # always HKCU
310 $registry{'Key'} = "Software\\$allvariables->{'MANUFACTURER'}\\$allvariables->{'PRODUCTNAME'} $allvariables->{'PRODUCTVERSION'}\\";
311 if ( $onefile->{'needs_user_registry_key'} ) { $registry{'Key'} = $registry{'Key'} . "StartMenu"; }
312 $registry{'Name'} = $onefile->{'Name'};
313 $registry{'Value'} = "1";
314 $registry{'Component_'} = $onefile->{'componentname'};
316 my $oneline = $registry{'Registry'} . "\t" . $registry{'Root'} . "\t" . $registry{'Key'} . "\t"
317 . $registry{'Name'} . "\t" . $registry{'Value'} . "\t" . $registry{'Component_'} . "\n";
319 push(@{$registrytable}, $oneline);
323 ######################################################
324 # Creating the file Registry.idt dynamically
325 # Content:
326 # Registry Root Key Name Value Component_
327 ######################################################
329 sub create_registry_table
331 my ($registryref, $allregistrycomponentsref, $basedir, $languagesarrayref, $allvariableshashref) = @_;
333 for ( my $m = 0; $m <= $#{$languagesarrayref}; $m++ )
335 my $onelanguage = ${$languagesarrayref}[$m];
337 my @registrytable = ();
339 installer::windows::idtglobal::write_idt_header(\@registrytable, "registry");
341 for ( my $i = 0; $i <= $#{$registryref}; $i++ )
343 my $oneregistry = ${$registryref}[$i];
345 # Controlling the language!
346 # Only language independent folderitems or folderitems with the correct language
347 # will be included into the table
349 if (! (!(( $oneregistry->{'ismultilingual'} )) || ( $oneregistry->{'specificlanguage'} eq $onelanguage )) ) { next; }
351 my %registry = ();
353 $registry{'Registry'} = get_registry_identifier($oneregistry);
354 $registry{'Root'} = get_registry_root($oneregistry);
355 $registry{'Key'} = get_registry_key($oneregistry, $allvariableshashref);
356 $registry{'Name'} = get_registry_name($oneregistry, $allvariableshashref);
357 $registry{'Value'} = get_registry_value($oneregistry, $allvariableshashref);
358 $registry{'Component_'} = get_registry_component($oneregistry, $allvariableshashref);
360 # Collecting all components
361 if (! grep {$_ eq $registry{'Component_'}} @{$allregistrycomponentsref})
363 push(@{$allregistrycomponentsref}, $registry{'Component_'});
366 # Collecting all components with DONT_DELETE style
367 my $style = "";
368 if ( $oneregistry->{'Styles'} ) { $style = $oneregistry->{'Styles'}; }
369 if ( $style =~ /\bDONT_DELETE\b/ ) { $installer::globals::dontdeletecomponents{$registry{'Component_'}} = 1; }
371 # Collecting all registry components with ALWAYS_REQUIRED style
372 if ( ! ( $style =~ /\bALWAYS_REQUIRED\b/ ))
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"; }
380 # Collecting all component conditions
381 if ( $oneregistry->{'ComponentCondition'} )
383 if ( ! exists($installer::globals::componentcondition{$registry{'Component_'}}))
385 $installer::globals::componentcondition{$registry{'Component_'}} = $oneregistry->{'ComponentCondition'};
389 my $oneline = $registry{'Registry'} . "\t" . $registry{'Root'} . "\t" . $registry{'Key'} . "\t"
390 . $registry{'Name'} . "\t" . $registry{'Value'} . "\t" . $registry{'Component_'} . "\n";
392 push(@registrytable, $oneline);
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.
399 if ( $installer::globals::addeduserregitrykeys ) { add_userregs_to_registry_table(\@registrytable, $allvariableshashref); }
401 # Saving the file
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);