xref: /trunk/main/solenv/bin/modules/installer/windows/assembly.pm (revision ec6d9e159f5d40bf5d1f27b0b525436f7e942929)
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
22cdf0e10cSrcweirpackage installer::windows::assembly;
23cdf0e10cSrcweir
24cdf0e10cSrcweiruse installer::files;
25cdf0e10cSrcweiruse installer::globals;
26cdf0e10cSrcweiruse installer::worker;
27cdf0e10cSrcweiruse installer::windows::idtglobal;
28cdf0e10cSrcweir
29dba1a2e4SAndre Fischeruse strict;
30dba1a2e4SAndre Fischer
31cdf0e10cSrcweir##############################################################
32cdf0e10cSrcweir# Returning the first module of a file from the
33cdf0e10cSrcweir# comma separated list of modules.
34cdf0e10cSrcweir##############################################################
35cdf0e10cSrcweir
36cdf0e10cSrcweirsub get_msiassembly_feature
37cdf0e10cSrcweir{
38cdf0e10cSrcweir    my ( $onefile ) = @_;
39cdf0e10cSrcweir
40cdf0e10cSrcweir    my $module = "";
41cdf0e10cSrcweir
42cdf0e10cSrcweir    if ( $onefile->{'modules'} ) { $module = $onefile->{'modules'}; }
43cdf0e10cSrcweir
44cdf0e10cSrcweir    # If modules contains a list of modules, only taking the first one.
45cdf0e10cSrcweir
46cdf0e10cSrcweir    if ( $module =~ /^\s*(.*?)\,/ ) { $module = $1; }
47cdf0e10cSrcweir
48cdf0e10cSrcweir    # Attention: Maximum feature length is 38!
49cdf0e10cSrcweir    installer::windows::idtglobal::shorten_feature_gid(\$module);
50cdf0e10cSrcweir
51cdf0e10cSrcweir    return $module;
52cdf0e10cSrcweir}
53cdf0e10cSrcweir
54cdf0e10cSrcweir##############################################################
55cdf0e10cSrcweir# Returning the component of a file.
56cdf0e10cSrcweir##############################################################
57cdf0e10cSrcweir
58cdf0e10cSrcweirsub get_msiassembly_component
59cdf0e10cSrcweir{
60cdf0e10cSrcweir    my ( $onefile ) = @_;
61cdf0e10cSrcweir
62cdf0e10cSrcweir    my $component = "";
63cdf0e10cSrcweir
64cdf0e10cSrcweir    $component = $onefile->{'componentname'};
65cdf0e10cSrcweir
66cdf0e10cSrcweir    return $component;
67cdf0e10cSrcweir}
68cdf0e10cSrcweir
69cdf0e10cSrcweir##############################################################
70cdf0e10cSrcweir# Returning the file name as manifest file
71cdf0e10cSrcweir##############################################################
72cdf0e10cSrcweir
73cdf0e10cSrcweirsub get_msiassembly_filemanifest
74cdf0e10cSrcweir{
75cdf0e10cSrcweir    my ( $onefile ) = @_;
76cdf0e10cSrcweir
77cdf0e10cSrcweir    my $filemanifest = "";
78cdf0e10cSrcweir
79cdf0e10cSrcweir    $filemanifest = $onefile->{'uniquename'};
80cdf0e10cSrcweir    # $filemanifest = $onefile->{'Name'};
81cdf0e10cSrcweir
82cdf0e10cSrcweir    return $filemanifest;
83cdf0e10cSrcweir}
84cdf0e10cSrcweir
85cdf0e10cSrcweir##############################################################
86cdf0e10cSrcweir# Returning the file application
87cdf0e10cSrcweir##############################################################
88cdf0e10cSrcweir
89cdf0e10cSrcweirsub get_msiassembly_fileapplication
90cdf0e10cSrcweir{
91cdf0e10cSrcweir    my ( $onefile ) = @_;
92cdf0e10cSrcweir
93cdf0e10cSrcweir    my $fileapplication = "";
94cdf0e10cSrcweir
95cdf0e10cSrcweir    return $fileapplication;
96cdf0e10cSrcweir}
97cdf0e10cSrcweir
98cdf0e10cSrcweir##############################################################
99cdf0e10cSrcweir# Returning the file attributes
100cdf0e10cSrcweir##############################################################
101cdf0e10cSrcweir
102cdf0e10cSrcweirsub get_msiassembly_attributes
103cdf0e10cSrcweir{
104cdf0e10cSrcweir    my ( $onefile ) = @_;
105cdf0e10cSrcweir
106cdf0e10cSrcweir    my $fileattributes = "";
107cdf0e10cSrcweir
108cdf0e10cSrcweir    if ( $onefile->{'Attributes'} ne "" ) { $fileattributes = $onefile->{'Attributes'}; }
109cdf0e10cSrcweir
110cdf0e10cSrcweir    return $fileattributes;
111cdf0e10cSrcweir}
112cdf0e10cSrcweir
113cdf0e10cSrcweir##############################################################
114cdf0e10cSrcweir# Returning the file object for the msiassembly table.
115cdf0e10cSrcweir##############################################################
116cdf0e10cSrcweir
117cdf0e10cSrcweirsub get_msiassembly_file
118cdf0e10cSrcweir{
119cdf0e10cSrcweir    my ( $filesref, $filename ) = @_;
120cdf0e10cSrcweir
121cdf0e10cSrcweir    my $foundfile = 0;
122cdf0e10cSrcweir    my $onefile;
123cdf0e10cSrcweir
124cdf0e10cSrcweir    for ( my $i = 0; $i <= $#{$filesref}; $i++ )
125cdf0e10cSrcweir    {
126cdf0e10cSrcweir        $onefile = ${$filesref}[$i];
127cdf0e10cSrcweir        my $name = $onefile->{'Name'};
128cdf0e10cSrcweir
129cdf0e10cSrcweir        if ( $name eq $filename )
130cdf0e10cSrcweir        {
131cdf0e10cSrcweir            $foundfile = 1;
132cdf0e10cSrcweir            last;
133cdf0e10cSrcweir        }
134cdf0e10cSrcweir    }
135cdf0e10cSrcweir
136cdf0e10cSrcweir    # It does not need to exist. For example products that do not contain the libraries.
137cdf0e10cSrcweir    # if (! $foundfile ) { installer::exiter::exit_program("ERROR: No unique file name found for $filename !", "get_selfreg_file"); }
138cdf0e10cSrcweir
139cdf0e10cSrcweir    if (! $foundfile ) { $onefile = ""; }
140cdf0e10cSrcweir
141cdf0e10cSrcweir    return $onefile;
142cdf0e10cSrcweir}
143cdf0e10cSrcweir
144cdf0e10cSrcweir##############################################################
145cdf0e10cSrcweir# Returning the file object for the msiassembly table.
146cdf0e10cSrcweir##############################################################
147cdf0e10cSrcweir
148cdf0e10cSrcweirsub get_msiassembly_file_by_gid
149cdf0e10cSrcweir{
150cdf0e10cSrcweir    my ( $filesref, $gid ) = @_;
151cdf0e10cSrcweir
152cdf0e10cSrcweir    my $foundfile = 0;
153cdf0e10cSrcweir    my $onefile;
154cdf0e10cSrcweir
155cdf0e10cSrcweir    for ( my $i = 0; $i <= $#{$filesref}; $i++ )
156cdf0e10cSrcweir    {
157cdf0e10cSrcweir        $onefile = ${$filesref}[$i];
158cdf0e10cSrcweir        my $filegid = $onefile->{'gid'};
159cdf0e10cSrcweir
160cdf0e10cSrcweir        if ( $filegid eq $gid )
161cdf0e10cSrcweir        {
162cdf0e10cSrcweir            $foundfile = 1;
163cdf0e10cSrcweir            last;
164cdf0e10cSrcweir        }
165cdf0e10cSrcweir    }
166cdf0e10cSrcweir
167cdf0e10cSrcweir    # It does not need to exist. For example products that do not contain the libraries.
168cdf0e10cSrcweir    # if (! $foundfile ) { installer::exiter::exit_program("ERROR: No unique file name found for $filename !", "get_selfreg_file"); }
169cdf0e10cSrcweir
170cdf0e10cSrcweir    if (! $foundfile ) { $onefile = ""; }
171cdf0e10cSrcweir
172cdf0e10cSrcweir    return $onefile;
173cdf0e10cSrcweir}
174cdf0e10cSrcweir
175cdf0e10cSrcweir####################################################################################
176cdf0e10cSrcweir# Creating the file MsiAssembly.idt dynamically
177cdf0e10cSrcweir# Content:
178cdf0e10cSrcweir# Component_    Feature_    File_Manifest   File_Application    Attributes
179cdf0e10cSrcweir# s72   s38 S72 S72 I2
180cdf0e10cSrcweir# MsiAssembly   Component_
181cdf0e10cSrcweir####################################################################################
182cdf0e10cSrcweir
183cdf0e10cSrcweirsub create_msiassembly_table
184cdf0e10cSrcweir{
185cdf0e10cSrcweir    my ($filesref, $basedir) = @_;
186cdf0e10cSrcweir
187cdf0e10cSrcweir    $installer::globals::msiassemblyfiles = installer::worker::collect_all_items_with_special_flag($filesref, "ASSEMBLY");
188cdf0e10cSrcweir
189cdf0e10cSrcweir    my @msiassemblytable = ();
190cdf0e10cSrcweir
191cdf0e10cSrcweir    installer::windows::idtglobal::write_idt_header(\@msiassemblytable, "msiassembly");
192cdf0e10cSrcweir
193cdf0e10cSrcweir    # Registering all libraries listed in $installer::globals::msiassemblyfiles
194cdf0e10cSrcweir
195cdf0e10cSrcweir    for ( my $i = 0; $i <= $#{$installer::globals::msiassemblyfiles}; $i++ )
196cdf0e10cSrcweir    {
197cdf0e10cSrcweir        my $onefile = ${$installer::globals::msiassemblyfiles}[$i];
198cdf0e10cSrcweir
199cdf0e10cSrcweir        my %msiassembly = ();
200cdf0e10cSrcweir
201cdf0e10cSrcweir        $msiassembly{'Component_'} = get_msiassembly_component($onefile);
202cdf0e10cSrcweir        $msiassembly{'Feature_'} = get_msiassembly_feature($onefile);
203cdf0e10cSrcweir        $msiassembly{'File_Manifest'} = get_msiassembly_filemanifest($onefile);
204cdf0e10cSrcweir        $msiassembly{'File_Application'} = get_msiassembly_fileapplication($onefile);
205cdf0e10cSrcweir        $msiassembly{'Attributes'} = get_msiassembly_attributes($onefile);
206cdf0e10cSrcweir
207cdf0e10cSrcweir        my $oneline = $msiassembly{'Component_'} . "\t" . $msiassembly{'Feature_'} . "\t" .
208cdf0e10cSrcweir                        $msiassembly{'File_Manifest'} . "\t" . $msiassembly{'File_Application'} . "\t" .
209cdf0e10cSrcweir                        $msiassembly{'Attributes'} . "\n";
210cdf0e10cSrcweir
211cdf0e10cSrcweir        push(@msiassemblytable, $oneline);
212cdf0e10cSrcweir    }
213cdf0e10cSrcweir
214cdf0e10cSrcweir    # Saving the file
215cdf0e10cSrcweir
216cdf0e10cSrcweir    my $msiassemblytablename = $basedir . $installer::globals::separator . "MsiAssem.idt";
217cdf0e10cSrcweir    installer::files::save_file($msiassemblytablename ,\@msiassemblytable);
218cdf0e10cSrcweir    my $infoline = "Created idt file: $msiassemblytablename\n";
219b274bc22SAndre Fischer    $installer::logger::Lang->print($infoline);
220cdf0e10cSrcweir}
221cdf0e10cSrcweir
222cdf0e10cSrcweir####################################################################################
223cdf0e10cSrcweir# Returning the name for the table MsiAssemblyName
224cdf0e10cSrcweir####################################################################################
225cdf0e10cSrcweir
226dba1a2e4SAndre Fischersub get_msiassemblyname_name ($)
227cdf0e10cSrcweir{
228dba1a2e4SAndre Fischer    my ($number) = @_;
229cdf0e10cSrcweir
230cdf0e10cSrcweir    my $name = "";
231cdf0e10cSrcweir
232cdf0e10cSrcweir    if ( $number == 1 ) { $name = "name"; }
233cdf0e10cSrcweir    elsif ( $number == 2 ) { $name = "publicKeyToken"; }
234cdf0e10cSrcweir    elsif ( $number == 3 ) { $name = "version"; }
235cdf0e10cSrcweir    elsif ( $number == 4 ) { $name = "culture"; }
236cdf0e10cSrcweir
237cdf0e10cSrcweir    return $name;
238cdf0e10cSrcweir}
239cdf0e10cSrcweir
240cdf0e10cSrcweir####################################################################################
241cdf0e10cSrcweir# Creating the file MsiAssemblyName.idt dynamically
242cdf0e10cSrcweir# Content:
243cdf0e10cSrcweir# Component_    Name    Value
244cdf0e10cSrcweir# s72   s255    s255
245cdf0e10cSrcweir# MsiAssemblyName   Component_  Name
246cdf0e10cSrcweir####################################################################################
247cdf0e10cSrcweir
248cdf0e10cSrcweirsub create_msiassemblyname_table
249cdf0e10cSrcweir{
250cdf0e10cSrcweir    my ($filesref, $basedir) = @_;
251cdf0e10cSrcweir
252cdf0e10cSrcweir    my @msiassemblynametable = ();
253cdf0e10cSrcweir
254cdf0e10cSrcweir    installer::windows::idtglobal::write_idt_header(\@msiassemblynametable, "msiassemblyname");
255cdf0e10cSrcweir
256cdf0e10cSrcweir    for ( my $i = 0; $i <= $#{$installer::globals::msiassemblyfiles}; $i++ )
257cdf0e10cSrcweir    {
258cdf0e10cSrcweir        my $onefile = ${$installer::globals::msiassemblyfiles}[$i];
259cdf0e10cSrcweir
260cdf0e10cSrcweir        my $component = get_msiassembly_component($onefile);
261cdf0e10cSrcweir        my $oneline = "";
262cdf0e10cSrcweir
263cdf0e10cSrcweir        # Order: (Assembly)name, publicKeyToken, version, culture.
264cdf0e10cSrcweir
265cdf0e10cSrcweir        if ( $onefile->{'Assemblyname'} )
266cdf0e10cSrcweir        {
267cdf0e10cSrcweir            $oneline = $component . "\t" . "name" . "\t" . $onefile->{'Assemblyname'} . "\n";
268cdf0e10cSrcweir            push(@msiassemblynametable, $oneline);
269cdf0e10cSrcweir        }
270cdf0e10cSrcweir
271cdf0e10cSrcweir        if ( $onefile->{'PublicKeyToken'} )
272cdf0e10cSrcweir        {
273cdf0e10cSrcweir            $oneline = $component . "\t" . "publicKeyToken" . "\t" . $onefile->{'PublicKeyToken'} . "\n";
274cdf0e10cSrcweir            push(@msiassemblynametable, $oneline);
275cdf0e10cSrcweir        }
276cdf0e10cSrcweir
277cdf0e10cSrcweir        if ( $onefile->{'Version'} )
278cdf0e10cSrcweir        {
279cdf0e10cSrcweir            $oneline = $component . "\t" . "version" . "\t" . $onefile->{'Version'} . "\n";
280cdf0e10cSrcweir            push(@msiassemblynametable, $oneline);
281cdf0e10cSrcweir        }
282cdf0e10cSrcweir
283cdf0e10cSrcweir        if ( $onefile->{'Culture'} )
284cdf0e10cSrcweir        {
285cdf0e10cSrcweir            $oneline = $component . "\t" . "culture" . "\t" . $onefile->{'Culture'} . "\n";
286cdf0e10cSrcweir            push(@msiassemblynametable, $oneline);
287cdf0e10cSrcweir        }
288cdf0e10cSrcweir
289cdf0e10cSrcweir        if ( $onefile->{'ProcessorArchitecture'} )
290cdf0e10cSrcweir        {
291cdf0e10cSrcweir            $oneline = $component . "\t" . "processorArchitecture" . "\t" . $onefile->{'ProcessorArchitecture'} . "\n";
292cdf0e10cSrcweir            push(@msiassemblynametable, $oneline);
293cdf0e10cSrcweir        }
294cdf0e10cSrcweir    }
295cdf0e10cSrcweir
296cdf0e10cSrcweir    # Saving the file
297cdf0e10cSrcweir
298cdf0e10cSrcweir    my $msiassemblynametablename = $basedir . $installer::globals::separator . "MsiAsseN.idt";
299cdf0e10cSrcweir    installer::files::save_file($msiassemblynametablename ,\@msiassemblynametable);
300cdf0e10cSrcweir    my $infoline = "Created idt file: $msiassemblynametablename\n";
301b274bc22SAndre Fischer    $installer::logger::Lang->print($infoline);
302cdf0e10cSrcweir
303cdf0e10cSrcweir}
304cdf0e10cSrcweir
305cdf0e10cSrcweir####################################################################################
306*ec6d9e15Smseidel# Śetting an installation condition for the assembly libraries saved in
307cdf0e10cSrcweir# @installer::globals::msiassemblynamecontent
308cdf0e10cSrcweir####################################################################################
309cdf0e10cSrcweir
310cdf0e10cSrcweirsub add_assembly_condition_into_component_table
311cdf0e10cSrcweir{
312cdf0e10cSrcweir    my ($filesref, $basedir) = @_;
313cdf0e10cSrcweir
314cdf0e10cSrcweir    my $componenttablename = $basedir . $installer::globals::separator . "Componen.idt";
315cdf0e10cSrcweir    my $componenttable = installer::files::read_file($componenttablename);
316cdf0e10cSrcweir    my $changed = 0;
317cdf0e10cSrcweir
318dba1a2e4SAndre Fischer    foreach my $onefile (@$installer::globals::msiassemblyfiles)
319cdf0e10cSrcweir    {
320cdf0e10cSrcweir        my $filecomponent = get_msiassembly_component($onefile);
321cdf0e10cSrcweir
322cdf0e10cSrcweir        for ( my $j = 0; $j <= $#{$componenttable}; $j++ )
323cdf0e10cSrcweir        {
324cdf0e10cSrcweir            my $oneline = ${$componenttable}[$j];
325cdf0e10cSrcweir
326cdf0e10cSrcweir            if ( $oneline =~ /(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)/ )
327cdf0e10cSrcweir            {
328cdf0e10cSrcweir                my $component = $1;
329cdf0e10cSrcweir                my $componentid = $2;
330cdf0e10cSrcweir                my $directory = $3;
331cdf0e10cSrcweir                my $attributes = $4;
332cdf0e10cSrcweir                my $condition = $5;
333cdf0e10cSrcweir                my $keypath = $6;
334cdf0e10cSrcweir
335cdf0e10cSrcweir                if ( $component eq $filecomponent )
336cdf0e10cSrcweir                {
337cdf0e10cSrcweir                    # setting the condition
338cdf0e10cSrcweir
339cdf0e10cSrcweir                    # $condition = "MsiNetAssemblySupport";
340cdf0e10cSrcweir                    $condition = "DOTNET_SUFFICIENT=1";
341dba1a2e4SAndre Fischer                    $oneline = join("\t",
342dba1a2e4SAndre Fischer                        $component,
343dba1a2e4SAndre Fischer                        $componentid,
344dba1a2e4SAndre Fischer                        $directory,
345dba1a2e4SAndre Fischer                        $attributes,
346dba1a2e4SAndre Fischer                        $condition,
347dba1a2e4SAndre Fischer                        $keypath) . "\n";
348cdf0e10cSrcweir                    ${$componenttable}[$j] = $oneline;
349cdf0e10cSrcweir                    $changed = 1;
3501ba1fd99SAndre Fischer
3511ba1fd99SAndre Fischer                    $installer::logger::Lang->printf("Changing %s :\n", $componenttablename);
352dba1a2e4SAndre Fischer                    $installer::logger::Lang->print($oneline);
3531ba1fd99SAndre Fischer
354cdf0e10cSrcweir                    last;
355cdf0e10cSrcweir                }
356cdf0e10cSrcweir            }
357cdf0e10cSrcweir        }
358cdf0e10cSrcweir    }
359cdf0e10cSrcweir
360cdf0e10cSrcweir    if ( $changed )
361cdf0e10cSrcweir    {
362cdf0e10cSrcweir        # Saving the file
363cdf0e10cSrcweir        installer::files::save_file($componenttablename ,$componenttable);
3641ba1fd99SAndre Fischer        $installer::logger::Lang->printf("Saved idt file: %s\n", $componenttablename);
365cdf0e10cSrcweir    }
366cdf0e10cSrcweir}
367cdf0e10cSrcweir
368cdf0e10cSrcweir1;
369