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