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