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
::scpzipfiles
;
25 use installer
::globals
;
26 use installer
::logger
;
27 use installer
::pathanalyzer
;
28 use installer
::systemactions
;
30 # Replacing all zip list variables.
31 # Called for setup script as well as files with flag scpzip_replace.
33 sub replace_all_ziplistvariables_in_file
35 my ( $fileref, $variablesref ) = @_;
37 for my $line ( @
{$fileref} )
39 # Avoid removing variables we do not recognise.
40 $line =~ s
/\$\{(\w+)\}/defined
$variablesref->{$1}
46 # Replacing all zip list variables in rtf files.
48 sub replace_all_ziplistvariables_in_rtffile
50 my ( $fileref, $variablesref ) = @_;
52 for my $line ( @
{$fileref} )
54 # In rtf files the braces are backslash-escaped.
55 # Avoid removing variables we do not recognise.
56 $line =~ s
/\$\\\{(\w+)\\\}/defined
$variablesref->{$1}
62 #########################################################
63 # Analyzing files with flag SCPZIP_REPLACE
64 # $item can be "File" or "ScpAction"
65 #########################################################
67 sub resolving_scpzip_replace_flag
69 my ($filesarrayref, $variableshashref, $item, $languagestringref) = @_;
71 my $diritem = lc($item);
73 my $replacedirbase = installer
::systemactions
::create_directories
("replace_$diritem", $languagestringref);
75 installer
::logger
::include_header_into_logfile
("$item with flag SCPZIP:");
77 for ( my $i = 0; $i <= $#{$filesarrayref}; $i++ )
79 my $onefile = ${$filesarrayref}[$i];
82 if ( $onefile->{'Styles'} ) { $styles = $onefile->{'Styles'}; }
84 if ( $styles =~ /\bSCPZIP_REPLACE\b/ )
86 # Language specific subdirectory
88 my $onelanguage = $onefile->{'specificlanguage'};
90 if ($onelanguage eq "")
92 $onelanguage = "00"; # files without language into directory "00"
95 my $replacedir = $replacedirbase . $installer::globals
::separator
. $onelanguage . $installer::globals
::separator
;
96 installer
::systemactions
::create_directory
($replacedir); # creating language specific directories
98 # copy files and edit them with the variables defined in the zip.lst
100 my $longfilename = 0;
102 my $onefilename = $onefile->{'Name'};
103 my $sourcepath = $onefile->{'sourcepath'};
105 if ( $onefilename =~ /^\s*\Q$installer::globals::separator\E/ ) # filename begins with a slash, for instance /registry/schema/org/openoffice/VCL.xcs
107 $onefilename =~ s/^\s*\Q$installer::globals::separator\E//;
111 my $destinationpath = $replacedir . $onefilename;
112 my $movepath = $destinationpath . ".orig";
114 if ( $longfilename ) # the destination directory has to be created before copying
116 my $destdir = $movepath;
117 installer
::pathanalyzer
::get_path_from_fullqualifiedname
(\
$destdir);
118 installer
::systemactions
::create_directory_structure
($destdir);
121 my $copysuccess = installer
::systemactions
::copy_one_file
($sourcepath, $movepath);
125 # Now the file can be edited
126 # ToDo: How about binary patching?
128 my $onefileref = installer
::files
::read_file
($movepath);
129 replace_all_ziplistvariables_in_file
($onefileref, $variableshashref);
130 installer
::files
::save_file
($destinationpath ,$onefileref);
133 # Saving the original source, where the file was found
134 $onefile->{'originalsourcepath'} = $onefile->{'sourcepath'};
136 # Writing the new sourcepath into the hashref, even if it was no copied
138 $onefile->{'sourcepath'} = $destinationpath;
143 push( @installer::globals
::logfileinfo
, $infoline);