bump product version to 4.1.6.2
[LibreOffice.git] / solenv / bin / modules / installer / windows / media.pm
blobbb894715d1a86b49e08031e61da0344130a68b04
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;
22 use installer::files;
23 use installer::globals;
24 use installer::windows::idtglobal;
26 ##############################################################
27 # Returning the diskid for the media table.
28 ##############################################################
30 sub get_media_diskid
32 my ($id) = @_;
34 return $id;
37 ##############################################################
38 # Returning the lastsequence for the media table.
39 ##############################################################
41 sub get_media_lastsequence
43 my ($fileref) = @_;
45 return $fileref->{'sequencenumber'};
48 ##############################################################
49 # Returning the diskprompt for the media table.
50 ##############################################################
52 sub get_media_diskprompt
54 return 1;
57 ##############################################################
58 # Returning the cabinet file name for the media table.
59 ##############################################################
61 sub get_media_cabinet
63 my ($id) = @_;
65 my $number = 1000 + $id;
66 my $filename = "f_" . $number . ".cab";
68 if ( $installer::globals::include_cab_in_msi ) { $filename = "\#" . $filename; }
70 return $filename;
73 ##############################################################
74 # Returning the volumelabel for the media table.
75 ##############################################################
77 sub get_media_volumelabel
79 return "DISK1";
82 ##############################################################
83 # Returning the source for the media table.
84 ##############################################################
86 sub get_media_source
88 return "";
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 )
108 my $cabinet = "";
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'};
130 $name = lc($name);
131 $name =~ s/\.//g;
132 $name =~ s/\s//g;
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; }
141 return $name;
144 #################################################
145 # Creating the cab file name for cab files
146 # defined in packages.
147 #################################################
149 sub get_cabfilename
151 my ($name) = @_;
153 if ( $installer::globals::include_cab_in_msi ) { $name = "\#" . $name; }
155 return $name;
158 #################################################
159 # Creating the cab file name dynamically
160 #################################################
162 sub generate_cab_filename
164 my ( $allvariables ) = @_;
166 my $name = $allvariables->{'PRODUCTNAME'};
168 $name = lc($name);
169 $name =~ s/\.//g;
170 $name =~ s/\s//g;
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; }
179 return $name;
182 sub get_maximum_filenumber
184 my ($allfiles, $maxcabfilenumber) = @_;
186 my $maxfile = 0;
188 while ( ! ( $allfiles%$maxcabfilenumber == 0 ))
190 $allfiles++;
193 $maxfile = $allfiles / $maxcabfilenumber;
195 $maxfile++; # for securitry
197 return $maxfile;
200 #################################################################################
201 # Setting the last sequence for the cabinet files
202 #################################################################################
204 sub get_last_sequence
206 my ( $cabfilename, $alludpatelastsequences ) = @_;
208 my $sequence = 0;
210 if (( $installer::globals::updatedatabase ) && ( exists($alludpatelastsequences->{$cabfilename}) ))
212 $sequence = $alludpatelastsequences->{$cabfilename};
214 else
216 $sequence = $installer::globals::lastsequence{$cabfilename};
219 return $sequence;
222 #################################################################################
223 # Creating the file Media.idt dynamically
224 # Content:
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) = @_;
233 my @mediatable = ();
235 my $diskid = 0;
237 installer::windows::idtglobal::write_idt_header(\@mediatable, "media");
239 if ( $installer::globals::fix_number_of_cab_files )
241 # number of cabfiles
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;
247 my $cabfull = 0;
248 my $counter = 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
273 if ( $cabfull )
275 my %media = ();
276 $cabfilenumber++;
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'}; }
300 $cabfull = 0;
301 $counter = 0;
305 else
307 installer::exiter::exit_program("ERROR: No cab file specification in globals.pm !", "create_media_table");
310 # Saving the file
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);