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::component;
25cdf0e10cSrcweir
26cdf0e10cSrcweiruse installer::converter;
27cdf0e10cSrcweiruse installer::existence;
28cdf0e10cSrcweiruse installer::exiter;
29cdf0e10cSrcweiruse installer::files;
30cdf0e10cSrcweiruse installer::globals;
31cdf0e10cSrcweiruse installer::windows::idtglobal;
32cdf0e10cSrcweiruse installer::windows::language;
33cdf0e10cSrcweir
341ba1fd99SAndre Fischeruse strict;
351ba1fd99SAndre Fischer
36cdf0e10cSrcweir##############################################################
37cdf0e10cSrcweir# Returning a globally unique ID (GUID) for a component
38cdf0e10cSrcweir# If the component is new, a unique guid has to be created.
39cdf0e10cSrcweir# If the component already exists, the guid has to be
40cdf0e10cSrcweir# taken from a list component <-> guid
41cdf0e10cSrcweir# Sample for a guid: {B68FD953-3CEF-4489-8269-8726848056E8}
42cdf0e10cSrcweir##############################################################
43cdf0e10cSrcweir
44dca4887fSAndre Fischersub get_component_guid ($)
45cdf0e10cSrcweir{
46dca4887fSAndre Fischer	my ($componentname) = @_;
47cdf0e10cSrcweir
48cdf0e10cSrcweir	# At this time only a template
49cdf0e10cSrcweir	my $returnvalue = "\{COMPONENTGUID\}";
50cdf0e10cSrcweir
51cdf0e10cSrcweir	# Returning a ComponentID, that is assigned in scp project
52cdf0e10cSrcweir	if ( exists($installer::globals::componentid{$componentname}) )
53cdf0e10cSrcweir	{
54dba1a2e4SAndre Fischer        $installer::logger::Lang->printf("reusing guid %s for component %s\n",
55dba1a2e4SAndre Fischer            $installer::globals::componentid{$componentname},
56dba1a2e4SAndre Fischer            $componentname);
57cdf0e10cSrcweir		$returnvalue = "\{" . $installer::globals::componentid{$componentname} . "\}";
58cdf0e10cSrcweir	}
59cdf0e10cSrcweir
60cdf0e10cSrcweir	return $returnvalue;
61cdf0e10cSrcweir}
62cdf0e10cSrcweir
63cdf0e10cSrcweir##############################################################
64cdf0e10cSrcweir# Returning the directory for a file component.
65cdf0e10cSrcweir##############################################################
66cdf0e10cSrcweir
67dba1a2e4SAndre Fischersub get_file_component_directory ($$$)
68cdf0e10cSrcweir{
691ba1fd99SAndre Fischer    my ($componentname, $filesref, $dirref) = @_;
70cdf0e10cSrcweir
711ba1fd99SAndre Fischer    my ($component,  $uniquedir);
72cdf0e10cSrcweir
731ba1fd99SAndre Fischer    foreach my $onefile (@$filesref)
741ba1fd99SAndre Fischer    {
751ba1fd99SAndre Fischer        if ($onefile->{'componentname'} eq $componentname)
761ba1fd99SAndre Fischer        {
77dba1a2e4SAndre Fischer            return get_file_component_directory_for_file($onefile, $dirref);
781ba1fd99SAndre Fischer        }
791ba1fd99SAndre Fischer    }
801ba1fd99SAndre Fischer
81dba1a2e4SAndre Fischer    # This component can be ignored, if it exists in a version with
82dba1a2e4SAndre Fischer    # extension "_pff" (this was renamed in file::get_sequence_for_file() )
83dba1a2e4SAndre Fischer    my $ignore_this_component = 0;
84dba1a2e4SAndre Fischer    my $origcomponentname = $componentname;
85dba1a2e4SAndre Fischer    my $componentname_pff = $componentname . "_pff";
861ba1fd99SAndre Fischer
87dba1a2e4SAndre Fischer    foreach my $onefile (@$filesref)
88dba1a2e4SAndre Fischer    {
89dba1a2e4SAndre Fischer        if ($onefile->{'componentname'} eq $componentname_pff)
90dba1a2e4SAndre Fischer        {
91dba1a2e4SAndre Fischer            return "IGNORE_COMP";
921ba1fd99SAndre Fischer        }
93dba1a2e4SAndre Fischer    }
941ba1fd99SAndre Fischer
95dba1a2e4SAndre Fischer    installer::exiter::exit_program(
96dba1a2e4SAndre Fischer        "ERROR: Did not find component \"$origcomponentname\" in file collection",
97dba1a2e4SAndre Fischer        "get_file_component_directory");
98dba1a2e4SAndre Fischer}
99cdf0e10cSrcweir
100cdf0e10cSrcweir
101dba1a2e4SAndre Fischer
102dba1a2e4SAndre Fischer
103dba1a2e4SAndre Fischersub get_file_component_directory_for_file ($$)
104dba1a2e4SAndre Fischer{
105dba1a2e4SAndre Fischer    my ($onefile, $dirref) = @_;
106dba1a2e4SAndre Fischer
107dba1a2e4SAndre Fischer	my $localstyles = $onefile->{'Styles'} // "";
108dba1a2e4SAndre Fischer
109cdf0e10cSrcweir	if ( $localstyles =~ /\bFONT\b/ )	# special handling for font files
110cdf0e10cSrcweir	{
111cdf0e10cSrcweir		return $installer::globals::fontsfolder;
112cdf0e10cSrcweir	}
113cdf0e10cSrcweir
114cdf0e10cSrcweir	my $destdir = "";
115cdf0e10cSrcweir
116cdf0e10cSrcweir	if ( $onefile->{'Dir'} ) { $destdir = $onefile->{'Dir'}; }
117cdf0e10cSrcweir
118cdf0e10cSrcweir	if ( $destdir =~ /\bPREDEFINED_OSSHELLNEWDIR\b/ )	# special handling for shellnew files
119cdf0e10cSrcweir	{
120cdf0e10cSrcweir		return $installer::globals::templatefolder;
121cdf0e10cSrcweir	}
122cdf0e10cSrcweir
123cdf0e10cSrcweir	my $destination = $onefile->{'destination'};
124cdf0e10cSrcweir
125cdf0e10cSrcweir	installer::pathanalyzer::get_path_from_fullqualifiedname(\$destination);
126cdf0e10cSrcweir
127cdf0e10cSrcweir	$destination =~ s/\Q$installer::globals::separator\E\s*$//;
1281ba1fd99SAndre Fischer
129cdf0e10cSrcweir	# This path has to be defined in the directory collection at "HostName"
130dba1a2e4SAndre Fischer
131dba1a2e4SAndre Fischer    my $uniquedir = undef;
132cdf0e10cSrcweir	if ($destination eq "")		# files in the installation root
133cdf0e10cSrcweir	{
134cdf0e10cSrcweir		$uniquedir = "INSTALLLOCATION";
135cdf0e10cSrcweir	}
136cdf0e10cSrcweir	else
137cdf0e10cSrcweir	{
1381ba1fd99SAndre Fischer		my $found = 0;
1391ba1fd99SAndre Fischer        foreach my $directory (@$dirref)
140cdf0e10cSrcweir		{
1411ba1fd99SAndre Fischer			if ($directory->{'HostName'} eq $destination)
142cdf0e10cSrcweir			{
143cdf0e10cSrcweir				$found = 1;
144dba1a2e4SAndre Fischer                $uniquedir = $directory->{'uniquename'};
145cdf0e10cSrcweir				last;
146cdf0e10cSrcweir			}
147cdf0e10cSrcweir		}
148cdf0e10cSrcweir
149dba1a2e4SAndre Fischer		if ( ! $found)
150cdf0e10cSrcweir		{
151dba1a2e4SAndre Fischer			installer::exiter::exit_program(
152dba1a2e4SAndre Fischer                "ERROR: Did not find destination $destination in directory collection",
153dba1a2e4SAndre Fischer                "get_file_component_directory");
154cdf0e10cSrcweir		}
1551ba1fd99SAndre Fischer
156cdf0e10cSrcweir		if ( $uniquedir eq $installer::globals::officeinstalldirectory )
157cdf0e10cSrcweir		{
158cdf0e10cSrcweir			$uniquedir = "INSTALLLOCATION";
159cdf0e10cSrcweir		}
160cdf0e10cSrcweir	}
1611ba1fd99SAndre Fischer
162cdf0e10cSrcweir	$onefile->{'uniquedirname'} = $uniquedir;		# saving it in the file collection
1631ba1fd99SAndre Fischer
164cdf0e10cSrcweir	return $uniquedir
165cdf0e10cSrcweir}
166cdf0e10cSrcweir
167cdf0e10cSrcweir##############################################################
168cdf0e10cSrcweir# Returning the directory for a registry component.
169cdf0e10cSrcweir# This cannot be a useful value
170cdf0e10cSrcweir##############################################################
171cdf0e10cSrcweir
172cdf0e10cSrcweirsub get_registry_component_directory
173cdf0e10cSrcweir{
174cdf0e10cSrcweir	my $componentdir = "INSTALLLOCATION";
175cdf0e10cSrcweir
176cdf0e10cSrcweir	return $componentdir;
177cdf0e10cSrcweir}
178cdf0e10cSrcweir
179cdf0e10cSrcweir##############################################################
180cdf0e10cSrcweir# Returning the attributes for a file component.
181cdf0e10cSrcweir# Always 8 in this first try?
182cdf0e10cSrcweir##############################################################
183cdf0e10cSrcweir
184cdf0e10cSrcweirsub get_file_component_attributes
185cdf0e10cSrcweir{
186cdf0e10cSrcweir	my ($componentname, $filesref, $allvariables) = @_;
187cdf0e10cSrcweir
188cdf0e10cSrcweir	my $attributes;
189cdf0e10cSrcweir
190cdf0e10cSrcweir	$attributes = 2;
191cdf0e10cSrcweir
192cdf0e10cSrcweir	# special handling for font files
193cdf0e10cSrcweir
194cdf0e10cSrcweir	my $onefile;
195cdf0e10cSrcweir	my $found = 0;
196cdf0e10cSrcweir
197cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$filesref}; $i++ )
198cdf0e10cSrcweir	{
199cdf0e10cSrcweir		$onefile = 	${$filesref}[$i];
200cdf0e10cSrcweir		my $component = $onefile->{'componentname'};
201cdf0e10cSrcweir
202cdf0e10cSrcweir		if ( $component eq $componentname )
203cdf0e10cSrcweir		{
204cdf0e10cSrcweir			$found = 1;
205cdf0e10cSrcweir			last;
206cdf0e10cSrcweir		}
207cdf0e10cSrcweir	}
208cdf0e10cSrcweir
209cdf0e10cSrcweir	if (!($found))
210cdf0e10cSrcweir	{
211cdf0e10cSrcweir		installer::exiter::exit_program("ERROR: Did not find component in file collection", "get_file_component_attributes");
212cdf0e10cSrcweir	}
213cdf0e10cSrcweir
214cdf0e10cSrcweir	my $localstyles = "";
215cdf0e10cSrcweir
216cdf0e10cSrcweir	if ( $onefile->{'Styles'} ) { $localstyles = $onefile->{'Styles'}; }
217cdf0e10cSrcweir
218cdf0e10cSrcweir	if ( $localstyles =~ /\bFONT\b/ )
219cdf0e10cSrcweir	{
22028a50f78SAndre Fischer		$attributes = 8;	# font files will be deinstalled if the ref count is 0
221cdf0e10cSrcweir	}
222cdf0e10cSrcweir
223cdf0e10cSrcweir	if ( $localstyles =~ /\bASSEMBLY\b/ )
224cdf0e10cSrcweir	{
225cdf0e10cSrcweir		$attributes = 0;	# Assembly files cannot run from source
226cdf0e10cSrcweir	}
227cdf0e10cSrcweir
228dba1a2e4SAndre Fischer	if ((defined $onefile->{'Dir'} && $onefile->{'Dir'} =~ /\bPREDEFINED_OSSHELLNEWDIR\b/)
229dba1a2e4SAndre Fischer        || $onefile->{'needs_user_registry_key'})
230cdf0e10cSrcweir	{
231cdf0e10cSrcweir		$attributes = 4;	# Files in shellnew dir and in non advertised startmenu entries must have user registry key as KeyPath
232cdf0e10cSrcweir	}
233cdf0e10cSrcweir
234cdf0e10cSrcweir	# Adding 256, if this is a 64 bit installation set.
235cdf0e10cSrcweir	if (( $allvariables->{'64BITPRODUCT'} ) && ( $allvariables->{'64BITPRODUCT'} == 1 )) { $attributes = $attributes + 256; }
236cdf0e10cSrcweir
237cdf0e10cSrcweir	return $attributes
238cdf0e10cSrcweir}
239cdf0e10cSrcweir
240cdf0e10cSrcweir##############################################################
241cdf0e10cSrcweir# Returning the attributes for a registry component.
242cdf0e10cSrcweir# Always 4, indicating, the keypath is a defined in
243cdf0e10cSrcweir# table registry
244cdf0e10cSrcweir##############################################################
245cdf0e10cSrcweir
246cdf0e10cSrcweirsub get_registry_component_attributes
247cdf0e10cSrcweir{
248cdf0e10cSrcweir	my ($componentname, $allvariables) = @_;
249cdf0e10cSrcweir
250cdf0e10cSrcweir	my $attributes;
251cdf0e10cSrcweir
252cdf0e10cSrcweir	$attributes = 4;
253cdf0e10cSrcweir
254cdf0e10cSrcweir	# Adding 256, if this is a 64 bit installation set.
255cdf0e10cSrcweir	if (( $allvariables->{'64BITPRODUCT'} ) && ( $allvariables->{'64BITPRODUCT'} == 1 )) { $attributes = $attributes + 256; }
256cdf0e10cSrcweir
257cdf0e10cSrcweir	if ( exists($installer::globals::dontdeletecomponents{$componentname}) ) { $attributes = $attributes + 16; }
258cdf0e10cSrcweir
259cdf0e10cSrcweir	return $attributes
260cdf0e10cSrcweir}
261cdf0e10cSrcweir
262cdf0e10cSrcweir##############################################################
263cdf0e10cSrcweir# Returning the conditions for a component.
264cdf0e10cSrcweir# This is important for language dependent components
265cdf0e10cSrcweir# in multilingual installation sets.
266cdf0e10cSrcweir##############################################################
267cdf0e10cSrcweir
268cdf0e10cSrcweirsub get_file_component_condition
269cdf0e10cSrcweir{
270cdf0e10cSrcweir	my ($componentname, $filesref) = @_;
271cdf0e10cSrcweir
272cdf0e10cSrcweir	my $condition = "";
273cdf0e10cSrcweir
274cdf0e10cSrcweir	if (exists($installer::globals::componentcondition{$componentname}))
275cdf0e10cSrcweir	{
276cdf0e10cSrcweir		$condition = $installer::globals::componentcondition{$componentname};
277cdf0e10cSrcweir	}
278cdf0e10cSrcweir
279cdf0e10cSrcweir	# there can be also tree conditions for multilayer products
280cdf0e10cSrcweir	if (exists($installer::globals::treeconditions{$componentname}))
281cdf0e10cSrcweir	{
282cdf0e10cSrcweir		if ( $condition eq "" )
283cdf0e10cSrcweir		{
284cdf0e10cSrcweir			$condition = $installer::globals::treeconditions{$componentname};
285cdf0e10cSrcweir		}
286cdf0e10cSrcweir		else
287cdf0e10cSrcweir		{
288cdf0e10cSrcweir			$condition = "($condition) And ($installer::globals::treeconditions{$componentname})";
289cdf0e10cSrcweir		}
290cdf0e10cSrcweir	}
291cdf0e10cSrcweir
292cdf0e10cSrcweir	return $condition
293cdf0e10cSrcweir}
294cdf0e10cSrcweir
295cdf0e10cSrcweir##############################################################
296cdf0e10cSrcweir# Returning the conditions for a registry component.
297cdf0e10cSrcweir##############################################################
298cdf0e10cSrcweir
299cdf0e10cSrcweirsub get_component_condition
300cdf0e10cSrcweir{
301cdf0e10cSrcweir	my ($componentname) = @_;
302cdf0e10cSrcweir
303cdf0e10cSrcweir	my $condition;
304cdf0e10cSrcweir
305cdf0e10cSrcweir	$condition = "";	# Always ?
306cdf0e10cSrcweir
307cdf0e10cSrcweir	if (exists($installer::globals::componentcondition{$componentname}))
308cdf0e10cSrcweir	{
309cdf0e10cSrcweir		$condition = $installer::globals::componentcondition{$componentname};
310cdf0e10cSrcweir	}
311cdf0e10cSrcweir
312cdf0e10cSrcweir	return $condition
313cdf0e10cSrcweir}
314cdf0e10cSrcweir
315cdf0e10cSrcweir####################################################################
316cdf0e10cSrcweir# Returning the keypath for a component.
317cdf0e10cSrcweir# This will be the name of the first file/registry, found in the
318cdf0e10cSrcweir# collection $itemsref
319cdf0e10cSrcweir# Attention: This has to be the unique (file)name, not the
320cdf0e10cSrcweir# real filename!
321cdf0e10cSrcweir####################################################################
322cdf0e10cSrcweir
323dca4887fSAndre Fischersub get_component_keypath ($$)
324cdf0e10cSrcweir{
325dca4887fSAndre Fischer	my ($componentname, $itemsref) = @_;
326cdf0e10cSrcweir
327dba1a2e4SAndre Fischer	foreach my $oneitem (@$itemsref)
328cdf0e10cSrcweir	{
3291ba1fd99SAndre Fischer		my $component = $oneitem->{'componentname'};
330dba1a2e4SAndre Fischer
331dba1a2e4SAndre Fischer		if ( ! defined $component)
332dba1a2e4SAndre Fischer        {
333dba1a2e4SAndre Fischer            installer::scriptitems::print_script_item($oneitem);
334dba1a2e4SAndre Fischer            installer::logger::PrintError("item in get_component_keypath has no 'componentname'\n");
335dba1a2e4SAndre Fischer            return "";
336dba1a2e4SAndre Fischer        }
337cdf0e10cSrcweir		if ( $component eq $componentname )
338dba1a2e4SAndre Fischer		{
339dba1a2e4SAndre Fischer            my $keypath = $oneitem->{'uniquename'};	# "uniquename", not "Name"
340dba1a2e4SAndre Fischer
341dba1a2e4SAndre Fischer            # Special handling for components in
342dba1a2e4SAndre Fischer            # PREDEFINED_OSSHELLNEWDIR. These components need as
343dba1a2e4SAndre Fischer            # KeyPath a RegistryItem in HKCU
344dba1a2e4SAndre Fischer            if ($oneitem->{'userregkeypath'})
345dba1a2e4SAndre Fischer            {
346dba1a2e4SAndre Fischer                $keypath = $oneitem->{'userregkeypath'};
347dba1a2e4SAndre Fischer            }
348dba1a2e4SAndre Fischer
349dba1a2e4SAndre Fischer            # saving it in the file and registry collection
350dba1a2e4SAndre Fischer            $oneitem->{'keypath'} = $keypath;
351dba1a2e4SAndre Fischer
352dba1a2e4SAndre Fischer            return $keypath
353dba1a2e4SAndre Fischer		}
354cdf0e10cSrcweir	}
3551ba1fd99SAndre Fischer
356dba1a2e4SAndre Fischer    installer::exiter::exit_program(
357dba1a2e4SAndre Fischer        "ERROR: Did not find component in file/registry collection, function get_component_keypath",
358dba1a2e4SAndre Fischer        "get_component_keypath");
359cdf0e10cSrcweir}
360cdf0e10cSrcweir
361cdf0e10cSrcweir
362*9f91b7e3SAndre Fischer
363*9f91b7e3SAndre Fischer
364*9f91b7e3SAndre Fischersub remove_ooversion_from_component_name($)
365cdf0e10cSrcweir{
366*9f91b7e3SAndre Fischer    my ($component_name) = @_;
367cdf0e10cSrcweir
368*9f91b7e3SAndre Fischer    $component_name =~ s/_openoffice\d+//;
369cdf0e10cSrcweir
370*9f91b7e3SAndre Fischer    return $component_name;
371*9f91b7e3SAndre Fischer}
372cdf0e10cSrcweir
373cdf0e10cSrcweir
374cdf0e10cSrcweir
375cdf0e10cSrcweir
376*9f91b7e3SAndre Fischersub prepare_component_table_creation ($$$)
377*9f91b7e3SAndre Fischer{
378*9f91b7e3SAndre Fischer    my ($file_components, $registry_components, $variables) = @_;
379*9f91b7e3SAndre Fischer
380*9f91b7e3SAndre Fischer    if ($installer::globals::is_release)
381*9f91b7e3SAndre Fischer    {
382*9f91b7e3SAndre Fischer        my %source_component_data = ();
383*9f91b7e3SAndre Fischer
384*9f91b7e3SAndre Fischer        # Collect the components that are used in the source release.
385*9f91b7e3SAndre Fischer        my $component_table = $installer::globals::source_msi->GetTable("Component");
386*9f91b7e3SAndre Fischer        foreach my $row (@{$component_table->GetAllRows()})
387*9f91b7e3SAndre Fischer        {
388*9f91b7e3SAndre Fischer            $source_component_data{$row->GetValue("Component")} = $row;
389*9f91b7e3SAndre Fischer        }
390*9f91b7e3SAndre Fischer
391*9f91b7e3SAndre Fischer        # Find source components that do not exist in the target components, ie have been removed.
392*9f91b7e3SAndre Fischer
393*9f91b7e3SAndre Fischer        # Process file components.
394*9f91b7e3SAndre Fischer        my @missing_source_component_names = ();
395*9f91b7e3SAndre Fischer        my %file_component_hash = map {$_ => 1} @$file_components;
396*9f91b7e3SAndre Fischer        foreach my $source_component_name (keys %source_component_data)
397*9f91b7e3SAndre Fischer        {
398*9f91b7e3SAndre Fischer            # In this loop we only process components for files and ignore those for registry entries.
399*9f91b7e3SAndre Fischer            next if $source_component_name =~ /^registry_/;
400*9f91b7e3SAndre Fischer
401*9f91b7e3SAndre Fischer            if ( ! defined $file_component_hash{$source_component_name})
402*9f91b7e3SAndre Fischer            {
403*9f91b7e3SAndre Fischer                push @missing_source_component_names, [$source_component_name, $source_component_name];
404*9f91b7e3SAndre Fischer                $installer::logger::Info->printf("missing file component %s\n", $source_component_name);
405*9f91b7e3SAndre Fischer            }
406*9f91b7e3SAndre Fischer        }
407*9f91b7e3SAndre Fischer
408*9f91b7e3SAndre Fischer        # Process registry components.
409*9f91b7e3SAndre Fischer        my %registry_component_hash = map {$_ => 1} @$registry_components;
410*9f91b7e3SAndre Fischer        my %registry_component_hash_normalized = map {remove_ooversion_from_component_name($_) => $_} @$registry_components;
411*9f91b7e3SAndre Fischer        my %target_registry_component_translation = ();
412*9f91b7e3SAndre Fischer        foreach my $source_component_name (keys %source_component_data)
413*9f91b7e3SAndre Fischer        {
414*9f91b7e3SAndre Fischer            # In this loop we only process components for registry entries and ignore those for files.
415*9f91b7e3SAndre Fischer            next if $source_component_name !~ /^registry_/;
416*9f91b7e3SAndre Fischer
417*9f91b7e3SAndre Fischer            if (defined $registry_component_hash{$source_component_name})
418*9f91b7e3SAndre Fischer            {
419*9f91b7e3SAndre Fischer                # Found the non-normalized name.
420*9f91b7e3SAndre Fischer            }
421*9f91b7e3SAndre Fischer            elsif (defined $registry_component_hash_normalized{
422*9f91b7e3SAndre Fischer                remove_ooversion_from_component_name($source_component_name)})
423*9f91b7e3SAndre Fischer            {
424*9f91b7e3SAndre Fischer                # Found the normalized name.
425*9f91b7e3SAndre Fischer                my $target_component_name = $registry_component_hash_normalized{
426*9f91b7e3SAndre Fischer                    remove_ooversion_from_component_name($source_component_name)};
427*9f91b7e3SAndre Fischer                $target_registry_component_translation{$target_component_name} = $source_component_name;
428*9f91b7e3SAndre Fischer                $installer::logger::Info->printf("found normalized component name %s\n", $source_component_name);
429*9f91b7e3SAndre Fischer                $installer::logger::Info->printf("    %s -> %s\n", $target_component_name, $source_component_name);
430*9f91b7e3SAndre Fischer            }
431*9f91b7e3SAndre Fischer            else
432*9f91b7e3SAndre Fischer            {
433*9f91b7e3SAndre Fischer                # Source component was not found.
434*9f91b7e3SAndre Fischer                push @missing_source_component_names, $source_component_name;
435*9f91b7e3SAndre Fischer                $installer::logger::Info->printf("missing component %s\n", $source_component_name);
436*9f91b7e3SAndre Fischer            }
437*9f91b7e3SAndre Fischer        }
438cdf0e10cSrcweir
439*9f91b7e3SAndre Fischer        if (scalar @missing_source_component_names > 0)
440*9f91b7e3SAndre Fischer        {
441*9f91b7e3SAndre Fischer            $installer::logger::Info->printf("Error: there are %d missing components\n",
442*9f91b7e3SAndre Fischer                scalar @missing_source_component_names);
443*9f91b7e3SAndre Fischer            return {};
444*9f91b7e3SAndre Fischer        }
445*9f91b7e3SAndre Fischer        else
446*9f91b7e3SAndre Fischer        {
447*9f91b7e3SAndre Fischer            return \%target_registry_component_translation;
448*9f91b7e3SAndre Fischer        }
449*9f91b7e3SAndre Fischer    }
450*9f91b7e3SAndre Fischer
451*9f91b7e3SAndre Fischer    return {};
452*9f91b7e3SAndre Fischer}
453*9f91b7e3SAndre Fischer
454*9f91b7e3SAndre Fischer
455*9f91b7e3SAndre Fischer
456*9f91b7e3SAndre Fischer
457*9f91b7e3SAndre Fischersub get_component_data ($$$$)
458*9f91b7e3SAndre Fischer{
459*9f91b7e3SAndre Fischer	my ($file_component_names,
460*9f91b7e3SAndre Fischer        $registry_component_names,
461*9f91b7e3SAndre Fischer        $files,
462*9f91b7e3SAndre Fischer        $registry_entries) = @_;
463*9f91b7e3SAndre Fischer
464*9f91b7e3SAndre Fischer    # When we are building a release then prepare building a patch by looking up some data
465*9f91b7e3SAndre Fischer    # from the previous release.
466*9f91b7e3SAndre Fischer    my %source_data = ();
467*9f91b7e3SAndre Fischer    if ($installer::globals::is_release)
468*9f91b7e3SAndre Fischer    {
469*9f91b7e3SAndre Fischer        my $source_component_table = $installer::globals::source_msi->GetTable("Component");
470*9f91b7e3SAndre Fischer        my $component_column_index = $source_component_table->GetColumnIndex("Component");
471*9f91b7e3SAndre Fischer        my $component_id_column_index = $source_component_table->GetColumnIndex("ComponentId");
472*9f91b7e3SAndre Fischer        my $key_path_column_index = $source_component_table->GetColumnIndex("KeyPath");
473*9f91b7e3SAndre Fischer        foreach my $source_row (@{$source_component_table->GetAllRows()})
474*9f91b7e3SAndre Fischer        {
475*9f91b7e3SAndre Fischer            my $component_name = $source_row->GetValue($component_column_index);
476*9f91b7e3SAndre Fischer            my $component_id = $source_row->GetValue($component_id_column_index);
477*9f91b7e3SAndre Fischer            my $key_path = $source_row->GetValue($key_path_column_index);
478*9f91b7e3SAndre Fischer
479*9f91b7e3SAndre Fischer            $source_data{$component_name} = {
480*9f91b7e3SAndre Fischer                'component_id' => $component_id,
481*9f91b7e3SAndre Fischer                'key_path' => $key_path
482*9f91b7e3SAndre Fischer            };
483*9f91b7e3SAndre Fischer        }
484*9f91b7e3SAndre Fischer    }
485*9f91b7e3SAndre Fischer
486*9f91b7e3SAndre Fischer    # Set up data for the target release.
487*9f91b7e3SAndre Fischer    # Use data from the source version where possible.
488*9f91b7e3SAndre Fischer    # Create missind data where necessary.
489*9f91b7e3SAndre Fischer
490*9f91b7e3SAndre Fischer    # Set up the target data with flags that remember whether a
491*9f91b7e3SAndre Fischer    # component contains files or registry entries.
492*9f91b7e3SAndre Fischer    my %target_data = ();
493*9f91b7e3SAndre Fischer    foreach my $name (@$file_component_names)
494*9f91b7e3SAndre Fischer    {
495*9f91b7e3SAndre Fischer        $target_data{$name} = {'is_file' => 1};
496*9f91b7e3SAndre Fischer    }
497*9f91b7e3SAndre Fischer    foreach my $name (@$registry_component_names)
498*9f91b7e3SAndre Fischer    {
499*9f91b7e3SAndre Fischer        $target_data{$name} = {'is_file' => 0};
500*9f91b7e3SAndre Fischer    }
501*9f91b7e3SAndre Fischer
502*9f91b7e3SAndre Fischer    # Add values for the ComponentId column.
503*9f91b7e3SAndre Fischer    $installer::logger::Lang->printf("preparing Component->ComponentId values\n");
504*9f91b7e3SAndre Fischer    foreach my $name (@$file_component_names,@$registry_component_names)
505*9f91b7e3SAndre Fischer    {
506*9f91b7e3SAndre Fischer        # Determine the component id.
507*9f91b7e3SAndre Fischer        my $guid = $installer::globals::is_release
508*9f91b7e3SAndre Fischer            ? $source_data{$name}->{'component_id'}
509*9f91b7e3SAndre Fischer            : undef;
510*9f91b7e3SAndre Fischer        if (defined $guid)
511*9f91b7e3SAndre Fischer        {
512*9f91b7e3SAndre Fischer            $installer::logger::Lang->printf("    reusing guid %s\n", $guid);
513*9f91b7e3SAndre Fischer        }
514*9f91b7e3SAndre Fischer        else
515*9f91b7e3SAndre Fischer        {
516*9f91b7e3SAndre Fischer            $guid = installer::windows::msiglobal::create_guid();
517*9f91b7e3SAndre Fischer            $installer::logger::Lang->printf("    creating new guid %s\n", $guid);
518*9f91b7e3SAndre Fischer        }
519*9f91b7e3SAndre Fischer        $target_data{$name}->{'component_id'} = $guid;
520*9f91b7e3SAndre Fischer    }
521*9f91b7e3SAndre Fischer
522*9f91b7e3SAndre Fischer    # Add values for the KeyPath column.
523*9f91b7e3SAndre Fischer    $installer::logger::Lang->printf("preparing Component->KeyPath values\n");
524*9f91b7e3SAndre Fischer    foreach my $name (@$file_component_names,@$registry_component_names)
525*9f91b7e3SAndre Fischer    {
526*9f91b7e3SAndre Fischer        # Determine the key path.
527*9f91b7e3SAndre Fischer        my $key_path = $installer::globals::is_release
528*9f91b7e3SAndre Fischer            ? $source_data{$name}->{'key_path'}
529*9f91b7e3SAndre Fischer            : undef;
530*9f91b7e3SAndre Fischer        if (defined $key_path)
531*9f91b7e3SAndre Fischer        {
532*9f91b7e3SAndre Fischer            $installer::logger::Lang->printf("    reusing key path %s\n", $key_path);
533*9f91b7e3SAndre Fischer        }
534*9f91b7e3SAndre Fischer        else
535*9f91b7e3SAndre Fischer        {
536*9f91b7e3SAndre Fischer            if ($target_data{$name}->{'is_file'})
537*9f91b7e3SAndre Fischer            {
538*9f91b7e3SAndre Fischer                $key_path = get_component_keypath($name, $files);
539*9f91b7e3SAndre Fischer            }
540*9f91b7e3SAndre Fischer            else
541*9f91b7e3SAndre Fischer            {
542*9f91b7e3SAndre Fischer                $key_path = get_component_keypath($name, $registry_entries);
543*9f91b7e3SAndre Fischer            }
544*9f91b7e3SAndre Fischer        }
545*9f91b7e3SAndre Fischer        $target_data{$name}->{'key_path'} = $key_path;
546*9f91b7e3SAndre Fischer    }
547*9f91b7e3SAndre Fischer
548*9f91b7e3SAndre Fischer    return \%target_data;
549*9f91b7e3SAndre Fischer}
550*9f91b7e3SAndre Fischer
551*9f91b7e3SAndre Fischer
552*9f91b7e3SAndre Fischer
553*9f91b7e3SAndre Fischer
554*9f91b7e3SAndre Fischersub	create_component_table_data ($$$$$$)
555*9f91b7e3SAndre Fischer{
556*9f91b7e3SAndre Fischer	my ($filesref, $registryref, $dirref, $allfilecomponentsref, $allregistrycomponents, $allvariables) = @_;
557*9f91b7e3SAndre Fischer
558*9f91b7e3SAndre Fischer    my $target_data = get_component_data($allfilecomponentsref, $allregistrycomponents, $filesref, $registryref);
559*9f91b7e3SAndre Fischer
560*9f91b7e3SAndre Fischer    my @table_data = ();
561*9f91b7e3SAndre Fischer
562*9f91b7e3SAndre Fischer	# File components
563*9f91b7e3SAndre Fischer	foreach my $name (@$allfilecomponentsref)
564cdf0e10cSrcweir	{
565cdf0e10cSrcweir		my %onecomponent = ();
566cdf0e10cSrcweir
567*9f91b7e3SAndre Fischer		$onecomponent{'name'} = $name;
568*9f91b7e3SAndre Fischer		$onecomponent{'guid'} = $target_data->{$name}->{'component_id'};
569*9f91b7e3SAndre Fischer		$onecomponent{'directory'} = get_file_component_directory($name, $filesref, $dirref);
570cdf0e10cSrcweir		if ( $onecomponent{'directory'} eq "IGNORE_COMP" ) { next; }
571*9f91b7e3SAndre Fischer		$onecomponent{'attributes'} = get_file_component_attributes($name, $filesref, $allvariables);
572*9f91b7e3SAndre Fischer		$onecomponent{'condition'} = get_file_component_condition($name, $filesref);
573*9f91b7e3SAndre Fischer		$onecomponent{'keypath'} = $target_data->{$name}->{'key_path'};
574cdf0e10cSrcweir
575*9f91b7e3SAndre Fischer        push @table_data, \%onecomponent;
576cdf0e10cSrcweir	}
577cdf0e10cSrcweir
578cdf0e10cSrcweir	# Registry components
579*9f91b7e3SAndre Fischer	foreach my $name (@$allregistrycomponents)
580cdf0e10cSrcweir	{
581cdf0e10cSrcweir		my %onecomponent = ();
582*9f91b7e3SAndre Fischer
583*9f91b7e3SAndre Fischer        $onecomponent{'name'} = $name;
584*9f91b7e3SAndre Fischer		$onecomponent{'guid'} = $target_data->{$name}->{'component_id'};
585cdf0e10cSrcweir		$onecomponent{'directory'} = get_registry_component_directory();
586*9f91b7e3SAndre Fischer		$onecomponent{'attributes'} = get_registry_component_attributes($name, $allvariables);
587*9f91b7e3SAndre Fischer		$onecomponent{'condition'} = get_component_condition($name);
588*9f91b7e3SAndre Fischer		$onecomponent{'keypath'} = $target_data->{$name}->{'key_path'};
589*9f91b7e3SAndre Fischer
590*9f91b7e3SAndre Fischer		push(@table_data, \%onecomponent);
591*9f91b7e3SAndre Fischer	}
592*9f91b7e3SAndre Fischer
593*9f91b7e3SAndre Fischer    return \@table_data;
594*9f91b7e3SAndre Fischer}
595*9f91b7e3SAndre Fischer
596*9f91b7e3SAndre Fischer
597cdf0e10cSrcweir
598cdf0e10cSrcweir
599*9f91b7e3SAndre Fischer###################################################################
600*9f91b7e3SAndre Fischer# Creating the file Componen.idt dynamically
601*9f91b7e3SAndre Fischer# Content:
602*9f91b7e3SAndre Fischer# Component ComponentId Directory_ Attributes Condition KeyPath
603*9f91b7e3SAndre Fischer###################################################################
604*9f91b7e3SAndre Fischer
605*9f91b7e3SAndre Fischer
606*9f91b7e3SAndre Fischersub	create_component_table ($$)
607*9f91b7e3SAndre Fischer{
608*9f91b7e3SAndre Fischer	my ($table_data, $basedir) = @_;
609*9f91b7e3SAndre Fischer
610*9f91b7e3SAndre Fischer	my @componenttable = ();
611*9f91b7e3SAndre Fischer
612*9f91b7e3SAndre Fischer	my ($oneline, $infoline);
613*9f91b7e3SAndre Fischer
614*9f91b7e3SAndre Fischer	installer::windows::idtglobal::write_idt_header(\@componenttable, "component");
615*9f91b7e3SAndre Fischer
616*9f91b7e3SAndre Fischer	foreach my $item (@$table_data)
617*9f91b7e3SAndre Fischer	{
618*9f91b7e3SAndre Fischer		$oneline = sprintf("%s\t%s\t%s\t%s\t%s\t%s\n",
619*9f91b7e3SAndre Fischer            $item->{'name'},
620*9f91b7e3SAndre Fischer            $item->{'guid'},
621*9f91b7e3SAndre Fischer            $item->{'directory'},
622*9f91b7e3SAndre Fischer            $item->{'attributes'},
623*9f91b7e3SAndre Fischer            $item->{'condition'},
624*9f91b7e3SAndre Fischer            $item->{'keypath'});
625cdf0e10cSrcweir		push(@componenttable, $oneline);
626*9f91b7e3SAndre Fischer	}
627cdf0e10cSrcweir
628cdf0e10cSrcweir	# Saving the file
629cdf0e10cSrcweir
630cdf0e10cSrcweir	my $componenttablename = $basedir . $installer::globals::separator . "Componen.idt";
631cdf0e10cSrcweir	installer::files::save_file($componenttablename ,\@componenttable);
632cdf0e10cSrcweir	$infoline = "Created idt file: $componenttablename\n";
633b274bc22SAndre Fischer	$installer::logger::Lang->print($infoline);
634cdf0e10cSrcweir}
635cdf0e10cSrcweir
636*9f91b7e3SAndre Fischer
637*9f91b7e3SAndre Fischer
638*9f91b7e3SAndre Fischer
639cdf0e10cSrcweir####################################################################################
640cdf0e10cSrcweir# Returning a component for a scp module gid.
641cdf0e10cSrcweir# Pairs are saved in the files collector.
642cdf0e10cSrcweir####################################################################################
643cdf0e10cSrcweir
644cdf0e10cSrcweirsub get_component_name_from_modulegid
645cdf0e10cSrcweir{
646cdf0e10cSrcweir	my ($modulegid, $filesref) = @_;
647cdf0e10cSrcweir
648cdf0e10cSrcweir	my $componentname = "";
649cdf0e10cSrcweir
650cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$filesref}; $i++ )
651cdf0e10cSrcweir	{
652cdf0e10cSrcweir		my $onefile = ${$filesref}[$i];
653cdf0e10cSrcweir
654cdf0e10cSrcweir		if ( $onefile->{'modules'} )
655cdf0e10cSrcweir		{
656cdf0e10cSrcweir			my $filemodules = $onefile->{'modules'};
657cdf0e10cSrcweir			my $filemodulesarrayref = installer::converter::convert_stringlist_into_array_without_newline(\$filemodules, ",");
658cdf0e10cSrcweir
659cdf0e10cSrcweir			if (installer::existence::exists_in_array($modulegid, $filemodulesarrayref))
660cdf0e10cSrcweir			{
661cdf0e10cSrcweir				$componentname = $onefile->{'componentname'};
662cdf0e10cSrcweir				last;
663cdf0e10cSrcweir			}
664cdf0e10cSrcweir		}
665cdf0e10cSrcweir	}
666cdf0e10cSrcweir
667cdf0e10cSrcweir	return $componentname;
668cdf0e10cSrcweir}
669cdf0e10cSrcweir
670cdf0e10cSrcweir####################################################################################
671cdf0e10cSrcweir# Updating the file Environm.idt dynamically
672cdf0e10cSrcweir# Content:
673cdf0e10cSrcweir# Environment Name Value Component_
674cdf0e10cSrcweir####################################################################################
675cdf0e10cSrcweir
676cdf0e10cSrcweirsub set_component_in_environment_table
677cdf0e10cSrcweir{
678cdf0e10cSrcweir	my ($basedir, $filesref) = @_;
679cdf0e10cSrcweir
680cdf0e10cSrcweir	my $infoline = "";
681cdf0e10cSrcweir
682cdf0e10cSrcweir	my $environmentfilename = $basedir . $installer::globals::separator . "Environm.idt";
683cdf0e10cSrcweir
684cdf0e10cSrcweir	if ( -f $environmentfilename )	# only do something, if file exists
685cdf0e10cSrcweir	{
686cdf0e10cSrcweir		my $environmentfile = installer::files::read_file($environmentfilename);
687cdf0e10cSrcweir
688cdf0e10cSrcweir		for ( my $i = 3; $i <= $#{$environmentfile}; $i++ )	# starting in line 4 of Environm.idt
689cdf0e10cSrcweir		{
690cdf0e10cSrcweir			if ( ${$environmentfile}[$i] =~ /^\s*(.*?)\t(.*?)\t(.*?)\t(.*?)\s*$/ )
691cdf0e10cSrcweir			{
692cdf0e10cSrcweir				my $modulegid = $4; # in Environment table a scp module gid can be used as component replacement
693cdf0e10cSrcweir
694cdf0e10cSrcweir				my $componentname = get_component_name_from_modulegid($modulegid, $filesref);
695cdf0e10cSrcweir
696cdf0e10cSrcweir				if ( $componentname )	# only do something if a component could be found
697cdf0e10cSrcweir				{
698cdf0e10cSrcweir					$infoline = "Updated Environment table:\n";
699b274bc22SAndre Fischer					$installer::logger::Lang->print($infoline);
700cdf0e10cSrcweir					$infoline = "Old line: ${$environmentfile}[$i]\n";
701b274bc22SAndre Fischer					$installer::logger::Lang->print($infoline);
702cdf0e10cSrcweir
703cdf0e10cSrcweir					${$environmentfile}[$i] =~ s/$modulegid/$componentname/;
704cdf0e10cSrcweir
705cdf0e10cSrcweir					$infoline = "New line: ${$environmentfile}[$i]\n";
706b274bc22SAndre Fischer					$installer::logger::Lang->print($infoline);
707cdf0e10cSrcweir
708cdf0e10cSrcweir				}
709cdf0e10cSrcweir			}
710cdf0e10cSrcweir		}
711cdf0e10cSrcweir
712cdf0e10cSrcweir		# Saving the file
713cdf0e10cSrcweir
714cdf0e10cSrcweir		installer::files::save_file($environmentfilename ,$environmentfile);
715cdf0e10cSrcweir		$infoline = "Updated idt file: $environmentfilename\n";
716b274bc22SAndre Fischer		$installer::logger::Lang->print($infoline);
717cdf0e10cSrcweir
718cdf0e10cSrcweir	}
719cdf0e10cSrcweir}
720cdf0e10cSrcweir
721*9f91b7e3SAndre Fischer
722*9f91b7e3SAndre Fischer
723*9f91b7e3SAndre Fischer
724*9f91b7e3SAndre Fischersub apply_component_translation ($@)
725*9f91b7e3SAndre Fischer{
726*9f91b7e3SAndre Fischer    my ($translation_map, @component_names) = @_;
727*9f91b7e3SAndre Fischer
728*9f91b7e3SAndre Fischer    my @translated_names = ();
729*9f91b7e3SAndre Fischer    foreach my $component_name (@component_names)
730*9f91b7e3SAndre Fischer    {
731*9f91b7e3SAndre Fischer        my $translated_name = $translation_map->{$component_name};
732*9f91b7e3SAndre Fischer        if (defined $translated_name)
733*9f91b7e3SAndre Fischer        {
734*9f91b7e3SAndre Fischer            push @translated_names, $translated_name;
735*9f91b7e3SAndre Fischer        }
736*9f91b7e3SAndre Fischer        else
737*9f91b7e3SAndre Fischer        {
738*9f91b7e3SAndre Fischer            push @translated_names, $component_name;
739*9f91b7e3SAndre Fischer        }
740*9f91b7e3SAndre Fischer    }
741*9f91b7e3SAndre Fischer
742*9f91b7e3SAndre Fischer    return @translated_names;
743*9f91b7e3SAndre Fischer}
744*9f91b7e3SAndre Fischer
745*9f91b7e3SAndre Fischer
746b274bc22SAndre Fischer1;
747