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