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::substfilenamefiles; 29*cdf0e10cSrcweir 30*cdf0e10cSrcweiruse installer::exiter; 31*cdf0e10cSrcweiruse installer::globals; 32*cdf0e10cSrcweiruse installer::logger; 33*cdf0e10cSrcweiruse installer::pathanalyzer; 34*cdf0e10cSrcweiruse installer::systemactions; 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir######################################################### 37*cdf0e10cSrcweir# Analyzing files with flag SUBST_FILENAME 38*cdf0e10cSrcweir######################################################### 39*cdf0e10cSrcweir 40*cdf0e10cSrcweirsub resolving_subst_filename_flag 41*cdf0e10cSrcweir{ 42*cdf0e10cSrcweir my ($filesarrayref, $variableshashref, $languagestringref) = @_; 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir my $replacedirbase = installer::systemactions::create_directories("change_filename", $languagestringref); 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir installer::logger::include_header_into_logfile("Files with flag SUBST_FILENAME:"); 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$filesarrayref}; $i++ ) 49*cdf0e10cSrcweir { 50*cdf0e10cSrcweir my $onefile = ${$filesarrayref}[$i]; 51*cdf0e10cSrcweir my $styles = ""; 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir if ( $onefile->{'Styles'} ) { $styles = $onefile->{'Styles'}; } 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir if ( $styles =~ /\bSUBST_FILENAME\b/ ) 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir # Files with flag SUBST_FILENAME must have a "Substitute" key 58*cdf0e10cSrcweir if (( ! $onefile->{'Substitute'} ) && ( ! $onefile->{'InstallName'} )) 59*cdf0e10cSrcweir { 60*cdf0e10cSrcweir 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*cdf0e10cSrcweir } 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir # Language specific subdirectory 64*cdf0e10cSrcweir my $onelanguage = $onefile->{'specificlanguage'}; 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir if ($onelanguage eq "") 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir $onelanguage = "00"; # files without language into directory "00" 69*cdf0e10cSrcweir } 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir my $replacedir = $replacedirbase . $installer::globals::separator . $onelanguage . $installer::globals::separator; 72*cdf0e10cSrcweir installer::systemactions::create_directory($replacedir); # creating language specific directories 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir # copy files and edit them with the variables defined in the zip.lst 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir my $longfilename = 0; 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir my $onefilename = $onefile->{'Name'}; 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir my $sourcepath = $onefile->{'sourcepath'}; 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir # if ( $onefilename =~ /^\s*\Q$installer::globals::separator\E/ ) # filename begins with a slash, for instance /registry/schema/org/openoffice/VCL.xcs 83*cdf0e10cSrcweir if ( $onefilename =~ /\Q$installer::globals::separator\E/ ) # filename begins with a slash, for instance /registry/schema/org/openoffice/VCL.xcs 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir $onefilename =~ s/^\s*\Q$installer::globals::separator\E//; 86*cdf0e10cSrcweir $longfilename = 1; 87*cdf0e10cSrcweir } 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir my $destinationpath = $replacedir . $onefilename; 90*cdf0e10cSrcweir my $movepath = $destinationpath . ".orig"; 91*cdf0e10cSrcweir my $destdir = $replacedir; 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir if ( $longfilename ) # the destination directory has to be created before copying 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir $destdir = $movepath; 96*cdf0e10cSrcweir installer::pathanalyzer::get_path_from_fullqualifiedname(\$destdir); 97*cdf0e10cSrcweir installer::systemactions::create_directory_structure($destdir); 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir my $copysuccess = installer::systemactions::copy_one_file($sourcepath, $movepath); 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir if ( $copysuccess ) 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir if ( $onefile->{'Substitute'} ) 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir my $substitute = $onefile->{'Substitute'}; 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir my $newfilename = $destinationpath; 109*cdf0e10cSrcweir installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$newfilename); 110*cdf0e10cSrcweir eval '$newfilename =~ ' . "$substitute"; 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir my $longnewfilename = $destdir . $newfilename; 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir $copysuccess = installer::systemactions::copy_one_file($movepath, $longnewfilename); 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir # Saving the new file name 117*cdf0e10cSrcweir $onefile->{'Name'} = $newfilename; 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir # Saving the new destination 120*cdf0e10cSrcweir my $newdest = $onefile->{'destination'}; 121*cdf0e10cSrcweir installer::pathanalyzer::get_path_from_fullqualifiedname(\$newdest); 122*cdf0e10cSrcweir $onefile->{'destination'} = $newdest . $newfilename; 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir # Saving the original source, where the file was found 125*cdf0e10cSrcweir $onefile->{'originalsourcepath'} = $onefile->{'sourcepath'}; 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir # Writing the new sourcepath into the hashref, even if it was not copied 128*cdf0e10cSrcweir $onefile->{'sourcepath'} = $longnewfilename; 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir else 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir if ( $onefile->{'InstallName'} ) 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir my $installname = $onefile->{'InstallName'}; 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir my $newfilename = $destinationpath; 137*cdf0e10cSrcweir installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$newfilename); 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir my $longnewfilename = $destdir . $installname; 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir $copysuccess = installer::systemactions::copy_one_file($movepath, $longnewfilename); 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir # Saving the new file name 144*cdf0e10cSrcweir $onefile->{'Name'} = $installname; 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir # Saving the new destination 147*cdf0e10cSrcweir my $newdest = $onefile->{'destination'}; 148*cdf0e10cSrcweir installer::pathanalyzer::get_path_from_fullqualifiedname(\$newdest); 149*cdf0e10cSrcweir $onefile->{'destination'} = $newdest . $installname; 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir # Saving the original source, where the file was found 152*cdf0e10cSrcweir $onefile->{'originalsourcepath'} = $onefile->{'sourcepath'}; 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir # Writing the new sourcepath into the hashref, even if it was not copied 155*cdf0e10cSrcweir $onefile->{'sourcepath'} = $longnewfilename; 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir my $infoline = "\n"; 163*cdf0e10cSrcweir push( @installer::globals::logfileinfo, $infoline); 164*cdf0e10cSrcweir} 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir1; 167