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