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