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: scppatchsoname.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
::scppatchsoname
;
35 use installer
::globals
;
36 use installer
::logger
;
37 use installer
::setupscript
;
38 use installer
::systemactions
;
40 ########################################################################################
41 # The length of the new string must be identical with the length of the old string
42 ########################################################################################
44 sub change_length_of_string
46 my ($newstringref, $oldstring) = @_;
48 while ( length($$newstringref) < length($oldstring) )
50 $$newstringref = $$newstringref . chr(0);
54 ########################################################################################
55 # The length of the new string must be identical with the length of the old string
56 ########################################################################################
58 sub change_length_of_string_with_letter
60 my ($newstringref, $oldstring, $onestring) = @_;
62 while ( length($$newstringref) < length($oldstring) )
64 $$newstringref = $$newstringref . $onestring;
68 ########################################################################################
69 # Converting a string to a unicode string
70 ########################################################################################
72 sub convert_to_unicode
76 my $unicodestring = "";
78 my $stringlength = length($string);
80 for ( my $i = 0; $i < $stringlength; $i++ )
82 $unicodestring = $unicodestring . substr($string, $i, 1);
83 $unicodestring = $unicodestring . chr(0);
86 return $unicodestring;
89 ########################################################################################
90 # Replacing the so name in all files with flag PATCH_SO_NAME
91 ########################################################################################
93 sub replace_productname_in_file
95 my ($sourcepath, $destpath, $variableshashref, $onefilehash, $styles) = @_;
97 my $onefile = installer
::files
::read_binary_file
($sourcepath);
101 my $onestring = "x" . chr(0);
102 my $replacestring = "";
103 for ( my $i = 1; $i <= 80; $i++ ) { $replacestring .= $onestring; }
105 my $productname = $variableshashref->{'PRODUCTNAME'} . " " . $variableshashref->{'PRODUCTVERSION'};
106 if ( exists($onefilehash->{'FileDescription'}) ) { $productname = $onefilehash->{'FileDescription'}; }
107 my $unicode_productname = convert_to_unicode
($productname);
109 change_length_of_string
(\
$unicode_productname, $replacestring);
111 my $found1 = $onefile =~ s/$replacestring/$unicode_productname/sg;
115 if ( $styles =~ /\bPATCH_SO_NAME_Z\b/ )
119 $onestring = "z" . chr(0);
121 for ( my $i = 1; $i <= 80; $i++ ) { $replacestring .= $onestring; }
123 my $productname2 = $variableshashref->{'PRODUCTNAME'} . " " . $variableshashref->{'PRODUCTVERSION'};
124 if ( exists($onefilehash->{'FileDescriptionZ'}) ) { $productname2 = $onefilehash->{'FileDescriptionZ'}; }
125 my $unicode_productname2 = convert_to_unicode
($productname2);
127 change_length_of_string_with_letter
(\
$unicode_productname2, $replacestring, $onestring);
129 $found2 = $onefile =~ s/$replacestring/$unicode_productname2/sg;
132 installer
::files
::save_binary_file
($onefile, $destpath);
134 my $found = $found1 + $found2;
139 #########################################################
140 # Analyzing files with flag PATCH_SO_NAME
141 #########################################################
143 sub resolving_patchsoname_flag
145 my ($filesarrayref, $variableshashref, $item, $languagestringref) = @_;
147 my $diritem = lc($item);
149 my $replacedirbase = installer
::systemactions
::create_directories
("patchsoname_$diritem", $languagestringref);
151 installer
::logger
::include_header_into_logfile
("$item with flag PATCH_SO_NAME:");
153 for ( my $i = 0; $i <= $#{$filesarrayref}; $i++ )
155 my $onefile = ${$filesarrayref}[$i];
158 if ( $onefile->{'Styles'} ) { $styles = $onefile->{'Styles'}; }
160 if ( $styles =~ /\bPATCH_SO_NAME\b/ )
162 # Language specific subdirectory
164 my $onelanguage = $onefile->{'specificlanguage'};
165 my $filedescription = "";
167 if ($onelanguage eq "")
169 $onelanguage = "00"; # files without language into directory "00"
172 my $replacedir = $replacedirbase . $installer::globals
::separator
. $onelanguage . $installer::globals
::separator
;
173 installer
::systemactions
::create_directory
($replacedir); # creating language specific directories
175 # copy files and edit them with the variables defined in the zip.lst
177 my $onefilename = $onefile->{'Name'};
178 my $sourcepath = $onefile->{'sourcepath'};
179 my $destinationpath = $replacedir . $onefilename;
180 my $movepath = $destinationpath . ".orig";
182 # if (!(-f $destinationpath)) # do nothing if the file already exists
185 my $copysuccess = installer
::systemactions
::copy_one_file
($sourcepath, $movepath);
189 # Now the file can be patch (binary!)
190 my $found = replace_productname_in_file
($movepath, $destinationpath, $variableshashref, $onefile, $styles);
194 my $infoline = "Did not patch the file $destinationpath\n";
195 push( @installer::globals
::logfileinfo
, $infoline);
199 my $infoline = "Successfully patched $destinationpath, Count: $found\n";
200 push( @installer::globals
::logfileinfo
, $infoline);
206 # Saving the original source, where the file was found
207 $onefile->{'originalsourcepath'} = $onefile->{'sourcepath'};
209 # Saving the original source, where the file was found
210 $onefile->{'originalsourcepath'} = $onefile->{'sourcepath'};
212 # Writing the new sourcepath into the hashref, even if it was no copied
214 $onefile->{'sourcepath'} = $destinationpath;
219 push( @installer::globals
::logfileinfo
, $infoline);