Branch libreoffice-5-0-4
[LibreOffice.git] / solenv / bin / modules / installer / scpzipfiles.pm
blobe6c773196302b04f43d7ee8d8d9996139b113336
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;
21 use installer::files;
22 use installer::globals;
23 use installer::logger;
24 use installer::pathanalyzer;
25 use installer::systemactions;
27 # Replacing all zip list variables.
28 # Called for setup script as well as files with flag scpzip_replace.
30 sub replace_all_ziplistvariables_in_file
32 my ( $fileref, $variablesref ) = @_;
34 for my $line ( @{$fileref} )
36 # Avoid removing variables we do not recognise.
37 $line =~ s/\$\{(\w+)\}/defined $variablesref->{$1}
38 ? $variablesref->{$1}
39 : $&/eg;
43 # Replacing all zip list variables in rtf files.
45 sub replace_all_ziplistvariables_in_rtffile
47 my ( $fileref, $variablesref ) = @_;
49 for my $line ( @{$fileref} )
51 # In rtf files the braces are backslash-escaped.
52 # Avoid removing variables we do not recognise.
53 $line =~ s/\$\\\{(\w+)\\\}/defined $variablesref->{$1}
54 ? $variablesref->{$1}
55 : $&/eg;
59 #########################################################
60 # Analyzing files with flag SCPZIP_REPLACE
61 # $item can be "File" or "ScpAction"
62 #########################################################
64 sub resolving_scpzip_replace_flag
66 my ($filesarrayref, $variableshashref, $item, $languagestringref) = @_;
68 my $diritem = lc($item);
70 my $replacedirbase = installer::systemactions::create_directories("replace_$diritem", $languagestringref);
72 installer::logger::include_header_into_logfile("$item with flag SCPZIP:");
74 for ( my $i = 0; $i <= $#{$filesarrayref}; $i++ )
76 my $onefile = ${$filesarrayref}[$i];
77 my $styles = "";
79 if ( $onefile->{'Styles'} ) { $styles = $onefile->{'Styles'}; }
81 if ( $styles =~ /\bSCPZIP_REPLACE\b/ )
83 # Language specific subdirectory
85 my $onelanguage = $onefile->{'specificlanguage'};
87 if ($onelanguage eq "")
89 $onelanguage = "00"; # files without language into directory "00"
92 my $replacedir = $replacedirbase . $installer::globals::separator . $onelanguage . $installer::globals::separator;
93 installer::systemactions::create_directory($replacedir); # creating language specific directories
95 # copy files and edit them with the variables defined in the zip.lst
97 my $longfilename = 0;
99 my $onefilename = $onefile->{'Name'};
100 my $sourcepath = $onefile->{'sourcepath'};
102 if ( $onefilename =~ /^\s*\Q$installer::globals::separator\E/ ) # filename begins with a slash, for instance /registry/schema/org/openoffice/VCL.xcs
104 $onefilename =~ s/^\s*\Q$installer::globals::separator\E//;
105 $longfilename = 1;
108 my $destinationpath = $replacedir . $onefilename;
109 my $movepath = $destinationpath . ".orig";
111 if ( $longfilename ) # the destination directory has to be created before copying
113 my $destdir = $movepath;
114 installer::pathanalyzer::get_path_from_fullqualifiedname(\$destdir);
115 installer::systemactions::create_directory_structure($destdir);
118 my $copysuccess = installer::systemactions::copy_one_file($sourcepath, $movepath);
120 if ( $copysuccess )
122 # Now the file can be edited
123 # ToDo: How about binary patching?
125 my $onefileref = installer::files::read_file($movepath);
126 replace_all_ziplistvariables_in_file($onefileref, $variableshashref);
127 installer::files::save_file($destinationpath ,$onefileref);
130 # Saving the original source, where the file was found
131 $onefile->{'originalsourcepath'} = $onefile->{'sourcepath'};
133 # Writing the new sourcepath into the hashref, even if it was no copied
135 $onefile->{'sourcepath'} = $destinationpath;
139 my $infoline = "\n";
140 push( @installer::globals::logfileinfo, $infoline);