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::scppatchsoname; 29 30use installer::files; 31use installer::globals; 32use installer::logger; 33use installer::setupscript; 34use installer::systemactions; 35 36######################################################################################## 37# The length of the new string must be identical with the length of the old string 38######################################################################################## 39 40sub change_length_of_string 41{ 42 my ($newstringref, $oldstring) = @_; 43 44 while ( length($$newstringref) < length($oldstring) ) 45 { 46 $$newstringref = $$newstringref . chr(0); 47 } 48} 49 50######################################################################################## 51# The length of the new string must be identical with the length of the old string 52######################################################################################## 53 54sub change_length_of_string_with_letter 55{ 56 my ($newstringref, $oldstring, $onestring) = @_; 57 58 while ( length($$newstringref) < length($oldstring) ) 59 { 60 $$newstringref = $$newstringref . $onestring; 61 } 62} 63 64######################################################################################## 65# Converting a string to a unicode string 66######################################################################################## 67 68sub convert_to_unicode 69{ 70 my ($string) = @_; 71 72 my $unicodestring = ""; 73 74 my $stringlength = length($string); 75 76 for ( my $i = 0; $i < $stringlength; $i++ ) 77 { 78 $unicodestring = $unicodestring . substr($string, $i, 1); 79 $unicodestring = $unicodestring . chr(0); 80 } 81 82 return $unicodestring; 83} 84 85######################################################################################## 86# Replacing the so name in all files with flag PATCH_SO_NAME 87######################################################################################## 88 89sub replace_productname_in_file 90{ 91 my ($sourcepath, $destpath, $variableshashref, $onefilehash, $styles) = @_; 92 93 my $onefile = installer::files::read_binary_file($sourcepath); 94 95 # searching for "x" 96 97 my $onestring = "x" . chr(0); 98 my $replacestring = ""; 99 for ( my $i = 1; $i <= 80; $i++ ) { $replacestring .= $onestring; } 100 101 my $productname = $variableshashref->{'PRODUCTNAME'} . " " . $variableshashref->{'PRODUCTVERSION'}; 102 if ( exists($onefilehash->{'FileDescription'}) ) { $productname = $onefilehash->{'FileDescription'}; } 103 my $unicode_productname = convert_to_unicode($productname); 104 105 change_length_of_string(\$unicode_productname, $replacestring); 106 107 my $found1 = $onefile =~ s/$replacestring/$unicode_productname/sg; 108 109 my $found2 = 0; 110 111 if ( $styles =~ /\bPATCH_SO_NAME_Z\b/ ) 112 { 113 # searching for "z" 114 115 $onestring = "z" . chr(0); 116 $replacestring = ""; 117 for ( my $i = 1; $i <= 80; $i++ ) { $replacestring .= $onestring; } 118 119 my $productname2 = $variableshashref->{'PRODUCTNAME'} . " " . $variableshashref->{'PRODUCTVERSION'}; 120 if ( exists($onefilehash->{'FileDescriptionZ'}) ) { $productname2 = $onefilehash->{'FileDescriptionZ'}; } 121 my $unicode_productname2 = convert_to_unicode($productname2); 122 123 change_length_of_string_with_letter(\$unicode_productname2, $replacestring, $onestring); 124 125 $found2 = $onefile =~ s/$replacestring/$unicode_productname2/sg; 126 } 127 128 installer::files::save_binary_file($onefile, $destpath); 129 130 my $found = $found1 + $found2; 131 132 return $found; 133} 134 135######################################################### 136# Analyzing files with flag PATCH_SO_NAME 137######################################################### 138 139sub resolving_patchsoname_flag 140{ 141 my ($filesarrayref, $variableshashref, $item, $languagestringref) = @_; 142 143 my $diritem = lc($item); 144 145 my $replacedirbase = installer::systemactions::create_directories("patchsoname_$diritem", $languagestringref); 146 147 installer::logger::include_header_into_logfile("$item with flag PATCH_SO_NAME:"); 148 149 for ( my $i = 0; $i <= $#{$filesarrayref}; $i++ ) 150 { 151 my $onefile = ${$filesarrayref}[$i]; 152 my $styles = ""; 153 154 if ( $onefile->{'Styles'} ) { $styles = $onefile->{'Styles'}; } 155 156 if ( $styles =~ /\bPATCH_SO_NAME\b/ ) 157 { 158 # Language specific subdirectory 159 160 my $onelanguage = $onefile->{'specificlanguage'}; 161 my $filedescription = ""; 162 163 if ($onelanguage eq "") 164 { 165 $onelanguage = "00"; # files without language into directory "00" 166 } 167 168 my $replacedir = $replacedirbase . $installer::globals::separator . $onelanguage . $installer::globals::separator; 169 installer::systemactions::create_directory($replacedir); # creating language specific directories 170 171 # copy files and edit them with the variables defined in the zip.lst 172 173 my $onefilename = $onefile->{'Name'}; 174 my $sourcepath = $onefile->{'sourcepath'}; 175 my $destinationpath = $replacedir . $onefilename; 176 my $movepath = $destinationpath . ".orig"; 177 178 # if (!(-f $destinationpath)) # do nothing if the file already exists 179 # { 180 181 my $copysuccess = installer::systemactions::copy_one_file($sourcepath, $movepath); 182 183 if ( $copysuccess ) 184 { 185 # Now the file can be patch (binary!) 186 my $found = replace_productname_in_file($movepath, $destinationpath, $variableshashref, $onefile, $styles); 187 188 if ($found == 0) 189 { 190 my $infoline = "Did not patch the file $destinationpath\n"; 191 push( @installer::globals::logfileinfo, $infoline); 192 } 193 else 194 { 195 my $infoline = "Successfully patched $destinationpath, Count: $found\n"; 196 push( @installer::globals::logfileinfo, $infoline); 197 } 198 } 199 200 # } 201 202 # Saving the original source, where the file was found 203 $onefile->{'originalsourcepath'} = $onefile->{'sourcepath'}; 204 205 # Saving the original source, where the file was found 206 $onefile->{'originalsourcepath'} = $onefile->{'sourcepath'}; 207 208 # Writing the new sourcepath into the hashref, even if it was no copied 209 210 $onefile->{'sourcepath'} = $destinationpath; 211 } 212 } 213 214 my $infoline = "\n"; 215 push( @installer::globals::logfileinfo, $infoline); 216} 217 2181; 219