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