2 # This file is part of the LibreOffice project.
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 # This file incorporates work covered by the following license notice:
10 # Licensed to the Apache Software Foundation (ASF) under one or more
11 # contributor license agreements. See the NOTICE file distributed
12 # with this work for additional information regarding copyright
13 # ownership. The ASF licenses this file to you under the Apache
14 # License, Version 2.0 (the "License"); you may not use this file
15 # except in compliance with the License. You may obtain a copy of
16 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package installer
::windows
::media
;
24 use installer
::exiter
;
26 use installer
::globals
;
27 use installer
::windows
::idtglobal
;
29 ##############################################################
30 # Returning the diskid for the media table.
31 ##############################################################
40 ##############################################################
41 # Returning the diskprompt for the media table.
42 ##############################################################
44 sub get_media_diskprompt
49 ##############################################################
50 # Returning the volumelabel for the media table.
51 ##############################################################
53 sub get_media_volumelabel
58 ##############################################################
59 # Returning the source for the media table.
60 ##############################################################
67 #################################################
68 # Creating the cab file name dynamically
69 #################################################
71 sub generate_cab_filename_for_some_cabs
73 my ( $allvariables, $id ) = @_;
75 my $name = $allvariables->{'PRODUCTNAME'};
81 # possibility to overwrite the name with variable CABFILENAME
82 if ( $allvariables->{'CABFILENAME'} ) { $name = $allvariables->{'CABFILENAME'}; }
84 $name = $name . $id . ".cab";
86 if ( $installer::globals
::include_cab_in_msi
) { $name = "\#" . $name; }
91 sub get_maximum_filenumber
93 my ($allfiles, $maxcabfilenumber) = @_;
97 while ( ! ( $allfiles%$maxcabfilenumber == 0 ))
102 $maxfile = $allfiles / $maxcabfilenumber;
104 $maxfile++; # for security
109 #################################################################################
110 # Creating the file Media.idt dynamically
112 # DiskId LastSequence DiskPrompt Cabinet VolumeLabel Source
113 # Idea: Every component is packed into each own cab file
114 #################################################################################
116 sub create_media_table
118 my ($filesref, $basedir, $allvariables, $allupdatelastsequences, $allupdatediskids) = @_;
124 installer
::windows
::idtglobal
::write_idt_header
(\
@mediatable, "media");
126 if ( $installer::globals
::fix_number_of_cab_files
)
129 my $maxcabfilenumber = $installer::globals
::number_of_cabfiles
;
130 if ( $allvariables->{'CABFILENUMBER'} ) { $maxcabfilenumber = $allvariables->{'CABFILENUMBER'}; }
131 my $allfiles = $#{$filesref} + 1;
132 my $maxfilenumber = get_maximum_filenumber
($allfiles, $maxcabfilenumber);
133 my $cabfilenumber = 0;
137 # Sorting of files collector files required !
138 # Attention: The order in the cab file is not guaranteed (especially in update process)
140 for ( my $i = 0; $i <= $#{$filesref}; $i++ )
142 if (( $counter >= $maxfilenumber ) || ( $i == $#{$filesref} )) { $cabfull = 1; }
144 $counter++; # counting the files in the cab file
146 my $onefile = ${$filesref}[$i];
147 my $nextfile = ${$filesref}[$i+1];
149 my $filecomponent = "";
150 my $nextcomponent = "";
152 if ( $onefile->{'componentname'} ) { $filecomponent = $onefile->{'componentname'}; }
153 if ( $nextfile->{'componentname'} ) { $nextcomponent = $nextfile->{'componentname'}; }
155 if ( $filecomponent eq $nextcomponent ) # all files of one component have to be in one cab file
157 next; # nothing to do, this is not the last file of a component
165 $media{'DiskId'} = get_media_diskid
($cabfilenumber);
166 $media{'LastSequence'} = $i + 1; # This should be correct, also for unsorted files collectors
167 $media{'DiskPrompt'} = get_media_diskprompt
();
168 $media{'Cabinet'} = generate_cab_filename_for_some_cabs
($allvariables, $cabfilenumber);
169 $media{'VolumeLabel'} = get_media_volumelabel
();
170 $media{'Source'} = get_media_source
();
172 my $oneline = $media{'DiskId'} . "\t" . $media{'LastSequence'} . "\t" . $media{'DiskPrompt'} . "\t"
173 . $media{'Cabinet'} . "\t" . $media{'VolumeLabel'} . "\t" . $media{'Source'} . "\n";
175 push(@mediatable, $oneline);
177 # Saving the cabinet file name in the file collector
179 $media{'Cabinet'} =~ s/^\s*\#//; # removing leading hash
181 for ( my $j = 0; $j <= $i; $j++ )
183 my $onefile = ${$filesref}[$j];
184 if ( ! $onefile->{'cabinet'} ) { $onefile->{'cabinet'} = $media{'Cabinet'}; }
194 installer
::exiter
::exit_program
("ERROR: No cab file specification in globals.pm !", "create_media_table");
199 my $mediatablename = $basedir . $installer::globals
::separator
. "Media.idt";
200 installer
::files
::save_file
($mediatablename ,\
@mediatable);
201 my $infoline = "Created idt file: $mediatablename\n";
202 push(@installer::globals
::logfileinfo
, $infoline);