1*9780544fSAndrew Rist#**************************************************************
2*9780544fSAndrew Rist#
3*9780544fSAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
4*9780544fSAndrew Rist#  or more contributor license agreements.  See the NOTICE file
5*9780544fSAndrew Rist#  distributed with this work for additional information
6*9780544fSAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
7*9780544fSAndrew Rist#  to you under the Apache License, Version 2.0 (the
8*9780544fSAndrew Rist#  "License"); you may not use this file except in compliance
9*9780544fSAndrew Rist#  with the License.  You may obtain a copy of the License at
10*9780544fSAndrew Rist#
11*9780544fSAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
12*9780544fSAndrew Rist#
13*9780544fSAndrew Rist#  Unless required by applicable law or agreed to in writing,
14*9780544fSAndrew Rist#  software distributed under the License is distributed on an
15*9780544fSAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9780544fSAndrew Rist#  KIND, either express or implied.  See the License for the
17*9780544fSAndrew Rist#  specific language governing permissions and limitations
18*9780544fSAndrew Rist#  under the License.
19*9780544fSAndrew Rist#
20*9780544fSAndrew Rist#**************************************************************
21*9780544fSAndrew Rist
22*9780544fSAndrew 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
34cdf0e10cSrcweir##############################################################
35cdf0e10cSrcweir# Returning a globally unique ID (GUID) for a component
36cdf0e10cSrcweir# If the component is new, a unique guid has to be created.
37cdf0e10cSrcweir# If the component already exists, the guid has to be
38cdf0e10cSrcweir# taken from a list component <-> guid
39cdf0e10cSrcweir# Sample for a guid: {B68FD953-3CEF-4489-8269-8726848056E8}
40cdf0e10cSrcweir##############################################################
41cdf0e10cSrcweir
42cdf0e10cSrcweirsub get_component_guid
43cdf0e10cSrcweir{
44cdf0e10cSrcweir	my ( $componentname, $componentidhashref ) = @_;
45cdf0e10cSrcweir
46cdf0e10cSrcweir	# At this time only a template
47cdf0e10cSrcweir	my $returnvalue = "\{COMPONENTGUID\}";
48cdf0e10cSrcweir
49cdf0e10cSrcweir	if (( $installer::globals::updatedatabase ) && ( exists($componentidhashref->{$componentname}) ))
50cdf0e10cSrcweir	{
51cdf0e10cSrcweir		$returnvalue = $componentidhashref->{$componentname};
52cdf0e10cSrcweir	}
53cdf0e10cSrcweir
54cdf0e10cSrcweir	# Returning a ComponentID, that is assigned in scp project
55cdf0e10cSrcweir	if ( exists($installer::globals::componentid{$componentname}) )
56cdf0e10cSrcweir	{
57cdf0e10cSrcweir		$returnvalue = "\{" . $installer::globals::componentid{$componentname} . "\}";
58cdf0e10cSrcweir	}
59cdf0e10cSrcweir
60cdf0e10cSrcweir	return $returnvalue;
61cdf0e10cSrcweir}
62cdf0e10cSrcweir
63cdf0e10cSrcweir##############################################################
64cdf0e10cSrcweir# Returning the directory for a file component.
65cdf0e10cSrcweir##############################################################
66cdf0e10cSrcweir
67cdf0e10cSrcweirsub get_file_component_directory
68cdf0e10cSrcweir{
69cdf0e10cSrcweir	my ($componentname, $filesref, $dirref) = @_;
70cdf0e10cSrcweir
71cdf0e10cSrcweir	my ($onefile, $component, $onedir, $hostname, $uniquedir);
72cdf0e10cSrcweir	my $found = 0;
73cdf0e10cSrcweir
74cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$filesref}; $i++ )
75cdf0e10cSrcweir	{
76cdf0e10cSrcweir		$onefile = 	${$filesref}[$i];
77cdf0e10cSrcweir		$component = $onefile->{'componentname'};
78cdf0e10cSrcweir
79cdf0e10cSrcweir		if ( $component eq $componentname )
80cdf0e10cSrcweir		{
81cdf0e10cSrcweir			$found = 1;
82cdf0e10cSrcweir			last;
83cdf0e10cSrcweir		}
84cdf0e10cSrcweir	}
85cdf0e10cSrcweir
86cdf0e10cSrcweir	if (!($found))
87cdf0e10cSrcweir	{
88cdf0e10cSrcweir		# This component can be ignored, if it exists in a version with extension "_pff" (this was renamed in file::get_sequence_for_file() )
89cdf0e10cSrcweir		my $ignore_this_component = 0;
90cdf0e10cSrcweir		my $origcomponentname = $componentname;
91cdf0e10cSrcweir		my $componentname = $componentname . "_pff";
92cdf0e10cSrcweir
93cdf0e10cSrcweir		for ( my $j = 0; $j <= $#{$filesref}; $j++ )
94cdf0e10cSrcweir		{
95cdf0e10cSrcweir			$onefile = 	${$filesref}[$j];
96cdf0e10cSrcweir			$component = $onefile->{'componentname'};
97cdf0e10cSrcweir
98cdf0e10cSrcweir			if ( $component eq $componentname )
99cdf0e10cSrcweir			{
100cdf0e10cSrcweir				$ignore_this_component = 1;
101cdf0e10cSrcweir				last;
102cdf0e10cSrcweir			}
103cdf0e10cSrcweir		}
104cdf0e10cSrcweir
105cdf0e10cSrcweir		if ( $ignore_this_component ) { return "IGNORE_COMP"; }
106cdf0e10cSrcweir		else { installer::exiter::exit_program("ERROR: Did not find component \"$origcomponentname\" in file collection", "get_file_component_directory"); }
107cdf0e10cSrcweir	}
108cdf0e10cSrcweir
109cdf0e10cSrcweir	my $localstyles = "";
110cdf0e10cSrcweir
111cdf0e10cSrcweir	if ( $onefile->{'Styles'} ) { $localstyles = $onefile->{'Styles'}; }
112cdf0e10cSrcweir
113cdf0e10cSrcweir	if ( $localstyles =~ /\bFONT\b/ )	# special handling for font files
114cdf0e10cSrcweir	{
115cdf0e10cSrcweir		return $installer::globals::fontsfolder;
116cdf0e10cSrcweir	}
117cdf0e10cSrcweir
118cdf0e10cSrcweir	my $destdir = "";
119cdf0e10cSrcweir
120cdf0e10cSrcweir	if ( $onefile->{'Dir'} ) { $destdir = $onefile->{'Dir'}; }
121cdf0e10cSrcweir
122cdf0e10cSrcweir	if ( $destdir =~ /\bPREDEFINED_OSSHELLNEWDIR\b/ )	# special handling for shellnew files
123cdf0e10cSrcweir	{
124cdf0e10cSrcweir		return $installer::globals::templatefolder;
125cdf0e10cSrcweir	}
126cdf0e10cSrcweir
127cdf0e10cSrcweir	my $destination = $onefile->{'destination'};
128cdf0e10cSrcweir
129cdf0e10cSrcweir	installer::pathanalyzer::get_path_from_fullqualifiedname(\$destination);
130cdf0e10cSrcweir
131cdf0e10cSrcweir	$destination =~ s/\Q$installer::globals::separator\E\s*$//;
132cdf0e10cSrcweir
133cdf0e10cSrcweir	# This path has to be defined in the directory collection at "HostName"
134cdf0e10cSrcweir
135cdf0e10cSrcweir	if ($destination eq "")		# files in the installation root
136cdf0e10cSrcweir	{
137cdf0e10cSrcweir		$uniquedir = "INSTALLLOCATION";
138cdf0e10cSrcweir	}
139cdf0e10cSrcweir	else
140cdf0e10cSrcweir	{
141cdf0e10cSrcweir		$found = 0;
142cdf0e10cSrcweir
143cdf0e10cSrcweir		for ( my $i = 0; $i <= $#{$dirref}; $i++ )
144cdf0e10cSrcweir		{
145cdf0e10cSrcweir			$onedir = 	${$dirref}[$i];
146cdf0e10cSrcweir			$hostname = $onedir->{'HostName'};
147cdf0e10cSrcweir
148cdf0e10cSrcweir			if ( $hostname eq $destination )
149cdf0e10cSrcweir			{
150cdf0e10cSrcweir				$found = 1;
151cdf0e10cSrcweir				last;
152cdf0e10cSrcweir			}
153cdf0e10cSrcweir		}
154cdf0e10cSrcweir
155cdf0e10cSrcweir		if (!($found))
156cdf0e10cSrcweir		{
157cdf0e10cSrcweir			installer::exiter::exit_program("ERROR: Did not find destination $destination in directory collection", "get_file_component_directory");
158cdf0e10cSrcweir		}
159cdf0e10cSrcweir
160cdf0e10cSrcweir		$uniquedir = $onedir->{'uniquename'};
161cdf0e10cSrcweir
162cdf0e10cSrcweir		if ( $uniquedir eq $installer::globals::officeinstalldirectory )
163cdf0e10cSrcweir		{
164cdf0e10cSrcweir			$uniquedir = "INSTALLLOCATION";
165cdf0e10cSrcweir		}
166cdf0e10cSrcweir	}
167cdf0e10cSrcweir
168cdf0e10cSrcweir	$onefile->{'uniquedirname'} = $uniquedir;		# saving it in the file collection
169cdf0e10cSrcweir
170cdf0e10cSrcweir	return $uniquedir
171cdf0e10cSrcweir}
172cdf0e10cSrcweir
173cdf0e10cSrcweir##############################################################
174cdf0e10cSrcweir# Returning the directory for a registry component.
175cdf0e10cSrcweir# This cannot be a useful value
176cdf0e10cSrcweir##############################################################
177cdf0e10cSrcweir
178cdf0e10cSrcweirsub get_registry_component_directory
179cdf0e10cSrcweir{
180cdf0e10cSrcweir	my $componentdir = "INSTALLLOCATION";
181cdf0e10cSrcweir
182cdf0e10cSrcweir	return $componentdir;
183cdf0e10cSrcweir}
184cdf0e10cSrcweir
185cdf0e10cSrcweir##############################################################
186cdf0e10cSrcweir# Returning the attributes for a file component.
187cdf0e10cSrcweir# Always 8 in this first try?
188cdf0e10cSrcweir##############################################################
189cdf0e10cSrcweir
190cdf0e10cSrcweirsub get_file_component_attributes
191cdf0e10cSrcweir{
192cdf0e10cSrcweir	my ($componentname, $filesref, $allvariables) = @_;
193cdf0e10cSrcweir
194cdf0e10cSrcweir	my $attributes;
195cdf0e10cSrcweir
196cdf0e10cSrcweir	$attributes = 2;
197cdf0e10cSrcweir
198cdf0e10cSrcweir	# special handling for font files
199cdf0e10cSrcweir
200cdf0e10cSrcweir	my $onefile;
201cdf0e10cSrcweir	my $found = 0;
202cdf0e10cSrcweir
203cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$filesref}; $i++ )
204cdf0e10cSrcweir	{
205cdf0e10cSrcweir		$onefile = 	${$filesref}[$i];
206cdf0e10cSrcweir		my $component = $onefile->{'componentname'};
207cdf0e10cSrcweir
208cdf0e10cSrcweir		if ( $component eq $componentname )
209cdf0e10cSrcweir		{
210cdf0e10cSrcweir			$found = 1;
211cdf0e10cSrcweir			last;
212cdf0e10cSrcweir		}
213cdf0e10cSrcweir	}
214cdf0e10cSrcweir
215cdf0e10cSrcweir	if (!($found))
216cdf0e10cSrcweir	{
217cdf0e10cSrcweir		installer::exiter::exit_program("ERROR: Did not find component in file collection", "get_file_component_attributes");
218cdf0e10cSrcweir	}
219cdf0e10cSrcweir
220cdf0e10cSrcweir	my $localstyles = "";
221cdf0e10cSrcweir
222cdf0e10cSrcweir	if ( $onefile->{'Styles'} ) { $localstyles = $onefile->{'Styles'}; }
223cdf0e10cSrcweir
224cdf0e10cSrcweir	if ( $localstyles =~ /\bFONT\b/ )
225cdf0e10cSrcweir	{
226cdf0e10cSrcweir		$attributes = 16;	# font files will not be deinstalled
227cdf0e10cSrcweir	}
228cdf0e10cSrcweir
229cdf0e10cSrcweir	if ( $localstyles =~ /\bASSEMBLY\b/ )
230cdf0e10cSrcweir	{
231cdf0e10cSrcweir		$attributes = 0;	# Assembly files cannot run from source
232cdf0e10cSrcweir	}
233cdf0e10cSrcweir
234cdf0e10cSrcweir	if (( $onefile->{'Dir'} =~ /\bPREDEFINED_OSSHELLNEWDIR\b/ ) || ( $onefile->{'needs_user_registry_key'} ))
235cdf0e10cSrcweir	{
236cdf0e10cSrcweir		$attributes = 4;	# Files in shellnew dir and in non advertised startmenu entries must have user registry key as KeyPath
237cdf0e10cSrcweir	}
238cdf0e10cSrcweir
239cdf0e10cSrcweir	# Adding 256, if this is a 64 bit installation set.
240cdf0e10cSrcweir	if (( $allvariables->{'64BITPRODUCT'} ) && ( $allvariables->{'64BITPRODUCT'} == 1 )) { $attributes = $attributes + 256; }
241cdf0e10cSrcweir
242cdf0e10cSrcweir	return $attributes
243cdf0e10cSrcweir}
244cdf0e10cSrcweir
245cdf0e10cSrcweir##############################################################
246cdf0e10cSrcweir# Returning the attributes for a registry component.
247cdf0e10cSrcweir# Always 4, indicating, the keypath is a defined in
248cdf0e10cSrcweir# table registry
249cdf0e10cSrcweir##############################################################
250cdf0e10cSrcweir
251cdf0e10cSrcweirsub get_registry_component_attributes
252cdf0e10cSrcweir{
253cdf0e10cSrcweir	my ($componentname, $allvariables) = @_;
254cdf0e10cSrcweir
255cdf0e10cSrcweir	my $attributes;
256cdf0e10cSrcweir
257cdf0e10cSrcweir	$attributes = 4;
258cdf0e10cSrcweir
259cdf0e10cSrcweir	# Adding 256, if this is a 64 bit installation set.
260cdf0e10cSrcweir	if (( $allvariables->{'64BITPRODUCT'} ) && ( $allvariables->{'64BITPRODUCT'} == 1 )) { $attributes = $attributes + 256; }
261cdf0e10cSrcweir
262cdf0e10cSrcweir	if ( exists($installer::globals::dontdeletecomponents{$componentname}) ) { $attributes = $attributes + 16; }
263cdf0e10cSrcweir
264cdf0e10cSrcweir	return $attributes
265cdf0e10cSrcweir}
266cdf0e10cSrcweir
267cdf0e10cSrcweir##############################################################
268cdf0e10cSrcweir# Returning the conditions for a component.
269cdf0e10cSrcweir# This is important for language dependent components
270cdf0e10cSrcweir# in multilingual installation sets.
271cdf0e10cSrcweir##############################################################
272cdf0e10cSrcweir
273cdf0e10cSrcweirsub get_file_component_condition
274cdf0e10cSrcweir{
275cdf0e10cSrcweir	my ($componentname, $filesref) = @_;
276cdf0e10cSrcweir
277cdf0e10cSrcweir	my $condition = "";
278cdf0e10cSrcweir
279cdf0e10cSrcweir	if (exists($installer::globals::componentcondition{$componentname}))
280cdf0e10cSrcweir	{
281cdf0e10cSrcweir		$condition = $installer::globals::componentcondition{$componentname};
282cdf0e10cSrcweir	}
283cdf0e10cSrcweir
284cdf0e10cSrcweir	# there can be also tree conditions for multilayer products
285cdf0e10cSrcweir	if (exists($installer::globals::treeconditions{$componentname}))
286cdf0e10cSrcweir	{
287cdf0e10cSrcweir		if ( $condition eq "" )
288cdf0e10cSrcweir		{
289cdf0e10cSrcweir			$condition = $installer::globals::treeconditions{$componentname};
290cdf0e10cSrcweir		}
291cdf0e10cSrcweir		else
292cdf0e10cSrcweir		{
293cdf0e10cSrcweir			$condition = "($condition) And ($installer::globals::treeconditions{$componentname})";
294cdf0e10cSrcweir		}
295cdf0e10cSrcweir	}
296cdf0e10cSrcweir
297cdf0e10cSrcweir	return $condition
298cdf0e10cSrcweir}
299cdf0e10cSrcweir
300cdf0e10cSrcweir##############################################################
301cdf0e10cSrcweir# Returning the conditions for a registry component.
302cdf0e10cSrcweir##############################################################
303cdf0e10cSrcweir
304cdf0e10cSrcweirsub get_component_condition
305cdf0e10cSrcweir{
306cdf0e10cSrcweir	my ($componentname) = @_;
307cdf0e10cSrcweir
308cdf0e10cSrcweir	my $condition;
309cdf0e10cSrcweir
310cdf0e10cSrcweir	$condition = "";	# Always ?
311cdf0e10cSrcweir
312cdf0e10cSrcweir	if (exists($installer::globals::componentcondition{$componentname}))
313cdf0e10cSrcweir	{
314cdf0e10cSrcweir		$condition = $installer::globals::componentcondition{$componentname};
315cdf0e10cSrcweir	}
316cdf0e10cSrcweir
317cdf0e10cSrcweir	return $condition
318cdf0e10cSrcweir}
319cdf0e10cSrcweir
320cdf0e10cSrcweir####################################################################
321cdf0e10cSrcweir# Returning the keypath for a component.
322cdf0e10cSrcweir# This will be the name of the first file/registry, found in the
323cdf0e10cSrcweir# collection $itemsref
324cdf0e10cSrcweir# Attention: This has to be the unique (file)name, not the
325cdf0e10cSrcweir# real filename!
326cdf0e10cSrcweir####################################################################
327cdf0e10cSrcweir
328cdf0e10cSrcweirsub get_component_keypath
329cdf0e10cSrcweir{
330cdf0e10cSrcweir	my ($componentname, $itemsref, $componentidkeypathhashref) = @_;
331cdf0e10cSrcweir
332cdf0e10cSrcweir	my $oneitem;
333cdf0e10cSrcweir	my $found = 0;
334cdf0e10cSrcweir	my $infoline = "";
335cdf0e10cSrcweir
336cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$itemsref}; $i++ )
337cdf0e10cSrcweir	{
338cdf0e10cSrcweir		$oneitem = 	${$itemsref}[$i];
339cdf0e10cSrcweir		my $component = $oneitem->{'componentname'};
340cdf0e10cSrcweir
341cdf0e10cSrcweir		if ( $component eq $componentname )
342cdf0e10cSrcweir		{
343cdf0e10cSrcweir			$found = 1;
344cdf0e10cSrcweir			last;
345cdf0e10cSrcweir		}
346cdf0e10cSrcweir	}
347cdf0e10cSrcweir
348cdf0e10cSrcweir	if (!($found))
349cdf0e10cSrcweir	{
350cdf0e10cSrcweir		installer::exiter::exit_program("ERROR: Did not find component in file/registry collection, function get_component_keypath", "get_component_keypath");
351cdf0e10cSrcweir	}
352cdf0e10cSrcweir
353cdf0e10cSrcweir	my $keypath = $oneitem->{'uniquename'};	# "uniquename", not "Name"
354cdf0e10cSrcweir
355cdf0e10cSrcweir	# Special handling for updates from existing databases, because KeyPath must not change
356cdf0e10cSrcweir	if (( $installer::globals::updatedatabase ) && ( exists($componentidkeypathhashref->{$componentname}) ))
357cdf0e10cSrcweir	{
358cdf0e10cSrcweir		$keypath = $componentidkeypathhashref->{$componentname};
359cdf0e10cSrcweir		# -> check, if this is a valid key path?!
360cdf0e10cSrcweir		if ( $keypath ne $oneitem->{'uniquename'} )
361cdf0e10cSrcweir		{
362cdf0e10cSrcweir			# Warning: This keypath was changed because of info from old database
363cdf0e10cSrcweir			$infoline = "WARNING: The KeyPath for component \"$componentname\" was changed from \"$oneitem->{'uniquename'}\" to \"$keypath\" because of information from update database";
364cdf0e10cSrcweir			push(@installer::globals::logfileinfo, $infoline);
365cdf0e10cSrcweir		}
366cdf0e10cSrcweir	}
367cdf0e10cSrcweir
368cdf0e10cSrcweir	# Special handling for components in PREDEFINED_OSSHELLNEWDIR. These components
369cdf0e10cSrcweir	# need as KeyPath a RegistryItem in HKCU
370cdf0e10cSrcweir	if ( $oneitem->{'userregkeypath'} ) { $keypath = $oneitem->{'userregkeypath'}; }
371cdf0e10cSrcweir
372cdf0e10cSrcweir	# saving it in the file and registry collection
373cdf0e10cSrcweir	$oneitem->{'keypath'} = $keypath;
374cdf0e10cSrcweir
375cdf0e10cSrcweir	return $keypath
376cdf0e10cSrcweir}
377cdf0e10cSrcweir
378cdf0e10cSrcweir###################################################################
379cdf0e10cSrcweir# Creating the file Componen.idt dynamically
380cdf0e10cSrcweir# Content:
381cdf0e10cSrcweir# Component ComponentId Directory_ Attributes Condition KeyPath
382cdf0e10cSrcweir###################################################################
383cdf0e10cSrcweir
384cdf0e10cSrcweirsub	create_component_table
385cdf0e10cSrcweir{
386cdf0e10cSrcweir	my ($filesref, $registryref, $dirref, $allfilecomponentsref, $allregistrycomponents, $basedir, $componentidhashref, $componentidkeypathhashref, $allvariables) = @_;
387cdf0e10cSrcweir
388cdf0e10cSrcweir	my @componenttable = ();
389cdf0e10cSrcweir
390cdf0e10cSrcweir	my ($oneline, $infoline);
391cdf0e10cSrcweir
392cdf0e10cSrcweir	installer::windows::idtglobal::write_idt_header(\@componenttable, "component");
393cdf0e10cSrcweir
394cdf0e10cSrcweir	# collect_layer_conditions();
395cdf0e10cSrcweir
396cdf0e10cSrcweir
397cdf0e10cSrcweir	# File components
398cdf0e10cSrcweir
399cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$allfilecomponentsref}; $i++ )
400cdf0e10cSrcweir	{
401cdf0e10cSrcweir		my %onecomponent = ();
402cdf0e10cSrcweir
403cdf0e10cSrcweir		$onecomponent{'name'} = ${$allfilecomponentsref}[$i];
404cdf0e10cSrcweir		$onecomponent{'guid'} = get_component_guid($onecomponent{'name'}, $componentidhashref);
405cdf0e10cSrcweir		$onecomponent{'directory'} = get_file_component_directory($onecomponent{'name'}, $filesref, $dirref);
406cdf0e10cSrcweir		if ( $onecomponent{'directory'} eq "IGNORE_COMP" ) { next; }
407cdf0e10cSrcweir		$onecomponent{'attributes'} = get_file_component_attributes($onecomponent{'name'}, $filesref, $allvariables);
408cdf0e10cSrcweir		$onecomponent{'condition'} = get_file_component_condition($onecomponent{'name'}, $filesref);
409cdf0e10cSrcweir		$onecomponent{'keypath'} = get_component_keypath($onecomponent{'name'}, $filesref, $componentidkeypathhashref);
410cdf0e10cSrcweir
411cdf0e10cSrcweir		$oneline = $onecomponent{'name'} . "\t" . $onecomponent{'guid'} . "\t" . $onecomponent{'directory'} . "\t"
412cdf0e10cSrcweir				. $onecomponent{'attributes'} . "\t" . $onecomponent{'condition'} . "\t" . $onecomponent{'keypath'} . "\n";
413cdf0e10cSrcweir
414cdf0e10cSrcweir		push(@componenttable, $oneline);
415cdf0e10cSrcweir	}
416cdf0e10cSrcweir
417cdf0e10cSrcweir	# Registry components
418cdf0e10cSrcweir
419cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$allregistrycomponents}; $i++ )
420cdf0e10cSrcweir	{
421cdf0e10cSrcweir		my %onecomponent = ();
422cdf0e10cSrcweir
423cdf0e10cSrcweir		$onecomponent{'name'} = ${$allregistrycomponents}[$i];
424cdf0e10cSrcweir		$onecomponent{'guid'} = get_component_guid($onecomponent{'name'}, $componentidhashref);
425cdf0e10cSrcweir		$onecomponent{'directory'} = get_registry_component_directory();
426cdf0e10cSrcweir		$onecomponent{'attributes'} = get_registry_component_attributes($onecomponent{'name'}, $allvariables);
427cdf0e10cSrcweir		$onecomponent{'condition'} = get_component_condition($onecomponent{'name'});
428cdf0e10cSrcweir		$onecomponent{'keypath'} = get_component_keypath($onecomponent{'name'}, $registryref, $componentidkeypathhashref);
429cdf0e10cSrcweir
430cdf0e10cSrcweir		$oneline = $onecomponent{'name'} . "\t" . $onecomponent{'guid'} . "\t" . $onecomponent{'directory'} . "\t"
431cdf0e10cSrcweir				. $onecomponent{'attributes'} . "\t" . $onecomponent{'condition'} . "\t" . $onecomponent{'keypath'} . "\n";
432cdf0e10cSrcweir
433cdf0e10cSrcweir		push(@componenttable, $oneline);
434cdf0e10cSrcweir	}
435cdf0e10cSrcweir
436cdf0e10cSrcweir	# Saving the file
437cdf0e10cSrcweir
438cdf0e10cSrcweir	my $componenttablename = $basedir . $installer::globals::separator . "Componen.idt";
439cdf0e10cSrcweir	installer::files::save_file($componenttablename ,\@componenttable);
440cdf0e10cSrcweir	$infoline = "Created idt file: $componenttablename\n";
441cdf0e10cSrcweir	push(@installer::globals::logfileinfo, $infoline);
442cdf0e10cSrcweir}
443cdf0e10cSrcweir
444cdf0e10cSrcweir####################################################################################
445cdf0e10cSrcweir# Returning a component for a scp module gid.
446cdf0e10cSrcweir# Pairs are saved in the files collector.
447cdf0e10cSrcweir####################################################################################
448cdf0e10cSrcweir
449cdf0e10cSrcweirsub get_component_name_from_modulegid
450cdf0e10cSrcweir{
451cdf0e10cSrcweir	my ($modulegid, $filesref) = @_;
452cdf0e10cSrcweir
453cdf0e10cSrcweir	my $componentname = "";
454cdf0e10cSrcweir
455cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$filesref}; $i++ )
456cdf0e10cSrcweir	{
457cdf0e10cSrcweir		my $onefile = ${$filesref}[$i];
458cdf0e10cSrcweir
459cdf0e10cSrcweir		if ( $onefile->{'modules'} )
460cdf0e10cSrcweir		{
461cdf0e10cSrcweir			my $filemodules = $onefile->{'modules'};
462cdf0e10cSrcweir			my $filemodulesarrayref = installer::converter::convert_stringlist_into_array_without_newline(\$filemodules, ",");
463cdf0e10cSrcweir
464cdf0e10cSrcweir			if (installer::existence::exists_in_array($modulegid, $filemodulesarrayref))
465cdf0e10cSrcweir			{
466cdf0e10cSrcweir				$componentname = $onefile->{'componentname'};
467cdf0e10cSrcweir				last;
468cdf0e10cSrcweir			}
469cdf0e10cSrcweir		}
470cdf0e10cSrcweir	}
471cdf0e10cSrcweir
472cdf0e10cSrcweir	return $componentname;
473cdf0e10cSrcweir}
474cdf0e10cSrcweir
475cdf0e10cSrcweir####################################################################################
476cdf0e10cSrcweir# Updating the file Environm.idt dynamically
477cdf0e10cSrcweir# Content:
478cdf0e10cSrcweir# Environment Name Value Component_
479cdf0e10cSrcweir####################################################################################
480cdf0e10cSrcweir
481cdf0e10cSrcweirsub set_component_in_environment_table
482cdf0e10cSrcweir{
483cdf0e10cSrcweir	my ($basedir, $filesref) = @_;
484cdf0e10cSrcweir
485cdf0e10cSrcweir	my $infoline = "";
486cdf0e10cSrcweir
487cdf0e10cSrcweir	my $environmentfilename = $basedir . $installer::globals::separator . "Environm.idt";
488cdf0e10cSrcweir
489cdf0e10cSrcweir	if ( -f $environmentfilename )	# only do something, if file exists
490cdf0e10cSrcweir	{
491cdf0e10cSrcweir		my $environmentfile = installer::files::read_file($environmentfilename);
492cdf0e10cSrcweir
493cdf0e10cSrcweir		for ( my $i = 3; $i <= $#{$environmentfile}; $i++ )	# starting in line 4 of Environm.idt
494cdf0e10cSrcweir		{
495cdf0e10cSrcweir			if ( ${$environmentfile}[$i] =~ /^\s*(.*?)\t(.*?)\t(.*?)\t(.*?)\s*$/ )
496cdf0e10cSrcweir			{
497cdf0e10cSrcweir				my $modulegid = $4; # in Environment table a scp module gid can be used as component replacement
498cdf0e10cSrcweir
499cdf0e10cSrcweir				my $componentname = get_component_name_from_modulegid($modulegid, $filesref);
500cdf0e10cSrcweir
501cdf0e10cSrcweir				if ( $componentname )	# only do something if a component could be found
502cdf0e10cSrcweir				{
503cdf0e10cSrcweir					$infoline = "Updated Environment table:\n";
504cdf0e10cSrcweir					push(@installer::globals::logfileinfo, $infoline);
505cdf0e10cSrcweir					$infoline = "Old line: ${$environmentfile}[$i]\n";
506cdf0e10cSrcweir					push(@installer::globals::logfileinfo, $infoline);
507cdf0e10cSrcweir
508cdf0e10cSrcweir					${$environmentfile}[$i] =~ s/$modulegid/$componentname/;
509cdf0e10cSrcweir
510cdf0e10cSrcweir					$infoline = "New line: ${$environmentfile}[$i]\n";
511cdf0e10cSrcweir					push(@installer::globals::logfileinfo, $infoline);
512cdf0e10cSrcweir
513cdf0e10cSrcweir				}
514cdf0e10cSrcweir			}
515cdf0e10cSrcweir		}
516cdf0e10cSrcweir
517cdf0e10cSrcweir		# Saving the file
518cdf0e10cSrcweir
519cdf0e10cSrcweir		installer::files::save_file($environmentfilename ,$environmentfile);
520cdf0e10cSrcweir		$infoline = "Updated idt file: $environmentfilename\n";
521cdf0e10cSrcweir		push(@installer::globals::logfileinfo, $infoline);
522cdf0e10cSrcweir
523cdf0e10cSrcweir	}
524cdf0e10cSrcweir}
525cdf0e10cSrcweir
526cdf0e10cSrcweir1;