Debian Codegraph @

solenv/bin/modules/installer/windows/media.pm

raw
1 #
2 # This file is part of the LibreOffice project.
3 #
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/.
7 #
8 # This file incorporates work covered by the following license notice:
9 #
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 .
17 #
18
19 package installer::windows::media;
20
21 use strict;
22 use warnings;
23
24 use installer::exiter;
25 use installer::files;
26 use installer::globals;
27 use installer::windows::idtglobal;
28
29 ##############################################################
30 # Returning the diskid for the media table.
31 ##############################################################
32
33 sub get_media_diskid
34 {
35 my ($id) = @_;
36
37 return $id;
38 }
39
40 ##############################################################
41 # Returning the diskprompt for the media table.
42 ##############################################################
43
44 sub get_media_diskprompt
45 {
46 return 1;
47 }
48
49 ##############################################################
50 # Returning the volumelabel for the media table.
51 ##############################################################
52
53 sub get_media_volumelabel
54 {
55 return "DISK1";
56 }
57
58 ##############################################################
59 # Returning the source for the media table.
60 ##############################################################
61
62 sub get_media_source
63 {
64 return "";
65 }
66
67 #################################################
68 # Creating the cab file name dynamically
69 #################################################
70
71 sub generate_cab_filename_for_some_cabs
72 {
73 my ( $allvariables, $id ) = @_;
74
75 my $name = $allvariables->{'PRODUCTNAME'};
76
77 $name = lc($name);
78 $name =~ s/\.//g;
79 $name =~ s/\s//g;
80
81 # possibility to overwrite the name with variable CABFILENAME
82 if ( $allvariables->{'CABFILENAME'} ) { $name = $allvariables->{'CABFILENAME'}; }
83
84 $name = $name . $id . ".cab";
85
86 if ( $installer::globals::include_cab_in_msi ) { $name = "\#" . $name; }
87
88 return $name;
89 }
90
91 sub get_maximum_filenumber
92 {
93 my ($allfiles, $maxcabfilenumber) = @_;
94
95 my $maxfile = 0;
96
97 while ( ! ( $allfiles%$maxcabfilenumber == 0 ))
98 {
99 $allfiles++;
100 }
101
102 $maxfile = $allfiles / $maxcabfilenumber;
103
104 $maxfile++; # for security
105
106 return $maxfile;
107 }
108
109 #################################################################################
110 # Creating the file Media.idt dynamically
111 # Content:
112 # DiskId LastSequence DiskPrompt Cabinet VolumeLabel Source
113 # Idea: Every component is packed into each own cab file
114 #################################################################################
115
116 sub create_media_table
117 {
118 my ($filesref, $basedir, $allvariables, $allupdatelastsequences, $allupdatediskids) = @_;
119
120 my @mediatable = ();
121
122 my $diskid = 0;
123
124 installer::windows::idtglobal::write_idt_header(\@mediatable, "media");
125
126 if ( $installer::globals::fix_number_of_cab_files )
127 {
128 # number of cabfiles
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;
134 my $cabfull = 0;
135 my $counter = 0;
136
137 # Sorting of files collector files required !
138 # Attention: The order in the cab file is not guaranteed (especially in update process)
139
140 for ( my $i = 0; $i <= $#{$filesref}; $i++ )
141 {
142 if (( $counter >= $maxfilenumber ) || ( $i == $#{$filesref} )) { $cabfull = 1; }
143
144 $counter++; # counting the files in the cab file
145
146 my $onefile = ${$filesref}[$i];
147 my $nextfile = ${$filesref}[$i+1];
148
149 my $filecomponent = "";
150 my $nextcomponent = "";
151
152 if ( $onefile->{'componentname'} ) { $filecomponent = $onefile->{'componentname'}; }
153 if ( $nextfile->{'componentname'} ) { $nextcomponent = $nextfile->{'componentname'}; }
154
155 if ( $filecomponent eq $nextcomponent ) # all files of one component have to be in one cab file
156 {
157 next; # nothing to do, this is not the last file of a component
158 }
159
160 if ( $cabfull )
161 {
162 my %media = ();
163 $cabfilenumber++;
164
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();
171
172 my $oneline = $media{'DiskId'} . "\t" . $media{'LastSequence'} . "\t" . $media{'DiskPrompt'} . "\t"
173 . $media{'Cabinet'} . "\t" . $media{'VolumeLabel'} . "\t" . $media{'Source'} . "\n";
174
175 push(@mediatable, $oneline);
176
177 # Saving the cabinet file name in the file collector
178
179 $media{'Cabinet'} =~ s/^\s*\#//; # removing leading hash
180
181 for ( my $j = 0; $j <= $i; $j++ )
182 {
183 my $onefile = ${$filesref}[$j];
184 if ( ! $onefile->{'cabinet'} ) { $onefile->{'cabinet'} = $media{'Cabinet'}; }
185 }
186
187 $cabfull = 0;
188 $counter = 0;
189 }
190 }
191 }
192 else
193 {
194 installer::exiter::exit_program("ERROR: No cab file specification in globals.pm !", "create_media_table");
195 }
196
197 # Saving the file
198
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);
203 }
204
205 1;