1#************************************************************************* 2# 3# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4# 5# Copyright 2000, 2010 Oracle and/or its affiliates. 6# 7# OpenOffice.org - a multi-platform office productivity suite 8# 9# This file is part of OpenOffice.org. 10# 11# OpenOffice.org is free software: you can redistribute it and/or modify 12# it under the terms of the GNU Lesser General Public License version 3 13# only, as published by the Free Software Foundation. 14# 15# OpenOffice.org is distributed in the hope that it will be useful, 16# but WITHOUT ANY WARRANTY; without even the implied warranty of 17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18# GNU Lesser General Public License version 3 for more details 19# (a copy is included in the LICENSE file that accompanied this code). 20# 21# You should have received a copy of the GNU Lesser General Public License 22# version 3 along with OpenOffice.org. If not, see 23# <http://www.openoffice.org/license.html> 24# for a copy of the LGPLv3 License. 25# 26#************************************************************************* 27 28package installer::substfilenamefiles; 29 30use installer::exiter; 31use installer::globals; 32use installer::logger; 33use installer::pathanalyzer; 34use installer::systemactions; 35 36######################################################### 37# Analyzing files with flag SUBST_FILENAME 38######################################################### 39 40sub resolving_subst_filename_flag 41{ 42 my ($filesarrayref, $variableshashref, $languagestringref) = @_; 43 44 my $replacedirbase = installer::systemactions::create_directories("change_filename", $languagestringref); 45 46 installer::logger::include_header_into_logfile("Files with flag SUBST_FILENAME:"); 47 48 for ( my $i = 0; $i <= $#{$filesarrayref}; $i++ ) 49 { 50 my $onefile = ${$filesarrayref}[$i]; 51 my $styles = ""; 52 53 if ( $onefile->{'Styles'} ) { $styles = $onefile->{'Styles'}; } 54 55 if ( $styles =~ /\bSUBST_FILENAME\b/ ) 56 { 57 # Files with flag SUBST_FILENAME must have a "Substitute" key 58 if (( ! $onefile->{'Substitute'} ) && ( ! $onefile->{'InstallName'} )) 59 { 60 installer::exiter::exit_program("ERROR: SUBST_FILENAME is set, but no Substitute and no InstallName defined at file $onefile->{'gid'}!", "resolving_subst_filename_flag"); 61 } 62 63 # Language specific subdirectory 64 my $onelanguage = $onefile->{'specificlanguage'}; 65 66 if ($onelanguage eq "") 67 { 68 $onelanguage = "00"; # files without language into directory "00" 69 } 70 71 my $replacedir = $replacedirbase . $installer::globals::separator . $onelanguage . $installer::globals::separator; 72 installer::systemactions::create_directory($replacedir); # creating language specific directories 73 74 # copy files and edit them with the variables defined in the zip.lst 75 76 my $longfilename = 0; 77 78 my $onefilename = $onefile->{'Name'}; 79 80 my $sourcepath = $onefile->{'sourcepath'}; 81 82 # if ( $onefilename =~ /^\s*\Q$installer::globals::separator\E/ ) # filename begins with a slash, for instance /registry/schema/org/openoffice/VCL.xcs 83 if ( $onefilename =~ /\Q$installer::globals::separator\E/ ) # filename begins with a slash, for instance /registry/schema/org/openoffice/VCL.xcs 84 { 85 $onefilename =~ s/^\s*\Q$installer::globals::separator\E//; 86 $longfilename = 1; 87 } 88 89 my $destinationpath = $replacedir . $onefilename; 90 my $movepath = $destinationpath . ".orig"; 91 my $destdir = $replacedir; 92 93 if ( $longfilename ) # the destination directory has to be created before copying 94 { 95 $destdir = $movepath; 96 installer::pathanalyzer::get_path_from_fullqualifiedname(\$destdir); 97 installer::systemactions::create_directory_structure($destdir); 98 } 99 100 my $copysuccess = installer::systemactions::copy_one_file($sourcepath, $movepath); 101 102 if ( $copysuccess ) 103 { 104 if ( $onefile->{'Substitute'} ) 105 { 106 my $substitute = $onefile->{'Substitute'}; 107 108 my $newfilename = $destinationpath; 109 installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$newfilename); 110 eval '$newfilename =~ ' . "$substitute"; 111 112 my $longnewfilename = $destdir . $newfilename; 113 114 $copysuccess = installer::systemactions::copy_one_file($movepath, $longnewfilename); 115 116 # Saving the new file name 117 $onefile->{'Name'} = $newfilename; 118 119 # Saving the new destination 120 my $newdest = $onefile->{'destination'}; 121 installer::pathanalyzer::get_path_from_fullqualifiedname(\$newdest); 122 $onefile->{'destination'} = $newdest . $newfilename; 123 124 # Saving the original source, where the file was found 125 $onefile->{'originalsourcepath'} = $onefile->{'sourcepath'}; 126 127 # Writing the new sourcepath into the hashref, even if it was not copied 128 $onefile->{'sourcepath'} = $longnewfilename; 129 } 130 else 131 { 132 if ( $onefile->{'InstallName'} ) 133 { 134 my $installname = $onefile->{'InstallName'}; 135 136 my $newfilename = $destinationpath; 137 installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$newfilename); 138 139 my $longnewfilename = $destdir . $installname; 140 141 $copysuccess = installer::systemactions::copy_one_file($movepath, $longnewfilename); 142 143 # Saving the new file name 144 $onefile->{'Name'} = $installname; 145 146 # Saving the new destination 147 my $newdest = $onefile->{'destination'}; 148 installer::pathanalyzer::get_path_from_fullqualifiedname(\$newdest); 149 $onefile->{'destination'} = $newdest . $installname; 150 151 # Saving the original source, where the file was found 152 $onefile->{'originalsourcepath'} = $onefile->{'sourcepath'}; 153 154 # Writing the new sourcepath into the hashref, even if it was not copied 155 $onefile->{'sourcepath'} = $longnewfilename; 156 } 157 } 158 } 159 } 160 } 161 162 my $infoline = "\n"; 163 push( @installer::globals::logfileinfo, $infoline); 164} 165 1661; 167