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