bump product version to 4.1.6.2
[LibreOffice.git] / solenv / bin / modules / installer / windows / feature.pm
blobf360337aa48050ab1f848f05e7ee9800eabbfd87
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::feature;
21 use installer::exiter;
22 use installer::files;
23 use installer::globals;
24 use installer::worker;
25 use installer::windows::idtglobal;
26 use installer::windows::language;
28 ##############################################################
29 # Returning the gid for a feature.
30 # Attention: Maximum length
31 ##############################################################
33 sub get_feature_gid
35 my ($onefeature) = @_;
37 my $gid = "";
39 if ( $onefeature->{'gid'} ) { $gid = $onefeature->{'gid'}; }
41 # Attention: Maximum feature length is 38!
42 installer::windows::idtglobal::shorten_feature_gid(\$gid);
44 return $gid
47 ##############################################################
48 # Returning the gid of the parent.
49 # Attention: Maximum length
50 ##############################################################
52 sub get_feature_parent
54 my ($onefeature) = @_;
56 my $parentgid = "";
58 if ( $onefeature->{'ParentID'} ) { $parentgid = $onefeature->{'ParentID'}; }
60 # The modules, hanging directly below the root, have to be root modules.
61 # Only then it is possible to make the "real" root module invisible by
62 # setting the display to "0".
64 if ( $parentgid eq $installer::globals::rootmodulegid ) { $parentgid = ""; }
66 # Attention: Maximum feature length is 38!
67 installer::windows::idtglobal::shorten_feature_gid(\$parentgid);
69 return $parentgid
72 ##############################################################
73 # Returning the display for a feature.
74 # 0: Feature is not shown
75 # odd: subfeatures are shown
76 # even: subfeatures are not shown
77 ##############################################################
79 sub get_feature_display
81 my ($onefeature) = @_;
83 my $display;
84 my $parentid = "";
86 if ( $onefeature->{'ParentID'} ) { $parentid = $onefeature->{'ParentID'}; }
88 if ( $parentid eq "" )
90 $display = "0"; # root module is not visible
92 elsif ( $onefeature->{'gid'} eq "gid_Module_Prg") # program module shows subfeatures
94 $display = "1"; # root module shows subfeatures
96 else
98 $display = "2"; # all other modules do not show subfeatures
101 # special case: Feature has flag "HIDDEN_ROOT" -> $display is 0
102 my $styles = "";
103 if ( $onefeature->{'Styles'} ) { $styles = $onefeature->{'Styles'}; }
104 if ( $styles =~ /\bHIDDEN_ROOT\b/ ) { $display = "0"; }
106 # Special handling for language modules. Only visible in multilingual installation set
107 if (( $styles =~ /\bSHOW_MULTILINGUAL_ONLY\b/ ) && ( ! $installer::globals::ismultilingual )) { $display = "0"; }
109 # Special handling for c05office. No program module visible.
110 if (( $onefeature->{'gid'} eq "gid_Module_Prg" ) && ( $installer::globals::product =~ /c05office/i )) { $display = "0"; }
112 # making all feature invisible in Language packs and in Help packs!
113 if ( $installer::globals::languagepack || $installer::globals::helppack ) { $display = "0"; }
115 return $display
118 ##############################################################
119 # Returning the level for a feature.
120 ##############################################################
122 sub get_feature_level
124 my ($onefeature) = @_;
126 my $level = "20"; # the default
128 my $localdefault = "";
130 if ( $onefeature->{'Default'} ) { $localdefault = $onefeature->{'Default'}; }
132 if ( $localdefault eq "NO" ) # explicitly set Default = "NO"
134 $level = "200"; # deselected in default installation, base is 100
137 # special handling for Java and Ada
138 if ( $onefeature->{'Name'} )
140 if ( $onefeature->{'Name'} =~ /java/i ) { $level = $level + 40; }
143 # if FeatureLevel is defined in scp, this will be used
145 if ( $onefeature->{'FeatureLevel'} ) { $level = $onefeature->{'FeatureLevel'}; }
147 return $level
150 ##############################################################
151 # Returning the directory for a feature.
152 ##############################################################
154 sub get_feature_directory
156 my ($onefeature) = @_;
158 my $directory;
160 $directory = "INSTALLLOCATION";
162 return $directory
165 ##############################################################
166 # Returning the directory for a feature.
167 ##############################################################
169 sub get_feature_attributes
171 my ($onefeature) = @_;
173 my $attributes;
175 # No advertising of features and no leaving on network.
176 # Feature without parent must not have the "2"
178 my $parentgid = "";
179 if ( $onefeature->{'ParentID'} ) { $parentgid = $onefeature->{'ParentID'}; }
181 if (( $parentgid eq "" ) || ( $parentgid eq $installer::globals::rootmodulegid )) { $attributes = "8"; }
182 elsif ( get_feature_display($onefeature) eq "0" ) { $attributes = "26"; } # fdo#33798
183 else { $attributes = "10"; }
185 return $attributes
188 #################################################################################
189 # Replacing one variable in one files
190 #################################################################################
192 sub replace_one_variable
194 my ($translationfile, $variable, $searchstring) = @_;
196 for ( my $i = 0; $i <= $#{$translationfile}; $i++ )
198 ${$translationfile}[$i] =~ s/\%$searchstring/$variable/g;
202 #################################################################################
203 # Replacing the variables in the feature names and descriptions
204 #################################################################################
206 sub replace_variables
208 my ($translationfile, $variableshashref) = @_;
210 # we want to substitute FOO_BR before FOO to avoid floating _BR suffixes
211 foreach $key (sort { length ($b) <=> length ($a) } keys %{$variableshashref})
213 my $value = $variableshashref->{$key};
214 replace_one_variable($translationfile, $value, $key);
218 #################################################################################
219 # Collecting the feature recursively.
220 #################################################################################
222 sub collect_modules_recursive
224 my ($modulesref, $parentid, $feature, $directaccess, $directgid, $directparent, $directsortkey, $sorted) = @_;
226 my @allchildren = ();
227 my $childrenexist = 0;
229 # Collecting children from Module $parentid
231 my $modulegid;
232 foreach $modulegid ( keys %{$directparent})
234 if ( $directparent->{$modulegid} eq $parentid )
236 push @allchildren, [ $directsortkey->{$modulegid}, $modulegid ];
237 $childrenexist = 1;
241 # Sorting children
243 if ( $childrenexist )
245 # Sort children
246 @allchildren = map { $_->[1] }
247 sort { $a->[0] <=> $b->[0] }
248 @allchildren;
250 # Adding children to new array
251 foreach my $gid ( @allchildren )
253 # Saving all lines, that have this 'gid'
255 my $unique;
256 foreach $unique ( keys %{$directgid} )
258 if ( $directgid->{$unique} eq $gid )
260 push(@{$feature}, ${$modulesref}[$directaccess->{$unique}]);
261 if ( $sorted->{$unique} == 1 ) { installer::exiter::exit_program("ERROR: Sorting feature failed! \"$unique\" already sorted.", "sort_feature"); }
262 $sorted->{$unique} = 1;
266 collect_modules_recursive($modulesref, $gid, $feature, $directaccess, $directgid, $directparent, $directsortkey, $sorted);
271 #################################################################################
272 # Sorting the feature in specified order. Evaluated is the key "Sortkey", that
273 # is set in scp2 projects.
274 # The display order of modules in Windows Installer is dependent from the order
275 # in the idt file. Therefore the order of the modules array has to be adapted
276 # to the Sortkey order, before the idt file is created.
277 #################################################################################
279 sub sort_feature
281 my ($modulesref) = @_;
283 my @feature = ();
285 my %directaccess = ();
286 my %directparent = ();
287 my %directgid = ();
288 my %directsortkey = ();
289 my %sorted = ();
291 for ( my $i = 0; $i <= $#{$modulesref}; $i++ )
293 my $onefeature = ${$modulesref}[$i];
295 my $uniquekey = $onefeature->{'uniquekey'};
296 my $modulegid = $onefeature->{'gid'};
298 $directaccess{$uniquekey} = $i;
300 $directgid{$uniquekey} = $onefeature->{'gid'};
302 # ParentID and Sortkey are not saved for the 'uniquekey', but only for the 'gid'
304 if ( $onefeature->{'ParentID'} ) { $directparent{$modulegid} = $onefeature->{'ParentID'}; }
305 else { $directparent{$modulegid} = ""; }
307 if ( $onefeature->{'Sortkey'} ) { $directsortkey{$modulegid} = $onefeature->{'Sortkey'}; }
308 else { $directsortkey{$modulegid} = "9999"; }
310 # Bookkeeping:
311 $sorted{$uniquekey} = 0;
314 # Searching all feature recursively, beginning with ParentID = ""
315 my $parentid = "";
316 collect_modules_recursive($modulesref, $parentid, \@feature, \%directaccess, \%directgid, \%directparent, \%directsortkey, \%sorted);
318 # Bookkeeping
319 my $modulekey;
320 foreach $modulekey ( keys %sorted )
322 if ( $sorted{$modulekey} == 0 )
324 my $infoline = "Warning: Module \"$modulekey\" could not be sorted. Added to the end of the module array.\n";
325 push(@installer::globals::logfileinfo, $infoline);
326 push(@feature, ${$modulesref}[$directaccess{$modulekey}]);
330 return \@feature;
333 #################################################################################
334 # Adding a unique key to the modules array. The gid is not unique for
335 # multilingual modules. Only the combination from gid and specific language
336 # is unique. Uniqueness is required for sorting mechanism.
337 #################################################################################
339 sub add_uniquekey
341 my ( $modulesref ) = @_;
343 for ( my $i = 0; $i <= $#{$modulesref}; $i++ )
345 my $uniquekey = ${$modulesref}[$i]->{'gid'};
346 if ( ${$modulesref}[$i]->{'specificlanguage'} ) { $uniquekey = $uniquekey . "_" . ${$modulesref}[$i]->{'specificlanguage'}; }
347 ${$modulesref}[$i]->{'uniquekey'} = $uniquekey;
351 #################################################################################
352 # Creating the file Feature.idt dynamically
353 # Content:
354 # Feature Feature_Parent Title Description Display Level Directory_ Attributes
355 #################################################################################
357 sub create_feature_table
359 my ($modulesref, $basedir, $languagesarrayref, $allvariableshashref) = @_;
361 for ( my $m = 0; $m <= $#{$languagesarrayref}; $m++ )
363 my $onelanguage = ${$languagesarrayref}[$m];
365 my $infoline;
367 my @featuretable = ();
369 installer::windows::idtglobal::write_idt_header(\@featuretable, "feature");
371 for ( my $i = 0; $i <= $#{$modulesref}; $i++ )
373 my $onefeature = ${$modulesref}[$i];
375 # Java and Ada only, if the correct settings are set
376 my $styles = "";
377 if ( $onefeature->{'Styles'} ) { $styles = $onefeature->{'Styles'}; }
379 # Controlling the language!
380 # Only language independent feature or feature with the correct language will be included into the table
381 # But help packs are different. They have en-US added as setup language.
383 if (! (!(( $onefeature->{'ismultilingual'} )) || ( $onefeature->{'specificlanguage'} eq $onelanguage ) || $installer::globals::helppack ) ) { next; }
385 my %feature = ();
387 $feature{'feature'} = get_feature_gid($onefeature);
388 $feature{'feature_parent'} = get_feature_parent($onefeature);
389 $feature{'Title'} = $onefeature->{'Name'};
390 $feature{'Description'} = $onefeature->{'Description'};
391 $feature{'Display'} = get_feature_display($onefeature);
392 $feature{'Level'} = get_feature_level($onefeature);
393 $feature{'Directory_'} = get_feature_directory($onefeature);
394 $feature{'Attributes'} = get_feature_attributes($onefeature);
396 my $oneline = $feature{'feature'} . "\t" . $feature{'feature_parent'} . "\t" . $feature{'Title'} . "\t"
397 . $feature{'Description'} . "\t" . $feature{'Display'} . "\t" . $feature{'Level'} . "\t"
398 . $feature{'Directory_'} . "\t" . $feature{'Attributes'} . "\n";
400 push(@featuretable, $oneline);
402 # collecting all feature in global feature collector (so that properties can be set in property table)
403 if ( ! grep {$_ eq $feature{'feature'}} @installer::globals::featurecollector )
405 push(@installer::globals::featurecollector, $feature{'feature'});
408 # collecting all language feature in feature collector for check of language selection
409 if (( $styles =~ /\bSHOW_MULTILINGUAL_ONLY\b/ ) && ( $onefeature->{'ParentID'} ne $installer::globals::rootmodulegid ))
411 $installer::globals::multilingual_only_modules{$feature{'feature'}} = 1;
414 # collecting all application feature in global feature collector for check of application selection
415 if ( $styles =~ /\bAPPLICATIONMODULE\b/ )
417 $installer::globals::application_modules{$feature{'feature'}} = 1;
421 # Saving the file
423 my $featuretablename = $basedir . $installer::globals::separator . "Feature.idt" . "." . $onelanguage;
424 installer::files::save_file($featuretablename ,\@featuretable);
425 $infoline = "Created idt file: $featuretablename\n";
426 push(@installer::globals::logfileinfo, $infoline);