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::media; 25 26use installer::exiter; 27use installer::files; 28use installer::globals; 29use installer::windows::idtglobal; 30 31############################################################## 32# Returning the diskid for the media table. 33############################################################## 34 35sub get_media_diskid 36{ 37 my ($id) = @_; 38 39 return $id; 40} 41 42############################################################## 43# Returning the lastsequence for the media table. 44############################################################## 45 46sub get_media_lastsequence 47{ 48 my ($fileref) = @_; 49 50 return $fileref->{'sequencenumber'}; 51} 52 53############################################################## 54# Returning the diskprompt for the media table. 55############################################################## 56 57sub get_media_diskprompt 58{ 59 return 1; 60} 61 62############################################################## 63# Returning the cabinet file name for the media table. 64############################################################## 65 66sub get_media_cabinet 67{ 68 my ($id) = @_; 69 70 my $number = 1000 + $id; 71 my $filename = "f_" . $number . ".cab"; 72 73 if ( $installer::globals::include_cab_in_msi ) { $filename = "\#" . $filename; } 74 75 return $filename; 76} 77 78############################################################## 79# Returning the volumelabel for the media table. 80############################################################## 81 82sub get_media_volumelabel 83{ 84 return "DISK1"; 85} 86 87############################################################## 88# Returning the source for the media table. 89############################################################## 90 91sub get_media_source 92{ 93 return ""; 94} 95 96############################################################## 97# Saving the cabinet file name in the files collector. 98# This is useful for making a list to connect the 99# source of each file with the destination cabinet file. 100############################################################## 101 102sub set_cabinetfilename_for_component_in_file_collector 103{ 104 my ($cabinetfilename, $filesref, $componentname, $max) = @_; 105 106 for ( my $i = 0; $i <= $max; $i++ ) 107 { 108 my $onefile = ${$filesref}[$i]; 109 my $component = $onefile->{'componentname'}; 110 111 if ( $component eq $componentname ) 112 { 113 my $cabinet = ""; 114 115 if ( $onefile->{'cabinet'} ) { $cabinet = $onefile->{'cabinet'}; } 116 117 if ( $cabinet eq "" ) 118 { 119 $onefile->{'cabinet'} = $cabinetfilename; 120 } 121 } 122 } 123} 124 125################################################# 126# Creating the cab file name dynamically 127################################################# 128 129sub generate_cab_filename_for_some_cabs 130{ 131 my ( $allvariables, $id ) = @_; 132 133 my $name = $allvariables->{'PRODUCTNAME'}; 134 135 $name = lc($name); 136 $name =~ s/\.//g; 137 $name =~ s/\s//g; 138 139 # possibility to overwrite the name with variable CABFILENAME 140 if ( $allvariables->{'CABFILENAME'} ) { $name = $allvariables->{'CABFILENAME'}; } 141 142 $name = $name . $id . ".cab"; 143 144 if ( $installer::globals::include_cab_in_msi ) { $name = "\#" . $name; } 145 146 return $name; 147} 148 149################################################# 150# Creating the cab file name for cab files 151# defined in packages. 152################################################# 153 154sub get_cabfilename 155{ 156 my ($name) = @_; 157 158 if ( $installer::globals::include_cab_in_msi ) { $name = "\#" . $name; } 159 160 return $name; 161} 162 163################################################# 164# Creating the cab file name dynamically 165################################################# 166 167sub generate_cab_filename 168{ 169 my ( $allvariables ) = @_; 170 171 my $name = $allvariables->{'PRODUCTNAME'}; 172 173 $name = lc($name); 174 $name =~ s/\.//g; 175 $name =~ s/\s//g; 176 177 # possibility to overwrite the name with variable CABFILENAME 178 if ( $allvariables->{'CABFILENAME'} ) { $name = $allvariables->{'CABFILENAME'}; } 179 180 $name = $name . ".cab"; 181 182 if ( $installer::globals::include_cab_in_msi ) { $name = "\#" . $name; } 183 184 return $name; 185} 186 187sub get_maximum_filenumber 188{ 189 my ($allfiles, $maxcabfilenumber) = @_; 190 191 my $maxfile = 0; 192 193 while ( ! ( $allfiles%$maxcabfilenumber == 0 )) 194 { 195 $allfiles++; 196 } 197 198 $maxfile = $allfiles / $maxcabfilenumber; 199 200 $maxfile++; # for securitry 201 202 return $maxfile; 203} 204 205################################################################################# 206# Setting the last sequence for the cabinet files 207################################################################################# 208 209sub get_last_sequence 210{ 211 my ( $cabfilename, $alludpatelastsequences ) = @_; 212 213 my $sequence = 0; 214 215 if (( $installer::globals::updatedatabase ) && ( exists($alludpatelastsequences->{$cabfilename}) )) 216 { 217 $sequence = $alludpatelastsequences->{$cabfilename}; 218 } 219 else 220 { 221 $sequence = $installer::globals::lastsequence{$cabfilename}; 222 } 223 224 return $sequence; 225} 226 227################################################################################# 228# Creating the file Media.idt dynamically 229# Content: 230# DiskId LastSequence DiskPrompt Cabinet VolumeLabel Source 231# Idea: Every component is packed into each own cab file 232################################################################################# 233 234sub create_media_table 235{ 236 my ($filesref, $basedir, $allvariables, $alludpatelastsequences, $allupdatediskids) = @_; 237 238 my @mediatable = (); 239 240 my $diskid = 0; 241 242 installer::windows::idtglobal::write_idt_header(\@mediatable, "media"); 243 244 if ( $allvariables->{'INCLUDE_CAB_IN_MSI'} ) { $installer::globals::include_cab_in_msi = 1; } 245 246 if ( $installer::globals::fix_number_of_cab_files ) 247 { 248 # number of cabfiles 249 my $maxcabfilenumber = $installer::globals::number_of_cabfiles; 250 if ( $allvariables->{'CABFILENUMBER'} ) { $maxcabfilenumber = $allvariables->{'CABFILENUMBER'}; } 251 my $allfiles = $#{$filesref} + 1; 252 my $maxfilenumber = get_maximum_filenumber($allfiles, $maxcabfilenumber); 253 # my $maxfilenumber = 1000; # maximum 1000 files in each cabinet file 254 my $cabfilenumber = 0; 255 my $cabfull = 0; 256 my $counter = 0; 257 258 # Sorting of files collector files required ! 259 # Attention: The order in the cab file is not guaranteed (especially in udpate process) 260 261 for ( my $i = 0; $i <= $#{$filesref}; $i++ ) 262 { 263 if (( $counter >= $maxfilenumber ) || ( $i == $#{$filesref} )) { $cabfull = 1; } 264 265 $counter++; # counting the files in the cab file 266 267 my $onefile = ${$filesref}[$i]; 268 my $nextfile = ${$filesref}[$i+1]; 269 270 my $filecomponent = ""; 271 my $nextcomponent = ""; 272 273 if ( $onefile->{'componentname'} ) { $filecomponent = $onefile->{'componentname'}; } 274 if ( $nextfile->{'componentname'} ) { $nextcomponent = $nextfile->{'componentname'}; } 275 276 if ( $filecomponent eq $nextcomponent ) # all files of one component have to be in one cab file 277 { 278 next; # nothing to do, this is not the last file of a component 279 } 280 281 if ( $cabfull ) 282 { 283 my %media = (); 284 $cabfilenumber++; 285 286 $media{'DiskId'} = get_media_diskid($cabfilenumber); 287 # $media{'LastSequence'} = get_media_lastsequence($onefile); 288 $media{'LastSequence'} = $i + 1; # This should be correct, also for unsorted files collectors 289 $media{'DiskPrompt'} = get_media_diskprompt(); 290 $media{'Cabinet'} = generate_cab_filename_for_some_cabs($allvariables, $cabfilenumber); 291 $media{'VolumeLabel'} = get_media_volumelabel(); 292 $media{'Source'} = get_media_source(); 293 294 my $oneline = $media{'DiskId'} . "\t" . $media{'LastSequence'} . "\t" . $media{'DiskPrompt'} . "\t" 295 . $media{'Cabinet'} . "\t" . $media{'VolumeLabel'} . "\t" . $media{'Source'} . "\n"; 296 297 push(@mediatable, $oneline); 298 299 # Saving the cabinet file name in the file collector 300 301 $media{'Cabinet'} =~ s/^\s*\#//; # removing leading hash 302 303 for ( my $j = 0; $j <= $i; $j++ ) 304 { 305 my $onefile = ${$filesref}[$j]; 306 if ( ! $onefile->{'cabinet'} ) { $onefile->{'cabinet'} = $media{'Cabinet'}; } 307 } 308 309 $cabfull = 0; 310 $counter = 0; 311 } 312 } 313 } 314 else 315 { 316 installer::exiter::exit_program("ERROR: No cab file specification in globals.pm !", "create_media_table"); 317 } 318 319 # Saving the file 320 321 my $mediatablename = $basedir . $installer::globals::separator . "Media.idt"; 322 installer::files::save_file($mediatablename ,\@mediatable); 323 $installer::logger::Lang->printf("Created idt file: %s\n", $mediatablename); 324} 325 3261; 327