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