1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # $RCSfile: media.pm,v $
13 # This file is part of OpenOffice.org.
15 # OpenOffice.org is free software: you can redistribute it and/or modify
16 # it under the terms of the GNU Lesser General Public License version 3
17 # only, as published by the Free Software Foundation.
19 # OpenOffice.org is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU Lesser General Public License version 3 for more details
23 # (a copy is included in the LICENSE file that accompanied this code).
25 # You should have received a copy of the GNU Lesser General Public License
26 # version 3 along with OpenOffice.org. If not, see
27 # <http://www.openoffice.org/license.html>
28 # for a copy of the LGPLv3 License.
30 #*************************************************************************
32 package installer
::windows
::media
;
34 use installer
::exiter
;
36 use installer
::globals
;
37 use installer
::windows
::idtglobal
;
39 ##############################################################
40 # Returning the diskid for the media table.
41 ##############################################################
50 ##############################################################
51 # Returning the lastsequence for the media table.
52 ##############################################################
54 sub get_media_lastsequence
58 return $fileref->{'sequencenumber'};
61 ##############################################################
62 # Returning the diskprompt for the media table.
63 ##############################################################
65 sub get_media_diskprompt
70 ##############################################################
71 # Returning the cabinet file name for the media table.
72 ##############################################################
78 my $number = 1000 + $id;
79 my $filename = "f_" . $number . ".cab";
81 if ( $installer::globals
::include_cab_in_msi
) { $filename = "\#" . $filename; }
86 ##############################################################
87 # Returning the volumelabel for the media table.
88 ##############################################################
90 sub get_media_volumelabel
95 ##############################################################
96 # Returning the source for the media table.
97 ##############################################################
104 ##############################################################
105 # Saving the cabinet file name in the files collector.
106 # This is useful for making a list to connect the
107 # source of each file with the destination cabinet file.
108 ##############################################################
110 sub set_cabinetfilename_for_component_in_file_collector
112 my ($cabinetfilename, $filesref, $componentname, $max) = @_;
114 for ( my $i = 0; $i <= $max; $i++ )
116 my $onefile = ${$filesref}[$i];
117 my $component = $onefile->{'componentname'};
119 if ( $component eq $componentname )
123 if ( $onefile->{'cabinet'} ) { $cabinet = $onefile->{'cabinet'}; }
125 if ( $cabinet eq "" )
127 $onefile->{'cabinet'} = $cabinetfilename;
133 #################################################
134 # Creating the cab file name dynamically
135 #################################################
137 sub generate_cab_filename_for_some_cabs
139 my ( $allvariables, $id ) = @_;
141 my $name = $allvariables->{'PRODUCTNAME'};
147 # possibility to overwrite the name with variable CABFILENAME
148 if ( $allvariables->{'CABFILENAME'} ) { $name = $allvariables->{'CABFILENAME'}; }
150 $name = $name . $id . ".cab";
152 if ( $installer::globals
::include_cab_in_msi
) { $name = "\#" . $name; }
157 #################################################
158 # Creating the cab file name for cab files
159 # defined in packages.
160 #################################################
166 if ( $installer::globals
::include_cab_in_msi
) { $name = "\#" . $name; }
171 #################################################
172 # Creating the cab file name dynamically
173 #################################################
175 sub generate_cab_filename
177 my ( $allvariables ) = @_;
179 my $name = $allvariables->{'PRODUCTNAME'};
185 # possibility to overwrite the name with variable CABFILENAME
186 if ( $allvariables->{'CABFILENAME'} ) { $name = $allvariables->{'CABFILENAME'}; }
188 $name = $name . ".cab";
190 if ( $installer::globals
::include_cab_in_msi
) { $name = "\#" . $name; }
195 sub get_maximum_filenumber
197 my ($allfiles, $maxcabfilenumber) = @_;
201 while ( ! ( $allfiles%$maxcabfilenumber == 0 ))
206 $maxfile = $allfiles / $maxcabfilenumber;
208 $maxfile++; # for securitry
213 #################################################################################
214 # Setting the last sequence for the cabinet files
215 #################################################################################
217 sub get_last_sequence
219 my ( $cabfilename, $alludpatelastsequences ) = @_;
223 if (( $installer::globals
::updatedatabase
) && ( exists($alludpatelastsequences->{$cabfilename}) ))
225 $sequence = $alludpatelastsequences->{$cabfilename};
229 $sequence = $installer::globals
::lastsequence
{$cabfilename};
235 #################################################################################
236 # Creating the file Media.idt dynamically
238 # DiskId LastSequence DiskPrompt Cabinet VolumeLabel Source
239 # Idea: Every component is packed into each own cab file
240 #################################################################################
242 sub create_media_table
244 my ($filesref, $basedir, $allvariables, $alludpatelastsequences, $allupdatediskids) = @_;
250 installer
::windows
::idtglobal
::write_idt_header
(\
@mediatable, "media");
252 if ( $allvariables->{'INCLUDE_CAB_IN_MSI'} ) { $installer::globals
::include_cab_in_msi
= 1; }
254 if ( $installer::globals
::use_packages_for_cabs
)
257 foreach $cabfile ( sort keys %installer::globals
::lastsequence
)
262 $media{'DiskId'} = get_media_diskid
($diskid);
263 $media{'LastSequence'} = get_last_sequence
($cabfile, $alludpatelastsequences);
264 $media{'DiskPrompt'} = get_media_diskprompt
();
265 $media{'Cabinet'} = get_cabfilename
($cabfile);
266 $media{'VolumeLabel'} = get_media_volumelabel
();
267 $media{'Source'} = get_media_source
();
269 my $oneline = $media{'DiskId'} . "\t" . $media{'LastSequence'} . "\t" . $media{'DiskPrompt'} . "\t"
270 . $media{'Cabinet'} . "\t" . $media{'VolumeLabel'} . "\t" . $media{'Source'} . "\n";
272 push(@mediatable, $oneline);
274 # Comparing the disk id with the disk id from update database. Both have to be identical. New files have to be added
275 # to the new pff cabinet file. And existing cab files must not be removed.
276 if ( $installer::globals
::updatedatabase
)
278 # Comparing lines in new media table with line from media table in udpate database.
279 if ( exists($allupdatediskids->{$media{'Cabinet'}}) )
281 if ( $media{'DiskId'} != $allupdatediskids->{$media{'Cabinet'}} )
283 installer
::exiter
::exit_program
("ERROR: Different DiskIDs for cab file \"$media{'Cabinet'}\".\nCurrent installation set: \"$media{'DiskId'}\", but update database used \"$allupdatediskids->{$media{'Cabinet'}}\".\nWere cabinet files removed or added?", "create_media_table");
288 my $localinfoline = "Warning: Could not find cabinet file \"$media{'Cabinet'}}\" in update database. This seems to be an new cabinet file!?\n";
289 push(@installer::globals
::logfileinfo
, $localinfoline);
294 # one new cabinet file for all files added after the final release
295 if (( $installer::globals
::updatedatabase
) && ( $installer::globals
::pfffileexists
))
300 $media{'DiskId'} = get_media_diskid
($diskid) + $installer::globals
::mergemodulenumber
; # Adding mergemodulenumber, because this files are included later
301 $media{'LastSequence'} = $installer::globals
::updatesequencecounter
;
302 $media{'DiskPrompt'} = get_media_diskprompt
();
303 $media{'Cabinet'} = get_cabfilename
($installer::globals
::pffcabfilename
);
304 $media{'VolumeLabel'} = get_media_volumelabel
();
305 $media{'Source'} = get_media_source
();
307 my $oneline = $media{'DiskId'} . "\t" . $media{'LastSequence'} . "\t" . $media{'DiskPrompt'} . "\t"
308 . $media{'Cabinet'} . "\t" . $media{'VolumeLabel'} . "\t" . $media{'Source'} . "\n";
310 push(@mediatable, $oneline);
314 elsif ( $installer::globals
::cab_file_per_component
)
316 for ( my $i = 0; $i <= $#{$filesref}; $i++ )
318 my $onefile = ${$filesref}[$i];
319 my $nextfile = ${$filesref}[$i+1];
321 my $filecomponent = "";
322 my $nextcomponent = "";
324 if ( $onefile->{'componentname'} ) { $filecomponent = $onefile->{'componentname'}; }
325 if ( $nextfile->{'componentname'} ) { $nextcomponent = $nextfile->{'componentname'}; }
327 if ( $filecomponent eq $nextcomponent )
329 next; # nothing to do, this is not the last file of a component
335 $media{'DiskId'} = get_media_diskid
($diskid);
336 $media{'LastSequence'} = get_media_lastsequence
($onefile);
337 $media{'DiskPrompt'} = get_media_diskprompt
();
338 $media{'Cabinet'} = get_media_cabinet
($diskid);
339 $media{'VolumeLabel'} = get_media_volumelabel
();
340 $media{'Source'} = get_media_source
();
342 my $oneline = $media{'DiskId'} . "\t" . $media{'LastSequence'} . "\t" . $media{'DiskPrompt'} . "\t"
343 . $media{'Cabinet'} . "\t" . $media{'VolumeLabel'} . "\t" . $media{'Source'} . "\n";
345 push(@mediatable, $oneline);
347 $media{'Cabinet'} =~ s/^\s*\#//; # removing leading hash
348 set_cabinetfilename_for_component_in_file_collector
($media{'Cabinet'}, $filesref, $filecomponent, $i);
351 elsif ( $installer::globals
::fix_number_of_cab_files
)
354 my $maxcabfilenumber = $installer::globals
::number_of_cabfiles
;
355 if ( $allvariables->{'CABFILENUMBER'} ) { $maxcabfilenumber = $allvariables->{'CABFILENUMBER'}; }
356 my $allfiles = $#{$filesref} + 1;
357 my $maxfilenumber = get_maximum_filenumber
($allfiles, $maxcabfilenumber);
358 # my $maxfilenumber = 1000; # maximum 1000 files in each cabinet file
359 my $cabfilenumber = 0;
363 # Sorting of files collector files required !
364 # Attention: The order in the cab file is not guaranteed (especially in udpate process)
366 for ( my $i = 0; $i <= $#{$filesref}; $i++ )
368 if (( $counter >= $maxfilenumber ) || ( $i == $#{$filesref} )) { $cabfull = 1; }
370 $counter++; # counting the files in the cab file
372 my $onefile = ${$filesref}[$i];
373 my $nextfile = ${$filesref}[$i+1];
375 my $filecomponent = "";
376 my $nextcomponent = "";
378 if ( $onefile->{'componentname'} ) { $filecomponent = $onefile->{'componentname'}; }
379 if ( $nextfile->{'componentname'} ) { $nextcomponent = $nextfile->{'componentname'}; }
381 if ( $filecomponent eq $nextcomponent ) # all files of one component have to be in one cab file
383 next; # nothing to do, this is not the last file of a component
391 $media{'DiskId'} = get_media_diskid
($cabfilenumber);
392 # $media{'LastSequence'} = get_media_lastsequence($onefile);
393 $media{'LastSequence'} = $i + 1; # This should be correct, also for unsorted files collectors
394 $media{'DiskPrompt'} = get_media_diskprompt
();
395 $media{'Cabinet'} = generate_cab_filename_for_some_cabs
($allvariables, $cabfilenumber);
396 $media{'VolumeLabel'} = get_media_volumelabel
();
397 $media{'Source'} = get_media_source
();
399 my $oneline = $media{'DiskId'} . "\t" . $media{'LastSequence'} . "\t" . $media{'DiskPrompt'} . "\t"
400 . $media{'Cabinet'} . "\t" . $media{'VolumeLabel'} . "\t" . $media{'Source'} . "\n";
402 push(@mediatable, $oneline);
404 # Saving the cabinet file name in the file collector
406 $media{'Cabinet'} =~ s/^\s*\#//; # removing leading hash
408 for ( my $j = 0; $j <= $i; $j++ )
410 my $onefile = ${$filesref}[$j];
411 if ( ! $onefile->{'cabinet'} ) { $onefile->{'cabinet'} = $media{'Cabinet'}; }
419 elsif ( $installer::globals
::one_cab_file
)
424 my $maximumfile = $#{$filesref};
426 $media{'DiskId'} = get_media_diskid
($diskid);
427 # $media{'LastSequence'} = ${$filesref}[$maximumfile]->{'sequencenumber'}; # sequence number of the last file
428 $media{'LastSequence'} = $maximumfile + 1; # This works also for unsorted file collector
429 $media{'DiskPrompt'} = get_media_diskprompt
();
430 $media{'Cabinet'} = generate_cab_filename
($allvariables);
431 $media{'VolumeLabel'} = get_media_volumelabel
();
432 $media{'Source'} = get_media_source
();
434 my $oneline = $media{'DiskId'} . "\t" . $media{'LastSequence'} . "\t" . $media{'DiskPrompt'} . "\t"
435 . $media{'Cabinet'} . "\t" . $media{'VolumeLabel'} . "\t" . $media{'Source'} . "\n";
437 push(@mediatable, $oneline);
439 # Saving the cabinet file name in the file collector
441 $media{'Cabinet'} =~ s/^\s*\#//; # removing leading hash
443 for ( my $i = 0; $i <= $#{$filesref}; $i++ )
445 my $onefile = ${$filesref}[$i];
446 $onefile->{'cabinet'} = $media{'Cabinet'};
451 installer
::exiter
::exit_program
("ERROR: No cab file specification in globals.pm !", "create_media_table");
456 my $mediatablename = $basedir . $installer::globals
::separator
. "Media.idt";
457 installer
::files
::save_file
($mediatablename ,\
@mediatable);
458 my $infoline = "Created idt file: $mediatablename\n";
459 push(@installer::globals
::logfileinfo
, $infoline);