Branch libreoffice-5-0-4
[LibreOffice.git] / solenv / bin / modules / installer / windows / media.pm
blob3e6f429ba8e13d15c8cd14e4e04392308b70b11f
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 diskprompt for the media table.
39 ##############################################################
41 sub get_media_diskprompt
43 return 1;
46 ##############################################################
47 # Returning the volumelabel for the media table.
48 ##############################################################
50 sub get_media_volumelabel
52 return "DISK1";
55 ##############################################################
56 # Returning the source for the media table.
57 ##############################################################
59 sub get_media_source
61 return "";
64 #################################################
65 # Creating the cab file name dynamically
66 #################################################
68 sub generate_cab_filename_for_some_cabs
70 my ( $allvariables, $id ) = @_;
72 my $name = $allvariables->{'PRODUCTNAME'};
74 $name = lc($name);
75 $name =~ s/\.//g;
76 $name =~ s/\s//g;
78 # possibility to overwrite the name with variable CABFILENAME
79 if ( $allvariables->{'CABFILENAME'} ) { $name = $allvariables->{'CABFILENAME'}; }
81 $name = $name . $id . ".cab";
83 if ( $installer::globals::include_cab_in_msi ) { $name = "\#" . $name; }
85 return $name;
88 sub get_maximum_filenumber
90 my ($allfiles, $maxcabfilenumber) = @_;
92 my $maxfile = 0;
94 while ( ! ( $allfiles%$maxcabfilenumber == 0 ))
96 $allfiles++;
99 $maxfile = $allfiles / $maxcabfilenumber;
101 $maxfile++; # for securitry
103 return $maxfile;
106 #################################################################################
107 # Creating the file Media.idt dynamically
108 # Content:
109 # DiskId LastSequence DiskPrompt Cabinet VolumeLabel Source
110 # Idea: Every component is packed into each own cab file
111 #################################################################################
113 sub create_media_table
115 my ($filesref, $basedir, $allvariables, $allupdatelastsequences, $allupdatediskids) = @_;
117 my @mediatable = ();
119 my $diskid = 0;
121 installer::windows::idtglobal::write_idt_header(\@mediatable, "media");
123 if ( $installer::globals::fix_number_of_cab_files )
125 # number of cabfiles
126 my $maxcabfilenumber = $installer::globals::number_of_cabfiles;
127 if ( $allvariables->{'CABFILENUMBER'} ) { $maxcabfilenumber = $allvariables->{'CABFILENUMBER'}; }
128 my $allfiles = $#{$filesref} + 1;
129 my $maxfilenumber = get_maximum_filenumber($allfiles, $maxcabfilenumber);
130 my $cabfilenumber = 0;
131 my $cabfull = 0;
132 my $counter = 0;
134 # Sorting of files collector files required !
135 # Attention: The order in the cab file is not guaranteed (especially in update process)
137 for ( my $i = 0; $i <= $#{$filesref}; $i++ )
139 if (( $counter >= $maxfilenumber ) || ( $i == $#{$filesref} )) { $cabfull = 1; }
141 $counter++; # counting the files in the cab file
143 my $onefile = ${$filesref}[$i];
144 my $nextfile = ${$filesref}[$i+1];
146 my $filecomponent = "";
147 my $nextcomponent = "";
149 if ( $onefile->{'componentname'} ) { $filecomponent = $onefile->{'componentname'}; }
150 if ( $nextfile->{'componentname'} ) { $nextcomponent = $nextfile->{'componentname'}; }
152 if ( $filecomponent eq $nextcomponent ) # all files of one component have to be in one cab file
154 next; # nothing to do, this is not the last file of a component
157 if ( $cabfull )
159 my %media = ();
160 $cabfilenumber++;
162 $media{'DiskId'} = get_media_diskid($cabfilenumber);
163 $media{'LastSequence'} = $i + 1; # This should be correct, also for unsorted files collectors
164 $media{'DiskPrompt'} = get_media_diskprompt();
165 $media{'Cabinet'} = generate_cab_filename_for_some_cabs($allvariables, $cabfilenumber);
166 $media{'VolumeLabel'} = get_media_volumelabel();
167 $media{'Source'} = get_media_source();
169 my $oneline = $media{'DiskId'} . "\t" . $media{'LastSequence'} . "\t" . $media{'DiskPrompt'} . "\t"
170 . $media{'Cabinet'} . "\t" . $media{'VolumeLabel'} . "\t" . $media{'Source'} . "\n";
172 push(@mediatable, $oneline);
174 # Saving the cabinet file name in the file collector
176 $media{'Cabinet'} =~ s/^\s*\#//; # removing leading hash
178 for ( my $j = 0; $j <= $i; $j++ )
180 my $onefile = ${$filesref}[$j];
181 if ( ! $onefile->{'cabinet'} ) { $onefile->{'cabinet'} = $media{'Cabinet'}; }
184 $cabfull = 0;
185 $counter = 0;
189 else
191 installer::exiter::exit_program("ERROR: No cab file specification in globals.pm !", "create_media_table");
194 # Saving the file
196 my $mediatablename = $basedir . $installer::globals::separator . "Media.idt";
197 installer::files::save_file($mediatablename ,\@mediatable);
198 my $infoline = "Created idt file: $mediatablename\n";
199 push(@installer::globals::logfileinfo, $infoline);