1*9780544fSAndrew Rist#************************************************************** 2*9780544fSAndrew Rist# 3*9780544fSAndrew Rist# Licensed to the Apache Software Foundation (ASF) under one 4*9780544fSAndrew Rist# or more contributor license agreements. See the NOTICE file 5*9780544fSAndrew Rist# distributed with this work for additional information 6*9780544fSAndrew Rist# regarding copyright ownership. The ASF licenses this file 7*9780544fSAndrew Rist# to you under the Apache License, Version 2.0 (the 8*9780544fSAndrew Rist# "License"); you may not use this file except in compliance 9*9780544fSAndrew Rist# with the License. You may obtain a copy of the License at 10*9780544fSAndrew Rist# 11*9780544fSAndrew Rist# http://www.apache.org/licenses/LICENSE-2.0 12*9780544fSAndrew Rist# 13*9780544fSAndrew Rist# Unless required by applicable law or agreed to in writing, 14*9780544fSAndrew Rist# software distributed under the License is distributed on an 15*9780544fSAndrew Rist# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9780544fSAndrew Rist# KIND, either express or implied. See the License for the 17*9780544fSAndrew Rist# specific language governing permissions and limitations 18*9780544fSAndrew Rist# under the License. 19*9780544fSAndrew Rist# 20*9780544fSAndrew Rist#************************************************************** 21*9780544fSAndrew Rist 22*9780544fSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweirpackage installer::scppatchsoname; 25cdf0e10cSrcweir 26cdf0e10cSrcweiruse installer::files; 27cdf0e10cSrcweiruse installer::globals; 28cdf0e10cSrcweiruse installer::logger; 29cdf0e10cSrcweiruse installer::setupscript; 30cdf0e10cSrcweiruse installer::systemactions; 31cdf0e10cSrcweir 32cdf0e10cSrcweir######################################################################################## 33cdf0e10cSrcweir# The length of the new string must be identical with the length of the old string 34cdf0e10cSrcweir######################################################################################## 35cdf0e10cSrcweir 36cdf0e10cSrcweirsub change_length_of_string 37cdf0e10cSrcweir{ 38cdf0e10cSrcweir my ($newstringref, $oldstring) = @_; 39cdf0e10cSrcweir 40cdf0e10cSrcweir while ( length($$newstringref) < length($oldstring) ) 41cdf0e10cSrcweir { 42cdf0e10cSrcweir $$newstringref = $$newstringref . chr(0); 43cdf0e10cSrcweir } 44cdf0e10cSrcweir} 45cdf0e10cSrcweir 46cdf0e10cSrcweir######################################################################################## 47cdf0e10cSrcweir# The length of the new string must be identical with the length of the old string 48cdf0e10cSrcweir######################################################################################## 49cdf0e10cSrcweir 50cdf0e10cSrcweirsub change_length_of_string_with_letter 51cdf0e10cSrcweir{ 52cdf0e10cSrcweir my ($newstringref, $oldstring, $onestring) = @_; 53cdf0e10cSrcweir 54cdf0e10cSrcweir while ( length($$newstringref) < length($oldstring) ) 55cdf0e10cSrcweir { 56cdf0e10cSrcweir $$newstringref = $$newstringref . $onestring; 57cdf0e10cSrcweir } 58cdf0e10cSrcweir} 59cdf0e10cSrcweir 60cdf0e10cSrcweir######################################################################################## 61cdf0e10cSrcweir# Converting a string to a unicode string 62cdf0e10cSrcweir######################################################################################## 63cdf0e10cSrcweir 64cdf0e10cSrcweirsub convert_to_unicode 65cdf0e10cSrcweir{ 66cdf0e10cSrcweir my ($string) = @_; 67cdf0e10cSrcweir 68cdf0e10cSrcweir my $unicodestring = ""; 69cdf0e10cSrcweir 70cdf0e10cSrcweir my $stringlength = length($string); 71cdf0e10cSrcweir 72cdf0e10cSrcweir for ( my $i = 0; $i < $stringlength; $i++ ) 73cdf0e10cSrcweir { 74cdf0e10cSrcweir $unicodestring = $unicodestring . substr($string, $i, 1); 75cdf0e10cSrcweir $unicodestring = $unicodestring . chr(0); 76cdf0e10cSrcweir } 77cdf0e10cSrcweir 78cdf0e10cSrcweir return $unicodestring; 79cdf0e10cSrcweir} 80cdf0e10cSrcweir 81cdf0e10cSrcweir######################################################################################## 82cdf0e10cSrcweir# Replacing the so name in all files with flag PATCH_SO_NAME 83cdf0e10cSrcweir######################################################################################## 84cdf0e10cSrcweir 85cdf0e10cSrcweirsub replace_productname_in_file 86cdf0e10cSrcweir{ 87cdf0e10cSrcweir my ($sourcepath, $destpath, $variableshashref, $onefilehash, $styles) = @_; 88cdf0e10cSrcweir 89cdf0e10cSrcweir my $onefile = installer::files::read_binary_file($sourcepath); 90cdf0e10cSrcweir 91cdf0e10cSrcweir # searching for "x" 92cdf0e10cSrcweir 93cdf0e10cSrcweir my $onestring = "x" . chr(0); 94cdf0e10cSrcweir my $replacestring = ""; 95cdf0e10cSrcweir for ( my $i = 1; $i <= 80; $i++ ) { $replacestring .= $onestring; } 96cdf0e10cSrcweir 97cdf0e10cSrcweir my $productname = $variableshashref->{'PRODUCTNAME'} . " " . $variableshashref->{'PRODUCTVERSION'}; 98cdf0e10cSrcweir if ( exists($onefilehash->{'FileDescription'}) ) { $productname = $onefilehash->{'FileDescription'}; } 99cdf0e10cSrcweir my $unicode_productname = convert_to_unicode($productname); 100cdf0e10cSrcweir 101cdf0e10cSrcweir change_length_of_string(\$unicode_productname, $replacestring); 102cdf0e10cSrcweir 103cdf0e10cSrcweir my $found1 = $onefile =~ s/$replacestring/$unicode_productname/sg; 104cdf0e10cSrcweir 105cdf0e10cSrcweir my $found2 = 0; 106cdf0e10cSrcweir 107cdf0e10cSrcweir if ( $styles =~ /\bPATCH_SO_NAME_Z\b/ ) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir # searching for "z" 110cdf0e10cSrcweir 111cdf0e10cSrcweir $onestring = "z" . chr(0); 112cdf0e10cSrcweir $replacestring = ""; 113cdf0e10cSrcweir for ( my $i = 1; $i <= 80; $i++ ) { $replacestring .= $onestring; } 114cdf0e10cSrcweir 115cdf0e10cSrcweir my $productname2 = $variableshashref->{'PRODUCTNAME'} . " " . $variableshashref->{'PRODUCTVERSION'}; 116cdf0e10cSrcweir if ( exists($onefilehash->{'FileDescriptionZ'}) ) { $productname2 = $onefilehash->{'FileDescriptionZ'}; } 117cdf0e10cSrcweir my $unicode_productname2 = convert_to_unicode($productname2); 118cdf0e10cSrcweir 119cdf0e10cSrcweir change_length_of_string_with_letter(\$unicode_productname2, $replacestring, $onestring); 120cdf0e10cSrcweir 121cdf0e10cSrcweir $found2 = $onefile =~ s/$replacestring/$unicode_productname2/sg; 122cdf0e10cSrcweir } 123cdf0e10cSrcweir 124cdf0e10cSrcweir installer::files::save_binary_file($onefile, $destpath); 125cdf0e10cSrcweir 126cdf0e10cSrcweir my $found = $found1 + $found2; 127cdf0e10cSrcweir 128cdf0e10cSrcweir return $found; 129cdf0e10cSrcweir} 130cdf0e10cSrcweir 131cdf0e10cSrcweir######################################################### 132cdf0e10cSrcweir# Analyzing files with flag PATCH_SO_NAME 133cdf0e10cSrcweir######################################################### 134cdf0e10cSrcweir 135cdf0e10cSrcweirsub resolving_patchsoname_flag 136cdf0e10cSrcweir{ 137cdf0e10cSrcweir my ($filesarrayref, $variableshashref, $item, $languagestringref) = @_; 138cdf0e10cSrcweir 139cdf0e10cSrcweir my $diritem = lc($item); 140cdf0e10cSrcweir 141cdf0e10cSrcweir my $replacedirbase = installer::systemactions::create_directories("patchsoname_$diritem", $languagestringref); 142cdf0e10cSrcweir 143cdf0e10cSrcweir installer::logger::include_header_into_logfile("$item with flag PATCH_SO_NAME:"); 144cdf0e10cSrcweir 145cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$filesarrayref}; $i++ ) 146cdf0e10cSrcweir { 147cdf0e10cSrcweir my $onefile = ${$filesarrayref}[$i]; 148cdf0e10cSrcweir my $styles = ""; 149cdf0e10cSrcweir 150cdf0e10cSrcweir if ( $onefile->{'Styles'} ) { $styles = $onefile->{'Styles'}; } 151cdf0e10cSrcweir 152cdf0e10cSrcweir if ( $styles =~ /\bPATCH_SO_NAME\b/ ) 153cdf0e10cSrcweir { 154cdf0e10cSrcweir # Language specific subdirectory 155cdf0e10cSrcweir 156cdf0e10cSrcweir my $onelanguage = $onefile->{'specificlanguage'}; 157cdf0e10cSrcweir my $filedescription = ""; 158cdf0e10cSrcweir 159cdf0e10cSrcweir if ($onelanguage eq "") 160cdf0e10cSrcweir { 161cdf0e10cSrcweir $onelanguage = "00"; # files without language into directory "00" 162cdf0e10cSrcweir } 163cdf0e10cSrcweir 164cdf0e10cSrcweir my $replacedir = $replacedirbase . $installer::globals::separator . $onelanguage . $installer::globals::separator; 165cdf0e10cSrcweir installer::systemactions::create_directory($replacedir); # creating language specific directories 166cdf0e10cSrcweir 167cdf0e10cSrcweir # copy files and edit them with the variables defined in the zip.lst 168cdf0e10cSrcweir 169cdf0e10cSrcweir my $onefilename = $onefile->{'Name'}; 170cdf0e10cSrcweir my $sourcepath = $onefile->{'sourcepath'}; 171cdf0e10cSrcweir my $destinationpath = $replacedir . $onefilename; 172cdf0e10cSrcweir my $movepath = $destinationpath . ".orig"; 173cdf0e10cSrcweir 174cdf0e10cSrcweir # if (!(-f $destinationpath)) # do nothing if the file already exists 175cdf0e10cSrcweir # { 176cdf0e10cSrcweir 177cdf0e10cSrcweir my $copysuccess = installer::systemactions::copy_one_file($sourcepath, $movepath); 178cdf0e10cSrcweir 179cdf0e10cSrcweir if ( $copysuccess ) 180cdf0e10cSrcweir { 181cdf0e10cSrcweir # Now the file can be patch (binary!) 182cdf0e10cSrcweir my $found = replace_productname_in_file($movepath, $destinationpath, $variableshashref, $onefile, $styles); 183cdf0e10cSrcweir 184cdf0e10cSrcweir if ($found == 0) 185cdf0e10cSrcweir { 186cdf0e10cSrcweir my $infoline = "Did not patch the file $destinationpath\n"; 187cdf0e10cSrcweir push( @installer::globals::logfileinfo, $infoline); 188cdf0e10cSrcweir } 189cdf0e10cSrcweir else 190cdf0e10cSrcweir { 191cdf0e10cSrcweir my $infoline = "Successfully patched $destinationpath, Count: $found\n"; 192cdf0e10cSrcweir push( @installer::globals::logfileinfo, $infoline); 193cdf0e10cSrcweir } 194cdf0e10cSrcweir } 195cdf0e10cSrcweir 196cdf0e10cSrcweir # } 197cdf0e10cSrcweir 198cdf0e10cSrcweir # Saving the original source, where the file was found 199cdf0e10cSrcweir $onefile->{'originalsourcepath'} = $onefile->{'sourcepath'}; 200cdf0e10cSrcweir 201cdf0e10cSrcweir # Saving the original source, where the file was found 202cdf0e10cSrcweir $onefile->{'originalsourcepath'} = $onefile->{'sourcepath'}; 203cdf0e10cSrcweir 204cdf0e10cSrcweir # Writing the new sourcepath into the hashref, even if it was no copied 205cdf0e10cSrcweir 206cdf0e10cSrcweir $onefile->{'sourcepath'} = $destinationpath; 207cdf0e10cSrcweir } 208cdf0e10cSrcweir } 209cdf0e10cSrcweir 210cdf0e10cSrcweir my $infoline = "\n"; 211cdf0e10cSrcweir push( @installer::globals::logfileinfo, $infoline); 212cdf0e10cSrcweir} 213cdf0e10cSrcweir 214cdf0e10cSrcweir1; 215