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
;
21 use installer
::exiter
;
23 use installer
::globals
;
24 use installer
::windows
::idtglobal
;
26 ##############################################################
27 # Returning the diskid for the media table.
28 ##############################################################
37 ##############################################################
38 # Returning the lastsequence for the media table.
39 ##############################################################
41 sub get_media_lastsequence
45 return $fileref->{'sequencenumber'};
48 ##############################################################
49 # Returning the diskprompt for the media table.
50 ##############################################################
52 sub get_media_diskprompt
57 ##############################################################
58 # Returning the cabinet file name for the media table.
59 ##############################################################
65 my $number = 1000 + $id;
66 my $filename = "f_" . $number . ".cab";
68 if ( $installer::globals
::include_cab_in_msi
) { $filename = "\#" . $filename; }
73 ##############################################################
74 # Returning the volumelabel for the media table.
75 ##############################################################
77 sub get_media_volumelabel
82 ##############################################################
83 # Returning the source for the media table.
84 ##############################################################
91 ##############################################################
92 # Saving the cabinet file name in the files collector.
93 # This is useful for making a list to connect the
94 # source of each file with the destination cabinet file.
95 ##############################################################
97 sub set_cabinetfilename_for_component_in_file_collector
99 my ($cabinetfilename, $filesref, $componentname, $max) = @_;
101 for ( my $i = 0; $i <= $max; $i++ )
103 my $onefile = ${$filesref}[$i];
104 my $component = $onefile->{'componentname'};
106 if ( $component eq $componentname )
110 if ( $onefile->{'cabinet'} ) { $cabinet = $onefile->{'cabinet'}; }
112 if ( $cabinet eq "" )
114 $onefile->{'cabinet'} = $cabinetfilename;
120 #################################################
121 # Creating the cab file name dynamically
122 #################################################
124 sub generate_cab_filename_for_some_cabs
126 my ( $allvariables, $id ) = @_;
128 my $name = $allvariables->{'PRODUCTNAME'};
134 # possibility to overwrite the name with variable CABFILENAME
135 if ( $allvariables->{'CABFILENAME'} ) { $name = $allvariables->{'CABFILENAME'}; }
137 $name = $name . $id . ".cab";
139 if ( $installer::globals
::include_cab_in_msi
) { $name = "\#" . $name; }
144 #################################################
145 # Creating the cab file name for cab files
146 # defined in packages.
147 #################################################
153 if ( $installer::globals
::include_cab_in_msi
) { $name = "\#" . $name; }
158 #################################################
159 # Creating the cab file name dynamically
160 #################################################
162 sub generate_cab_filename
164 my ( $allvariables ) = @_;
166 my $name = $allvariables->{'PRODUCTNAME'};
172 # possibility to overwrite the name with variable CABFILENAME
173 if ( $allvariables->{'CABFILENAME'} ) { $name = $allvariables->{'CABFILENAME'}; }
175 $name = $name . ".cab";
177 if ( $installer::globals
::include_cab_in_msi
) { $name = "\#" . $name; }
182 sub get_maximum_filenumber
184 my ($allfiles, $maxcabfilenumber) = @_;
188 while ( ! ( $allfiles%$maxcabfilenumber == 0 ))
193 $maxfile = $allfiles / $maxcabfilenumber;
195 $maxfile++; # for securitry
200 #################################################################################
201 # Setting the last sequence for the cabinet files
202 #################################################################################
204 sub get_last_sequence
206 my ( $cabfilename, $alludpatelastsequences ) = @_;
210 if (( $installer::globals
::updatedatabase
) && ( exists($alludpatelastsequences->{$cabfilename}) ))
212 $sequence = $alludpatelastsequences->{$cabfilename};
216 $sequence = $installer::globals
::lastsequence
{$cabfilename};
222 #################################################################################
223 # Creating the file Media.idt dynamically
225 # DiskId LastSequence DiskPrompt Cabinet VolumeLabel Source
226 # Idea: Every component is packed into each own cab file
227 #################################################################################
229 sub create_media_table
231 my ($filesref, $basedir, $allvariables, $alludpatelastsequences, $allupdatediskids) = @_;
237 installer
::windows
::idtglobal
::write_idt_header
(\
@mediatable, "media");
239 if ( $installer::globals
::fix_number_of_cab_files
)
242 my $maxcabfilenumber = $installer::globals
::number_of_cabfiles
;
243 if ( $allvariables->{'CABFILENUMBER'} ) { $maxcabfilenumber = $allvariables->{'CABFILENUMBER'}; }
244 my $allfiles = $#{$filesref} + 1;
245 my $maxfilenumber = get_maximum_filenumber
($allfiles, $maxcabfilenumber);
246 my $cabfilenumber = 0;
250 # Sorting of files collector files required !
251 # Attention: The order in the cab file is not guaranteed (especially in udpate process)
253 for ( my $i = 0; $i <= $#{$filesref}; $i++ )
255 if (( $counter >= $maxfilenumber ) || ( $i == $#{$filesref} )) { $cabfull = 1; }
257 $counter++; # counting the files in the cab file
259 my $onefile = ${$filesref}[$i];
260 my $nextfile = ${$filesref}[$i+1];
262 my $filecomponent = "";
263 my $nextcomponent = "";
265 if ( $onefile->{'componentname'} ) { $filecomponent = $onefile->{'componentname'}; }
266 if ( $nextfile->{'componentname'} ) { $nextcomponent = $nextfile->{'componentname'}; }
268 if ( $filecomponent eq $nextcomponent ) # all files of one component have to be in one cab file
270 next; # nothing to do, this is not the last file of a component
278 $media{'DiskId'} = get_media_diskid
($cabfilenumber);
279 $media{'LastSequence'} = $i + 1; # This should be correct, also for unsorted files collectors
280 $media{'DiskPrompt'} = get_media_diskprompt
();
281 $media{'Cabinet'} = generate_cab_filename_for_some_cabs
($allvariables, $cabfilenumber);
282 $media{'VolumeLabel'} = get_media_volumelabel
();
283 $media{'Source'} = get_media_source
();
285 my $oneline = $media{'DiskId'} . "\t" . $media{'LastSequence'} . "\t" . $media{'DiskPrompt'} . "\t"
286 . $media{'Cabinet'} . "\t" . $media{'VolumeLabel'} . "\t" . $media{'Source'} . "\n";
288 push(@mediatable, $oneline);
290 # Saving the cabinet file name in the file collector
292 $media{'Cabinet'} =~ s/^\s*\#//; # removing leading hash
294 for ( my $j = 0; $j <= $i; $j++ )
296 my $onefile = ${$filesref}[$j];
297 if ( ! $onefile->{'cabinet'} ) { $onefile->{'cabinet'} = $media{'Cabinet'}; }
307 installer
::exiter
::exit_program
("ERROR: No cab file specification in globals.pm !", "create_media_table");
312 my $mediatablename = $basedir . $installer::globals
::separator
. "Media.idt";
313 installer
::files
::save_file
($mediatablename ,\
@mediatable);
314 my $infoline = "Created idt file: $mediatablename\n";
315 push(@installer::globals
::logfileinfo
, $infoline);