Update ooo320-m1
[ooovba.git] / solenv / bin / modules / installer / windows / feature.pm
blob70ec6c07363caf194bc3f7267067691f31efa55f
1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 #
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # $RCSfile: feature.pm,v $
11 # $Revision: 1.24 $
13 # This file is part of OpenOffice.org.
15 # OpenOffice.org is free software: you can redistribute it and/or modify
16 # it under the terms of the GNU Lesser General Public License version 3
17 # only, as published by the Free Software Foundation.
19 # OpenOffice.org is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU Lesser General Public License version 3 for more details
23 # (a copy is included in the LICENSE file that accompanied this code).
25 # You should have received a copy of the GNU Lesser General Public License
26 # version 3 along with OpenOffice.org. If not, see
27 # <http://www.openoffice.org/license.html>
28 # for a copy of the LGPLv3 License.
30 #*************************************************************************
32 package installer::windows::feature;
34 use installer::existence;
35 use installer::exiter;
36 use installer::files;
37 use installer::globals;
38 use installer::sorter;
39 use installer::worker;
40 use installer::windows::idtglobal;
41 use installer::windows::language;
43 ##############################################################
44 # Returning the gid for a feature.
45 # Attention: Maximum length
46 ##############################################################
48 sub get_feature_gid
50 my ($onefeature) = @_;
52 my $gid = "";
54 if ( $onefeature->{'gid'} ) { $gid = $onefeature->{'gid'}; }
56 # Attention: Maximum feature length is 38!
57 installer::windows::idtglobal::shorten_feature_gid(\$gid);
59 return $gid
62 ##############################################################
63 # Returning the gid of the parent.
64 # Attention: Maximum length
65 ##############################################################
67 sub get_feature_parent
69 my ($onefeature) = @_;
71 my $parentgid = "";
73 if ( $onefeature->{'ParentID'} ) { $parentgid = $onefeature->{'ParentID'}; }
75 # The modules, hanging directly below the root, have to be root modules.
76 # Only then it is possible to make the "real" root module invisible by
77 # setting the display to "0".
79 if ( $parentgid eq $installer::globals::rootmodulegid ) { $parentgid = ""; }
81 # Attention: Maximum feature length is 38!
82 installer::windows::idtglobal::shorten_feature_gid(\$parentgid);
84 return $parentgid
87 ##############################################################
88 # Returning the display for a feature.
89 # 0: Feature is not shown
90 # odd: subfeatures are shown
91 # even: subfeatures are not shown
92 ##############################################################
94 sub get_feature_display
96 my ($onefeature) = @_;
98 my $display;
99 my $parentid = "";
101 if ( $onefeature->{'ParentID'} ) { $parentid = $onefeature->{'ParentID'}; }
103 if ( $parentid eq "" )
105 $display = "0"; # root module is not visible
107 elsif ( $onefeature->{'gid'} eq "gid_Module_Prg") # program module shows subfeatures
109 $display = "1"; # root module shows subfeatures
111 else
113 $display = "2"; # all other modules do not show subfeatures
116 # special case: Feature has flag "HIDDEN_ROOT" -> $display is 0
117 my $styles = "";
118 if ( $onefeature->{'Styles'} ) { $styles = $onefeature->{'Styles'}; }
119 if ( $styles =~ /\bHIDDEN_ROOT\b/ ) { $display = "0"; }
121 # Special handling for language modules. Only visible in multilingual installation set
122 if (( $styles =~ /\bSHOW_MULTILINGUAL_ONLY\b/ ) && ( ! $installer::globals::ismultilingual )) { $display = "0"; }
124 # Special handling for c05office. No program module visible.
125 if (( $onefeature->{'gid'} eq "gid_Module_Prg" ) && ( $installer::globals::product =~ /c05office/i )) { $display = "0"; }
127 # making all feature invisible in Language packs!
128 if ( $installer::globals::languagepack ) { $display = "0"; }
130 return $display
133 ##############################################################
134 # Returning the level for a feature.
135 ##############################################################
137 sub get_feature_level
139 my ($onefeature) = @_;
141 my $level = "20"; # the default
143 my $localdefault = "";
145 if ( $onefeature->{'Default'} ) { $localdefault = $onefeature->{'Default'}; }
147 if ( $localdefault eq "NO" ) # explicitely set Default = "NO"
149 $level = "200"; # deselected in default installation, base is 100
150 if ( $installer::globals::patch ) { $level = "20"; }
153 # special handling for Java and Ada
154 if ( $onefeature->{'Name'} )
156 if ( $onefeature->{'Name'} =~ /java/i ) { $level = $level + 40; }
159 # if FeatureLevel is defined in scp, this will be used
161 if ( $onefeature->{'FeatureLevel'} ) { $level = $onefeature->{'FeatureLevel'}; }
163 return $level
166 ##############################################################
167 # Returning the directory for a feature.
168 ##############################################################
170 sub get_feature_directory
172 my ($onefeature) = @_;
174 my $directory;
176 $directory = "INSTALLLOCATION";
178 return $directory
181 ##############################################################
182 # Returning the directory for a feature.
183 ##############################################################
185 sub get_feature_attributes
187 my ($onefeature) = @_;
189 my $attributes;
191 # No advertising of features and no leaving on network.
192 # Feature without parent must not have the "2"
194 my $parentgid = "";
195 if ( $onefeature->{'ParentID'} ) { $parentgid = $onefeature->{'ParentID'}; }
197 if (( $parentgid eq "" ) || ( $parentgid eq $installer::globals::rootmodulegid )) { $attributes = "8"; }
198 else { $attributes = "10"; }
200 return $attributes
203 #################################################################################
204 # Replacing one variable in one files
205 #################################################################################
207 sub replace_one_variable
209 my ($translationfile, $variable, $searchstring) = @_;
211 for ( my $i = 0; $i <= $#{$translationfile}; $i++ )
213 ${$translationfile}[$i] =~ s/\%$searchstring/$variable/g;
217 #################################################################################
218 # Replacing the variables in the feature names and descriptions
219 #################################################################################
221 sub replace_variables
223 my ($translationfile, $variableshashref) = @_;
225 foreach $key (keys %{$variableshashref})
227 my $value = $variableshashref->{$key};
228 replace_one_variable($translationfile, $value, $key);
232 #################################################################################
233 # Collecting the feature recursively.
234 #################################################################################
236 sub collect_modules_recursive
238 my ($modulesref, $parentid, $feature, $directaccess, $directgid, $directparent, $directsortkey, $sorted) = @_;
240 my @allchildren = ();
241 my $childrenexist = 0;
243 # Collecting children from Module $parentid
245 my $modulegid;
246 foreach $modulegid ( keys %{$directparent})
248 if ( $directparent->{$modulegid} eq $parentid )
250 my %childhash = ( "gid" => "$modulegid", "Sortkey" => "$directsortkey->{$modulegid}");
251 push(@allchildren, \%childhash);
252 $childrenexist = 1;
256 # Sorting children
258 if ( $childrenexist )
260 # Sort children
261 installer::sorter::sort_array_of_hashes_numerically(\@allchildren, "Sortkey");
263 # Adding children to new array
264 my $childhashref;
265 foreach $childhashref ( @allchildren )
267 my $gid = $childhashref->{'gid'};
269 # Saving all lines, that have this 'gid'
271 my $unique;
272 foreach $unique ( keys %{$directgid} )
274 if ( $directgid->{$unique} eq $gid )
276 push(@{$feature}, ${$modulesref}[$directaccess->{$unique}]);
277 if ( $sorted->{$unique} == 1 ) { installer::exiter::exit_program("ERROR: Sorting feature failed! \"$unique\" already sorted.", "sort_feature"); }
278 $sorted->{$unique} = 1;
282 collect_modules_recursive($modulesref, $gid, $feature, $directaccess, $directgid, $directparent, $directsortkey, $sorted);
287 #################################################################################
288 # Sorting the feature in specified order. Evaluated is the key "Sortkey", that
289 # is set in scp2 projects.
290 # The display order of modules in Windows Installer is dependent from the order
291 # in the idt file. Therefore the order of the modules array has to be adapted
292 # to the Sortkey order, before the idt file is created.
293 #################################################################################
295 sub sort_feature
297 my ($modulesref) = @_;
299 my @feature = ();
301 my %directaccess = ();
302 my %directparent = ();
303 my %directgid = ();
304 my %directsortkey = ();
305 my %sorted = ();
307 for ( my $i = 0; $i <= $#{$modulesref}; $i++ )
309 my $onefeature = ${$modulesref}[$i];
311 my $uniquekey = $onefeature->{'uniquekey'};
312 my $modulegid = $onefeature->{'gid'};
314 $directaccess{$uniquekey} = $i;
316 $directgid{$uniquekey} = $onefeature->{'gid'};
318 # ParentID and Sortkey are not saved for the 'uniquekey', but only for the 'gid'
320 if ( $onefeature->{'ParentID'} ) { $directparent{$modulegid} = $onefeature->{'ParentID'}; }
321 else { $directparent{$modulegid} = ""; }
323 if ( $onefeature->{'Sortkey'} ) { $directsortkey{$modulegid} = $onefeature->{'Sortkey'}; }
324 else { $directsortkey{$modulegid} = "9999"; }
326 # Bookkeeping:
327 $sorted{$uniquekey} = 0;
330 # Searching all feature recursively, beginning with ParentID = ""
331 my $parentid = "";
332 collect_modules_recursive($modulesref, $parentid, \@feature, \%directaccess, \%directgid, \%directparent, \%directsortkey, \%sorted);
334 # Bookkeeping
335 my $modulekey;
336 foreach $modulekey ( keys %sorted )
338 if ( $sorted{$modulekey} == 0 )
340 my $infoline = "Warning: Module \"$modulekey\" could not be sorted. Added to the end of the module array.\n";
341 push(@installer::globals::logfileinfo, $infoline);
342 push(@feature, ${$modulesref}[$directaccess{$modulekey}]);
346 return \@feature;
349 #################################################################################
350 # Adding a unique key to the modules array. The gid is not unique for
351 # multilingual modules. Only the combination from gid and specific language
352 # is unique. Uniqueness is required for sorting mechanism.
353 #################################################################################
355 sub add_uniquekey
357 my ( $modulesref ) = @_;
359 for ( my $i = 0; $i <= $#{$modulesref}; $i++ )
361 my $uniquekey = ${$modulesref}[$i]->{'gid'};
362 if ( ${$modulesref}[$i]->{'specificlanguage'} ) { $uniquekey = $uniquekey . "_" . ${$modulesref}[$i]->{'specificlanguage'}; }
363 ${$modulesref}[$i]->{'uniquekey'} = $uniquekey;
367 #################################################################################
368 # Creating the file Feature.idt dynamically
369 # Content:
370 # Feature Feature_Parent Title Description Display Level Directory_ Attributes
371 #################################################################################
373 sub create_feature_table
375 my ($modulesref, $basedir, $languagesarrayref, $allvariableshashref) = @_;
377 for ( my $m = 0; $m <= $#{$languagesarrayref}; $m++ )
379 my $onelanguage = ${$languagesarrayref}[$m];
381 my $infoline;
383 my @featuretable = ();
385 installer::windows::idtglobal::write_idt_header(\@featuretable, "feature");
387 for ( my $i = 0; $i <= $#{$modulesref}; $i++ )
389 my $onefeature = ${$modulesref}[$i];
391 # Java and Ada only, if the correct settings are set
392 my $styles = "";
393 if ( $onefeature->{'Styles'} ) { $styles = $onefeature->{'Styles'}; }
394 if (( $styles =~ /\bJAVAMODULE\b/ ) && ( ! ($allvariableshashref->{'JAVAPRODUCT'} ))) { next; }
395 if (( $styles =~ /\bADAMODULE\b/ ) && ( ! ($allvariableshashref->{'ADAPRODUCT'} ))) { next; }
397 # Controlling the language!
398 # Only language independent feature or feature with the correct language will be included into the table
400 if (! (!(( $onefeature->{'ismultilingual'} )) || ( $onefeature->{'specificlanguage'} eq $onelanguage )) ) { next; }
402 my %feature = ();
404 $feature{'feature'} = get_feature_gid($onefeature);
405 $feature{'feature_parent'} = get_feature_parent($onefeature);
406 # if ( $onefeature->{'ParentID'} eq "" ) { $feature{'feature_parent'} = ""; } # Root has no parent
407 $feature{'Title'} = $onefeature->{'Name'};
408 $feature{'Description'} = $onefeature->{'Description'};
409 $feature{'Display'} = get_feature_display($onefeature);
410 $feature{'Level'} = get_feature_level($onefeature);
411 $feature{'Directory_'} = get_feature_directory($onefeature);
412 $feature{'Attributes'} = get_feature_attributes($onefeature);
414 my $oneline = $feature{'feature'} . "\t" . $feature{'feature_parent'} . "\t" . $feature{'Title'} . "\t"
415 . $feature{'Description'} . "\t" . $feature{'Display'} . "\t" . $feature{'Level'} . "\t"
416 . $feature{'Directory_'} . "\t" . $feature{'Attributes'} . "\n";
418 push(@featuretable, $oneline);
420 # collecting all feature in global feature collector (so that properties can be set in property table)
421 if ( ! installer::existence::exists_in_array($feature{'feature'}, \@installer::globals::featurecollector) )
423 push(@installer::globals::featurecollector, $feature{'feature'});
426 # collecting all language feature in feature collector for check of language selection
427 if (( $styles =~ /\bSHOW_MULTILINGUAL_ONLY\b/ ) && ( $onefeature->{'ParentID'} ne $installer::globals::rootmodulegid ))
429 $installer::globals::multilingual_only_modules{$feature{'feature'}} = 1;
432 # collecting all application feature in global feature collector for check of application selection
433 if ( $styles =~ /\bAPPLICATIONMODULE\b/ )
435 $installer::globals::application_modules{$feature{'feature'}} = 1;
439 # Saving the file
441 my $featuretablename = $basedir . $installer::globals::separator . "Feature.idt" . "." . $onelanguage;
442 installer::files::save_file($featuretablename ,\@featuretable);
443 $infoline = "Created idt file: $featuretablename\n";
444 push(@installer::globals::logfileinfo, $infoline);