1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # $RCSfile: substfilenamefiles.pm,v $
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
::substfilenamefiles
;
34 use installer
::exiter
;
35 use installer
::globals
;
36 use installer
::logger
;
37 use installer
::pathanalyzer
;
38 use installer
::systemactions
;
40 #########################################################
41 # Analyzing files with flag SCPZIP_REPLACE
42 # $item can be "File" or "ScpAction"
43 #########################################################
45 sub resolving_subst_filename_flag
47 my ($filesarrayref, $variableshashref, $languagestringref) = @_;
49 my $diritem = lc($item);
51 my $replacedirbase = installer
::systemactions
::create_directories
("change_filename", $languagestringref);
53 installer
::logger
::include_header_into_logfile
("Files with flag SUBST_FILENAME:");
55 for ( my $i = 0; $i <= $#{$filesarrayref}; $i++ )
57 my $onefile = ${$filesarrayref}[$i];
60 if ( $onefile->{'Styles'} ) { $styles = $onefile->{'Styles'}; }
62 if ( $styles =~ /\bSUBST_FILENAME\b/ )
64 # Files with flag SUBST_FILENAME must have a "Substitute" key
65 if (( ! $onefile->{'Substitute'} ) && ( ! $onefile->{'InstallName'} ))
67 installer
::exiter
::exit_program
("ERROR: SUBST_FILENAME is set, but no Substitute and no InstallName defined at file $onefile->{'gid'}!", "resolving_subst_filename_flag");
70 # Language specific subdirectory
71 my $onelanguage = $onefile->{'specificlanguage'};
73 if ($onelanguage eq "")
75 $onelanguage = "00"; # files without language into directory "00"
78 my $replacedir = $replacedirbase . $installer::globals
::separator
. $onelanguage . $installer::globals
::separator
;
79 installer
::systemactions
::create_directory
($replacedir); # creating language specific directories
81 # copy files and edit them with the variables defined in the zip.lst
85 my $onefilename = $onefile->{'Name'};
87 my $sourcepath = $onefile->{'sourcepath'};
89 # if ( $onefilename =~ /^\s*\Q$installer::globals::separator\E/ ) # filename begins with a slash, for instance /registry/schema/org/openoffice/VCL.xcs
90 if ( $onefilename =~ /\Q$installer::globals::separator\E/ ) # filename begins with a slash, for instance /registry/schema/org/openoffice/VCL.xcs
92 $onefilename =~ s/^\s*\Q$installer::globals::separator\E//;
96 my $destinationpath = $replacedir . $onefilename;
97 my $movepath = $destinationpath . ".orig";
98 my $destdir = $replacedir;
100 if ( $longfilename ) # the destination directory has to be created before copying
102 $destdir = $movepath;
103 installer
::pathanalyzer
::get_path_from_fullqualifiedname
(\
$destdir);
104 installer
::systemactions
::create_directory_structure
($destdir);
107 my $copysuccess = installer
::systemactions
::copy_one_file
($sourcepath, $movepath);
111 if ( $onefile->{'Substitute'} )
113 my $substitute = $onefile->{'Substitute'};
115 my $newfilename = $destinationpath;
116 installer
::pathanalyzer
::make_absolute_filename_to_relative_filename
(\
$newfilename);
117 eval '$newfilename =~ ' . "$substitute";
119 my $longnewfilename = $destdir . $newfilename;
121 $copysuccess = installer
::systemactions
::copy_one_file
($movepath, $longnewfilename);
123 # Saving the new file name
124 $onefile->{'Name'} = $newfilename;
126 # Saving the new destination
127 my $newdest = $onefile->{'destination'};
128 installer
::pathanalyzer
::get_path_from_fullqualifiedname
(\
$newdest);
129 $onefile->{'destination'} = $newdest . $newfilename;
131 # Saving the original source, where the file was found
132 $onefile->{'originalsourcepath'} = $onefile->{'sourcepath'};
134 # Writing the new sourcepath into the hashref, even if it was not copied
135 $onefile->{'sourcepath'} = $longnewfilename;
139 if ( $onefile->{'InstallName'} )
141 my $installname = $onefile->{'InstallName'};
143 my $newfilename = $destinationpath;
144 installer
::pathanalyzer
::make_absolute_filename_to_relative_filename
(\
$newfilename);
146 my $longnewfilename = $destdir . $installname;
148 $copysuccess = installer
::systemactions
::copy_one_file
($movepath, $longnewfilename);
150 # Saving the new file name
151 $onefile->{'Name'} = $installname;
153 # Saving the new destination
154 my $newdest = $onefile->{'destination'};
155 installer
::pathanalyzer
::get_path_from_fullqualifiedname
(\
$newdest);
156 $onefile->{'destination'} = $newdest . $installname;
158 # Saving the original source, where the file was found
159 $onefile->{'originalsourcepath'} = $onefile->{'sourcepath'};
161 # Writing the new sourcepath into the hashref, even if it was not copied
162 $onefile->{'sourcepath'} = $longnewfilename;
170 push( @installer::globals
::logfileinfo
, $infoline);