tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / solenv / bin / modules / installer / ziplist.pm
blobca94f764f9b1d3e07ff58f070f4a2d34c7de8ce6
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::ziplist;
21 use strict;
22 use warnings;
24 use base 'Exporter';
26 use File::Spec::Functions qw(rel2abs);
28 use installer::converter;
29 use installer::exiter;
30 use installer::files;
31 use installer::globals;
32 use installer::logger;
33 use installer::remover;
34 use installer::systemactions;
36 our @EXPORT_OK = qw(read_ziplist);
38 sub read_ziplist {
39 my $ziplistname = shift;
41 installer::logger::globallog("zip list file: $ziplistname");
43 my $ziplistref = installer::files::read_file($ziplistname);
45 installer::logger::print_message( "... analyzing $ziplistname ... \n" );
47 my ($productblockref, $parent) = getproductblock($ziplistref, $installer::globals::product, 1); # product block from zip.lst
49 my ($settingsblockref, undef) = getproductblock($productblockref, "Settings", 0); # settings block from zip.lst
50 $settingsblockref = analyze_settings_block($settingsblockref); # select data from settings block in zip.lst
52 my $allsettingsarrayref = get_settings_from_ziplist($settingsblockref);
53 my $allvariablesarrayref = get_variables_from_ziplist($settingsblockref);
55 my ($globalproductblockref, undef) = getproductblock($ziplistref, $installer::globals::globalblock, 0); # global product block from zip.lst
57 while (defined $parent) {
58 my $parentproductblockref;
59 ($parentproductblockref, $parent) = getproductblock($ziplistref, $parent, 1);
60 my ($parentsettingsblockref, undef) = getproductblock($parentproductblockref, "Settings", 0);
61 $parentsettingsblockref = analyze_settings_block($parentsettingsblockref);
62 my $allparentsettingsarrayref = get_settings_from_ziplist($parentsettingsblockref);
63 my $allparentvariablesarrayref = get_variables_from_ziplist($parentsettingsblockref);
64 $allsettingsarrayref =
65 installer::converter::combine_arrays_from_references_first_win(
66 $allsettingsarrayref, $allparentsettingsarrayref)
67 if $#{$allparentsettingsarrayref} > -1;
68 $allvariablesarrayref =
69 installer::converter::combine_arrays_from_references_first_win(
70 $allvariablesarrayref, $allparentvariablesarrayref)
71 if $#{$allparentvariablesarrayref} > -1;
74 if ( @{$globalproductblockref} ) {
75 my ($globalsettingsblockref, undef) = getproductblock($globalproductblockref, "Settings", 0); # settings block from zip.lst
77 $globalsettingsblockref = analyze_settings_block($globalsettingsblockref); # select data from settings block in zip.lst
79 my $allglobalsettingsarrayref = get_settings_from_ziplist($globalsettingsblockref);
81 my $allglobalvariablesarrayref = get_variables_from_ziplist($globalsettingsblockref);
83 if ( @{$allglobalsettingsarrayref} ) {
84 $allsettingsarrayref = installer::converter::combine_arrays_from_references_first_win($allsettingsarrayref, $allglobalsettingsarrayref);
86 if ( @{$allglobalvariablesarrayref} ) {
87 $allvariablesarrayref = installer::converter::combine_arrays_from_references_first_win($allvariablesarrayref, $allglobalvariablesarrayref);
91 $allsettingsarrayref = remove_multiples_from_ziplist($allsettingsarrayref);
92 $allvariablesarrayref = remove_multiples_from_ziplist($allvariablesarrayref);
94 replace_variables_in_ziplist_variables($allvariablesarrayref);
96 my $allvariableshashref = installer::converter::convert_array_to_hash($allvariablesarrayref);
98 set_default_productversion_if_required($allvariableshashref);
99 add_variables_to_allvariableshashref($allvariableshashref);
100 overwrite_branding( $allvariableshashref );
102 return $allsettingsarrayref, $allvariableshashref;
105 #################################################
106 # Getting data from path file and zip list file
107 #################################################
109 sub getproductblock
111 my ($fileref, $search, $inheritance) = @_;
113 my @searchblock = ();
114 my $searchexists = 0;
115 my $record = 0;
116 my $count = 0;
117 my $line;
118 my $inh = $inheritance ? '(?::\s*(\S+)\s*)?' : "";
119 my $parent;
121 for ( my $i = 0; $i <= $#{$fileref}; $i++ )
123 $line = ${$fileref}[$i];
125 if ( $line =~ /^\s*\Q$search\E\s*$inh$/i ) # case insensitive
127 $record = 1;
128 $searchexists = 1;
129 $parent = $1 if $inheritance;
132 if ($record)
134 push(@searchblock, $line);
137 if ( ($record) && ($line =~ /\{/) )
139 $count++;
142 if ( ($record) && ($line =~ /\}/) )
144 $count--;
147 if ( ($record) && ($line =~ /\}/) && ( $count == 0 ) )
149 $record = 0;
153 if (( ! $searchexists ) && ( $search ne $installer::globals::globalblock ))
155 if ($search eq $installer::globals::product )
157 installer::exiter::exit_program("ERROR: Product $installer::globals::product not defined in $installer::globals::ziplistname", "getproductblock");
159 else # this is not possible
161 installer::exiter::exit_program("ERROR: Unknown value for $search in getproductblock()", "getproductblock");
165 return (\@searchblock, $parent);
168 ###############################################
169 # Analyzing the settings in the zip list file
170 ###############################################
172 sub analyze_settings_block
174 my ($blockref) = @_;
176 my @newsettingsblock = ();
177 my $record = 1;
178 my $counter = 0;
180 # Allowed values in settings block:
181 # "Settings", "Variables", "unix" (for destination path and logfile)
183 # Comment line in settings block begin with "#" or ";"
185 for ( my $i = 0; $i <= $#{$blockref}; $i++ )
187 my $line = ${$blockref}[$i];
188 my $nextline = "";
190 if ( ${$blockref}[$i+1] ) { $nextline = ${$blockref}[$i+1]; }
192 # removing comment lines
194 if (($line =~ /^\s*\#/) || ($line =~ /^\s*\;/))
196 next;
199 # complete blocks of unknown strings are not recorded
201 if ((!($line =~ /^\s*\Q$installer::globals::build\E\s*$/i)) &&
202 (!($line =~ /^\s*\bSettings\b\s*$/i)) &&
203 (!($line =~ /^\s*\bVariables\b\s*$/i)) &&
204 (!($line =~ /^\s*\bunix\b\s*$/i)) &&
205 ($nextline =~ /^\s*\{\s*$/i))
207 $record = 0;
208 next; # continue with next $i
211 if (!( $record ))
213 if ($line =~ /^\s*\{\s*$/i)
215 $counter++;
218 if ($line =~ /^\s*\}\s*$/i)
220 $counter--;
223 if ($counter == 0)
225 $record = 1;
226 next; # continue with next $i
230 if ($record)
232 push(@newsettingsblock, $line);
236 return \@newsettingsblock;
239 ########################################
240 # Settings in zip list file
241 ########################################
243 sub get_settings_from_ziplist
245 my ($blockref) = @_;
247 my @allsettings = ();
248 my $isvariables = 0;
249 my $counter = 0;
250 my $variablescounter = 0;
252 # Take all settings from the settings block
253 # Do not take the variables from the settings block
254 # If a setting is defined more than once, take the
255 # setting with the largest counter (open brackets)
257 for ( my $i = 0; $i <= $#{$blockref}; $i++ )
259 my $line = ${$blockref}[$i];
260 my $nextline = "";
262 if ( ${$blockref}[$i+1] ) { $nextline = ${$blockref}[$i+1]; }
264 if (($line =~ /^\s*\S+\s*$/i) &&
265 ($nextline =~ /^\s*\{\s*$/i) &&
266 (!($line =~ /^\s*Variables\s*$/i)))
268 next;
271 if ($line =~ /^\s*Variables\s*$/i)
273 # This is a block of variables
275 $isvariables = 1;
276 next;
279 if ($line =~ /^\s*\{\s*$/i)
281 if ($isvariables)
283 $variablescounter++;
285 else
287 $counter++;
290 next;
293 if ($line =~ /^\s*\}\s*$/i)
295 if ($isvariables)
297 $variablescounter--;
299 if ($variablescounter == 0)
301 $isvariables = 0;
304 else
306 $counter--;
309 next;
312 if ($isvariables)
314 next;
317 installer::remover::remove_leading_and_ending_whitespaces(\$line);
319 $line .= "\t##$counter##\n";
321 push(@allsettings, $line);
324 return \@allsettings;
327 #######################################
328 # Variables from zip list file
329 #######################################
331 sub get_variables_from_ziplist
333 my ($blockref) = @_;
335 my @allvariables = ();
336 my $isvariables = 0;
337 my $counter = 0;
338 my $variablescounter = 0;
339 my $countersum = 0;
341 # Take all variables from the settings block
342 # Do not take the other settings from the settings block
343 # If a variable is defined more than once, take the
344 # variable with the largest counter (open brackets)
346 for ( my $i = 0; $i <= $#{$blockref}; $i++ )
348 my $line = ${$blockref}[$i];
349 my $nextline = ${$blockref}[$i+1];
351 if ($line =~ /^\s*Variables\s*$/i)
353 # This is a block of variables
355 $isvariables = 1;
356 next;
359 if ($line =~ /^\s*\{\s*$/i)
361 if ($isvariables)
363 $variablescounter++;
365 else
367 $counter++;
370 next;
373 if ($line =~ /^\s*\}\s*$/i)
375 if ($isvariables)
377 $variablescounter--;
379 if ($variablescounter == 0)
381 $isvariables = 0;
384 else
386 $counter--;
389 next;
392 if (!($isvariables))
394 next;
397 $countersum = $counter + $variablescounter;
399 installer::remover::remove_leading_and_ending_whitespaces(\$line);
401 $line .= "\t##$countersum##\n";
403 push(@allvariables, $line);
406 return \@allvariables;
409 #######################################################################
410 # Removing multiple variables and settings, defined in zip list file
411 #######################################################################
413 sub remove_multiples_from_ziplist
415 my ($blockref) = @_;
417 # remove all definitions of settings and variables
418 # that occur more than once in the zip list file.
419 # Take the one with the most open brackets. This
420 # number is stored at the end of the string.
422 my @newarray = ();
423 my @itemarray = ();
424 my ($line, $itemname, $itemnumber);
426 # first collecting all variables and settings names
428 for ( my $i = 0; $i <= $#{$blockref}; $i++ )
430 $line = ${$blockref}[$i];
432 if ($line =~ /^\s*\b(\S*)\b\s+.*\#\#\d+\#\#\s*$/i)
434 $itemname = $1;
437 if (! grep {$_ eq $itemname} @itemarray)
439 push(@itemarray, $itemname);
443 # and now all $items can be selected with the highest number
445 for ( my $i = 0; $i <= $#itemarray; $i++ )
447 $itemname = $itemarray[$i];
449 my $itemnumbermax = 0;
450 my $printline = "";
452 for ( my $j = 0; $j <= $#{$blockref}; $j++ )
454 $line = ${$blockref}[$j];
456 if ($line =~ /^\s*\Q$itemname\E\s+.*\#\#(\d+)\#\#\s*$/)
458 $itemnumber = $1;
460 if ($itemnumber >= $itemnumbermax)
462 $printline = $line;
463 $itemnumbermax = $itemnumber;
468 # removing the ending number from the printline
469 # and putting it into the array
471 $printline =~ s/\#\#\d+\#\#//;
472 installer::remover::remove_leading_and_ending_whitespaces(\$line);
473 push(@newarray, $printline);
476 return \@newarray;
479 #########################################################
480 # Reading one variable defined in the zip list file
481 #########################################################
483 sub getinfofromziplist
485 my ($blockref, $variable) = @_;
487 my $searchstring = "";
488 my $line;
490 for ( my $i = 0; $i <= $#{$blockref}; $i++ )
492 $line = ${$blockref}[$i];
494 if ( $line =~ /^\s*\Q$variable\E\s+(.+?)\s*$/ ) # "?" for minimal matching
496 $searchstring = $1;
497 last;
501 return \$searchstring;
504 ####################################################
505 # Replacing variables in include path
506 ####################################################
508 sub replace_all_variables_in_paths
510 my ( $patharrayref, $variableshashref ) = @_;
512 for ( my $i = 0; $i <= $#{$patharrayref}; $i++ )
514 my $line = ${$patharrayref}[$i];
516 my $key;
518 foreach $key (sort { length ($b) <=> length ($a) } keys %{$variableshashref})
520 my $value = $variableshashref->{$key};
522 if (( $line =~ /\{$key\}/ ) && ( $value eq "" )) { $line = ".\n"; }
524 $line =~ s/\{\Q$key\E\}/$value/g;
527 ${$patharrayref}[$i] = $line;
531 ####################################################
532 # Replacing minor in include path
533 ####################################################
535 sub replace_minor_in_paths
537 my ( $patharrayref ) = @_;
539 for ( my $i = 0; $i <= $#{$patharrayref}; $i++ )
541 my $line = ${$patharrayref}[$i];
543 $line =~ s/\.\{minor\}//g;
544 $line =~ s/\.\{minornonpre\}//g;
546 ${$patharrayref}[$i] = $line;
550 ####################################################
551 # Replacing packagetype in include path
552 ####################################################
554 sub replace_packagetype_in_paths
556 my ( $patharrayref ) = @_;
558 for ( my $i = 0; $i <= $#{$patharrayref}; $i++ )
560 my $line = ${$patharrayref}[$i];
562 if (( $installer::globals::installertypedir ) && ( $line =~ /\{pkgtype\}/ ))
564 $line =~ s/\{pkgtype\}/$installer::globals::installertypedir/g;
567 ${$patharrayref}[$i] = $line;
571 ####################################################
572 # Removing ending separators in paths
573 ####################################################
575 sub remove_ending_separator
577 my ( $patharrayref ) = @_;
579 for ( my $i = 0; $i <= $#{$patharrayref}; $i++ )
581 my $line = ${$patharrayref}[$i];
583 installer::remover::remove_ending_pathseparator(\$line);
585 $line =~ s/\s*$//;
586 $line = $line . "\n";
588 ${$patharrayref}[$i] = $line;
592 ####################################################
593 # Replacing languages in include path
594 ####################################################
596 sub replace_languages_in_paths
598 my ( $patharrayref, $languagesref ) = @_;
600 installer::logger::include_header_into_logfile("Replacing languages in include paths:");
602 my @patharray = ();
603 my $infoline = "";
605 for ( my $i = 0; $i <= $#{$patharrayref}; $i++ )
607 my $line = ${$patharrayref}[$i];
609 if ( $line =~ /\$\(LANG\)/ )
611 my $originalline = $line;
612 my $newline = "";
614 for ( my $j = 0; $j <= $#{$languagesref}; $j++ )
616 my $language = ${$languagesref}[$j];
617 $line =~ s/\$\(LANG\)/$language/g;
618 push(@patharray ,$line);
619 my $newdir = $line;
620 $line = $originalline;
622 installer::remover::remove_leading_and_ending_whitespaces(\$newline);
624 # Is it necessary to refresh the global array, containing all files of all include paths?
625 if ( -d $newdir )
627 # Checking if $newdir is empty
628 if ( ! installer::systemactions::is_empty_dir($newdir) )
630 $installer::globals::refresh_includepaths = 1;
631 $infoline = "Directory $newdir exists and is not empty. Refreshing global file array is required.\n";
632 push( @installer::globals::logfileinfo, $infoline);
634 else
636 $infoline = "Directory $newdir is empty. No refresh of global file array required.\n";
637 push( @installer::globals::logfileinfo, $infoline);
640 else
642 $infoline = "Directory $newdir does not exist. No refresh of global file array required.\n";
643 push( @installer::globals::logfileinfo, $infoline);
647 else # not language dependent include path
649 push(@patharray ,$line);
653 return \@patharray;
656 #####################################################
657 # Collecting all files from all include paths
658 #####################################################
660 sub list_all_files_from_include_path
662 my ( $patharrayref) = @_;
664 installer::logger::include_header_into_logfile("Include paths:");
666 for ( my $i = 0; $i <= $#{$patharrayref}; $i++ )
668 my $path = ${$patharrayref}[$i];
669 installer::remover::remove_leading_and_ending_whitespaces(\$path);
670 my $infoline = "$path\n";
671 push( @installer::globals::logfileinfo, $infoline);
674 push( @installer::globals::logfileinfo, "\n");
677 #####################################################
678 # Collecting all files from all include paths
679 #####################################################
681 sub set_manufacturer
683 my ($allvariables) = @_;
684 my $manufacturer;
686 if( defined $ENV{'OOO_VENDOR'} && $ENV{'OOO_VENDOR'} ne "" )
688 $manufacturer = $ENV{'OOO_VENDOR'};
690 elsif( defined $ENV{'USERNAME'} && $ENV{'USERNAME'} ne "" )
692 $manufacturer = $ENV{'USERNAME'};
694 elsif( defined $ENV{'USER'} && $ENV{'USER'} ne "" )
696 $manufacturer = $ENV{'USER'};
698 else
700 $manufacturer = "default";
703 $installer::globals::manufacturer = $manufacturer;
704 $installer::globals::longmanufacturer = $manufacturer;
706 $allvariables->{'MANUFACTURER'} = $installer::globals::manufacturer;
709 ##############################################################
710 # A ProductVersion has to be defined. If it is not set in
711 # zip.lst, it is set now to "1"
712 ##############################################################
714 sub set_default_productversion_if_required
716 my ($allvariables) = @_;
718 if (!($allvariables->{'PRODUCTVERSION'}))
720 $allvariables->{'PRODUCTVERSION'} = 1; # FAKE
724 ####################################################
725 # Removing .. in paths
726 ####################################################
728 sub simplify_path
730 my ( $pathref ) = @_;
732 my $oldpath = $$pathref;
734 my $change = 0;
736 while ( $oldpath =~ /(^.*)(\Q$installer::globals::separator\E.*\w+?)(\Q$installer::globals::separator\E\.\.)(\Q$installer::globals::separator\E.*$)/ )
738 my $part1 = $1;
739 my $part2 = $4;
740 $oldpath = $part1 . $part2;
741 $change = 1;
744 if ( $change ) { $$pathref = $oldpath . "\n"; }
747 ####################################################
748 # Removing ending separators in paths
749 ####################################################
751 sub resolve_relative_paths
753 my ( $patharrayref ) = @_;
755 for my $path ( @{$patharrayref} )
757 $path = rel2abs($path);
758 simplify_path(\$path);
762 ####################################################
763 # Replacing variables inside zip list variables
764 # Example: {milestone} to be replaced by
765 # $installer::globals::lastminor
766 ####################################################
768 sub replace_variables_in_ziplist_variables
770 my ($blockref) = @_;
772 for ( my $i = 0; $i <= $#{$blockref}; $i++ )
774 ${$blockref}[$i] =~ s/\{milestone\}//;
775 ${$blockref}[$i] =~ s/\{minor\}//;
776 if ( $installer::globals::buildid ) { ${$blockref}[$i] =~ s/\{buildid\}/$installer::globals::buildid/; }
777 else { ${$blockref}[$i] =~ s/\{buildid\}//; }
778 if ( $installer::globals::build ) { ${$blockref}[$i] =~ s/\{buildsource\}/$installer::globals::build/; }
779 else { ${$blockref}[$i] =~ s/\{build\}//; }
783 ###########################################################
784 # Overwrite branding data in openoffice.lst that is defined in configure
785 ###########################################################
787 sub overwrite_branding
789 my ($variableshashref) = @_;
790 $variableshashref->{'PROGRESSBARCOLOR'} = $ENV{'PROGRESSBARCOLOR'} , if( defined $ENV{'PROGRESSBARCOLOR'} && $ENV{'PROGRESSBARCOLOR'} ne "" );
791 $variableshashref->{'PROGRESSSIZE'} = $ENV{'PROGRESSSIZE'} , if( defined $ENV{'PROGRESSSIZE'} && $ENV{'PROGRESSSIZE'} ne "" );
792 $variableshashref->{'PROGRESSPOSITION'} = $ENV{'PROGRESSPOSITION'} , if( defined $ENV{'PROGRESSPOSITION'} && $ENV{'PROGRESSPOSITION'} ne "" );
793 $variableshashref->{'PROGRESSFRAMECOLOR'} = $ENV{'PROGRESSFRAMECOLOR'} , if( defined $ENV{'PROGRESSFRAMECOLOR'} && $ENV{'PROGRESSFRAMECOLOR'} ne "" );
794 $variableshashref->{'PROGRESSTEXTCOLOR'} = $ENV{'PROGRESSTEXTCOLOR'} , if( defined $ENV{'PROGRESSTEXTCOLOR'} && $ENV{'PROGRESSTEXTCOLOR'} ne "" );
795 $variableshashref->{'PROGRESSTEXTBASELINE'} = $ENV{'PROGRESSTEXTBASELINE'} , if( defined $ENV{'PROGRESSTEXTBASELINE'} && $ENV{'PROGRESSTEXTBASELINE'} ne "" );
798 ###########################################################
799 # Adding the lowercase variables into the variableshashref
800 ###########################################################
802 sub add_variables_to_allvariableshashref
804 my ($variableshashref) = @_;
806 my $lcvariable = lc($variableshashref->{'PRODUCTNAME'});
807 $variableshashref->{'LCPRODUCTNAME'} = $lcvariable;
809 if ($variableshashref->{'PRODUCTEXTENSION'})
811 $variableshashref->{'LCPRODUCTEXTENSION'} = "\-" . lc($variableshashref->{'PRODUCTEXTENSION'}); # including the "-" !
813 else
815 $variableshashref->{'LCPRODUCTEXTENSION'} = "";
818 if ( $installer::globals::languagepack ) { $variableshashref->{'PRODUCTADDON'} = $installer::globals::languagepackaddon; }
819 elsif ( $installer::globals::helppack ) { $variableshashref->{'PRODUCTADDON'} = $installer::globals::helppackaddon; }
820 else { $variableshashref->{'PRODUCTADDON'} = ""; }
822 my $localbuild = $installer::globals::build;
823 if ( $localbuild =~ /^\s*(\w+?)(\d+)\s*$/ ) { $localbuild = $2; } # using "680" instead of "src680"
824 $variableshashref->{'PRODUCTMAJOR'} = $localbuild;
826 $variableshashref->{'PRODUCTBUILDID'} = $installer::globals::buildid;