19780544fSAndrew Rist#**************************************************************
29780544fSAndrew Rist#
39780544fSAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
49780544fSAndrew Rist#  or more contributor license agreements.  See the NOTICE file
59780544fSAndrew Rist#  distributed with this work for additional information
69780544fSAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
79780544fSAndrew Rist#  to you under the Apache License, Version 2.0 (the
89780544fSAndrew Rist#  "License"); you may not use this file except in compliance
99780544fSAndrew Rist#  with the License.  You may obtain a copy of the License at
109780544fSAndrew Rist#
119780544fSAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
129780544fSAndrew Rist#
139780544fSAndrew Rist#  Unless required by applicable law or agreed to in writing,
149780544fSAndrew Rist#  software distributed under the License is distributed on an
159780544fSAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169780544fSAndrew Rist#  KIND, either express or implied.  See the License for the
179780544fSAndrew Rist#  specific language governing permissions and limitations
189780544fSAndrew Rist#  under the License.
199780544fSAndrew Rist#
209780544fSAndrew Rist#**************************************************************
219780544fSAndrew Rist
229780544fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweirpackage installer::windows::registry;
25cdf0e10cSrcweir
26cdf0e10cSrcweiruse installer::files;
27cdf0e10cSrcweiruse installer::globals;
28cdf0e10cSrcweiruse installer::worker;
2919d58b3aSEike Rathkeuse installer::windows::msiglobal;
30cdf0e10cSrcweiruse installer::windows::idtglobal;
31cdf0e10cSrcweir
329f91b7e3SAndre Fischeruse strict;
339f91b7e3SAndre Fischer
34cdf0e10cSrcweir#####################################################
35cdf0e10cSrcweir# Generating the component name from a registryitem
36cdf0e10cSrcweir#####################################################
37cdf0e10cSrcweir
38cdf0e10cSrcweirsub get_registry_component_name
39cdf0e10cSrcweir{
40cdf0e10cSrcweir	my ($registryref, $allvariables) = @_;
41cdf0e10cSrcweir
42cdf0e10cSrcweir	# In this function exists the rule to create components from registryitems
43cdf0e10cSrcweir	# Rule:
44cdf0e10cSrcweir	# The componentname can be directly taken from the ModuleID.
45cdf0e10cSrcweir	# All registryitems belonging to one module can get the same component.
46cdf0e10cSrcweir
47cdf0e10cSrcweir	my $componentname = "";
48cdf0e10cSrcweir	my $isrootmodule = 0;
49cdf0e10cSrcweir
50*677600b0SAndre Fischer	if ($registryref->{'ModuleID'})
51*677600b0SAndre Fischer    {
52*677600b0SAndre Fischer        $componentname = $registryref->{'ModuleID'};
53*677600b0SAndre Fischer    }
54cdf0e10cSrcweir
55cdf0e10cSrcweir	$componentname =~ s/\\/\_/g;
56cdf0e10cSrcweir	$componentname =~ s/\//\_/g;
57cdf0e10cSrcweir	$componentname =~ s/\-/\_/g;
58cdf0e10cSrcweir	$componentname =~ s/\_\s*$//g;
59cdf0e10cSrcweir
60cdf0e10cSrcweir	$componentname = lc($componentname);	# componentnames always lowercase
61cdf0e10cSrcweir
62*677600b0SAndre Fischer	if ( $componentname eq "gid_module_root" )
63*677600b0SAndre Fischer    {
64*677600b0SAndre Fischer        $isrootmodule = 1;
65*677600b0SAndre Fischer    }
66cdf0e10cSrcweir
67cdf0e10cSrcweir	# Attention: Maximum length for the componentname is 72
68cdf0e10cSrcweir
69cdf0e10cSrcweir	# identifying this component as registryitem component
70cdf0e10cSrcweir	$componentname = "registry_" . $componentname;
71cdf0e10cSrcweir
72cdf0e10cSrcweir	$componentname =~ s/gid_module_/g_m_/g;
73cdf0e10cSrcweir	$componentname =~ s/_optional_/_o_/g;
74cdf0e10cSrcweir	$componentname =~ s/_javafilter_/_jf_/g;
75cdf0e10cSrcweir
76cdf0e10cSrcweir	# This componentname must be more specific
77cdf0e10cSrcweir	my $addon = "_";
78*677600b0SAndre Fischer	if ($allvariables->{'PRODUCTNAME'})
79*677600b0SAndre Fischer    {
80*677600b0SAndre Fischer        $addon .= $allvariables->{'PRODUCTNAME'};
81*677600b0SAndre Fischer    }
82*677600b0SAndre Fischer
83*677600b0SAndre Fischer    # Append the version number.
84*677600b0SAndre Fischer    # Previously that was the full version number as provided by 'PRODUCTVERSION'.
85*677600b0SAndre Fischer    # But MSI patches introduce the restriction that component names must not change.
86*677600b0SAndre Fischer    # Use just the major version number.
87*677600b0SAndre Fischer    my $version = $allvariables->{"BRANDPACKAGEVERSION"} // "";
88*677600b0SAndre Fischer    $addon .= $version;
89cdf0e10cSrcweir	$addon = lc($addon);
90cdf0e10cSrcweir	$addon =~ s/ //g;
91cdf0e10cSrcweir	$addon =~ s/-//g;
92cdf0e10cSrcweir	$addon =~ s/\.//g;
93cdf0e10cSrcweir
94cdf0e10cSrcweir	$componentname = $componentname . $addon;
95cdf0e10cSrcweir
96*677600b0SAndre Fischer	my $styles = $registryref->{'Styles'};
97*677600b0SAndre Fischer	if (defined $styles)
98*677600b0SAndre Fischer    {
99*677600b0SAndre Fischer        if (($styles =~ /\bLANGUAGEPACK\b/) && $installer::globals::languagepack)
100*677600b0SAndre Fischer        {
101*677600b0SAndre Fischer            $componentname .= "_lang";
102*677600b0SAndre Fischer        }
103*677600b0SAndre Fischer        if ($styles =~ /\bALWAYS_REQUIRED\b/)
104*677600b0SAndre Fischer        {
105*677600b0SAndre Fischer            $componentname .= "_forced";
106*677600b0SAndre Fischer        }
107*677600b0SAndre Fischer    }
108cdf0e10cSrcweir
109cdf0e10cSrcweir	# Attention: Maximum length for the componentname is 72
110cdf0e10cSrcweir	# %installer::globals::allregistrycomponents_in_this_database_ : resetted for each database
111cdf0e10cSrcweir	# %installer::globals::allregistrycomponents_ : not resetted for each database
112cdf0e10cSrcweir	# Component strings must be unique for the complete product, because they are used for
113cdf0e10cSrcweir	# the creation of the globally unique identifier.
114cdf0e10cSrcweir
115cdf0e10cSrcweir	my $fullname = $componentname;  # This can be longer than 72
116cdf0e10cSrcweir
117*677600b0SAndre Fischer	if (exists($installer::globals::allregistrycomponents_{$fullname})
118*677600b0SAndre Fischer        && ! exists($installer::globals::allregistrycomponents_in_this_database_{$fullname}))
119cdf0e10cSrcweir	{
120cdf0e10cSrcweir		# This is not allowed: One component cannot be installed with different packages.
121*677600b0SAndre Fischer		installer::exiter::exit_program(
122*677600b0SAndre Fischer            "ERROR: Windows registry component \"$fullname\" is already included into another package. This is not allowed.",
123*677600b0SAndre Fischer            "get_registry_component_name");
124cdf0e10cSrcweir	}
125cdf0e10cSrcweir
126cdf0e10cSrcweir	if ( exists($installer::globals::allregistrycomponents_{$fullname}) )
127cdf0e10cSrcweir	{
128cdf0e10cSrcweir		$componentname = $installer::globals::allregistrycomponents_{$fullname};
129cdf0e10cSrcweir	}
130cdf0e10cSrcweir	else
131cdf0e10cSrcweir	{
13219d58b3aSEike Rathke		if ( length($componentname) > 70 )
133cdf0e10cSrcweir		{
134cdf0e10cSrcweir			$componentname = generate_new_short_registrycomponentname($componentname); # This has to be unique for the complete product, not only one package
135cdf0e10cSrcweir		}
136cdf0e10cSrcweir
137cdf0e10cSrcweir		$installer::globals::allregistrycomponents_{$fullname} = $componentname;
138cdf0e10cSrcweir		$installer::globals::allregistrycomponents_in_this_database_{$fullname} = 1;
139cdf0e10cSrcweir	}
140cdf0e10cSrcweir
141*677600b0SAndre Fischer	if ( $isrootmodule )
142*677600b0SAndre Fischer    {
143*677600b0SAndre Fischer        $installer::globals::registryrootcomponent = $componentname;
144*677600b0SAndre Fischer    }
145cdf0e10cSrcweir
146cdf0e10cSrcweir	return $componentname;
147cdf0e10cSrcweir}
148cdf0e10cSrcweir
149cdf0e10cSrcweir#########################################################
150cdf0e10cSrcweir# Create a shorter version of a long component name,
151cdf0e10cSrcweir# because maximum length in msi database is 72.
152cdf0e10cSrcweir# Attention: In multi msi installation sets, the short
153cdf0e10cSrcweir# names have to be unique over all packages, because
154cdf0e10cSrcweir# this string is used to create the globally unique id
155cdf0e10cSrcweir# -> no resetting of
156cdf0e10cSrcweir# %installer::globals::allshortregistrycomponents
157cdf0e10cSrcweir# after a package was created.
158cdf0e10cSrcweir#########################################################
159cdf0e10cSrcweir
160cdf0e10cSrcweirsub generate_new_short_registrycomponentname
161cdf0e10cSrcweir{
162cdf0e10cSrcweir	my ($componentname) = @_;
16319d58b3aSEike Rathke
164cdf0e10cSrcweir	my $startversion = substr($componentname, 0, 60); # taking only the first 60 characters
16519d58b3aSEike Rathke	my $subid = installer::windows::msiglobal::calculate_id($componentname, 9); # taking only the first 9 digits
16619d58b3aSEike Rathke	my $shortcomponentname = $startversion . "_" . $subid;
167cdf0e10cSrcweir
16819d58b3aSEike Rathke	if ( exists($installer::globals::allshortregistrycomponents{$shortcomponentname}) ) { installer::exiter::exit_program("Failed to create unique component name: \"$shortcomponentname\"", "generate_new_short_registrycomponentname"); }
169cdf0e10cSrcweir
170cdf0e10cSrcweir	$installer::globals::allshortregistrycomponents{$shortcomponentname} = 1;
171cdf0e10cSrcweir
172cdf0e10cSrcweir	return $shortcomponentname;
173cdf0e10cSrcweir}
174cdf0e10cSrcweir
175cdf0e10cSrcweir##############################################################
176cdf0e10cSrcweir# Returning identifier for registry table.
177cdf0e10cSrcweir##############################################################
178cdf0e10cSrcweir
179cdf0e10cSrcweirsub get_registry_identifier
180cdf0e10cSrcweir{
181cdf0e10cSrcweir	my ($registry) = @_;
182cdf0e10cSrcweir
183cdf0e10cSrcweir	my $identifier = "";
184cdf0e10cSrcweir
185cdf0e10cSrcweir	if ( $registry->{'gid'} ) { $identifier = $registry->{'gid'}; }
186cdf0e10cSrcweir
187cdf0e10cSrcweir	$identifier = lc($identifier);	# always lower case
188cdf0e10cSrcweir
189cdf0e10cSrcweir	# Attention: Maximum length is 72
190cdf0e10cSrcweir
191cdf0e10cSrcweir	$identifier =~ s/gid_regitem_/g_r_/;
192cdf0e10cSrcweir	$identifier =~ s/_soffice_/_s_/;
193cdf0e10cSrcweir	$identifier =~ s/_clsid_/_c_/;
194cdf0e10cSrcweir	$identifier =~ s/_currentversion_/_cv_/;
195cdf0e10cSrcweir	$identifier =~ s/_microsoft_/_ms_/;
196cdf0e10cSrcweir	$identifier =~ s/_manufacturer_/_mf_/;
197cdf0e10cSrcweir	$identifier =~ s/_productname_/_pn_/;
198cdf0e10cSrcweir	$identifier =~ s/_productversion_/_pv_/;
199cdf0e10cSrcweir	$identifier =~ s/_staroffice_/_so_/;
200cdf0e10cSrcweir	$identifier =~ s/_software_/_sw_/;
201cdf0e10cSrcweir	$identifier =~ s/_capabilities_/_cap_/;
202cdf0e10cSrcweir	$identifier =~ s/_classpath_/_cp_/;
203cdf0e10cSrcweir	$identifier =~ s/_extension_/_ex_/;
204cdf0e10cSrcweir	$identifier =~ s/_fileassociations_/_fa_/;
205cdf0e10cSrcweir	$identifier =~ s/_propertysheethandlers_/_psh_/;
206cdf0e10cSrcweir	$identifier =~ s/__/_/g;
207cdf0e10cSrcweir
208cdf0e10cSrcweir	# Saving this in the registry collector
209cdf0e10cSrcweir
210cdf0e10cSrcweir	$registry->{'uniquename'} = $identifier;
211cdf0e10cSrcweir
212cdf0e10cSrcweir	return $identifier;
213cdf0e10cSrcweir}
214cdf0e10cSrcweir
215cdf0e10cSrcweir##################################################################
216cdf0e10cSrcweir# Returning root value for registry table.
217cdf0e10cSrcweir##################################################################
218cdf0e10cSrcweir
219cdf0e10cSrcweirsub get_registry_root
220cdf0e10cSrcweir{
221cdf0e10cSrcweir	my ($registry) = @_;
222cdf0e10cSrcweir
223cdf0e10cSrcweir	my $rootvalue = 0;	# Default: Parent is KKEY_CLASSES_ROOT
224cdf0e10cSrcweir	my $scproot = "";
225cdf0e10cSrcweir
226cdf0e10cSrcweir	if ( $registry->{'ParentID'} ) { $scproot = $registry->{'ParentID'}; }
227cdf0e10cSrcweir
228cdf0e10cSrcweir	if ( $scproot eq "PREDEFINED_HKEY_LOCAL_MACHINE" ) { $rootvalue = -1; }
229cdf0e10cSrcweir
230cdf0e10cSrcweir	if ( $scproot eq "PREDEFINED_HKEY_CLASSES_ROOT" ) { $rootvalue = 0; }
231cdf0e10cSrcweir
232cdf0e10cSrcweir	if ( $scproot eq "PREDEFINED_HKEY_CURRENT_USER_ONLY" ) { $rootvalue = 1; }
233cdf0e10cSrcweir
234cdf0e10cSrcweir	if ( $scproot eq "PREDEFINED_HKEY_LOCAL_MACHINE_ONLY" ) { $rootvalue = 2; }
235cdf0e10cSrcweir
236cdf0e10cSrcweir	return $rootvalue;
237cdf0e10cSrcweir}
238cdf0e10cSrcweir
239cdf0e10cSrcweir##############################################################
240cdf0e10cSrcweir# Returning key for registry table.
241cdf0e10cSrcweir##############################################################
242cdf0e10cSrcweir
243cdf0e10cSrcweirsub get_registry_key
244cdf0e10cSrcweir{
245cdf0e10cSrcweir	my ($registry, $allvariableshashref) = @_;
246cdf0e10cSrcweir
247cdf0e10cSrcweir	my $key = "";
248cdf0e10cSrcweir
249cdf0e10cSrcweir	if ( $registry->{'Subkey'} ) { $key = $registry->{'Subkey'}; }
250cdf0e10cSrcweir
251cdf0e10cSrcweir	if ( $key =~ /\%/ ) { $key = installer::worker::replace_variables_in_string($key, $allvariableshashref); }
252cdf0e10cSrcweir
253cdf0e10cSrcweir	return $key;
254cdf0e10cSrcweir}
255cdf0e10cSrcweir
256cdf0e10cSrcweir##############################################################
257cdf0e10cSrcweir# Returning name for registry table.
258cdf0e10cSrcweir##############################################################
259cdf0e10cSrcweir
260cdf0e10cSrcweirsub get_registry_name
261cdf0e10cSrcweir{
262cdf0e10cSrcweir	my ($registry, $allvariableshashref) = @_;
263cdf0e10cSrcweir
264cdf0e10cSrcweir	my $name = "";
265cdf0e10cSrcweir
266cdf0e10cSrcweir	if ( $registry->{'Name'} ) { $name = $registry->{'Name'}; }
267cdf0e10cSrcweir
268cdf0e10cSrcweir	if ( $name =~ /\%/ ) { $name = installer::worker::replace_variables_in_string($name, $allvariableshashref); }
269cdf0e10cSrcweir
270cdf0e10cSrcweir	return $name;
271cdf0e10cSrcweir}
272cdf0e10cSrcweir
273cdf0e10cSrcweir##############################################################
274cdf0e10cSrcweir# Returning value for registry table.
275cdf0e10cSrcweir##############################################################
276cdf0e10cSrcweir
277cdf0e10cSrcweirsub get_registry_value
278cdf0e10cSrcweir{
279cdf0e10cSrcweir	my ($registry, $allvariableshashref) = @_;
280cdf0e10cSrcweir
281cdf0e10cSrcweir	my $value = "";
282cdf0e10cSrcweir
283cdf0e10cSrcweir	if ( $registry->{'Value'} ) { $value = $registry->{'Value'}; }
284cdf0e10cSrcweir
285cdf0e10cSrcweir	$value =~ s/\\\"/\"/g;	# no more masquerading of '"'
286cdf0e10cSrcweir	$value =~ s/\\\\\s*$/\\/g;	# making "\\" at end of value to "\"
287cdf0e10cSrcweir	$value =~ s/\<progpath\>/\[INSTALLLOCATION\]/;
288cdf0e10cSrcweir	$value =~ s/\[INSTALLLOCATION\]\\/\[INSTALLLOCATION\]/;	# removing "\" after "[INSTALLLOCATION]"
289cdf0e10cSrcweir
290cdf0e10cSrcweir	if ( $value =~ /\%/ ) { $value = installer::worker::replace_variables_in_string($value, $allvariableshashref); }
291cdf0e10cSrcweir
292cdf0e10cSrcweir	return $value;
293cdf0e10cSrcweir}
294cdf0e10cSrcweir
295cdf0e10cSrcweir##############################################################
296cdf0e10cSrcweir# Returning 64 bit value for registry table.
297cdf0e10cSrcweir##############################################################
298cdf0e10cSrcweir
299cdf0e10cSrcweirsub get_registry_val64
300cdf0e10cSrcweir{
301cdf0e10cSrcweir	my ($registry, $allvariableshashref) = @_;
302cdf0e10cSrcweir
303cdf0e10cSrcweir	my $value = "";
304cdf0e10cSrcweir
305cdf0e10cSrcweir	if ( $registry->{'Val64'} ) { $value = $registry->{'Val64'}; }
306cdf0e10cSrcweir
307cdf0e10cSrcweir	$value =~ s/\\\"/\"/g;	# no more masquerading of '"'
308cdf0e10cSrcweir	$value =~ s/\\\\\s*$/\\/g;	# making "\\" at end of value to "\"
309cdf0e10cSrcweir	$value =~ s/\<progpath\>/\[INSTALLLOCATION\]/;
310cdf0e10cSrcweir	$value =~ s/\[INSTALLLOCATION\]\\/\[INSTALLLOCATION\]/;	# removing "\" after "[INSTALLLOCATION]"
311cdf0e10cSrcweir
312cdf0e10cSrcweir	if ( $value =~ /\%/ ) { $value = installer::worker::replace_variables_in_string($value, $allvariableshashref); }
313cdf0e10cSrcweir
314cdf0e10cSrcweir	return $value;
315cdf0e10cSrcweir}
316cdf0e10cSrcweir
317cdf0e10cSrcweir
318cdf0e10cSrcweir######################################################
319cdf0e10cSrcweir# Adding the content of
320cdf0e10cSrcweir# @installer::globals::userregistrycollector
321cdf0e10cSrcweir# to the registry table. The content was collected
322cdf0e10cSrcweir# in create_files_table() in file.pm.
323cdf0e10cSrcweir######################################################
324cdf0e10cSrcweir
325cdf0e10cSrcweirsub add_userregs_to_registry_table
326cdf0e10cSrcweir{
327cdf0e10cSrcweir	my ( $registrytable, $allvariables ) = @_;
328cdf0e10cSrcweir
329cdf0e10cSrcweir	for ( my $i = 0; $i <= $#installer::globals::userregistrycollector; $i++ )
330cdf0e10cSrcweir	{
331cdf0e10cSrcweir		my $onefile = $installer::globals::userregistrycollector[$i];
332cdf0e10cSrcweir
333cdf0e10cSrcweir		my $styles = "";
334cdf0e10cSrcweir		if ( $onefile->{'Styles'} ) { $styles = $onefile->{'Styles'}; }
335cdf0e10cSrcweir
336cdf0e10cSrcweir		my %registry = ();
337cdf0e10cSrcweir
338cdf0e10cSrcweir		$registry{'Registry'} = $onefile->{'userregkeypath'};
339cdf0e10cSrcweir		$registry{'Root'} = "1";  # always HKCU
340cdf0e10cSrcweir		$registry{'Key'} = "Software\\$allvariables->{'MANUFACTURER'}\\$allvariables->{'PRODUCTNAME'} $allvariables->{'PRODUCTVERSION'}\\";
341cdf0e10cSrcweir		if ( $onefile->{'needs_user_registry_key'} ) { $registry{'Key'} = $registry{'Key'} . "StartMenu"; }
342cdf0e10cSrcweir		else { $registry{'Key'} = $registry{'Key'} . "ShellNew"; }
343cdf0e10cSrcweir		$registry{'Name'} = $onefile->{'Name'};
344cdf0e10cSrcweir		$registry{'Value'} = "1";
345cdf0e10cSrcweir		$registry{'Component_'} = $onefile->{'componentname'};
346cdf0e10cSrcweir
347cdf0e10cSrcweir		my $oneline = $registry{'Registry'} . "\t" . $registry{'Root'} . "\t" . $registry{'Key'} . "\t"
348cdf0e10cSrcweir					. $registry{'Name'} . "\t" . $registry{'Value'} . "\t" . $registry{'Component_'} . "\n";
349cdf0e10cSrcweir
350cdf0e10cSrcweir		push(@{$registrytable}, $oneline);
351cdf0e10cSrcweir	}
352cdf0e10cSrcweir}
353cdf0e10cSrcweir
354cdf0e10cSrcweir######################################################
355cdf0e10cSrcweir# Creating the file Registry.idt dynamically
356cdf0e10cSrcweir# Content:
357cdf0e10cSrcweir# Registry Root Key Name Value Component_
358cdf0e10cSrcweir######################################################
3599f91b7e3SAndre Fischersub prepare_registry_table ($$$)
360cdf0e10cSrcweir{
3619f91b7e3SAndre Fischer	my ($registryref, $languagesarrayref, $allvariableshashref) = @_;
362cdf0e10cSrcweir
3631ba1fd99SAndre Fischer    my %table_data = ();
3641ba1fd99SAndre Fischer	foreach my $onelanguage (@$languagesarrayref)
365cdf0e10cSrcweir	{
3661ba1fd99SAndre Fischer        my $table_items = [];
3671ba1fd99SAndre Fischer		foreach my $oneregistry (@$registryref)
368cdf0e10cSrcweir		{
369cdf0e10cSrcweir			# Controlling the language!
370cdf0e10cSrcweir			# Only language independent folderitems or folderitems with the correct language
371cdf0e10cSrcweir			# will be included into the table
372cdf0e10cSrcweir
3731ba1fd99SAndre Fischer			next if $oneregistry->{'ismultilingual'}
3741ba1fd99SAndre Fischer                && $oneregistry->{'specificlanguage'} ne $onelanguage;
375cdf0e10cSrcweir
376cdf0e10cSrcweir			my %registry = ();
377cdf0e10cSrcweir
378cdf0e10cSrcweir			$registry{'Registry'} = get_registry_identifier($oneregistry);
379cdf0e10cSrcweir			$registry{'Root'} = get_registry_root($oneregistry);
380cdf0e10cSrcweir			$registry{'Key'} = get_registry_key($oneregistry, $allvariableshashref);
381cdf0e10cSrcweir			$registry{'Name'} = get_registry_name($oneregistry, $allvariableshashref);
382cdf0e10cSrcweir			$registry{'Value'} = get_registry_value($oneregistry, $allvariableshashref);
383cdf0e10cSrcweir			$registry{'Val64'} = get_registry_val64($oneregistry, $allvariableshashref);
3841ba1fd99SAndre Fischer            my $component_name = get_registry_component_name($oneregistry, $allvariableshashref);
3851ba1fd99SAndre Fischer            $oneregistry->{'componentname'} = $component_name;
3861ba1fd99SAndre Fischer			$registry{'Component_'} = $component_name;
387cdf0e10cSrcweir
388cdf0e10cSrcweir			# Collecting all components with DONT_DELETE style
3891ba1fd99SAndre Fischer			my $style = $oneregistry->{'Styles'} // "";
3901ba1fd99SAndre Fischer            $registry{'styles'} = $style;
3911ba1fd99SAndre Fischer
3921ba1fd99SAndre Fischer			if ( $style =~ /\bDONT_DELETE\b/ )
3931ba1fd99SAndre Fischer            {
3941ba1fd99SAndre Fischer                $installer::globals::dontdeletecomponents{$component_name} = 1;
3951ba1fd99SAndre Fischer            }
396cdf0e10cSrcweir
397cdf0e10cSrcweir			# Saving upgradekey to write this into setup.ini for minor upgrades
3981ba1fd99SAndre Fischer			if ( $style =~ /\bUPGRADEKEY\b/ )
3991ba1fd99SAndre Fischer            {
4001ba1fd99SAndre Fischer                $installer::globals::minorupgradekey = $registry{'Key'};
4011ba1fd99SAndre Fischer            }
402cdf0e10cSrcweir
403cdf0e10cSrcweir			# Collecting all registry components with ALWAYS_REQUIRED style
404cdf0e10cSrcweir			if ( ! ( $style =~ /\bALWAYS_REQUIRED\b/ ))
405cdf0e10cSrcweir			{
406cdf0e10cSrcweir				# Setting a component condition for unforced registry components!
407cdf0e10cSrcweir				# Only write into registry, if WRITE_REGISTRY is set.
408cdf0e10cSrcweir				if ( $oneregistry->{'ComponentCondition'} ) { $oneregistry->{'ComponentCondition'} = "(" . $oneregistry->{'ComponentCondition'} . ") AND (WRITE_REGISTRY=1)"; }
409cdf0e10cSrcweir				else { $oneregistry->{'ComponentCondition'} = "WRITE_REGISTRY=1"; }
410cdf0e10cSrcweir			}
411cdf0e10cSrcweir
412cdf0e10cSrcweir			# Collecting all component conditions
413cdf0e10cSrcweir			if ( $oneregistry->{'ComponentCondition'} )
414cdf0e10cSrcweir			{
415cdf0e10cSrcweir				if ( ! exists($installer::globals::componentcondition{$registry{'Component_'}}))
416cdf0e10cSrcweir				{
417cdf0e10cSrcweir					$installer::globals::componentcondition{$registry{'Component_'}} = $oneregistry->{'ComponentCondition'};
418cdf0e10cSrcweir				}
419cdf0e10cSrcweir			}
420cdf0e10cSrcweir
4219f91b7e3SAndre Fischer            push @$table_items, \%registry;
4229f91b7e3SAndre Fischer		}
4239f91b7e3SAndre Fischer        $table_data{$onelanguage} = $table_items;
4249f91b7e3SAndre Fischer    }
4259f91b7e3SAndre Fischer
4269f91b7e3SAndre Fischer    return \%table_data;
4279f91b7e3SAndre Fischer}
4289f91b7e3SAndre Fischer
4299f91b7e3SAndre Fischer
4309f91b7e3SAndre Fischer
4319f91b7e3SAndre Fischer
4329f91b7e3SAndre Fischersub collect_registry_components ($)
4339f91b7e3SAndre Fischer{
4349f91b7e3SAndre Fischer    my ($table_data) = @_;
4359f91b7e3SAndre Fischer
4369f91b7e3SAndre Fischer    my %components = ();
4379f91b7e3SAndre Fischer    foreach my $language_data (values %$table_data)
4389f91b7e3SAndre Fischer    {
4399f91b7e3SAndre Fischer        foreach my $item (@$language_data)
4409f91b7e3SAndre Fischer        {
4419f91b7e3SAndre Fischer			$components{$item->{'Component_'}} = 1;
4429f91b7e3SAndre Fischer        }
4439f91b7e3SAndre Fischer    }
4449f91b7e3SAndre Fischer    return keys %components;
4459f91b7e3SAndre Fischer}
4469f91b7e3SAndre Fischer
4479f91b7e3SAndre Fischer
4489f91b7e3SAndre Fischer
4499f91b7e3SAndre Fischer
4509f91b7e3SAndre Fischersub translate_component_names ($$$)
4519f91b7e3SAndre Fischer{
4529f91b7e3SAndre Fischer    my ($translation_map, $registry_items, $table_data) = @_;
4539f91b7e3SAndre Fischer
4549f91b7e3SAndre Fischer    my $replacement_count = 0;
4559f91b7e3SAndre Fischer    foreach my $item (@$registry_items)
4569f91b7e3SAndre Fischer    {
4579f91b7e3SAndre Fischer        my $translated_name = $translation_map->{$item->{'componentname'}};
4589f91b7e3SAndre Fischer        if (defined $translated_name)
4599f91b7e3SAndre Fischer        {
4609f91b7e3SAndre Fischer            $item->{'componentname'} = $translated_name;
4619f91b7e3SAndre Fischer            ++$replacement_count;
4629f91b7e3SAndre Fischer        }
4639f91b7e3SAndre Fischer    }
4649f91b7e3SAndre Fischer    $installer::logger::Lang->printf("replaced %d component names in registry items\n", $replacement_count);
4659f91b7e3SAndre Fischer
4669f91b7e3SAndre Fischer    $replacement_count = 0;
4679f91b7e3SAndre Fischer    foreach my $language_data (values %$table_data)
4689f91b7e3SAndre Fischer    {
4699f91b7e3SAndre Fischer        foreach my $item (@$language_data)
4709f91b7e3SAndre Fischer        {
4719f91b7e3SAndre Fischer            my $translated_name = $translation_map->{$item->{'Component_'}};
4729f91b7e3SAndre Fischer            if (defined $translated_name)
4739f91b7e3SAndre Fischer            {
4749f91b7e3SAndre Fischer                $item->{'Component_'} = $translated_name;
4759f91b7e3SAndre Fischer                ++$replacement_count;
4769f91b7e3SAndre Fischer            }
4779f91b7e3SAndre Fischer        }
4789f91b7e3SAndre Fischer    }
4799f91b7e3SAndre Fischer    $installer::logger::Lang->printf("replaced %d component names in registry table\n", $replacement_count);
4809f91b7e3SAndre Fischer}
4819f91b7e3SAndre Fischer
4829f91b7e3SAndre Fischer
4839f91b7e3SAndre Fischer
484cdf0e10cSrcweir
4859f91b7e3SAndre Fischersub create_registry_table_32 ($$$$)
4869f91b7e3SAndre Fischer{
4879f91b7e3SAndre Fischer	my ($basedir, $languagesarrayref, $allvariableshashref, $table_data) = @_;
4889f91b7e3SAndre Fischer
4899f91b7e3SAndre Fischer	foreach my $onelanguage (@$languagesarrayref)
4909f91b7e3SAndre Fischer	{
4919f91b7e3SAndre Fischer		my @registrytable = ();
4929f91b7e3SAndre Fischer        installer::windows::idtglobal::write_idt_header(\@registrytable, "registry");
493cdf0e10cSrcweir
4949f91b7e3SAndre Fischer		foreach my $item (@{$table_data->{$onelanguage}})
4959f91b7e3SAndre Fischer		{
4969f91b7e3SAndre Fischer			next if $item->{'styles'} =~ /\bX64_ONLY\b/;
4979f91b7e3SAndre Fischer
4989f91b7e3SAndre Fischer			my $oneline = join("\t",
4999f91b7e3SAndre Fischer                $item->{'Registry'},
5009f91b7e3SAndre Fischer                $item->{'Root'},
5019f91b7e3SAndre Fischer                $item->{'Key'},
5029f91b7e3SAndre Fischer                $item->{'Name'},
5039f91b7e3SAndre Fischer                $item->{'Value'},
5049f91b7e3SAndre Fischer                $item->{'Component_'})
5059f91b7e3SAndre Fischer                . "\n";
5069f91b7e3SAndre Fischer
5079f91b7e3SAndre Fischer            push(@registrytable, $oneline);
508cdf0e10cSrcweir		}
509cdf0e10cSrcweir
510cdf0e10cSrcweir		# If there are added user registry keys for files collected in
511cdf0e10cSrcweir		# @installer::globals::userregistrycollector (file.pm), then
512cdf0e10cSrcweir		# this registry keys have to be added now. This is necessary for
513cdf0e10cSrcweir		# files in PREDEFINED_OSSHELLNEWDIR, because their component
514cdf0e10cSrcweir		# needs as KeyPath a RegistryItem in HKCU.
515cdf0e10cSrcweir
5169f91b7e3SAndre Fischer		if ( $installer::globals::addeduserregitrykeys )
5179f91b7e3SAndre Fischer        {
5189f91b7e3SAndre Fischer            add_userregs_to_registry_table(\@registrytable, $allvariableshashref);
5199f91b7e3SAndre Fischer        }
520cdf0e10cSrcweir
5219f91b7e3SAndre Fischer		# Save the database file.
522cdf0e10cSrcweir		my $registrytablename = $basedir . $installer::globals::separator . "Registry.idt" . "." . $onelanguage;
523cdf0e10cSrcweir		installer::files::save_file($registrytablename ,\@registrytable);
524b274bc22SAndre Fischer        $installer::logger::Lang->printf("Created idt file: %s\n", $registrytablename);
5259f91b7e3SAndre Fischer	}
5269f91b7e3SAndre Fischer}
5279f91b7e3SAndre Fischer
528cdf0e10cSrcweir
5299f91b7e3SAndre Fischer
5309f91b7e3SAndre Fischer
5319f91b7e3SAndre Fischersub create_registry_table_64 ($$$$)
5329f91b7e3SAndre Fischer{
5339f91b7e3SAndre Fischer	my ($basedir, $languagesarrayref, $allvariableshashref, $table_data) = @_;
5349f91b7e3SAndre Fischer
5359f91b7e3SAndre Fischer	foreach my $onelanguage (@$languagesarrayref)
5369f91b7e3SAndre Fischer	{
5379f91b7e3SAndre Fischer        my @reg64table = ();
5389f91b7e3SAndre Fischer		installer::windows::idtglobal::write_idt_header(\@reg64table, "reg64");
5399f91b7e3SAndre Fischer		foreach my $item (@{$table_data->{$onelanguage}})
5409f91b7e3SAndre Fischer        {
5419f91b7e3SAndre Fischer			next unless $item->{'styles'} =~ /\b(X64|X64_ONLY)\b/;
5429f91b7e3SAndre Fischer
5439f91b7e3SAndre Fischer            my $oneline64 = join("\t",
5449f91b7e3SAndre Fischer                $item->{'Registry'},
5459f91b7e3SAndre Fischer                $item->{'Root'},
5469f91b7e3SAndre Fischer                $item->{'Key'},
5479f91b7e3SAndre Fischer                $item->{'Name'},
5489f91b7e3SAndre Fischer                $item->{'Val64'},
5499f91b7e3SAndre Fischer                $item->{'Component_'})
5509f91b7e3SAndre Fischer                . "\n";
5519f91b7e3SAndre Fischer
5529f91b7e3SAndre Fischer            push(@reg64table , $oneline64);
5539f91b7e3SAndre Fischer        }
5549f91b7e3SAndre Fischer
5559f91b7e3SAndre Fischer        # Save the database file.
5569f91b7e3SAndre Fischer		my $registrytablename = $basedir . $installer::globals::separator . "Reg64.idt" . "." . $onelanguage;
557cdf0e10cSrcweir		installer::files::save_file($registrytablename ,\@reg64table );
558b274bc22SAndre Fischer        $installer::logger::Lang->printf("Created idt file: %s\n", $registrytablename);
559cdf0e10cSrcweir	}
560cdf0e10cSrcweir}
561cdf0e10cSrcweir
562cdf0e10cSrcweir1;
563