Debian Codegraph @

solenv/bin/modules/installer/windows/feature.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::feature;
20
21 use strict;
22 use warnings;
23
24 use installer::exiter;
25 use installer::files;
26 use installer::globals;
27 use installer::worker;
28 use installer::windows::idtglobal;
29 use installer::windows::language;
30
31 ##############################################################
32 # Returning the gid for a feature.
33 # Attention: Maximum length
34 ##############################################################
35
36 sub get_feature_gid
37 {
38 my ($onefeature) = @_;
39
40 my $gid = "";
41
42 if ( $onefeature->{'gid'} ) { $gid = $onefeature->{'gid'}; }
43
44 # Attention: Maximum feature length is 38!
45 installer::windows::idtglobal::shorten_feature_gid(\$gid);
46
47 return $gid
48 }
49
50 ##############################################################
51 # Returning the gid of the parent.
52 # Attention: Maximum length
53 ##############################################################
54
55 sub get_feature_parent
56 {
57 my ($onefeature) = @_;
58
59 my $parentgid = "";
60
61 if ( $onefeature->{'ParentID'} ) { $parentgid = $onefeature->{'ParentID'}; }
62
63 # The modules, hanging directly below the root, have to be root modules.
64 # Only then it is possible to make the "real" root module invisible by
65 # setting the display to "0".
66
67 if ( $parentgid eq $installer::globals::rootmodulegid ) { $parentgid = ""; }
68
69 # Attention: Maximum feature length is 38!
70 installer::windows::idtglobal::shorten_feature_gid(\$parentgid);
71
72 return $parentgid
73 }
74
75 ##############################################################
76 # Returning the display for a feature.
77 # 0: Feature is not shown
78 # odd: subfeatures are shown
79 # even: subfeatures are not shown
80 ##############################################################
81
82 sub get_feature_display
83 {
84 my ($onefeature) = @_;
85
86 my $display;
87 my $parentid = "";
88
89 if ( $onefeature->{'ParentID'} ) { $parentid = $onefeature->{'ParentID'}; }
90
91 if ( $parentid eq "" )
92 {
93 $display = "0"; # root module is not visible
94 }
95 elsif ( $onefeature->{'gid'} eq "gid_Module_Prg") # program module shows subfeatures
96 {
97 $display = "1"; # root module shows subfeatures
98 }
99 else
100 {
101 $display = "2"; # all other modules do not show subfeatures
102 }
103
104 # special case: Feature has flag "HIDDEN_ROOT" -> $display is 0
105 my $styles = "";
106 if ( $onefeature->{'Styles'} ) { $styles = $onefeature->{'Styles'}; }
107 if ( $styles =~ /\bHIDDEN_ROOT\b/ ) { $display = "0"; }
108
109 # Special handling for language modules. Only visible in multilingual installation set
110 if (( $styles =~ /\bSHOW_MULTILINGUAL_ONLY\b/ ) && ( ! $installer::globals::ismultilingual )) { $display = "0"; }
111
112 # No program module visible.
113 if ( $onefeature->{'gid'} eq "gid_Module_Prg" ) { $display = "0"; }
114
115 # hide en-US languagepack/always install it (unless using commandline arguments)
116 # mar-updater would add new languages that could be picked by default if the en-US fallback
117 # is not available/wasn't installed originally. (see tdf#164070)
118 $display = "0" if($onefeature->{'gid'} eq "gid_Module_Langpack_Root_en_US");
119
120 # making all feature invisible in Language packs and in Help packs!
121 if ( $installer::globals::languagepack || $installer::globals::helppack ) { $display = "0"; }
122
123 return $display
124 }
125
126 ##############################################################
127 # Returning the level for a feature.
128 ##############################################################
129
130 sub get_feature_level
131 {
132 my ($onefeature) = @_;
133
134 my $level = "20"; # the default
135
136 if ( $onefeature->{'Disabled'} )
137 {
138 if ( $onefeature->{'Disabled'} eq "YES" ) # Disabled = "YES"
139 {
140 $level = "0"; # disabled for installation at any INSTALLLEVEL
141 }
142 }
143 elsif ( $onefeature->{'Default'} )
144 {
145 if ( $onefeature->{'Default'} eq "NO" ) # explicitly set Default = "NO"
146 {
147 $level = "200"; # deselected in default installation, base is 100
148 }
149 }
150
151 return $level
152 }
153
154 ##############################################################
155 # Returning the directory for a feature.
156 ##############################################################
157
158 sub get_feature_directory
159 {
160 my ($onefeature) = @_;
161
162 my $directory;
163
164 $directory = "INSTALLLOCATION";
165
166 return $directory
167 }
168
169 ##############################################################
170 # Returning the directory for a feature.
171 ##############################################################
172
173 sub get_feature_attributes
174 {
175 my ($onefeature) = @_;
176
177 my $attributes;
178
179 # 2 = msidbFeatureAttributesFollowParent
180 # 8 = msidbFeatureAttributesDisallowAdvertise
181 # 16 = msidbFeatureAttributesUIDisallowAbsent
182
183 # No advertising of features and no leaving on network.
184 # Feature without parent must not have the "2"
185
186 my $parentgid = "";
187 if ( $onefeature->{'ParentID'} ) { $parentgid = $onefeature->{'ParentID'}; }
188
189 if (( $parentgid eq "" ) || ( $parentgid eq $installer::globals::rootmodulegid )) { $attributes = "8"; }
190 elsif ( $onefeature->{'Independent'} && ($onefeature->{'Independent'} eq "YES") ) { $attributes = "8"; }
191 elsif ( get_feature_display($onefeature) eq "0" ) { $attributes = "26"; } # fdo#33798
192 else { $attributes = "10"; }
193
194 return $attributes
195 }
196
197 #################################################################################
198 # Collecting the feature recursively.
199 #################################################################################
200
201 sub collect_modules_recursive
202 {
203 my ($modulesref, $parentid, $feature, $directaccess, $directgid, $directparent, $directsortkey, $sorted) = @_;
204
205 my @allchildren = ();
206 my $childrenexist = 0;
207
208 # Collecting children from Module $parentid
209
210 my $modulegid;
211 foreach $modulegid ( keys %{$directparent})
212 {
213 if ( $directparent->{$modulegid} eq $parentid )
214 {
215 push @allchildren, [ $directsortkey->{$modulegid}, $modulegid ];
216 $childrenexist = 1;
217 }
218 }
219
220 # Sorting children
221
222 if ( $childrenexist )
223 {
224 # Sort children
225 @allchildren = map { $_->[1] }
226 sort { $a->[0] <=> $b->[0] }
227 @allchildren;
228
229 # Adding children to new array
230 foreach my $gid ( @allchildren )
231 {
232 # Saving all lines, that have this 'gid'
233
234 my $unique;
235 foreach $unique ( keys %{$directgid} )
236 {
237 if ( $directgid->{$unique} eq $gid )
238 {
239 push(@{$feature}, ${$modulesref}[$directaccess->{$unique}]);
240 if ( $sorted->{$unique} == 1 ) { installer::exiter::exit_program("ERROR: Sorting feature failed! \"$unique\" already sorted.", "sort_feature"); }
241 $sorted->{$unique} = 1;
242 }
243 }
244
245 collect_modules_recursive($modulesref, $gid, $feature, $directaccess, $directgid, $directparent, $directsortkey, $sorted);
246 }
247 }
248 }
249
250 #################################################################################
251 # Sorting the feature in specified order. Evaluated is the key "Sortkey", that
252 # is set in scp2 projects.
253 # The display order of modules in Windows Installer is dependent from the order
254 # in the idt file. Therefore the order of the modules array has to be adapted
255 # to the Sortkey order, before the idt file is created.
256 #################################################################################
257
258 sub sort_feature
259 {
260 my ($modulesref) = @_;
261
262 my @feature = ();
263
264 my %directaccess = ();
265 my %directparent = ();
266 my %directgid = ();
267 my %directsortkey = ();
268 my %sorted = ();
269
270 for ( my $i = 0; $i <= $#{$modulesref}; $i++ )
271 {
272 my $onefeature = ${$modulesref}[$i];
273
274 my $uniquekey = $onefeature->{'uniquekey'};
275 my $modulegid = $onefeature->{'gid'};
276
277 $directaccess{$uniquekey} = $i;
278
279 $directgid{$uniquekey} = $onefeature->{'gid'};
280
281 # ParentID and Sortkey are not saved for the 'uniquekey', but only for the 'gid'
282
283 if ( $onefeature->{'ParentID'} ) { $directparent{$modulegid} = $onefeature->{'ParentID'}; }
284 else { $directparent{$modulegid} = ""; }
285
286 if ( $onefeature->{'Sortkey'} ) { $directsortkey{$modulegid} = $onefeature->{'Sortkey'}; }
287 else { $directsortkey{$modulegid} = "9999"; }
288
289 # Bookkeeping:
290 $sorted{$uniquekey} = 0;
291 }
292
293 # Searching all feature recursively, beginning with ParentID = ""
294 my $parentid = "";
295 collect_modules_recursive($modulesref, $parentid, \@feature, \%directaccess, \%directgid, \%directparent, \%directsortkey, \%sorted);
296
297 # Bookkeeping
298 my $modulekey;
299 foreach $modulekey ( keys %sorted )
300 {
301 if ( $sorted{$modulekey} == 0 )
302 {
303 my $infoline = "Warning: Module \"$modulekey\" could not be sorted. Added to the end of the module array.\n";
304 push(@installer::globals::logfileinfo, $infoline);
305 push(@feature, ${$modulesref}[$directaccess{$modulekey}]);
306 }
307 }
308
309 return \@feature;
310 }
311
312 #################################################################################
313 # Adding a unique key to the modules array. The gid is not unique for
314 # multilingual modules. Only the combination from gid and specific language
315 # is unique. Uniqueness is required for sorting mechanism.
316 #################################################################################
317
318 sub add_uniquekey
319 {
320 my ( $modulesref ) = @_;
321
322 for ( my $i = 0; $i <= $#{$modulesref}; $i++ )
323 {
324 my $uniquekey = ${$modulesref}[$i]->{'gid'};
325 if ( ${$modulesref}[$i]->{'specificlanguage'} ) { $uniquekey = $uniquekey . "_" . ${$modulesref}[$i]->{'specificlanguage'}; }
326 ${$modulesref}[$i]->{'uniquekey'} = $uniquekey;
327 }
328 }
329
330 #################################################################################
331 # Creating the file Feature.idt dynamically
332 # Content:
333 # Feature Feature_Parent Title Description Display Level Directory_ Attributes
334 #################################################################################
335
336 sub create_feature_table
337 {
338 my ($modulesref, $basedir, $languagesarrayref, $allvariableshashref) = @_;
339
340 for ( my $m = 0; $m <= $#{$languagesarrayref}; $m++ )
341 {
342 my $onelanguage = ${$languagesarrayref}[$m];
343
344 my $infoline;
345
346 my @featuretable = ();
347
348 installer::windows::idtglobal::write_idt_header(\@featuretable, "feature");
349
350 for ( my $i = 0; $i <= $#{$modulesref}; $i++ )
351 {
352 my $onefeature = ${$modulesref}[$i];
353
354 # Java and Ada only, if the correct settings are set
355 my $styles = "";
356 if ( $onefeature->{'Styles'} ) { $styles = $onefeature->{'Styles'}; }
357
358 # Controlling the language!
359 # Only language independent feature or feature with the correct language will be included into the table
360 # But help packs are different. They have en-US added as setup language.
361
362 if (! (!(( $onefeature->{'ismultilingual'} )) || ( $onefeature->{'specificlanguage'} eq $onelanguage ) || $installer::globals::helppack ) ) { next; }
363
364 my %feature = ();
365
366 $feature{'feature'} = get_feature_gid($onefeature);
367 $feature{'feature_parent'} = get_feature_parent($onefeature);
368 $feature{'Title'} = $onefeature->{'Name'} // "";
369 $feature{'Description'} = $onefeature->{'Description'} // "";
370 $feature{'Description'} =~ s/\\\"/\"/g; # no more masquerading of '"'
371 $feature{'Display'} = get_feature_display($onefeature);
372 $feature{'Level'} = get_feature_level($onefeature);
373 $feature{'Directory_'} = get_feature_directory($onefeature);
374 $feature{'Attributes'} = get_feature_attributes($onefeature);
375
376 my $oneline = $feature{'feature'} . "\t" . $feature{'feature_parent'} . "\t" . $feature{'Title'} . "\t"
377 . $feature{'Description'} . "\t" . $feature{'Display'} . "\t" . $feature{'Level'} . "\t"
378 . $feature{'Directory_'} . "\t" . $feature{'Attributes'} . "\n";
379
380 push(@featuretable, $oneline);
381
382 # collecting all feature in global feature collector (so that properties can be set in property table)
383 if ( ! grep {$_ eq $feature{'feature'}} @installer::globals::featurecollector )
384 {
385 push(@installer::globals::featurecollector, $feature{'feature'});
386 }
387
388 # collecting all language feature in feature collector for check of language selection
389 if (( $styles =~ /\bSHOW_MULTILINGUAL_ONLY\b/ ) && ( $onefeature->{'ParentID'} ne $installer::globals::rootmodulegid ))
390 {
391 $installer::globals::multilingual_only_modules{$feature{'feature'}} = 1;
392 }
393
394 # collecting all application feature in global feature collector for check of application selection
395 if ( $styles =~ /\bAPPLICATIONMODULE\b/ )
396 {
397 $installer::globals::application_modules{$feature{'feature'}} = 1;
398 }
399 }
400
401 # Saving the file
402
403 my $featuretablename = $basedir . $installer::globals::separator . "Feature.idt" . "." . $onelanguage;
404 installer::files::save_file($featuretablename ,\@featuretable);
405 $infoline = "Created idt file: $featuretablename\n";
406 push(@installer::globals::logfileinfo, $infoline);
407 }
408
409 }
410
411 1;