1*cdf0e10cSrcweir#*************************************************************************
2*cdf0e10cSrcweir#
3*cdf0e10cSrcweir# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir#
5*cdf0e10cSrcweir# Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir#
7*cdf0e10cSrcweir# OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir#
9*cdf0e10cSrcweir# This file is part of OpenOffice.org.
10*cdf0e10cSrcweir#
11*cdf0e10cSrcweir# OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir# it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir# only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir#
15*cdf0e10cSrcweir# OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir# but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir# GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir# (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir#
21*cdf0e10cSrcweir# You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir# version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir# <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir# for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir#
26*cdf0e10cSrcweir#*************************************************************************
27*cdf0e10cSrcweir
28*cdf0e10cSrcweirpackage installer::scpzipfiles;
29*cdf0e10cSrcweir
30*cdf0e10cSrcweiruse installer::files;
31*cdf0e10cSrcweiruse installer::globals;
32*cdf0e10cSrcweiruse installer::logger;
33*cdf0e10cSrcweiruse installer::pathanalyzer;
34*cdf0e10cSrcweiruse installer::systemactions;
35*cdf0e10cSrcweir
36*cdf0e10cSrcweir########################################################################################
37*cdf0e10cSrcweir# Replacing all zip list variables in setup script and files with flag scpzip_replace
38*cdf0e10cSrcweir########################################################################################
39*cdf0e10cSrcweir
40*cdf0e10cSrcweirsub replace_all_ziplistvariables_in_file
41*cdf0e10cSrcweir{
42*cdf0e10cSrcweir	my ( $fileref, $variableshashref ) = @_;
43*cdf0e10cSrcweir
44*cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$fileref}; $i++ )
45*cdf0e10cSrcweir	{
46*cdf0e10cSrcweir		my $line = ${$fileref}[$i];
47*cdf0e10cSrcweir
48*cdf0e10cSrcweir		if ( $line =~ /^.*\$\{\w+\}.*$/ )	# only occurence of ${abc}
49*cdf0e10cSrcweir		{
50*cdf0e10cSrcweir			my $key;
51*cdf0e10cSrcweir
52*cdf0e10cSrcweir			foreach $key (keys %{$variableshashref})
53*cdf0e10cSrcweir			{
54*cdf0e10cSrcweir				my $value = $variableshashref->{$key};
55*cdf0e10cSrcweir				$key = '${' . $key . '}';
56*cdf0e10cSrcweir				$line =~ s/\Q$key\E/$value/g;
57*cdf0e10cSrcweir				${$fileref}[$i] = $line;
58*cdf0e10cSrcweir			}
59*cdf0e10cSrcweir		}
60*cdf0e10cSrcweir	}
61*cdf0e10cSrcweir}
62*cdf0e10cSrcweir
63*cdf0e10cSrcweir########################################################################################
64*cdf0e10cSrcweir# Replacing all zip list variables in rtf files. In rtf files
65*cdf0e10cSrcweir# the brackets are masked.
66*cdf0e10cSrcweir########################################################################################
67*cdf0e10cSrcweir
68*cdf0e10cSrcweirsub replace_all_ziplistvariables_in_rtffile
69*cdf0e10cSrcweir{
70*cdf0e10cSrcweir	my ( $fileref, $variablesref, $onelanguage, $loggingdir ) = @_;
71*cdf0e10cSrcweir
72*cdf0e10cSrcweir	# installer::files::save_file($loggingdir . "license_" . $onelanguage . "_before.rtf", $fileref);
73*cdf0e10cSrcweir
74*cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$fileref}; $i++ )
75*cdf0e10cSrcweir	{
76*cdf0e10cSrcweir		my $line = ${$fileref}[$i];
77*cdf0e10cSrcweir
78*cdf0e10cSrcweir		if ( $line =~ /^.*\$\\\{\w+\\\}.*$/ )	# only occurence of $\{abc\}
79*cdf0e10cSrcweir		{
80*cdf0e10cSrcweir			for ( my $j = 0; $j <= $#{$variablesref}; $j++ )
81*cdf0e10cSrcweir			{
82*cdf0e10cSrcweir				my $variableline = ${$variablesref}[$j];
83*cdf0e10cSrcweir
84*cdf0e10cSrcweir				my ($key, $value);
85*cdf0e10cSrcweir
86*cdf0e10cSrcweir				if ( $variableline =~ /^\s*([\w-]+?)\s+(.*?)\s*$/ )
87*cdf0e10cSrcweir				{
88*cdf0e10cSrcweir					$key = $1;
89*cdf0e10cSrcweir					$value = $2;
90*cdf0e10cSrcweir					$key = '$\{' . $key . '\}';
91*cdf0e10cSrcweir				}
92*cdf0e10cSrcweir
93*cdf0e10cSrcweir				$line =~ s/\Q$key\E/$value/g;
94*cdf0e10cSrcweir
95*cdf0e10cSrcweir				${$fileref}[$i] = $line;
96*cdf0e10cSrcweir			}
97*cdf0e10cSrcweir		}
98*cdf0e10cSrcweir	}
99*cdf0e10cSrcweir
100*cdf0e10cSrcweir	# installer::files::save_file($loggingdir . "license_" . $onelanguage . "_after.rtf", $fileref);
101*cdf0e10cSrcweir}
102*cdf0e10cSrcweir
103*cdf0e10cSrcweir#########################################################
104*cdf0e10cSrcweir# Analyzing files with flag SCPZIP_REPLACE
105*cdf0e10cSrcweir# $item can be "File" or "ScpAction"
106*cdf0e10cSrcweir#########################################################
107*cdf0e10cSrcweir
108*cdf0e10cSrcweirsub resolving_scpzip_replace_flag
109*cdf0e10cSrcweir{
110*cdf0e10cSrcweir	my ($filesarrayref, $variableshashref, $item, $languagestringref) = @_;
111*cdf0e10cSrcweir
112*cdf0e10cSrcweir	my $diritem = lc($item);
113*cdf0e10cSrcweir
114*cdf0e10cSrcweir	my $replacedirbase = installer::systemactions::create_directories("replace_$diritem", $languagestringref);
115*cdf0e10cSrcweir
116*cdf0e10cSrcweir	installer::logger::include_header_into_logfile("$item with flag SCPZIP:");
117*cdf0e10cSrcweir
118*cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$filesarrayref}; $i++ )
119*cdf0e10cSrcweir	{
120*cdf0e10cSrcweir		my $onefile = ${$filesarrayref}[$i];
121*cdf0e10cSrcweir		my $styles = "";
122*cdf0e10cSrcweir
123*cdf0e10cSrcweir		if ( $onefile->{'Styles'} ) { $styles = $onefile->{'Styles'}; }
124*cdf0e10cSrcweir
125*cdf0e10cSrcweir		if ( $styles =~ /\bSCPZIP_REPLACE\b/ )
126*cdf0e10cSrcweir		{
127*cdf0e10cSrcweir			# Language specific subdirectory
128*cdf0e10cSrcweir
129*cdf0e10cSrcweir			my $onelanguage = $onefile->{'specificlanguage'};
130*cdf0e10cSrcweir
131*cdf0e10cSrcweir			if ($onelanguage eq "")
132*cdf0e10cSrcweir			{
133*cdf0e10cSrcweir				$onelanguage = "00";	# files without language into directory "00"
134*cdf0e10cSrcweir			}
135*cdf0e10cSrcweir
136*cdf0e10cSrcweir			my $replacedir = $replacedirbase . $installer::globals::separator . $onelanguage . $installer::globals::separator;
137*cdf0e10cSrcweir			installer::systemactions::create_directory($replacedir);	# creating language specific directories
138*cdf0e10cSrcweir
139*cdf0e10cSrcweir			# copy files and edit them with the variables defined in the zip.lst
140*cdf0e10cSrcweir
141*cdf0e10cSrcweir			my $longfilename = 0;
142*cdf0e10cSrcweir
143*cdf0e10cSrcweir			my $onefilename = $onefile->{'Name'};
144*cdf0e10cSrcweir			my $sourcepath = $onefile->{'sourcepath'};
145*cdf0e10cSrcweir
146*cdf0e10cSrcweir			if ( $onefilename =~ /^\s*\Q$installer::globals::separator\E/ )	# filename begins with a slash, for instance /registry/schema/org/openoffice/VCL.xcs
147*cdf0e10cSrcweir			{
148*cdf0e10cSrcweir				$onefilename =~ s/^\s*\Q$installer::globals::separator\E//;
149*cdf0e10cSrcweir				$longfilename = 1;
150*cdf0e10cSrcweir			}
151*cdf0e10cSrcweir
152*cdf0e10cSrcweir			my $destinationpath = $replacedir . $onefilename;
153*cdf0e10cSrcweir			my $movepath = $destinationpath . ".orig";
154*cdf0e10cSrcweir
155*cdf0e10cSrcweir			if ( $longfilename )	# the destination directory has to be created before copying
156*cdf0e10cSrcweir			{
157*cdf0e10cSrcweir				my $destdir = $movepath;
158*cdf0e10cSrcweir				installer::pathanalyzer::get_path_from_fullqualifiedname(\$destdir);
159*cdf0e10cSrcweir				installer::systemactions::create_directory_structure($destdir);
160*cdf0e10cSrcweir			}
161*cdf0e10cSrcweir
162*cdf0e10cSrcweir			my $copysuccess = installer::systemactions::copy_one_file($sourcepath, $movepath);
163*cdf0e10cSrcweir
164*cdf0e10cSrcweir			if ( $copysuccess )
165*cdf0e10cSrcweir			{
166*cdf0e10cSrcweir				# Now the file can be edited
167*cdf0e10cSrcweir				# ToDo: How about binary patching?
168*cdf0e10cSrcweir
169*cdf0e10cSrcweir				my $onefileref = installer::files::read_file($movepath);
170*cdf0e10cSrcweir				replace_all_ziplistvariables_in_file($onefileref, $variableshashref);
171*cdf0e10cSrcweir				installer::files::save_file($destinationpath ,$onefileref);
172*cdf0e10cSrcweir			}
173*cdf0e10cSrcweir
174*cdf0e10cSrcweir			# Saving the original source, where the file was found
175*cdf0e10cSrcweir			$onefile->{'originalsourcepath'} = $onefile->{'sourcepath'};
176*cdf0e10cSrcweir
177*cdf0e10cSrcweir			# Writing the new sourcepath into the hashref, even if it was no copied
178*cdf0e10cSrcweir
179*cdf0e10cSrcweir			$onefile->{'sourcepath'} = $destinationpath;
180*cdf0e10cSrcweir		}
181*cdf0e10cSrcweir	}
182*cdf0e10cSrcweir
183*cdf0e10cSrcweir	my $infoline = "\n";
184*cdf0e10cSrcweir	push( @installer::globals::logfileinfo, $infoline);
185*cdf0e10cSrcweir}
186*cdf0e10cSrcweir
187*cdf0e10cSrcweir1;
188