merge the formfield patch from ooo-build
[ooovba.git] / solenv / bin / modules / installer / windows / registry.pm
bloba2db8c11eb770660bf8081c0cbeb529415f9958d
1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 #
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # $RCSfile: registry.pm,v $
11 # $Revision: 1.18 $
13 # This file is part of OpenOffice.org.
15 # OpenOffice.org is free software: you can redistribute it and/or modify
16 # it under the terms of the GNU Lesser General Public License version 3
17 # only, as published by the Free Software Foundation.
19 # OpenOffice.org is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU Lesser General Public License version 3 for more details
23 # (a copy is included in the LICENSE file that accompanied this code).
25 # You should have received a copy of the GNU Lesser General Public License
26 # version 3 along with OpenOffice.org. If not, see
27 # <http://www.openoffice.org/license.html>
28 # for a copy of the LGPLv3 License.
30 #*************************************************************************
32 package installer::windows::registry;
34 use installer::files;
35 use installer::globals;
36 use installer::worker;
37 use installer::windows::idtglobal;
39 #####################################################
40 # Generating the component name from a registryitem
41 #####################################################
43 sub get_registry_component_name
45 my ($registryref, $allvariables) = @_;
47 # In this function exists the rule to create components from registryitems
48 # Rule:
49 # The componentname can be directly taken from the ModuleID.
50 # All registryitems belonging to one module can get the same component.
52 my $componentname = "";
53 my $isrootmodule = 0;
55 if ( $registryref->{'ModuleID'} ) { $componentname = $registryref->{'ModuleID'}; }
57 $componentname =~ s/\\/\_/g;
58 $componentname =~ s/\//\_/g;
59 $componentname =~ s/\-/\_/g;
60 $componentname =~ s/\_\s*$//g;
62 $componentname = lc($componentname); # componentnames always lowercase
64 if ( $componentname eq "gid_module_root" ) { $isrootmodule = 1; }
66 # Attention: Maximum length for the componentname is 72
68 $componentname =~ s/gid_module_/g_m_/g;
69 $componentname =~ s/_optional_/_o_/g;
70 $componentname =~ s/_javafilter_/_jf_/g;
72 $componentname = $componentname . "_registry"; # identifying this component as registryitem component
74 # This componentname must be more specific
75 my $addon = "_";
76 if ( $allvariables->{'PRODUCTNAME'} ) { $addon = $addon . $allvariables->{'PRODUCTNAME'}; }
77 if ( $allvariables->{'PRODUCTVERSION'} ) { $addon = $addon . $allvariables->{'PRODUCTVERSION'}; }
78 $addon = lc($addon);
79 $addon =~ s/ //g;
80 $addon =~ s/-//g;
81 $addon =~ s/\.//g;
83 my $styles = "";
84 if ( $registryref->{'Styles'} ) { $styles = $registryref->{'Styles'}; }
86 # Layer links must have unique Component GUID for all products. This is necessary, because only the
87 # uninstallation of the last product has to delete registry keys.
88 if ( $styles =~ /\bLAYER_REGISTRY\b/ )
90 $componentname = "g_m_root_registry_layer_ooo_reglayer";
91 # Styles USE_URELAYERVERSION, USE_OOOBASEVERSION
92 if ( $styles =~ /\bUSE_URELAYERVERSION\b/ ) { $addon = "_ure_" . $allvariables->{'URELAYERVERSION'}; }
93 if ( $styles =~ /\bUSE_OOOBASEVERSION\b/ ) { $addon = "_basis_" . $allvariables->{'OOOBASEVERSION'}; }
94 $addon =~ s/\.//g;
97 $componentname = $componentname . $addon;
99 if (( $styles =~ /\bLANGUAGEPACK\b/ ) && ( $installer::globals::languagepack )) { $componentname = $componentname . "_lang"; }
100 if ( $styles =~ /\bALWAYS_REQUIRED\b/ ) { $componentname = $componentname . "_forced"; }
102 if ( $isrootmodule ) { $installer::globals::registryrootcomponent = $componentname; }
104 return $componentname;
107 ##############################################################
108 # Returning identifier for registry table.
109 ##############################################################
111 sub get_registry_identifier
113 my ($registry) = @_;
115 my $identifier = "";
117 if ( $registry->{'gid'} ) { $identifier = $registry->{'gid'}; }
119 $identifier = lc($identifier); # always lower case
121 # Attention: Maximum length is 72
123 $identifier =~ s/gid_regitem_/g_r_/;
124 $identifier =~ s/_soffice_/_s_/;
125 $identifier =~ s/_clsid_/_c_/;
126 $identifier =~ s/_currentversion_/_cv_/;
127 $identifier =~ s/_microsoft_/_ms_/;
128 $identifier =~ s/_staroffice_/_so_/;
129 $identifier =~ s/_classpath_/_cp_/;
130 $identifier =~ s/__/_/g;
132 # Saving this in the registry collector
134 $registry->{'uniquename'} = $identifier;
136 return $identifier;
139 ##################################################################
140 # Returning root value for registry table.
141 ##################################################################
143 sub get_registry_root
145 my ($registry) = @_;
147 my $rootvalue = 0; # Default: Parent is KKEY_CLASSES_ROOT
148 my $scproot = "";
150 if ( $registry->{'ParentID'} ) { $scproot = $registry->{'ParentID'}; }
152 if ( $scproot eq "PREDEFINED_HKEY_LOCAL_MACHINE" ) { $rootvalue = -1; }
154 if ( $scproot eq "PREDEFINED_HKEY_CLASSES_ROOT" ) { $rootvalue = 0; }
156 if ( $scproot eq "PREDEFINED_HKEY_CURRENT_USER_ONLY" ) { $rootvalue = 1; }
158 if ( $scproot eq "PREDEFINED_HKEY_LOCAL_MACHINE_ONLY" ) { $rootvalue = 2; }
160 return $rootvalue;
163 ##############################################################
164 # Returning key for registry table.
165 ##############################################################
167 sub get_registry_key
169 my ($registry, $allvariableshashref) = @_;
171 my $key = "";
173 if ( $registry->{'Subkey'} ) { $key = $registry->{'Subkey'}; }
175 if ( $key =~ /\%/ ) { $key = installer::worker::replace_variables_in_string($key, $allvariableshashref); }
177 return $key;
180 ##############################################################
181 # Returning name for registry table.
182 ##############################################################
184 sub get_registry_name
186 my ($registry, $allvariableshashref) = @_;
188 my $name = "";
190 if ( $registry->{'Name'} ) { $name = $registry->{'Name'}; }
192 if ( $name =~ /\%/ ) { $name = installer::worker::replace_variables_in_string($name, $allvariableshashref); }
194 return $name;
197 ##############################################################
198 # Returning value for registry table.
199 ##############################################################
201 sub get_registry_value
203 my ($registry, $allvariableshashref) = @_;
205 my $value = "";
207 if ( $registry->{'Value'} ) { $value = $registry->{'Value'}; }
209 $value =~ s/\\\"/\"/g; # no more masquerading of '"'
210 $value =~ s/\<progpath\>/\[OFFICEINSTALLLOCATION\]/;
211 $value =~ s/\[OFFICEINSTALLLOCATION\]\\/\[OFFICEINSTALLLOCATION\]/; # removing "\" after "[OFFICEINSTALLLOCATION]"
213 if ( $value =~ /\%/ ) { $value = installer::worker::replace_variables_in_string($value, $allvariableshashref); }
215 return $value;
218 ##############################################################
219 # Returning component for registry table.
220 ##############################################################
222 sub get_registry_component
224 my ($registry, $allvariables) = @_;
226 # All registry items belonging to one module can
227 # be included into one component
229 my $componentname = get_registry_component_name($registry, $allvariables);
231 # saving componentname in the registryitem collector
233 $registry->{'componentname'} = $componentname;
235 return $componentname;
238 ######################################################
239 # Adding the content of
240 # @installer::globals::userregistrycollector
241 # to the registry table. The content was collected
242 # in create_files_table() in file.pm.
243 ######################################################
245 sub add_userregs_to_registry_table
247 my ( $registrytable, $allvariables ) = @_;
249 for ( my $i = 0; $i <= $#installer::globals::userregistrycollector; $i++ )
251 my $onefile = $installer::globals::userregistrycollector[$i];
253 my $styles = "";
254 if ( $onefile->{'Styles'} ) { $styles = $onefile->{'Styles'}; }
256 my %registry = ();
258 $registry{'Registry'} = $onefile->{'userregkeypath'};
259 $registry{'Root'} = "1"; # always HKCU
260 $registry{'Key'} = "Software\\$allvariables->{'MANUFACTURER'}\\$allvariables->{'PRODUCTNAME'} $allvariables->{'PRODUCTVERSION'}\\";
261 if ( $onefile->{'needs_user_registry_key'} ) { $registry{'Key'} = $registry{'Key'} . "StartMenu"; }
262 else { $registry{'Key'} = $registry{'Key'} . "ShellNew"; }
263 $registry{'Name'} = $onefile->{'Name'};
264 $registry{'Value'} = "1";
265 $registry{'Component_'} = $onefile->{'componentname'};
267 my $oneline = $registry{'Registry'} . "\t" . $registry{'Root'} . "\t" . $registry{'Key'} . "\t"
268 . $registry{'Name'} . "\t" . $registry{'Value'} . "\t" . $registry{'Component_'} . "\n";
270 push(@{$registrytable}, $oneline);
274 ######################################################
275 # Creating the file Registry.idt dynamically
276 # Content:
277 # Registry Root Key Name Value Component_
278 ######################################################
280 sub create_registry_table
282 my ($registryref, $allregistrycomponentsref, $basedir, $languagesarrayref, $allvariableshashref) = @_;
284 for ( my $m = 0; $m <= $#{$languagesarrayref}; $m++ )
286 my $onelanguage = ${$languagesarrayref}[$m];
288 my @registrytable = ();
290 installer::windows::idtglobal::write_idt_header(\@registrytable, "registry");
292 for ( my $i = 0; $i <= $#{$registryref}; $i++ )
294 my $oneregistry = ${$registryref}[$i];
296 # Controlling the language!
297 # Only language independent folderitems or folderitems with the correct language
298 # will be included into the table
300 if (! (!(( $oneregistry->{'ismultilingual'} )) || ( $oneregistry->{'specificlanguage'} eq $onelanguage )) ) { next; }
302 my %registry = ();
304 $registry{'Registry'} = get_registry_identifier($oneregistry);
305 $registry{'Root'} = get_registry_root($oneregistry);
306 $registry{'Key'} = get_registry_key($oneregistry, $allvariableshashref);
307 $registry{'Name'} = get_registry_name($oneregistry, $allvariableshashref);
308 $registry{'Value'} = get_registry_value($oneregistry, $allvariableshashref);
309 $registry{'Component_'} = get_registry_component($oneregistry, $allvariableshashref);
311 # Collecting all components
312 if (!(installer::existence::exists_in_array($registry{'Component_'}, $allregistrycomponentsref)))
314 push(@{$allregistrycomponentsref}, $registry{'Component_'});
317 # Collecting all components with DONT_DELETE style
318 my $style = "";
319 if ( $oneregistry->{'Styles'} ) { $style = $oneregistry->{'Styles'}; }
320 if ( $style =~ /\bDONT_DELETE\b/ ) { $installer::globals::dontdeletecomponents{$registry{'Component_'}} = 1; }
322 # Saving upgradekey to write this into setup.ini for minor upgrades
323 if ( $style =~ /\bUPGRADEKEY\b/ ) { $installer::globals::minorupgradekey = $registry{'Key'}; }
325 # Collecting all registry components with ALWAYS_REQUIRED style
326 if ( ! ( $style =~ /\bALWAYS_REQUIRED\b/ ))
328 # Setting a component condition for unforced registry components!
329 # Only write into registry, if WRITE_REGISTRY is set.
330 if ( $oneregistry->{'ComponentCondition'} ) { $oneregistry->{'ComponentCondition'} = "(" . $oneregistry->{'ComponentCondition'} . ") AND (WRITE_REGISTRY=1)"; }
331 else { $oneregistry->{'ComponentCondition'} = "WRITE_REGISTRY=1"; }
334 # Collecting all component conditions
335 if ( $oneregistry->{'ComponentCondition'} )
337 if ( ! exists($installer::globals::componentcondition{$registry{'Component_'}}))
339 $installer::globals::componentcondition{$registry{'Component_'}} = $oneregistry->{'ComponentCondition'};
343 my $oneline = $registry{'Registry'} . "\t" . $registry{'Root'} . "\t" . $registry{'Key'} . "\t"
344 . $registry{'Name'} . "\t" . $registry{'Value'} . "\t" . $registry{'Component_'} . "\n";
346 push(@registrytable, $oneline);
349 # If there are added user registry keys for files collected in
350 # @installer::globals::userregistrycollector (file.pm), then
351 # this registry keys have to be added now. This is necessary for
352 # files in PREDEFINED_OSSHELLNEWDIR, because their component
353 # needs as KeyPath a RegistryItem in HKCU.
355 if ( $installer::globals::addeduserregitrykeys ) { add_userregs_to_registry_table(\@registrytable, $allvariableshashref); }
357 # Saving the file
359 my $registrytablename = $basedir . $installer::globals::separator . "Registry.idt" . "." . $onelanguage;
360 installer::files::save_file($registrytablename ,\@registrytable);
361 my $infoline = "Created idt file: $registrytablename\n";
362 push(@installer::globals::logfileinfo, $infoline);