xref: /trunk/main/solenv/bin/modules/installer/windows/component.pm (revision d620b54767df0d2c7d9557af4be4c7303d55d13c)
19780544fSAndrew Rist#**************************************************************
2cdf0e10cSrcweir#
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
10cdf0e10cSrcweir#
119780544fSAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir#
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.
19cdf0e10cSrcweir#
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{
69cdf0e10cSrcweir    my ($componentname, $filesref, $dirref) = @_;
70cdf0e10cSrcweir
71dba1a2e4SAndre Fischer    my ($component,  $uniquedir);
72cdf0e10cSrcweir
73dba1a2e4SAndre Fischer    foreach my $onefile (@$filesref)
74cdf0e10cSrcweir    {
75dba1a2e4SAndre Fischer        if ($onefile->{'componentname'} eq $componentname)
76cdf0e10cSrcweir        {
77dba1a2e4SAndre Fischer            return get_file_component_directory_for_file($onefile, $dirref);
78cdf0e10cSrcweir        }
79cdf0e10cSrcweir    }
80cdf0e10cSrcweir
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() )
83cdf0e10cSrcweir    my $ignore_this_component = 0;
84cdf0e10cSrcweir    my $origcomponentname = $componentname;
85dba1a2e4SAndre Fischer    my $componentname_pff = $componentname . "_pff";
86cdf0e10cSrcweir
87dba1a2e4SAndre Fischer    foreach my $onefile (@$filesref)
88cdf0e10cSrcweir    {
89dba1a2e4SAndre Fischer        if ($onefile->{'componentname'} eq $componentname_pff)
90cdf0e10cSrcweir        {
91dba1a2e4SAndre Fischer            return "IGNORE_COMP";
92cdf0e10cSrcweir        }
93cdf0e10cSrcweir    }
94cdf0e10cSrcweir
95dba1a2e4SAndre Fischer    installer::exiter::exit_program(
96dba1a2e4SAndre Fischer        "ERROR: Did not find component \"$origcomponentname\" in file collection",
97dba1a2e4SAndre Fischer        "get_file_component_directory");
98cdf0e10cSrcweir}
99cdf0e10cSrcweir
100cdf0e10cSrcweir
101dba1a2e4SAndre Fischer
102dba1a2e4SAndre Fischer
103dba1a2e4SAndre Fischersub get_file_component_directory_for_file ($$)
104dba1a2e4SAndre Fischer{
105dba1a2e4SAndre Fischer    my ($onefile, $dirref) = @_;
106dba1a2e4SAndre Fischer
107*d62abd1aSAndre Fischer    my $localstyles = $onefile->{'Styles'};
108*d62abd1aSAndre Fischer    $localstyles = "" unless defined $localstyles;
109cdf0e10cSrcweir
110cdf0e10cSrcweir    if ( $localstyles =~ /\bFONT\b/ )   # special handling for font files
111cdf0e10cSrcweir    {
112cdf0e10cSrcweir    return $installer::globals::fontsfolder;
113cdf0e10cSrcweir    }
114cdf0e10cSrcweir
115cdf0e10cSrcweir    my $destdir = "";
116cdf0e10cSrcweir
117cdf0e10cSrcweir    if ( $onefile->{'Dir'} ) { $destdir = $onefile->{'Dir'}; }
118cdf0e10cSrcweir
119cdf0e10cSrcweir    if ( $destdir =~ /\bPREDEFINED_OSSHELLNEWDIR\b/ )   # special handling for shellnew files
120cdf0e10cSrcweir    {
121cdf0e10cSrcweir    return $installer::globals::templatefolder;
122cdf0e10cSrcweir    }
123cdf0e10cSrcweir
124cdf0e10cSrcweir    my $destination = $onefile->{'destination'};
125cdf0e10cSrcweir
126cdf0e10cSrcweir    installer::pathanalyzer::get_path_from_fullqualifiedname(\$destination);
127cdf0e10cSrcweir
128cdf0e10cSrcweir    $destination =~ s/\Q$installer::globals::separator\E\s*$//;
129cdf0e10cSrcweir
130cdf0e10cSrcweir    # This path has to be defined in the directory collection at "HostName"
131cdf0e10cSrcweir
132dba1a2e4SAndre Fischer    my $uniquedir = undef;
133cdf0e10cSrcweir    if ($destination eq "")     # files in the installation root
134cdf0e10cSrcweir    {
135cdf0e10cSrcweir    $uniquedir = "INSTALLLOCATION";
136cdf0e10cSrcweir    }
137cdf0e10cSrcweir    else
138cdf0e10cSrcweir    {
1391ba1fd99SAndre Fischer    my $found = 0;
140dba1a2e4SAndre Fischer        foreach my $directory (@$dirref)
141cdf0e10cSrcweir    {
142dba1a2e4SAndre Fischer        if ($directory->{'HostName'} eq $destination)
143cdf0e10cSrcweir        {
144cdf0e10cSrcweir        $found = 1;
145dba1a2e4SAndre Fischer                $uniquedir = $directory->{'uniquename'};
146cdf0e10cSrcweir        last;
147cdf0e10cSrcweir        }
148cdf0e10cSrcweir    }
149cdf0e10cSrcweir
150dba1a2e4SAndre Fischer    if ( ! $found)
151cdf0e10cSrcweir    {
152dba1a2e4SAndre Fischer        installer::exiter::exit_program(
153dba1a2e4SAndre Fischer                "ERROR: Did not find destination $destination in directory collection",
154dba1a2e4SAndre Fischer                "get_file_component_directory");
155cdf0e10cSrcweir    }
156cdf0e10cSrcweir
157cdf0e10cSrcweir    if ( $uniquedir eq $installer::globals::officeinstalldirectory )
158cdf0e10cSrcweir    {
159cdf0e10cSrcweir        $uniquedir = "INSTALLLOCATION";
160cdf0e10cSrcweir    }
161cdf0e10cSrcweir    }
162cdf0e10cSrcweir
163cdf0e10cSrcweir    $onefile->{'uniquedirname'} = $uniquedir;       # saving it in the file collection
164cdf0e10cSrcweir
165cdf0e10cSrcweir    return $uniquedir
166cdf0e10cSrcweir}
167cdf0e10cSrcweir
168cdf0e10cSrcweir##############################################################
169cdf0e10cSrcweir# Returning the directory for a registry component.
170cdf0e10cSrcweir# This cannot be a useful value
171cdf0e10cSrcweir##############################################################
172cdf0e10cSrcweir
173cdf0e10cSrcweirsub get_registry_component_directory
174cdf0e10cSrcweir{
175cdf0e10cSrcweir    my $componentdir = "INSTALLLOCATION";
176cdf0e10cSrcweir
177cdf0e10cSrcweir    return $componentdir;
178cdf0e10cSrcweir}
179cdf0e10cSrcweir
180cdf0e10cSrcweir##############################################################
181cdf0e10cSrcweir# Returning the attributes for a file component.
182cdf0e10cSrcweir# Always 8 in this first try?
183cdf0e10cSrcweir##############################################################
184cdf0e10cSrcweir
185cdf0e10cSrcweirsub get_file_component_attributes
186cdf0e10cSrcweir{
187cdf0e10cSrcweir    my ($componentname, $filesref, $allvariables) = @_;
188cdf0e10cSrcweir
189cdf0e10cSrcweir    my $attributes;
190cdf0e10cSrcweir
191cdf0e10cSrcweir    $attributes = 2;
192cdf0e10cSrcweir
193cdf0e10cSrcweir    # special handling for font files
194cdf0e10cSrcweir
195cdf0e10cSrcweir    my $onefile;
196cdf0e10cSrcweir    my $found = 0;
197cdf0e10cSrcweir
198cdf0e10cSrcweir    for ( my $i = 0; $i <= $#{$filesref}; $i++ )
199cdf0e10cSrcweir    {
200cdf0e10cSrcweir        $onefile =  ${$filesref}[$i];
201cdf0e10cSrcweir        my $component = $onefile->{'componentname'};
202cdf0e10cSrcweir
203cdf0e10cSrcweir        if ( $component eq $componentname )
204cdf0e10cSrcweir        {
205cdf0e10cSrcweir            $found = 1;
206cdf0e10cSrcweir            last;
207cdf0e10cSrcweir        }
208cdf0e10cSrcweir    }
209cdf0e10cSrcweir
210cdf0e10cSrcweir    if (!($found))
211cdf0e10cSrcweir    {
212cdf0e10cSrcweir        installer::exiter::exit_program("ERROR: Did not find component in file collection", "get_file_component_attributes");
213cdf0e10cSrcweir    }
214cdf0e10cSrcweir
215cdf0e10cSrcweir    my $localstyles = "";
216cdf0e10cSrcweir
217cdf0e10cSrcweir    if ( $onefile->{'Styles'} ) { $localstyles = $onefile->{'Styles'}; }
218cdf0e10cSrcweir
219cdf0e10cSrcweir    if ( $localstyles =~ /\bFONT\b/ )
220cdf0e10cSrcweir    {
22128a50f78SAndre Fischer        $attributes = 8;    # font files will be deinstalled if the ref count is 0
222cdf0e10cSrcweir    }
223cdf0e10cSrcweir
224cdf0e10cSrcweir    if ( $localstyles =~ /\bASSEMBLY\b/ )
225cdf0e10cSrcweir    {
226cdf0e10cSrcweir        $attributes = 0;    # Assembly files cannot run from source
227cdf0e10cSrcweir    }
228cdf0e10cSrcweir
229dba1a2e4SAndre Fischer    if ((defined $onefile->{'Dir'} && $onefile->{'Dir'} =~ /\bPREDEFINED_OSSHELLNEWDIR\b/)
230dba1a2e4SAndre Fischer        || $onefile->{'needs_user_registry_key'})
231cdf0e10cSrcweir    {
232cdf0e10cSrcweir        $attributes = 4;    # Files in shellnew dir and in non advertised startmenu entries must have user registry key as KeyPath
233cdf0e10cSrcweir    }
234cdf0e10cSrcweir
235cdf0e10cSrcweir    # Adding 256, if this is a 64 bit installation set.
236cdf0e10cSrcweir    if (( $allvariables->{'64BITPRODUCT'} ) && ( $allvariables->{'64BITPRODUCT'} == 1 )) { $attributes = $attributes + 256; }
237cdf0e10cSrcweir
238cdf0e10cSrcweir    return $attributes
239cdf0e10cSrcweir}
240cdf0e10cSrcweir
241cdf0e10cSrcweir##############################################################
242cdf0e10cSrcweir# Returning the attributes for a registry component.
243cdf0e10cSrcweir# Always 4, indicating, the keypath is a defined in
244cdf0e10cSrcweir# table registry
245cdf0e10cSrcweir##############################################################
246cdf0e10cSrcweir
247cdf0e10cSrcweirsub get_registry_component_attributes
248cdf0e10cSrcweir{
249cdf0e10cSrcweir    my ($componentname, $allvariables) = @_;
250cdf0e10cSrcweir
251cdf0e10cSrcweir    my $attributes;
252cdf0e10cSrcweir
253cdf0e10cSrcweir    $attributes = 4;
254cdf0e10cSrcweir
255cdf0e10cSrcweir    # Adding 256, if this is a 64 bit installation set.
256cdf0e10cSrcweir    if (( $allvariables->{'64BITPRODUCT'} ) && ( $allvariables->{'64BITPRODUCT'} == 1 )) { $attributes = $attributes + 256; }
257cdf0e10cSrcweir
258cdf0e10cSrcweir    if ( exists($installer::globals::dontdeletecomponents{$componentname}) ) { $attributes = $attributes + 16; }
259cdf0e10cSrcweir
260cdf0e10cSrcweir    return $attributes
261cdf0e10cSrcweir}
262cdf0e10cSrcweir
263cdf0e10cSrcweir##############################################################
264cdf0e10cSrcweir# Returning the conditions for a component.
265cdf0e10cSrcweir# This is important for language dependent components
266cdf0e10cSrcweir# in multilingual installation sets.
267cdf0e10cSrcweir##############################################################
268cdf0e10cSrcweir
269cdf0e10cSrcweirsub get_file_component_condition
270cdf0e10cSrcweir{
271cdf0e10cSrcweir    my ($componentname, $filesref) = @_;
272cdf0e10cSrcweir
273cdf0e10cSrcweir    my $condition = "";
274cdf0e10cSrcweir
275cdf0e10cSrcweir    if (exists($installer::globals::componentcondition{$componentname}))
276cdf0e10cSrcweir    {
277cdf0e10cSrcweir        $condition = $installer::globals::componentcondition{$componentname};
278cdf0e10cSrcweir    }
279cdf0e10cSrcweir
280cdf0e10cSrcweir    # there can be also tree conditions for multilayer products
281cdf0e10cSrcweir    if (exists($installer::globals::treeconditions{$componentname}))
282cdf0e10cSrcweir    {
283cdf0e10cSrcweir        if ( $condition eq "" )
284cdf0e10cSrcweir        {
285cdf0e10cSrcweir            $condition = $installer::globals::treeconditions{$componentname};
286cdf0e10cSrcweir        }
287cdf0e10cSrcweir        else
288cdf0e10cSrcweir        {
289cdf0e10cSrcweir            $condition = "($condition) And ($installer::globals::treeconditions{$componentname})";
290cdf0e10cSrcweir        }
291cdf0e10cSrcweir    }
292cdf0e10cSrcweir
293cdf0e10cSrcweir    return $condition
294cdf0e10cSrcweir}
295cdf0e10cSrcweir
296cdf0e10cSrcweir##############################################################
297cdf0e10cSrcweir# Returning the conditions for a registry component.
298cdf0e10cSrcweir##############################################################
299cdf0e10cSrcweir
300cdf0e10cSrcweirsub get_component_condition
301cdf0e10cSrcweir{
302cdf0e10cSrcweir    my ($componentname) = @_;
303cdf0e10cSrcweir
304cdf0e10cSrcweir    my $condition;
305cdf0e10cSrcweir
306cdf0e10cSrcweir    $condition = "";    # Always ?
307cdf0e10cSrcweir
308cdf0e10cSrcweir    if (exists($installer::globals::componentcondition{$componentname}))
309cdf0e10cSrcweir    {
310cdf0e10cSrcweir        $condition = $installer::globals::componentcondition{$componentname};
311cdf0e10cSrcweir    }
312cdf0e10cSrcweir
313cdf0e10cSrcweir    return $condition
314cdf0e10cSrcweir}
315cdf0e10cSrcweir
316cdf0e10cSrcweir####################################################################
317cdf0e10cSrcweir# Returning the keypath for a component.
318cdf0e10cSrcweir# This will be the name of the first file/registry, found in the
319cdf0e10cSrcweir# collection $itemsref
320cdf0e10cSrcweir# Attention: This has to be the unique (file)name, not the
321cdf0e10cSrcweir# real filename!
322cdf0e10cSrcweir####################################################################
323cdf0e10cSrcweir
324dca4887fSAndre Fischersub get_component_keypath ($$)
325cdf0e10cSrcweir{
326dca4887fSAndre Fischer    my ($componentname, $itemsref) = @_;
327cdf0e10cSrcweir
328dba1a2e4SAndre Fischer    foreach my $oneitem (@$itemsref)
329cdf0e10cSrcweir    {
330cdf0e10cSrcweir        my $component = $oneitem->{'componentname'};
331cdf0e10cSrcweir
332dba1a2e4SAndre Fischer        if ( ! defined $component)
333dba1a2e4SAndre Fischer        {
334dba1a2e4SAndre Fischer            installer::scriptitems::print_script_item($oneitem);
335dba1a2e4SAndre Fischer            installer::logger::PrintError("item in get_component_keypath has no 'componentname'\n");
336dba1a2e4SAndre Fischer            return "";
337dba1a2e4SAndre Fischer        }
338cdf0e10cSrcweir        if ( $component eq $componentname )
339cdf0e10cSrcweir        {
340dba1a2e4SAndre Fischer            my $keypath = $oneitem->{'uniquename'}; # "uniquename", not "Name"
341dba1a2e4SAndre Fischer
342dba1a2e4SAndre Fischer            # Special handling for components in
343dba1a2e4SAndre Fischer            # PREDEFINED_OSSHELLNEWDIR. These components need as
344dba1a2e4SAndre Fischer            # KeyPath a RegistryItem in HKCU
345dba1a2e4SAndre Fischer            if ($oneitem->{'userregkeypath'})
346dba1a2e4SAndre Fischer            {
347dba1a2e4SAndre Fischer                $keypath = $oneitem->{'userregkeypath'};
348dba1a2e4SAndre Fischer            }
349dba1a2e4SAndre Fischer
350dba1a2e4SAndre Fischer            # saving it in the file and registry collection
351dba1a2e4SAndre Fischer            $oneitem->{'keypath'} = $keypath;
352dba1a2e4SAndre Fischer
353dba1a2e4SAndre Fischer            return $keypath
354dba1a2e4SAndre Fischer        }
355cdf0e10cSrcweir    }
356cdf0e10cSrcweir
357dba1a2e4SAndre Fischer    installer::exiter::exit_program(
358dba1a2e4SAndre Fischer        "ERROR: Did not find component in file/registry collection, function get_component_keypath",
359dba1a2e4SAndre Fischer        "get_component_keypath");
360cdf0e10cSrcweir}
361cdf0e10cSrcweir
3629f91b7e3SAndre Fischer
3639f91b7e3SAndre Fischer
3649f91b7e3SAndre Fischer
3659f91b7e3SAndre Fischersub remove_ooversion_from_component_name($)
3669f91b7e3SAndre Fischer{
3679f91b7e3SAndre Fischer    my ($component_name) = @_;
3689f91b7e3SAndre Fischer
3699f91b7e3SAndre Fischer    $component_name =~ s/_openoffice\d+//;
3709f91b7e3SAndre Fischer
3719f91b7e3SAndre Fischer    return $component_name;
3729f91b7e3SAndre Fischer}
3739f91b7e3SAndre Fischer
3749f91b7e3SAndre Fischer
3759f91b7e3SAndre Fischer
3769f91b7e3SAndre Fischer
3779f91b7e3SAndre Fischersub prepare_component_table_creation ($$$)
3789f91b7e3SAndre Fischer{
3799f91b7e3SAndre Fischer    my ($file_components, $registry_components, $variables) = @_;
3809f91b7e3SAndre Fischer
3819f91b7e3SAndre Fischer    if ($installer::globals::is_release)
3829f91b7e3SAndre Fischer    {
3839f91b7e3SAndre Fischer        my %source_component_data = ();
3849f91b7e3SAndre Fischer
3859f91b7e3SAndre Fischer        # Collect the components that are used in the source release.
3869f91b7e3SAndre Fischer        my $component_table = $installer::globals::source_msi->GetTable("Component");
3879f91b7e3SAndre Fischer        foreach my $row (@{$component_table->GetAllRows()})
3889f91b7e3SAndre Fischer        {
3899f91b7e3SAndre Fischer            $source_component_data{$row->GetValue("Component")} = $row;
3909f91b7e3SAndre Fischer        }
3919f91b7e3SAndre Fischer
3929f91b7e3SAndre Fischer        # Find source components that do not exist in the target components, ie have been removed.
3939f91b7e3SAndre Fischer
3949f91b7e3SAndre Fischer        # Process file components.
3959f91b7e3SAndre Fischer        my @missing_source_component_names = ();
3969f91b7e3SAndre Fischer        my %file_component_hash = map {$_ => 1} @$file_components;
3979f91b7e3SAndre Fischer        foreach my $source_component_name (keys %source_component_data)
3989f91b7e3SAndre Fischer        {
3999f91b7e3SAndre Fischer            # In this loop we only process components for files and ignore those for registry entries.
4009f91b7e3SAndre Fischer            next if $source_component_name =~ /^registry_/;
4019f91b7e3SAndre Fischer
4029f91b7e3SAndre Fischer            if ( ! defined $file_component_hash{$source_component_name})
4039f91b7e3SAndre Fischer            {
4049f91b7e3SAndre Fischer                push @missing_source_component_names, [$source_component_name, $source_component_name];
4059f91b7e3SAndre Fischer                $installer::logger::Info->printf("missing file component %s\n", $source_component_name);
4069f91b7e3SAndre Fischer            }
4079f91b7e3SAndre Fischer        }
4089f91b7e3SAndre Fischer
4099f91b7e3SAndre Fischer        # Process registry components.
4109f91b7e3SAndre Fischer        my %registry_component_hash = map {$_ => 1} @$registry_components;
4119f91b7e3SAndre Fischer        my %registry_component_hash_normalized = map {remove_ooversion_from_component_name($_) => $_} @$registry_components;
4129f91b7e3SAndre Fischer        my %target_registry_component_translation = ();
4139f91b7e3SAndre Fischer        foreach my $source_component_name (keys %source_component_data)
4149f91b7e3SAndre Fischer        {
4159f91b7e3SAndre Fischer            # In this loop we only process components for registry entries and ignore those for files.
4169f91b7e3SAndre Fischer            next if $source_component_name !~ /^registry_/;
4179f91b7e3SAndre Fischer
4189f91b7e3SAndre Fischer            if (defined $registry_component_hash{$source_component_name})
4199f91b7e3SAndre Fischer            {
4209f91b7e3SAndre Fischer                # Found the non-normalized name.
4219f91b7e3SAndre Fischer            }
4229f91b7e3SAndre Fischer            elsif (defined $registry_component_hash_normalized{
4239f91b7e3SAndre Fischer                remove_ooversion_from_component_name($source_component_name)})
4249f91b7e3SAndre Fischer            {
4259f91b7e3SAndre Fischer                # Found the normalized name.
4269f91b7e3SAndre Fischer                my $target_component_name = $registry_component_hash_normalized{
4279f91b7e3SAndre Fischer                    remove_ooversion_from_component_name($source_component_name)};
4289f91b7e3SAndre Fischer                $target_registry_component_translation{$target_component_name} = $source_component_name;
4299f91b7e3SAndre Fischer                $installer::logger::Info->printf("found normalized component name %s\n", $source_component_name);
4309f91b7e3SAndre Fischer                $installer::logger::Info->printf("    %s -> %s\n", $target_component_name, $source_component_name);
4319f91b7e3SAndre Fischer            }
4329f91b7e3SAndre Fischer            else
4339f91b7e3SAndre Fischer            {
4349f91b7e3SAndre Fischer                # Source component was not found.
4359f91b7e3SAndre Fischer                push @missing_source_component_names, $source_component_name;
4369f91b7e3SAndre Fischer                $installer::logger::Info->printf("missing component %s\n", $source_component_name);
4379f91b7e3SAndre Fischer            }
4389f91b7e3SAndre Fischer        }
4399f91b7e3SAndre Fischer
4409f91b7e3SAndre Fischer        if (scalar @missing_source_component_names > 0)
4419f91b7e3SAndre Fischer        {
4429f91b7e3SAndre Fischer            $installer::logger::Info->printf("Error: there are %d missing components\n",
4439f91b7e3SAndre Fischer                scalar @missing_source_component_names);
4449f91b7e3SAndre Fischer            return {};
4459f91b7e3SAndre Fischer        }
4469f91b7e3SAndre Fischer        else
4479f91b7e3SAndre Fischer        {
4489f91b7e3SAndre Fischer            return \%target_registry_component_translation;
4499f91b7e3SAndre Fischer        }
4509f91b7e3SAndre Fischer    }
4519f91b7e3SAndre Fischer
4529f91b7e3SAndre Fischer    return {};
4539f91b7e3SAndre Fischer}
4549f91b7e3SAndre Fischer
4559f91b7e3SAndre Fischer
4569f91b7e3SAndre Fischer
4579f91b7e3SAndre Fischer
4589f91b7e3SAndre Fischersub get_component_data ($$$$)
4599f91b7e3SAndre Fischer{
4609f91b7e3SAndre Fischer    my ($file_component_names,
4619f91b7e3SAndre Fischer        $registry_component_names,
4629f91b7e3SAndre Fischer        $files,
4639f91b7e3SAndre Fischer        $registry_entries) = @_;
4649f91b7e3SAndre Fischer
4659f91b7e3SAndre Fischer    # When we are building a release then prepare building a patch by looking up some data
4669f91b7e3SAndre Fischer    # from the previous release.
4679f91b7e3SAndre Fischer    my %source_data = ();
4689f91b7e3SAndre Fischer    if ($installer::globals::is_release)
4699f91b7e3SAndre Fischer    {
4709f91b7e3SAndre Fischer        my $source_component_table = $installer::globals::source_msi->GetTable("Component");
4719f91b7e3SAndre Fischer        my $component_column_index = $source_component_table->GetColumnIndex("Component");
4729f91b7e3SAndre Fischer        my $component_id_column_index = $source_component_table->GetColumnIndex("ComponentId");
4739f91b7e3SAndre Fischer        my $key_path_column_index = $source_component_table->GetColumnIndex("KeyPath");
4749f91b7e3SAndre Fischer        foreach my $source_row (@{$source_component_table->GetAllRows()})
4759f91b7e3SAndre Fischer        {
4769f91b7e3SAndre Fischer            my $component_name = $source_row->GetValue($component_column_index);
4779f91b7e3SAndre Fischer            my $component_id = $source_row->GetValue($component_id_column_index);
4789f91b7e3SAndre Fischer            my $key_path = $source_row->GetValue($key_path_column_index);
4799f91b7e3SAndre Fischer
4809f91b7e3SAndre Fischer            $source_data{$component_name} = {
4819f91b7e3SAndre Fischer                'component_id' => $component_id,
4829f91b7e3SAndre Fischer                'key_path' => $key_path
4839f91b7e3SAndre Fischer            };
4849f91b7e3SAndre Fischer        }
4859f91b7e3SAndre Fischer    }
4869f91b7e3SAndre Fischer
4879f91b7e3SAndre Fischer    # Set up data for the target release.
4889f91b7e3SAndre Fischer    # Use data from the source version where possible.
4899f91b7e3SAndre Fischer    # Create missind data where necessary.
4909f91b7e3SAndre Fischer
4919f91b7e3SAndre Fischer    # Set up the target data with flags that remember whether a
4929f91b7e3SAndre Fischer    # component contains files or registry entries.
4939f91b7e3SAndre Fischer    my %target_data = ();
4949f91b7e3SAndre Fischer    foreach my $name (@$file_component_names)
4959f91b7e3SAndre Fischer    {
4969f91b7e3SAndre Fischer        $target_data{$name} = {'is_file' => 1};
4979f91b7e3SAndre Fischer    }
4989f91b7e3SAndre Fischer    foreach my $name (@$registry_component_names)
4999f91b7e3SAndre Fischer    {
5009f91b7e3SAndre Fischer        $target_data{$name} = {'is_file' => 0};
5019f91b7e3SAndre Fischer    }
5029f91b7e3SAndre Fischer
5039f91b7e3SAndre Fischer    # Add values for the ComponentId column.
5049f91b7e3SAndre Fischer    $installer::logger::Lang->printf("preparing Component->ComponentId values\n");
5059f91b7e3SAndre Fischer    foreach my $name (@$file_component_names,@$registry_component_names)
5069f91b7e3SAndre Fischer    {
5079f91b7e3SAndre Fischer        # Determine the component id.
5089f91b7e3SAndre Fischer        my $guid = $installer::globals::is_release
5099f91b7e3SAndre Fischer            ? $source_data{$name}->{'component_id'}
5109f91b7e3SAndre Fischer            : undef;
5119f91b7e3SAndre Fischer        if (defined $guid)
5129f91b7e3SAndre Fischer        {
5139f91b7e3SAndre Fischer            $installer::logger::Lang->printf("    reusing guid %s\n", $guid);
5149f91b7e3SAndre Fischer        }
5159f91b7e3SAndre Fischer        else
5169f91b7e3SAndre Fischer        {
517677600b0SAndre Fischer            $guid = "{" . installer::windows::msiglobal::create_guid() . "}";
5189f91b7e3SAndre Fischer            $installer::logger::Lang->printf("    creating new guid %s\n", $guid);
5199f91b7e3SAndre Fischer        }
5209f91b7e3SAndre Fischer        $target_data{$name}->{'component_id'} = $guid;
5219f91b7e3SAndre Fischer    }
5229f91b7e3SAndre Fischer
5239f91b7e3SAndre Fischer    # Add values for the KeyPath column.
5249f91b7e3SAndre Fischer    $installer::logger::Lang->printf("preparing Component->KeyPath values\n");
525677600b0SAndre Fischer    foreach my $component_name (@$file_component_names,@$registry_component_names)
5269f91b7e3SAndre Fischer    {
5279f91b7e3SAndre Fischer        # Determine the key path.
5289f91b7e3SAndre Fischer        my $key_path = $installer::globals::is_release
529677600b0SAndre Fischer            ? $source_data{$component_name}->{'key_path'}
5309f91b7e3SAndre Fischer            : undef;
5319f91b7e3SAndre Fischer        if (defined $key_path)
5329f91b7e3SAndre Fischer        {
533677600b0SAndre Fischer            $installer::logger::Lang->printf("    reusing key path %s for component %s\n",
534677600b0SAndre Fischer                $key_path,
535677600b0SAndre Fischer                $component_name);
5369f91b7e3SAndre Fischer        }
5379f91b7e3SAndre Fischer        else
5389f91b7e3SAndre Fischer        {
539677600b0SAndre Fischer            if ($target_data{$component_name}->{'is_file'})
5409f91b7e3SAndre Fischer            {
541677600b0SAndre Fischer                $key_path = get_component_keypath($component_name, $files);
5429f91b7e3SAndre Fischer            }
5439f91b7e3SAndre Fischer            else
5449f91b7e3SAndre Fischer            {
545677600b0SAndre Fischer                $key_path = get_component_keypath($component_name, $registry_entries);
5469f91b7e3SAndre Fischer            }
547677600b0SAndre Fischer            $installer::logger::Lang->printf("    created key path %s for component %s\n",
548677600b0SAndre Fischer                $key_path,
549677600b0SAndre Fischer                $component_name);
5509f91b7e3SAndre Fischer        }
551677600b0SAndre Fischer        $target_data{$component_name}->{'key_path'} = $key_path;
5529f91b7e3SAndre Fischer    }
5539f91b7e3SAndre Fischer
5549f91b7e3SAndre Fischer    return \%target_data;
5559f91b7e3SAndre Fischer}
5569f91b7e3SAndre Fischer
5579f91b7e3SAndre Fischer
5589f91b7e3SAndre Fischer
5599f91b7e3SAndre Fischer
5609f91b7e3SAndre Fischersub create_component_table_data ($$$$$$)
5619f91b7e3SAndre Fischer{
5629f91b7e3SAndre Fischer    my ($filesref, $registryref, $dirref, $allfilecomponentsref, $allregistrycomponents, $allvariables) = @_;
5639f91b7e3SAndre Fischer
5649f91b7e3SAndre Fischer    my $target_data = get_component_data($allfilecomponentsref, $allregistrycomponents, $filesref, $registryref);
5659f91b7e3SAndre Fischer
5669f91b7e3SAndre Fischer    my @table_data = ();
5679f91b7e3SAndre Fischer
5689f91b7e3SAndre Fischer    # File components
5699f91b7e3SAndre Fischer    foreach my $name (@$allfilecomponentsref)
5709f91b7e3SAndre Fischer    {
5719f91b7e3SAndre Fischer        my %onecomponent = ();
5729f91b7e3SAndre Fischer
5739f91b7e3SAndre Fischer        $onecomponent{'name'} = $name;
5749f91b7e3SAndre Fischer        $onecomponent{'guid'} = $target_data->{$name}->{'component_id'};
5759f91b7e3SAndre Fischer        $onecomponent{'directory'} = get_file_component_directory($name, $filesref, $dirref);
5769f91b7e3SAndre Fischer        if ( $onecomponent{'directory'} eq "IGNORE_COMP" ) { next; }
5779f91b7e3SAndre Fischer        $onecomponent{'attributes'} = get_file_component_attributes($name, $filesref, $allvariables);
5789f91b7e3SAndre Fischer        $onecomponent{'condition'} = get_file_component_condition($name, $filesref);
5799f91b7e3SAndre Fischer        $onecomponent{'keypath'} = $target_data->{$name}->{'key_path'};
5809f91b7e3SAndre Fischer
5819f91b7e3SAndre Fischer        push @table_data, \%onecomponent;
5829f91b7e3SAndre Fischer    }
5839f91b7e3SAndre Fischer
5849f91b7e3SAndre Fischer    # Registry components
5859f91b7e3SAndre Fischer    foreach my $name (@$allregistrycomponents)
5869f91b7e3SAndre Fischer    {
5879f91b7e3SAndre Fischer        my %onecomponent = ();
5889f91b7e3SAndre Fischer
5899f91b7e3SAndre Fischer        $onecomponent{'name'} = $name;
5909f91b7e3SAndre Fischer        $onecomponent{'guid'} = $target_data->{$name}->{'component_id'};
5919f91b7e3SAndre Fischer        $onecomponent{'directory'} = get_registry_component_directory();
5929f91b7e3SAndre Fischer        $onecomponent{'attributes'} = get_registry_component_attributes($name, $allvariables);
5939f91b7e3SAndre Fischer        $onecomponent{'condition'} = get_component_condition($name);
5949f91b7e3SAndre Fischer        $onecomponent{'keypath'} = $target_data->{$name}->{'key_path'};
5959f91b7e3SAndre Fischer
5969f91b7e3SAndre Fischer        push(@table_data, \%onecomponent);
5979f91b7e3SAndre Fischer    }
5989f91b7e3SAndre Fischer
5999f91b7e3SAndre Fischer    return \@table_data;
6009f91b7e3SAndre Fischer}
6019f91b7e3SAndre Fischer
6029f91b7e3SAndre Fischer
6039f91b7e3SAndre Fischer
6049f91b7e3SAndre Fischer
605cdf0e10cSrcweir###################################################################
606cdf0e10cSrcweir# Creating the file Componen.idt dynamically
607cdf0e10cSrcweir# Content:
608cdf0e10cSrcweir# Component ComponentId Directory_ Attributes Condition KeyPath
609cdf0e10cSrcweir###################################################################
610cdf0e10cSrcweir
6119f91b7e3SAndre Fischer
6129f91b7e3SAndre Fischersub create_component_table ($$)
613cdf0e10cSrcweir{
6149f91b7e3SAndre Fischer    my ($table_data, $basedir) = @_;
615cdf0e10cSrcweir
616cdf0e10cSrcweir    my @componenttable = ();
617cdf0e10cSrcweir
618cdf0e10cSrcweir    my ($oneline, $infoline);
619cdf0e10cSrcweir
620cdf0e10cSrcweir    installer::windows::idtglobal::write_idt_header(\@componenttable, "component");
621cdf0e10cSrcweir
6229f91b7e3SAndre Fischer    foreach my $item (@$table_data)
623cdf0e10cSrcweir    {
6249f91b7e3SAndre Fischer        $oneline = sprintf("%s\t%s\t%s\t%s\t%s\t%s\n",
6259f91b7e3SAndre Fischer            $item->{'name'},
6269f91b7e3SAndre Fischer            $item->{'guid'},
6279f91b7e3SAndre Fischer            $item->{'directory'},
6289f91b7e3SAndre Fischer            $item->{'attributes'},
6299f91b7e3SAndre Fischer            $item->{'condition'},
6309f91b7e3SAndre Fischer            $item->{'keypath'});
631cdf0e10cSrcweir        push(@componenttable, $oneline);
632cdf0e10cSrcweir    }
633cdf0e10cSrcweir
634cdf0e10cSrcweir    # Saving the file
635cdf0e10cSrcweir
636cdf0e10cSrcweir    my $componenttablename = $basedir . $installer::globals::separator . "Componen.idt";
637cdf0e10cSrcweir    installer::files::save_file($componenttablename ,\@componenttable);
638cdf0e10cSrcweir    $infoline = "Created idt file: $componenttablename\n";
639b274bc22SAndre Fischer    $installer::logger::Lang->print($infoline);
640cdf0e10cSrcweir}
641cdf0e10cSrcweir
6429f91b7e3SAndre Fischer
6439f91b7e3SAndre Fischer
6449f91b7e3SAndre Fischer
645cdf0e10cSrcweir####################################################################################
646cdf0e10cSrcweir# Returning a component for a scp module gid.
647cdf0e10cSrcweir# Pairs are saved in the files collector.
648cdf0e10cSrcweir####################################################################################
649cdf0e10cSrcweir
650cdf0e10cSrcweirsub get_component_name_from_modulegid
651cdf0e10cSrcweir{
652cdf0e10cSrcweir    my ($modulegid, $filesref) = @_;
653cdf0e10cSrcweir
654cdf0e10cSrcweir    my $componentname = "";
655cdf0e10cSrcweir
656cdf0e10cSrcweir    for ( my $i = 0; $i <= $#{$filesref}; $i++ )
657cdf0e10cSrcweir    {
658cdf0e10cSrcweir        my $onefile = ${$filesref}[$i];
659cdf0e10cSrcweir
660cdf0e10cSrcweir        if ( $onefile->{'modules'} )
661cdf0e10cSrcweir        {
662cdf0e10cSrcweir            my $filemodules = $onefile->{'modules'};
663cdf0e10cSrcweir            my $filemodulesarrayref = installer::converter::convert_stringlist_into_array_without_newline(\$filemodules, ",");
664cdf0e10cSrcweir
665cdf0e10cSrcweir            if (installer::existence::exists_in_array($modulegid, $filemodulesarrayref))
666cdf0e10cSrcweir            {
667cdf0e10cSrcweir                $componentname = $onefile->{'componentname'};
668cdf0e10cSrcweir                last;
669cdf0e10cSrcweir            }
670cdf0e10cSrcweir        }
671cdf0e10cSrcweir    }
672cdf0e10cSrcweir
673cdf0e10cSrcweir    return $componentname;
674cdf0e10cSrcweir}
675cdf0e10cSrcweir
676cdf0e10cSrcweir####################################################################################
677cdf0e10cSrcweir# Updating the file Environm.idt dynamically
678cdf0e10cSrcweir# Content:
679cdf0e10cSrcweir# Environment Name Value Component_
680cdf0e10cSrcweir####################################################################################
681cdf0e10cSrcweir
682cdf0e10cSrcweirsub set_component_in_environment_table
683cdf0e10cSrcweir{
684cdf0e10cSrcweir    my ($basedir, $filesref) = @_;
685cdf0e10cSrcweir
686cdf0e10cSrcweir    my $infoline = "";
687cdf0e10cSrcweir
688cdf0e10cSrcweir    my $environmentfilename = $basedir . $installer::globals::separator . "Environm.idt";
689cdf0e10cSrcweir
690cdf0e10cSrcweir    if ( -f $environmentfilename )  # only do something, if file exists
691cdf0e10cSrcweir    {
692cdf0e10cSrcweir        my $environmentfile = installer::files::read_file($environmentfilename);
693cdf0e10cSrcweir
694cdf0e10cSrcweir        for ( my $i = 3; $i <= $#{$environmentfile}; $i++ ) # starting in line 4 of Environm.idt
695cdf0e10cSrcweir        {
696cdf0e10cSrcweir            if ( ${$environmentfile}[$i] =~ /^\s*(.*?)\t(.*?)\t(.*?)\t(.*?)\s*$/ )
697cdf0e10cSrcweir            {
698cdf0e10cSrcweir                my $modulegid = $4; # in Environment table a scp module gid can be used as component replacement
699cdf0e10cSrcweir
700cdf0e10cSrcweir                my $componentname = get_component_name_from_modulegid($modulegid, $filesref);
701cdf0e10cSrcweir
702cdf0e10cSrcweir                if ( $componentname )   # only do something if a component could be found
703cdf0e10cSrcweir                {
704cdf0e10cSrcweir                    $infoline = "Updated Environment table:\n";
705b274bc22SAndre Fischer                    $installer::logger::Lang->print($infoline);
706cdf0e10cSrcweir                    $infoline = "Old line: ${$environmentfile}[$i]\n";
707b274bc22SAndre Fischer                    $installer::logger::Lang->print($infoline);
708cdf0e10cSrcweir
709cdf0e10cSrcweir                    ${$environmentfile}[$i] =~ s/$modulegid/$componentname/;
710cdf0e10cSrcweir
711cdf0e10cSrcweir                    $infoline = "New line: ${$environmentfile}[$i]\n";
712b274bc22SAndre Fischer                    $installer::logger::Lang->print($infoline);
713cdf0e10cSrcweir
714cdf0e10cSrcweir                }
715cdf0e10cSrcweir            }
716cdf0e10cSrcweir        }
717cdf0e10cSrcweir
718cdf0e10cSrcweir        # Saving the file
719cdf0e10cSrcweir
720cdf0e10cSrcweir        installer::files::save_file($environmentfilename ,$environmentfile);
721cdf0e10cSrcweir        $infoline = "Updated idt file: $environmentfilename\n";
722b274bc22SAndre Fischer        $installer::logger::Lang->print($infoline);
723cdf0e10cSrcweir
724cdf0e10cSrcweir    }
725cdf0e10cSrcweir}
726cdf0e10cSrcweir
7279f91b7e3SAndre Fischer
7289f91b7e3SAndre Fischer
7299f91b7e3SAndre Fischer
7309f91b7e3SAndre Fischersub apply_component_translation ($@)
7319f91b7e3SAndre Fischer{
7329f91b7e3SAndre Fischer    my ($translation_map, @component_names) = @_;
7339f91b7e3SAndre Fischer
7349f91b7e3SAndre Fischer    my @translated_names = ();
7359f91b7e3SAndre Fischer    foreach my $component_name (@component_names)
7369f91b7e3SAndre Fischer    {
7379f91b7e3SAndre Fischer        my $translated_name = $translation_map->{$component_name};
7389f91b7e3SAndre Fischer        if (defined $translated_name)
7399f91b7e3SAndre Fischer        {
7409f91b7e3SAndre Fischer            push @translated_names, $translated_name;
7419f91b7e3SAndre Fischer        }
7429f91b7e3SAndre Fischer        else
7439f91b7e3SAndre Fischer        {
7449f91b7e3SAndre Fischer            push @translated_names, $component_name;
7459f91b7e3SAndre Fischer        }
7469f91b7e3SAndre Fischer    }
7479f91b7e3SAndre Fischer
7489f91b7e3SAndre Fischer    return @translated_names;
7499f91b7e3SAndre Fischer}
7509f91b7e3SAndre Fischer
7519f91b7e3SAndre Fischer
752cdf0e10cSrcweir1;
753