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
;
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 ##############################################################
35 my ($onefeature) = @_;
39 if ( $onefeature->{'gid'} ) { $gid = $onefeature->{'gid'}; }
41 # Attention: Maximum feature length is 38!
42 installer
::windows
::idtglobal
::shorten_feature_gid
(\
$gid);
47 ##############################################################
48 # Returning the gid of the parent.
49 # Attention: Maximum length
50 ##############################################################
52 sub get_feature_parent
54 my ($onefeature) = @_;
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);
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) = @_;
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
98 $display = "2"; # all other modules do not show subfeatures
101 # special case: Feature has flag "HIDDEN_ROOT" -> $display is 0
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 # No program module visible.
110 if ( $onefeature->{'gid'} eq "gid_Module_Prg" ) { $display = "0"; }
112 # making all feature invisible in Language packs and in Help packs!
113 if ( $installer::globals
::languagepack
|| $installer::globals
::helppack
) { $display = "0"; }
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
140 ##############################################################
141 # Returning the directory for a feature.
142 ##############################################################
144 sub get_feature_directory
146 my ($onefeature) = @_;
150 $directory = "INSTALLLOCATION";
155 ##############################################################
156 # Returning the directory for a feature.
157 ##############################################################
159 sub get_feature_attributes
161 my ($onefeature) = @_;
165 # No advertising of features and no leaving on network.
166 # Feature without parent must not have the "2"
169 if ( $onefeature->{'ParentID'} ) { $parentgid = $onefeature->{'ParentID'}; }
171 if (( $parentgid eq "" ) || ( $parentgid eq $installer::globals
::rootmodulegid
)) { $attributes = "8"; }
172 elsif ( get_feature_display
($onefeature) eq "0" ) { $attributes = "26"; } # fdo#33798
173 else { $attributes = "10"; }
178 #################################################################################
179 # Collecting the feature recursively.
180 #################################################################################
182 sub collect_modules_recursive
184 my ($modulesref, $parentid, $feature, $directaccess, $directgid, $directparent, $directsortkey, $sorted) = @_;
186 my @allchildren = ();
187 my $childrenexist = 0;
189 # Collecting children from Module $parentid
192 foreach $modulegid ( keys %{$directparent})
194 if ( $directparent->{$modulegid} eq $parentid )
196 push @allchildren, [ $directsortkey->{$modulegid}, $modulegid ];
203 if ( $childrenexist )
206 @allchildren = map { $_->[1] }
207 sort { $a->[0] <=> $b->[0] }
210 # Adding children to new array
211 foreach my $gid ( @allchildren )
213 # Saving all lines, that have this 'gid'
216 foreach $unique ( keys %{$directgid} )
218 if ( $directgid->{$unique} eq $gid )
220 push(@
{$feature}, ${$modulesref}[$directaccess->{$unique}]);
221 if ( $sorted->{$unique} == 1 ) { installer
::exiter
::exit_program
("ERROR: Sorting feature failed! \"$unique\" already sorted.", "sort_feature"); }
222 $sorted->{$unique} = 1;
226 collect_modules_recursive
($modulesref, $gid, $feature, $directaccess, $directgid, $directparent, $directsortkey, $sorted);
231 #################################################################################
232 # Sorting the feature in specified order. Evaluated is the key "Sortkey", that
233 # is set in scp2 projects.
234 # The display order of modules in Windows Installer is dependent from the order
235 # in the idt file. Therefore the order of the modules array has to be adapted
236 # to the Sortkey order, before the idt file is created.
237 #################################################################################
241 my ($modulesref) = @_;
245 my %directaccess = ();
246 my %directparent = ();
248 my %directsortkey = ();
251 for ( my $i = 0; $i <= $#{$modulesref}; $i++ )
253 my $onefeature = ${$modulesref}[$i];
255 my $uniquekey = $onefeature->{'uniquekey'};
256 my $modulegid = $onefeature->{'gid'};
258 $directaccess{$uniquekey} = $i;
260 $directgid{$uniquekey} = $onefeature->{'gid'};
262 # ParentID and Sortkey are not saved for the 'uniquekey', but only for the 'gid'
264 if ( $onefeature->{'ParentID'} ) { $directparent{$modulegid} = $onefeature->{'ParentID'}; }
265 else { $directparent{$modulegid} = ""; }
267 if ( $onefeature->{'Sortkey'} ) { $directsortkey{$modulegid} = $onefeature->{'Sortkey'}; }
268 else { $directsortkey{$modulegid} = "9999"; }
271 $sorted{$uniquekey} = 0;
274 # Searching all feature recursively, beginning with ParentID = ""
276 collect_modules_recursive
($modulesref, $parentid, \
@feature, \
%directaccess, \
%directgid, \
%directparent, \
%directsortkey, \
%sorted);
280 foreach $modulekey ( keys %sorted )
282 if ( $sorted{$modulekey} == 0 )
284 my $infoline = "Warning: Module \"$modulekey\" could not be sorted. Added to the end of the module array.\n";
285 push(@installer::globals
::logfileinfo
, $infoline);
286 push(@feature, ${$modulesref}[$directaccess{$modulekey}]);
293 #################################################################################
294 # Adding a unique key to the modules array. The gid is not unique for
295 # multilingual modules. Only the combination from gid and specific language
296 # is unique. Uniqueness is required for sorting mechanism.
297 #################################################################################
301 my ( $modulesref ) = @_;
303 for ( my $i = 0; $i <= $#{$modulesref}; $i++ )
305 my $uniquekey = ${$modulesref}[$i]->{'gid'};
306 if ( ${$modulesref}[$i]->{'specificlanguage'} ) { $uniquekey = $uniquekey . "_" . ${$modulesref}[$i]->{'specificlanguage'}; }
307 ${$modulesref}[$i]->{'uniquekey'} = $uniquekey;
311 #################################################################################
312 # Creating the file Feature.idt dynamically
314 # Feature Feature_Parent Title Description Display Level Directory_ Attributes
315 #################################################################################
317 sub create_feature_table
319 my ($modulesref, $basedir, $languagesarrayref, $allvariableshashref) = @_;
321 for ( my $m = 0; $m <= $#{$languagesarrayref}; $m++ )
323 my $onelanguage = ${$languagesarrayref}[$m];
327 my @featuretable = ();
329 installer
::windows
::idtglobal
::write_idt_header
(\
@featuretable, "feature");
331 for ( my $i = 0; $i <= $#{$modulesref}; $i++ )
333 my $onefeature = ${$modulesref}[$i];
335 # Java and Ada only, if the correct settings are set
337 if ( $onefeature->{'Styles'} ) { $styles = $onefeature->{'Styles'}; }
339 # Controlling the language!
340 # Only language independent feature or feature with the correct language will be included into the table
341 # But help packs are different. They have en-US added as setup language.
343 if (! (!(( $onefeature->{'ismultilingual'} )) || ( $onefeature->{'specificlanguage'} eq $onelanguage ) || $installer::globals
::helppack
) ) { next; }
347 $feature{'feature'} = get_feature_gid
($onefeature);
348 $feature{'feature_parent'} = get_feature_parent
($onefeature);
349 $feature{'Title'} = $onefeature->{'Name'};
350 $feature{'Description'} = $onefeature->{'Description'};
351 $feature{'Description'} =~ s/\\\"/\"/g; # no more masquerading of '"'
352 $feature{'Display'} = get_feature_display
($onefeature);
353 $feature{'Level'} = get_feature_level
($onefeature);
354 $feature{'Directory_'} = get_feature_directory
($onefeature);
355 $feature{'Attributes'} = get_feature_attributes
($onefeature);
357 my $oneline = $feature{'feature'} . "\t" . $feature{'feature_parent'} . "\t" . $feature{'Title'} . "\t"
358 . $feature{'Description'} . "\t" . $feature{'Display'} . "\t" . $feature{'Level'} . "\t"
359 . $feature{'Directory_'} . "\t" . $feature{'Attributes'} . "\n";
361 push(@featuretable, $oneline);
363 # collecting all feature in global feature collector (so that properties can be set in property table)
364 if ( ! grep {$_ eq $feature{'feature'}} @installer::globals
::featurecollector
)
366 push(@installer::globals
::featurecollector
, $feature{'feature'});
369 # collecting all language feature in feature collector for check of language selection
370 if (( $styles =~ /\bSHOW_MULTILINGUAL_ONLY\b/ ) && ( $onefeature->{'ParentID'} ne $installer::globals
::rootmodulegid
))
372 $installer::globals
::multilingual_only_modules
{$feature{'feature'}} = 1;
375 # collecting all application feature in global feature collector for check of application selection
376 if ( $styles =~ /\bAPPLICATIONMODULE\b/ )
378 $installer::globals
::application_modules
{$feature{'feature'}} = 1;
384 my $featuretablename = $basedir . $installer::globals
::separator
. "Feature.idt" . "." . $onelanguage;
385 installer
::files
::save_file
($featuretablename ,\
@featuretable);
386 $infoline = "Created idt file: $featuretablename\n";
387 push(@installer::globals
::logfileinfo
, $infoline);