update dev300-m58
[ooovba.git] / solenv / bin / modules / installer / scpzipfiles.pm
blob302b28e658e3dc7e5c96636329fdfc2f2845e51f
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: scpzipfiles.pm,v $
11 # $Revision: 1.15 $
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::scpzipfiles;
34 use installer::files;
35 use installer::globals;
36 use installer::logger;
37 use installer::pathanalyzer;
38 use installer::systemactions;
40 ########################################################################################
41 # Replacing all zip list variables in setup script and files with flag scpzip_replace
42 ########################################################################################
44 sub replace_all_ziplistvariables_in_file
46 my ( $fileref, $variableshashref ) = @_;
48 for ( my $i = 0; $i <= $#{$fileref}; $i++ )
50 my $line = ${$fileref}[$i];
52 if ( $line =~ /^.*\$\{\w+\}.*$/ ) # only occurence of ${abc}
54 my $key;
56 foreach $key (keys %{$variableshashref})
58 my $value = $variableshashref->{$key};
59 $key = '${' . $key . '}';
60 $line =~ s/\Q$key\E/$value/g;
61 ${$fileref}[$i] = $line;
67 ########################################################################################
68 # Replacing all zip list variables in rtf files. In rtf files
69 # the brackets are masked.
70 ########################################################################################
72 sub replace_all_ziplistvariables_in_rtffile
74 my ( $fileref, $variablesref, $onelanguage, $loggingdir ) = @_;
76 # installer::files::save_file($loggingdir . "license_" . $onelanguage . "_before.rtf", $fileref);
78 for ( my $i = 0; $i <= $#{$fileref}; $i++ )
80 my $line = ${$fileref}[$i];
82 if ( $line =~ /^.*\$\\\{\w+\\\}.*$/ ) # only occurence of $\{abc\}
84 for ( my $j = 0; $j <= $#{$variablesref}; $j++ )
86 my $variableline = ${$variablesref}[$j];
88 my ($key, $value);
90 if ( $variableline =~ /^\s*([\w-]+?)\s+(.*?)\s*$/ )
92 $key = $1;
93 $value = $2;
94 $key = '$\{' . $key . '\}';
97 $line =~ s/\Q$key\E/$value/g;
99 ${$fileref}[$i] = $line;
104 # installer::files::save_file($loggingdir . "license_" . $onelanguage . "_after.rtf", $fileref);
107 #########################################################
108 # Analyzing files with flag SCPZIP_REPLACE
109 # $item can be "File" or "ScpAction"
110 #########################################################
112 sub resolving_scpzip_replace_flag
114 my ($filesarrayref, $variableshashref, $item, $languagestringref) = @_;
116 my $diritem = lc($item);
118 my $replacedirbase = installer::systemactions::create_directories("replace_$diritem", $languagestringref);
120 installer::logger::include_header_into_logfile("$item with flag SCPZIP:");
122 for ( my $i = 0; $i <= $#{$filesarrayref}; $i++ )
124 my $onefile = ${$filesarrayref}[$i];
125 my $styles = "";
127 if ( $onefile->{'Styles'} ) { $styles = $onefile->{'Styles'}; }
129 if ( $styles =~ /\bSCPZIP_REPLACE\b/ )
131 # Language specific subdirectory
133 my $onelanguage = $onefile->{'specificlanguage'};
135 if ($onelanguage eq "")
137 $onelanguage = "00"; # files without language into directory "00"
140 my $replacedir = $replacedirbase . $installer::globals::separator . $onelanguage . $installer::globals::separator;
141 installer::systemactions::create_directory($replacedir); # creating language specific directories
143 # copy files and edit them with the variables defined in the zip.lst
145 my $longfilename = 0;
147 my $onefilename = $onefile->{'Name'};
148 my $sourcepath = $onefile->{'sourcepath'};
150 if ( $onefilename =~ /^\s*\Q$installer::globals::separator\E/ ) # filename begins with a slash, for instance /registry/schema/org/openoffice/VCL.xcs
152 $onefilename =~ s/^\s*\Q$installer::globals::separator\E//;
153 $longfilename = 1;
156 my $destinationpath = $replacedir . $onefilename;
157 my $movepath = $destinationpath . ".orig";
159 if ( $longfilename ) # the destination directory has to be created before copying
161 my $destdir = $movepath;
162 installer::pathanalyzer::get_path_from_fullqualifiedname(\$destdir);
163 installer::systemactions::create_directory_structure($destdir);
166 my $copysuccess = installer::systemactions::copy_one_file($sourcepath, $movepath);
168 if ( $copysuccess )
170 # Now the file can be edited
171 # ToDo: How about binary patching?
173 my $onefileref = installer::files::read_file($movepath);
174 replace_all_ziplistvariables_in_file($onefileref, $variableshashref);
175 installer::files::save_file($destinationpath ,$onefileref);
178 # Saving the original source, where the file was found
179 $onefile->{'originalsourcepath'} = $onefile->{'sourcepath'};
181 # Writing the new sourcepath into the hashref, even if it was no copied
183 $onefile->{'sourcepath'} = $destinationpath;
187 my $infoline = "\n";
188 push( @installer::globals::logfileinfo, $infoline);