| 1 |
# |
| 2 |
# This file is part of the LibreOffice project. |
| 3 |
# |
| 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/. |
| 7 |
# |
| 8 |
# This file incorporates work covered by the following license notice: |
| 9 |
# |
| 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 . |
| 17 |
# |
| 18 |
|
| 19 |
package installer::scpzipfiles; |
| 20 |
|
| 21 |
use strict; |
| 22 |
use warnings; |
| 23 |
|
| 24 |
use installer::files; |
| 25 |
use installer::globals; |
| 26 |
use installer::logger; |
| 27 |
use installer::pathanalyzer; |
| 28 |
use installer::systemactions; |
| 29 |
|
| 30 |
# Replacing all zip list variables. |
| 31 |
# Called for setup script as well as files with flag scpzip_replace. |
| 32 |
|
| 33 |
sub replace_all_ziplistvariables_in_file |
| 34 |
{ |
| 35 |
my ( $fileref, $variablesref ) = @_; |
| 36 |
|
| 37 |
for my $line ( @{$fileref} ) |
| 38 |
{ |
| 39 |
# Avoid removing variables we do not recognise. |
| 40 |
$line =~ s/\$\{(\w+)\}/defined $variablesref->{$1} |
| 41 |
? $variablesref->{$1} |
| 42 |
: $&/eg; |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
# Replacing all zip list variables in rtf files. |
| 47 |
|
| 48 |
sub replace_all_ziplistvariables_in_rtffile |
| 49 |
{ |
| 50 |
my ( $fileref, $variablesref ) = @_; |
| 51 |
|
| 52 |
for my $line ( @{$fileref} ) |
| 53 |
{ |
| 54 |
# In rtf files the braces are backslash-escaped. |
| 55 |
# Avoid removing variables we do not recognise. |
| 56 |
$line =~ s/\$\\\{(\w+)\\\}/defined $variablesref->{$1} |
| 57 |
? $variablesref->{$1} |
| 58 |
: $&/eg; |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
######################################################### |
| 63 |
# Analyzing files with flag SCPZIP_REPLACE |
| 64 |
# $item can be "File" or "ScpAction" |
| 65 |
######################################################### |
| 66 |
|
| 67 |
sub resolving_scpzip_replace_flag |
| 68 |
{ |
| 69 |
my ($filesarrayref, $variableshashref, $item, $languagestringref) = @_; |
| 70 |
|
| 71 |
my $diritem = lc($item); |
| 72 |
|
| 73 |
my $replacedirbase = installer::systemactions::create_directories("replace_$diritem", $languagestringref); |
| 74 |
|
| 75 |
installer::logger::include_header_into_logfile("$item with flag SCPZIP:"); |
| 76 |
|
| 77 |
for ( my $i = 0; $i <= $#{$filesarrayref}; $i++ ) |
| 78 |
{ |
| 79 |
my $onefile = ${$filesarrayref}[$i]; |
| 80 |
my $styles = ""; |
| 81 |
|
| 82 |
if ( $onefile->{'Styles'} ) { $styles = $onefile->{'Styles'}; } |
| 83 |
|
| 84 |
if ( $styles =~ /\bSCPZIP_REPLACE\b/ ) |
| 85 |
{ |
| 86 |
# Language specific subdirectory |
| 87 |
|
| 88 |
my $onelanguage = $onefile->{'specificlanguage'}; |
| 89 |
|
| 90 |
if ($onelanguage eq "") |
| 91 |
{ |
| 92 |
$onelanguage = "00"; # files without language into directory "00" |
| 93 |
} |
| 94 |
|
| 95 |
my $replacedir = $replacedirbase . $installer::globals::separator . $onelanguage . $installer::globals::separator; |
| 96 |
installer::systemactions::create_directory($replacedir); # creating language specific directories |
| 97 |
|
| 98 |
# copy files and edit them with the variables defined in the zip.lst |
| 99 |
|
| 100 |
my $longfilename = 0; |
| 101 |
|
| 102 |
my $onefilename = $onefile->{'Name'}; |
| 103 |
my $sourcepath = $onefile->{'sourcepath'}; |
| 104 |
|
| 105 |
if ( $onefilename =~ /^\s*\Q$installer::globals::separator\E/ ) # filename begins with a slash, for instance /registry/schema/org/openoffice/VCL.xcs |
| 106 |
{ |
| 107 |
$onefilename =~ s/^\s*\Q$installer::globals::separator\E//; |
| 108 |
$longfilename = 1; |
| 109 |
} |
| 110 |
|
| 111 |
my $destinationpath = $replacedir . $onefilename; |
| 112 |
my $movepath = $destinationpath . ".orig"; |
| 113 |
|
| 114 |
if ( $longfilename ) # the destination directory has to be created before copying |
| 115 |
{ |
| 116 |
my $destdir = $movepath; |
| 117 |
installer::pathanalyzer::get_path_from_fullqualifiedname(\$destdir); |
| 118 |
installer::systemactions::create_directory_structure($destdir); |
| 119 |
} |
| 120 |
|
| 121 |
my $copysuccess = installer::systemactions::copy_one_file($sourcepath, $movepath); |
| 122 |
|
| 123 |
if ( $copysuccess ) |
| 124 |
{ |
| 125 |
# Now the file can be edited |
| 126 |
# ToDo: How about binary patching? |
| 127 |
|
| 128 |
my $onefileref = installer::files::read_file($movepath); |
| 129 |
replace_all_ziplistvariables_in_file($onefileref, $variableshashref); |
| 130 |
installer::files::save_file($destinationpath ,$onefileref); |
| 131 |
} |
| 132 |
|
| 133 |
# Saving the original source, where the file was found |
| 134 |
$onefile->{'originalsourcepath'} = $onefile->{'sourcepath'}; |
| 135 |
|
| 136 |
# Writing the new sourcepath into the hashref, even if it was no copied |
| 137 |
|
| 138 |
$onefile->{'sourcepath'} = $destinationpath; |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
my $infoline = "\n"; |
| 143 |
push( @installer::globals::logfileinfo, $infoline); |
| 144 |
} |
| 145 |
|
| 146 |
1; |