19780544fSAndrew Rist#**************************************************************
29780544fSAndrew Rist#
39780544fSAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
49780544fSAndrew Rist#  or more contributor license agreements.  See the NOTICE file
59780544fSAndrew Rist#  distributed with this work for additional information
69780544fSAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
79780544fSAndrew Rist#  to you under the Apache License, Version 2.0 (the
89780544fSAndrew Rist#  "License"); you may not use this file except in compliance
99780544fSAndrew Rist#  with the License.  You may obtain a copy of the License at
109780544fSAndrew Rist#
119780544fSAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
129780544fSAndrew Rist#
139780544fSAndrew Rist#  Unless required by applicable law or agreed to in writing,
149780544fSAndrew Rist#  software distributed under the License is distributed on an
159780544fSAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169780544fSAndrew Rist#  KIND, either express or implied.  See the License for the
179780544fSAndrew Rist#  specific language governing permissions and limitations
189780544fSAndrew Rist#  under the License.
199780544fSAndrew Rist#
209780544fSAndrew Rist#**************************************************************
219780544fSAndrew Rist
229780544fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweirpackage installer::windows::file;
25cdf0e10cSrcweir
26cdf0e10cSrcweiruse Digest::MD5;
27cdf0e10cSrcweiruse installer::existence;
28cdf0e10cSrcweiruse installer::exiter;
29cdf0e10cSrcweiruse installer::files;
30cdf0e10cSrcweiruse installer::globals;
31cdf0e10cSrcweiruse installer::logger;
32cdf0e10cSrcweiruse installer::pathanalyzer;
33cdf0e10cSrcweiruse installer::worker;
34cdf0e10cSrcweiruse installer::windows::font;
35cdf0e10cSrcweiruse installer::windows::idtglobal;
3619d58b3aSEike Rathkeuse installer::windows::msiglobal;
37cdf0e10cSrcweiruse installer::windows::language;
38cdf0e10cSrcweir
39cdf0e10cSrcweir##########################################################################
40cdf0e10cSrcweir# Assigning one cabinet file to each file. This is requrired,
41cdf0e10cSrcweir# if cabinet files shall be equivalent to packages.
42cdf0e10cSrcweir##########################################################################
43cdf0e10cSrcweir
44cdf0e10cSrcweirsub assign_cab_to_files
45cdf0e10cSrcweir{
46cdf0e10cSrcweir	my ( $filesref ) = @_;
47cdf0e10cSrcweir
48cdf0e10cSrcweir	my $infoline = "";
49cdf0e10cSrcweir
50cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$filesref}; $i++ )
51cdf0e10cSrcweir	{
52cdf0e10cSrcweir		if ( ! exists(${$filesref}[$i]->{'modules'}) ) { installer::exiter::exit_program("ERROR: No module assignment found for ${$filesref}[$i]->{'gid'} !", "assign_cab_to_files"); }
53cdf0e10cSrcweir		my $module = ${$filesref}[$i]->{'modules'};
54cdf0e10cSrcweir		# If modules contains a list of modules, only taking the first one.
55cdf0e10cSrcweir		if ( $module =~ /^\s*(.*?)\,/ ) { $module = $1; }
56cdf0e10cSrcweir
57cdf0e10cSrcweir		if ( ! exists($installer::globals::allcabinetassigns{$module}) ) { installer::exiter::exit_program("ERROR: No cabinet file assigned to module \"$module\" (${$filesref}[$i]->{'gid'}) !", "assign_cab_to_files"); }
58cdf0e10cSrcweir		${$filesref}[$i]->{'assignedcabinetfile'} = $installer::globals::allcabinetassigns{$module};
59cdf0e10cSrcweir
60cdf0e10cSrcweir		# Counting the files in each cabinet file
61cdf0e10cSrcweir		if ( ! exists($installer::globals::cabfilecounter{${$filesref}[$i]->{'assignedcabinetfile'}}) )
62cdf0e10cSrcweir		{
63cdf0e10cSrcweir			$installer::globals::cabfilecounter{${$filesref}[$i]->{'assignedcabinetfile'}} = 1;
64cdf0e10cSrcweir		}
65cdf0e10cSrcweir		else
66cdf0e10cSrcweir		{
67cdf0e10cSrcweir			$installer::globals::cabfilecounter{${$filesref}[$i]->{'assignedcabinetfile'}}++;
68cdf0e10cSrcweir		}
69cdf0e10cSrcweir	}
70cdf0e10cSrcweir
71cdf0e10cSrcweir	# logging the number of files in each cabinet file
72cdf0e10cSrcweir
73b274bc22SAndre Fischer	$installer::logger::Lang->print("\n");
74b274bc22SAndre Fischer	$installer::logger::Lang->print("Cabinet file content:\n");
75cdf0e10cSrcweir	my $cabfile;
76cdf0e10cSrcweir	foreach $cabfile ( sort keys %installer::globals::cabfilecounter )
77cdf0e10cSrcweir	{
78cdf0e10cSrcweir		$infoline = "$cabfile : $installer::globals::cabfilecounter{$cabfile} files\n";
79b274bc22SAndre Fischer		$installer::logger::Lang->print($infoline);
80cdf0e10cSrcweir	}
81cdf0e10cSrcweir
82cdf0e10cSrcweir	# assigning startsequencenumbers for each cab file
83cdf0e10cSrcweir
84cdf0e10cSrcweir	my $offset = 1;
85cdf0e10cSrcweir	foreach $cabfile ( sort keys %installer::globals::cabfilecounter )
86cdf0e10cSrcweir	{
87cdf0e10cSrcweir		my $filecount = $installer::globals::cabfilecounter{$cabfile};
88cdf0e10cSrcweir		$installer::globals::cabfilecounter{$cabfile} = $offset;
89cdf0e10cSrcweir		$offset = $offset + $filecount;
90cdf0e10cSrcweir
91cdf0e10cSrcweir		$installer::globals::lastsequence{$cabfile} = $offset - 1;
92cdf0e10cSrcweir	}
93cdf0e10cSrcweir
94cdf0e10cSrcweir	# logging the start sequence numbers
95cdf0e10cSrcweir
96b274bc22SAndre Fischer	$installer::logger::Lang->print("\n");
97b274bc22SAndre Fischer	$installer::logger::Lang->print("Cabinet file start sequences:\n");
98cdf0e10cSrcweir	foreach $cabfile ( sort keys %installer::globals::cabfilecounter )
99cdf0e10cSrcweir	{
100cdf0e10cSrcweir		$infoline = "$cabfile : $installer::globals::cabfilecounter{$cabfile}\n";
101b274bc22SAndre Fischer		$installer::logger::Lang->print($infoline);
102cdf0e10cSrcweir	}
103cdf0e10cSrcweir
104cdf0e10cSrcweir	# logging the last sequence numbers
105cdf0e10cSrcweir
106b274bc22SAndre Fischer	$installer::logger::Lang->print("\n");
107b274bc22SAndre Fischer	$installer::logger::Lang->print("Cabinet file last sequences:\n");
108cdf0e10cSrcweir	foreach $cabfile ( sort keys %installer::globals::lastsequence )
109cdf0e10cSrcweir	{
110cdf0e10cSrcweir		$infoline = "$cabfile : $installer::globals::lastsequence{$cabfile}\n";
111b274bc22SAndre Fischer		$installer::logger::Lang->print($infoline);
112cdf0e10cSrcweir	}
113cdf0e10cSrcweir}
114cdf0e10cSrcweir
115cdf0e10cSrcweir##########################################################################
116cdf0e10cSrcweir# Assigning sequencenumbers to files. This is requrired,
117cdf0e10cSrcweir# if cabinet files shall be equivalent to packages.
118cdf0e10cSrcweir##########################################################################
119cdf0e10cSrcweir
120cdf0e10cSrcweirsub assign_sequencenumbers_to_files
121cdf0e10cSrcweir{
122cdf0e10cSrcweir	my ( $filesref ) = @_;
123cdf0e10cSrcweir
124cdf0e10cSrcweir	my %directaccess = ();
125cdf0e10cSrcweir	my %allassigns = ();
126cdf0e10cSrcweir
127cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$filesref}; $i++ )
128cdf0e10cSrcweir	{
129cdf0e10cSrcweir		my $onefile = ${$filesref}[$i];
130cdf0e10cSrcweir
131cdf0e10cSrcweir		# Keeping order in cabinet files
132cdf0e10cSrcweir		# -> collecting all files in one cabinet file
133cdf0e10cSrcweir		# -> sorting files and assigning numbers
134cdf0e10cSrcweir
135cdf0e10cSrcweir		# Saving counter $i for direct access into files array
136cdf0e10cSrcweir		# "destination" of the file is a unique identifier ('Name' is not unique!)
137cdf0e10cSrcweir		if ( exists($directaccess{$onefile->{'destination'}}) ) { installer::exiter::exit_program("ERROR: 'destination' at file not unique: $onefile->{'destination'}", "assign_sequencenumbers_to_files"); }
138cdf0e10cSrcweir		$directaccess{$onefile->{'destination'}} = $i;
139cdf0e10cSrcweir
140cdf0e10cSrcweir		my $cabfilename = $onefile->{'assignedcabinetfile'};
141cdf0e10cSrcweir		# collecting files in cabinet files
142cdf0e10cSrcweir		if ( ! exists($allassigns{$cabfilename}) )
143cdf0e10cSrcweir		{
144cdf0e10cSrcweir			my %onecabfile = ();
145cdf0e10cSrcweir			$onecabfile{$onefile->{'destination'}} = 1;
146cdf0e10cSrcweir			$allassigns{$cabfilename} = \%onecabfile;
147cdf0e10cSrcweir		}
148cdf0e10cSrcweir		else
149cdf0e10cSrcweir		{
150cdf0e10cSrcweir			$allassigns{$cabfilename}->{$onefile->{'destination'}} = 1;
151cdf0e10cSrcweir		}
152cdf0e10cSrcweir	}
153cdf0e10cSrcweir
154cdf0e10cSrcweir	# Sorting each hash and assigning numbers
155cdf0e10cSrcweir	# The destination of the file determines the sort order, not the filename!
156cdf0e10cSrcweir	my $cabfile;
157cdf0e10cSrcweir	foreach $cabfile ( sort keys %allassigns )
158cdf0e10cSrcweir	{
159cdf0e10cSrcweir		my $counter = $installer::globals::cabfilecounter{$cabfile};
160cdf0e10cSrcweir		my $dest;
161cdf0e10cSrcweir		foreach $dest ( sort keys %{$allassigns{$cabfile}} ) # <- sorting the destination!
162cdf0e10cSrcweir		{
163cdf0e10cSrcweir			my $directaccessnumber = $directaccess{$dest};
164cdf0e10cSrcweir			${$filesref}[$directaccessnumber]->{'assignedsequencenumber'} = $counter;
165cdf0e10cSrcweir			$counter++;
166cdf0e10cSrcweir		}
167cdf0e10cSrcweir	}
168cdf0e10cSrcweir}
169cdf0e10cSrcweir
170cdf0e10cSrcweir#########################################################
171cdf0e10cSrcweir# Create a shorter version of a long component name,
172cdf0e10cSrcweir# because maximum length in msi database is 72.
173cdf0e10cSrcweir# Attention: In multi msi installation sets, the short
174cdf0e10cSrcweir# names have to be unique over all packages, because
175cdf0e10cSrcweir# this string is used to create the globally unique id
176cdf0e10cSrcweir# -> no resetting of
177cdf0e10cSrcweir# %installer::globals::allshortcomponents
178cdf0e10cSrcweir# after a package was created.
17919d58b3aSEike Rathke# Using no counter because of reproducibility.
180cdf0e10cSrcweir#########################################################
181cdf0e10cSrcweir
182cdf0e10cSrcweirsub generate_new_short_componentname
183cdf0e10cSrcweir{
184cdf0e10cSrcweir	my ($componentname) = @_;
185cdf0e10cSrcweir
186cdf0e10cSrcweir	my $startversion = substr($componentname, 0, 60); # taking only the first 60 characters
18719d58b3aSEike Rathke	my $subid = installer::windows::msiglobal::calculate_id($componentname, 9); # taking only the first 9 digits
18819d58b3aSEike Rathke	my $shortcomponentname = $startversion . "_" . $subid;
189cdf0e10cSrcweir
19019d58b3aSEike Rathke	if ( exists($installer::globals::allshortcomponents{$shortcomponentname}) ) { installer::exiter::exit_program("Failed to create unique component name: \"$shortcomponentname\"", "generate_new_short_componentname"); }
191cdf0e10cSrcweir
192cdf0e10cSrcweir	$installer::globals::allshortcomponents{$shortcomponentname} = 1;
193cdf0e10cSrcweir
194cdf0e10cSrcweir	return $shortcomponentname;
195cdf0e10cSrcweir}
196cdf0e10cSrcweir
197cdf0e10cSrcweir###############################################
198cdf0e10cSrcweir# Generating the component name from a file
199cdf0e10cSrcweir###############################################
200cdf0e10cSrcweir
201cdf0e10cSrcweirsub get_file_component_name
202cdf0e10cSrcweir{
203cdf0e10cSrcweir	my ($fileref, $filesref) = @_;
204cdf0e10cSrcweir
205cdf0e10cSrcweir	my $componentname = "";
206cdf0e10cSrcweir
207cdf0e10cSrcweir	# Special handling for files with ASSIGNCOMPOMENT
208cdf0e10cSrcweir
209cdf0e10cSrcweir	my $styles = "";
210cdf0e10cSrcweir	if ( $fileref->{'Styles'} ) { $styles = $fileref->{'Styles'}; }
211cdf0e10cSrcweir	if ( $styles =~ /\bASSIGNCOMPOMENT\b/ )
212cdf0e10cSrcweir	{
213cdf0e10cSrcweir		$componentname = get_component_from_assigned_file($fileref->{'AssignComponent'}, $filesref);
214cdf0e10cSrcweir	}
215cdf0e10cSrcweir	else
216cdf0e10cSrcweir	{
217cdf0e10cSrcweir		# In this function exists the rule to create components from files
218cdf0e10cSrcweir		# Rule:
219cdf0e10cSrcweir		# Two files get the same componentid, if:
220cdf0e10cSrcweir		# both have the same destination directory.
221cdf0e10cSrcweir		# both have the same "gid" -> both were packed in the same zip file
222cdf0e10cSrcweir		# All other files are included into different components!
223cdf0e10cSrcweir
224cdf0e10cSrcweir		# my $componentname = $fileref->{'gid'} . "_" . $fileref->{'Dir'};
225cdf0e10cSrcweir
226cdf0e10cSrcweir		# $fileref->{'Dir'} is not sufficient! All files in a zip file have the same $fileref->{'Dir'},
227cdf0e10cSrcweir		# but can be in different subdirectories.
228cdf0e10cSrcweir		# Solution: destination=share\Scripts\beanshell\Capitalise\capitalise.bsh
229cdf0e10cSrcweir		# in which the filename (capitalise.bsh) has to be removed and all backslashes (slashes) are
230cdf0e10cSrcweir		# converted into underline.
231cdf0e10cSrcweir
232cdf0e10cSrcweir		my $destination = $fileref->{'destination'};
233cdf0e10cSrcweir		installer::pathanalyzer::get_path_from_fullqualifiedname(\$destination);
234cdf0e10cSrcweir		$destination =~ s/\s//g;
235cdf0e10cSrcweir		$destination =~ s/\\/\_/g;
236cdf0e10cSrcweir		$destination =~ s/\//\_/g;
237cdf0e10cSrcweir		$destination =~ s/\_\s*$//g;	# removing ending underline
238cdf0e10cSrcweir
239cdf0e10cSrcweir		$componentname = $fileref->{'gid'} . "__" . $destination;
240cdf0e10cSrcweir
241cdf0e10cSrcweir		# Files with different languages, need to be packed into different components.
242cdf0e10cSrcweir		# Then the installation of the language specific component is determined by a language condition.
243cdf0e10cSrcweir
244cdf0e10cSrcweir		if ( $fileref->{'ismultilingual'} )
245cdf0e10cSrcweir		{
246cdf0e10cSrcweir			my $officelanguage = $fileref->{'specificlanguage'};
247cdf0e10cSrcweir			$componentname = $componentname . "_" . $officelanguage;
248cdf0e10cSrcweir		}
249cdf0e10cSrcweir
250cdf0e10cSrcweir		$componentname = lc($componentname);	# componentnames always lowercase
251cdf0e10cSrcweir
252cdf0e10cSrcweir		$componentname =~ s/\-/\_/g;			# converting "-" to "_"
253cdf0e10cSrcweir		$componentname =~ s/\./\_/g;			# converting "-" to "_"
254cdf0e10cSrcweir
255cdf0e10cSrcweir		# Attention: Maximum length for the componentname is 72
256cdf0e10cSrcweir		# %installer::globals::allcomponents_in_this_database : resetted for each database
257cdf0e10cSrcweir		# %installer::globals::allcomponents : not resetted for each database
258cdf0e10cSrcweir		# Component strings must be unique for the complete product, because they are used for
259cdf0e10cSrcweir		# the creation of the globally unique identifier.
260cdf0e10cSrcweir
261cdf0e10cSrcweir		my $fullname = $componentname;  # This can be longer than 72
262cdf0e10cSrcweir
263cdf0e10cSrcweir		if (( exists($installer::globals::allcomponents{$fullname}) ) && ( ! exists($installer::globals::allcomponents_in_this_database{$fullname}) ))
264cdf0e10cSrcweir		{
265cdf0e10cSrcweir			# This is not allowed: One component cannot be installed with different packages.
266cdf0e10cSrcweir			installer::exiter::exit_program("ERROR: Component \"$fullname\" is already included into another package. This is not allowed.", "get_file_component_name");
267cdf0e10cSrcweir		}
268cdf0e10cSrcweir
269cdf0e10cSrcweir		if ( exists($installer::globals::allcomponents{$fullname}) )
270cdf0e10cSrcweir		{
271cdf0e10cSrcweir			$componentname = $installer::globals::allcomponents{$fullname};
272cdf0e10cSrcweir		}
273cdf0e10cSrcweir		else
274cdf0e10cSrcweir		{
27519d58b3aSEike Rathke			if ( length($componentname) > 70 )
276cdf0e10cSrcweir			{
277cdf0e10cSrcweir				$componentname = generate_new_short_componentname($componentname); # This has to be unique for the complete product, not only one package
278cdf0e10cSrcweir			}
279cdf0e10cSrcweir
280cdf0e10cSrcweir			$installer::globals::allcomponents{$fullname} = $componentname;
281cdf0e10cSrcweir			$installer::globals::allcomponents_in_this_database{$fullname} = 1;
282cdf0e10cSrcweir		}
283cdf0e10cSrcweir
284cdf0e10cSrcweir		# $componentname =~ s/gid_file_/g_f_/g;
285cdf0e10cSrcweir		# $componentname =~ s/_extra_/_e_/g;
286cdf0e10cSrcweir		# $componentname =~ s/_config_/_c_/g;
287cdf0e10cSrcweir		# $componentname =~ s/_org_openoffice_/_o_o_/g;
288cdf0e10cSrcweir		# $componentname =~ s/_program_/_p_/g;
289cdf0e10cSrcweir		# $componentname =~ s/_typedetection_/_td_/g;
290cdf0e10cSrcweir		# $componentname =~ s/_linguistic_/_l_/g;
291cdf0e10cSrcweir		# $componentname =~ s/_module_/_m_/g;
292cdf0e10cSrcweir		# $componentname =~ s/_optional_/_opt_/g;
293cdf0e10cSrcweir		# $componentname =~ s/_packages/_pack/g;
294cdf0e10cSrcweir		# $componentname =~ s/_menubar/_mb/g;
295cdf0e10cSrcweir		# $componentname =~ s/_common_/_cm_/g;
296cdf0e10cSrcweir		# $componentname =~ s/_export_/_exp_/g;
297cdf0e10cSrcweir		# $componentname =~ s/_table_/_tb_/g;
298cdf0e10cSrcweir		# $componentname =~ s/_sofficecfg_/_sc_/g;
299cdf0e10cSrcweir		# $componentname =~ s/_soffice_cfg_/_sc_/g;
300cdf0e10cSrcweir		# $componentname =~ s/_startmodulecommands_/_smc_/g;
301cdf0e10cSrcweir		# $componentname =~ s/_drawimpresscommands_/_dic_/g;
302cdf0e10cSrcweir		# $componentname =~ s/_basiccommands_/_bac_/g;
303cdf0e10cSrcweir		# $componentname =~ s/_basicidecommands_/_baic_/g;
304cdf0e10cSrcweir		# $componentname =~ s/_genericcommands_/_genc_/g;
305cdf0e10cSrcweir		# $componentname =~ s/_bibliographycommands_/_bibc_/g;
306cdf0e10cSrcweir		# $componentname =~ s/_gentiumbookbasicbolditalic_/_gbbbi_/g;
307cdf0e10cSrcweir		# $componentname =~ s/_share_/_s_/g;
308cdf0e10cSrcweir		# $componentname =~ s/_extension_/_ext_/g;
309cdf0e10cSrcweir		# $componentname =~ s/_extensions_/_exs_/g;
310cdf0e10cSrcweir		# $componentname =~ s/_modules_/_ms_/g;
311cdf0e10cSrcweir		# $componentname =~ s/_uiconfig_zip_/_ucz_/g;
312cdf0e10cSrcweir		# $componentname =~ s/_productivity_/_pr_/g;
313cdf0e10cSrcweir		# $componentname =~ s/_wizard_/_wz_/g;
314cdf0e10cSrcweir		# $componentname =~ s/_import_/_im_/g;
315cdf0e10cSrcweir		# $componentname =~ s/_javascript_/_js_/g;
316cdf0e10cSrcweir		# $componentname =~ s/_template_/_tpl_/g;
317cdf0e10cSrcweir		# $componentname =~ s/_tplwizletter_/_twl_/g;
318cdf0e10cSrcweir		# $componentname =~ s/_beanshell_/_bs_/g;
319cdf0e10cSrcweir		# $componentname =~ s/_presentation_/_bs_/g;
320cdf0e10cSrcweir		# $componentname =~ s/_columns_/_cls_/g;
321cdf0e10cSrcweir		# $componentname =~ s/_python_/_py_/g;
322cdf0e10cSrcweir
323cdf0e10cSrcweir		# $componentname =~ s/_tools/_ts/g;
324cdf0e10cSrcweir		# $componentname =~ s/_transitions/_trs/g;
325cdf0e10cSrcweir		# $componentname =~ s/_scriptbinding/_scrb/g;
326cdf0e10cSrcweir		# $componentname =~ s/_spreadsheet/_ssh/g;
327cdf0e10cSrcweir		# $componentname =~ s/_publisher/_pub/g;
328cdf0e10cSrcweir		# $componentname =~ s/_presenter/_pre/g;
329cdf0e10cSrcweir		# $componentname =~ s/_registry/_reg/g;
330cdf0e10cSrcweir
331cdf0e10cSrcweir		# $componentname =~ s/screen/sc/g;
332cdf0e10cSrcweir		# $componentname =~ s/wordml/wm/g;
333cdf0e10cSrcweir		# $componentname =~ s/openoffice/oo/g;
334cdf0e10cSrcweir	}
335cdf0e10cSrcweir
336cdf0e10cSrcweir	return $componentname;
337cdf0e10cSrcweir}
338cdf0e10cSrcweir
339cdf0e10cSrcweir####################################################################
340cdf0e10cSrcweir# Returning the component name for a defined file gid.
341cdf0e10cSrcweir# This is necessary for files with flag ASSIGNCOMPOMENT
342cdf0e10cSrcweir####################################################################
343cdf0e10cSrcweir
344cdf0e10cSrcweirsub get_component_from_assigned_file
345cdf0e10cSrcweir{
346cdf0e10cSrcweir	my ($gid, $filesref) = @_;
347cdf0e10cSrcweir
348cdf0e10cSrcweir	my $onefile = installer::existence::get_specified_file($filesref, $gid);
349cdf0e10cSrcweir	my $componentname = "";
350cdf0e10cSrcweir	if ( $onefile->{'componentname'} ) { $componentname = $onefile->{'componentname'}; }
351cdf0e10cSrcweir	else { installer::exiter::exit_program("ERROR: No component defined for file: $gid", "get_component_from_assigned_file"); }
352cdf0e10cSrcweir
353cdf0e10cSrcweir	return $componentname;
354cdf0e10cSrcweir}
355cdf0e10cSrcweir
356cdf0e10cSrcweir####################################################################
357cdf0e10cSrcweir# Generating the special filename for the database file File.idt
358cdf0e10cSrcweir# Sample: CONTEXTS, CONTEXTS1
359cdf0e10cSrcweir# This name has to be unique.
360cdf0e10cSrcweir# In most cases this is simply the filename.
361cdf0e10cSrcweir####################################################################
362cdf0e10cSrcweir
363*dca4887fSAndre Fischersub generate_unique_filename_for_filetable ($$)
364cdf0e10cSrcweir{
365*dca4887fSAndre Fischer	my ($fileref, $component) = @_;
366cdf0e10cSrcweir
367cdf0e10cSrcweir	# This new filename has to be saved into $fileref, because this is needed to find the source.
368cdf0e10cSrcweir	# The filename sbasic.idx/OFFSETS is changed to OFFSETS, but OFFSETS is not unique.
369cdf0e10cSrcweir	# In this procedure names like OFFSETS5 are produced. And exactly this string has to be added to
370cdf0e10cSrcweir	# the array of all files.
371cdf0e10cSrcweir
372cdf0e10cSrcweir	my $uniquefilename = "";
373cdf0e10cSrcweir	my $counter = 0;
374cdf0e10cSrcweir
375cdf0e10cSrcweir	if ( $fileref->{'Name'} ) { $uniquefilename = $fileref->{'Name'}; }
376cdf0e10cSrcweir
377cdf0e10cSrcweir	installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$uniquefilename);	# making /registry/schema/org/openoffice/VCL.xcs to VCL.xcs
378cdf0e10cSrcweir
379cdf0e10cSrcweir	# Reading unique filename with help of "Component_" in File table from old database
380f30bf281SAndre Fischer	if (( $installer::globals::prepare_winpatch ) && ( exists($installer::globals::savedmapping{"$component/$uniquefilename"}) ))
381cdf0e10cSrcweir	{
382cdf0e10cSrcweir		# If we have a FTK mapping for this component/file, use it.
383cdf0e10cSrcweir		$installer::globals::savedmapping{"$component/$uniquefilename"} =~ m/^(.*);/;
384cdf0e10cSrcweir		$uniquefilename = $1;
385cdf0e10cSrcweir 		$lcuniquefilename = lc($uniquefilename);
386cdf0e10cSrcweir		$installer::globals::alluniquefilenames{$uniquefilename} = 1;
387cdf0e10cSrcweir		$installer::globals::alllcuniquefilenames{$lcuniquefilename} = 1;
388cdf0e10cSrcweir		return $uniquefilename;
389cdf0e10cSrcweir	}
390cdf0e10cSrcweir
391cdf0e10cSrcweir	$uniquefilename =~ s/\-/\_/g;		# no "-" allowed
392cdf0e10cSrcweir	$uniquefilename =~ s/\@/\_/g;		# no "@" allowed
393cdf0e10cSrcweir	$uniquefilename =~ s/\$/\_/g;		# no "$" allowed
394cdf0e10cSrcweir	$uniquefilename =~ s/^\s*\./\_/g;		# no "." at the beginning allowed allowed
395cdf0e10cSrcweir	$uniquefilename =~ s/^\s*\d/\_d/g;		# no number at the beginning allowed allowed (even file "0.gif", replacing to "_d.gif")
396cdf0e10cSrcweir	$uniquefilename =~ s/org_openoffice_/ooo_/g;	# shorten the unique file name
397cdf0e10cSrcweir
398cdf0e10cSrcweir	my $lcuniquefilename = lc($uniquefilename);	# only lowercase names
399cdf0e10cSrcweir
400cdf0e10cSrcweir	my $newname = 0;
401cdf0e10cSrcweir
402cdf0e10cSrcweir	if ( ! exists($installer::globals::alllcuniquefilenames{$lcuniquefilename}) &&
403cdf0e10cSrcweir	     ! exists($installer::globals::savedrevmapping{$lcuniquefilename}) )
404cdf0e10cSrcweir	{
405cdf0e10cSrcweir		$installer::globals::alluniquefilenames{$uniquefilename} = 1;
406cdf0e10cSrcweir		$installer::globals::alllcuniquefilenames{$lcuniquefilename} = 1;
407cdf0e10cSrcweir		$newname = 1;
408cdf0e10cSrcweir	}
409cdf0e10cSrcweir
410cdf0e10cSrcweir	if ( ! $newname )
411cdf0e10cSrcweir	{
412cdf0e10cSrcweir		# adding a number until the name is really unique: OFFSETS, OFFSETS1, OFFSETS2, ...
413cdf0e10cSrcweir		# But attention: Making "abc.xcu" to "abc1.xcu"
414cdf0e10cSrcweir
415cdf0e10cSrcweir		my $uniquefilenamebase = $uniquefilename;
416cdf0e10cSrcweir
417cdf0e10cSrcweir		do
418cdf0e10cSrcweir		{
419cdf0e10cSrcweir			$counter++;
420cdf0e10cSrcweir
421cdf0e10cSrcweir			if ( $uniquefilenamebase =~ /\./ )
422cdf0e10cSrcweir			{
423cdf0e10cSrcweir				$uniquefilename = $uniquefilenamebase;
424cdf0e10cSrcweir				$uniquefilename =~ s/\./$counter\./;
425cdf0e10cSrcweir			}
426cdf0e10cSrcweir			else
427cdf0e10cSrcweir			{
428cdf0e10cSrcweir				$uniquefilename = $uniquefilenamebase . $counter;
429cdf0e10cSrcweir			}
430cdf0e10cSrcweir
431cdf0e10cSrcweir			$newname = 0;
432cdf0e10cSrcweir			$lcuniquefilename = lc($uniquefilename);	# only lowercase names
433cdf0e10cSrcweir
434cdf0e10cSrcweir			if ( ! exists($installer::globals::alllcuniquefilenames{$lcuniquefilename}) &&
435cdf0e10cSrcweir			     ! exists($installer::globals::savedrevmapping{$lcuniquefilename}) )
436cdf0e10cSrcweir			{
437cdf0e10cSrcweir				$installer::globals::alluniquefilenames{$uniquefilename} = 1;
438cdf0e10cSrcweir				$installer::globals::alllcuniquefilenames{$lcuniquefilename} = 1;
439cdf0e10cSrcweir				$newname = 1;
440cdf0e10cSrcweir			}
441cdf0e10cSrcweir		}
442cdf0e10cSrcweir		until ( $newname )
443cdf0e10cSrcweir	}
444cdf0e10cSrcweir
445cdf0e10cSrcweir	return $uniquefilename;
446cdf0e10cSrcweir}
447cdf0e10cSrcweir
448cdf0e10cSrcweir####################################################################
449cdf0e10cSrcweir# Generating the special file column for the database file File.idt
450cdf0e10cSrcweir# Sample: NAMETR~1.TAB|.nametranslation.table
451cdf0e10cSrcweir# The first part has to be 8.3 conform.
452cdf0e10cSrcweir####################################################################
453cdf0e10cSrcweir
454*dca4887fSAndre Fischersub generate_filename_for_filetable ($$)
455cdf0e10cSrcweir{
456*dca4887fSAndre Fischer	my ($fileref, $shortnamesref) = @_;
457cdf0e10cSrcweir
458cdf0e10cSrcweir	my $returnstring = "";
459cdf0e10cSrcweir
460cdf0e10cSrcweir	my $filename = $fileref->{'Name'};
461cdf0e10cSrcweir
462cdf0e10cSrcweir	installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$filename);	# making /registry/schema/org/openoffice/VCL.xcs to VCL.xcs
463cdf0e10cSrcweir
464cdf0e10cSrcweir	my $shortstring;
465cdf0e10cSrcweir
466cdf0e10cSrcweir	# Reading short string with help of "FileName" in File table from old database
467f30bf281SAndre Fischer	if (( $installer::globals::prepare_winpatch ) && ( exists($installer::globals::savedmapping{"$fileref->{'componentname'}/$filename"}) ))
468cdf0e10cSrcweir	{
469cdf0e10cSrcweir		$installer::globals::savedmapping{"$fileref->{'componentname'}/$filename"} =~ m/.*;(.*)/;
470cdf0e10cSrcweir		if ($1 ne '')
471cdf0e10cSrcweir		{
472cdf0e10cSrcweir			$shortstring = $1;
473cdf0e10cSrcweir		}
474cdf0e10cSrcweir		else
475cdf0e10cSrcweir		{
476cdf0e10cSrcweir			$shortstring = installer::windows::idtglobal::make_eight_three_conform_with_hash($filename, "file", $shortnamesref);
477cdf0e10cSrcweir		}
478cdf0e10cSrcweir	}
479cdf0e10cSrcweir	else
480cdf0e10cSrcweir	{
481cdf0e10cSrcweir		$shortstring = installer::windows::idtglobal::make_eight_three_conform_with_hash($filename, "file", $shortnamesref);
482cdf0e10cSrcweir	}
483cdf0e10cSrcweir
484cdf0e10cSrcweir	if ( $shortstring eq $filename ) { $returnstring = $filename; }	# nothing changed
485cdf0e10cSrcweir	else {$returnstring = $shortstring . "\|" . $filename; }
486cdf0e10cSrcweir
487cdf0e10cSrcweir	return $returnstring;
488cdf0e10cSrcweir}
489cdf0e10cSrcweir
490cdf0e10cSrcweir#########################################
491cdf0e10cSrcweir# Returning the filesize of a file
492cdf0e10cSrcweir#########################################
493cdf0e10cSrcweir
494cdf0e10cSrcweirsub get_filesize
495cdf0e10cSrcweir{
496cdf0e10cSrcweir	my ($fileref) = @_;
497cdf0e10cSrcweir
498cdf0e10cSrcweir	my $file = $fileref->{'sourcepath'};
499cdf0e10cSrcweir
500cdf0e10cSrcweir	my $filesize;
501cdf0e10cSrcweir
502cdf0e10cSrcweir	if ( -f $file )	# test of existence. For instance services.rdb does not always exist
503cdf0e10cSrcweir	{
504cdf0e10cSrcweir		$filesize = ( -s $file );	# file size can be "0"
505cdf0e10cSrcweir	}
506cdf0e10cSrcweir	else
507cdf0e10cSrcweir	{
508cdf0e10cSrcweir		$filesize = -1;
509cdf0e10cSrcweir	}
510cdf0e10cSrcweir
511cdf0e10cSrcweir	return $filesize;
512cdf0e10cSrcweir}
513cdf0e10cSrcweir
514cdf0e10cSrcweir#############################################
515cdf0e10cSrcweir# Returning the file version, if required
516cdf0e10cSrcweir# Sample: "8.0.1.8976";
517cdf0e10cSrcweir#############################################
518cdf0e10cSrcweir
519cdf0e10cSrcweirsub get_fileversion
520cdf0e10cSrcweir{
521cdf0e10cSrcweir	my ($onefile, $allvariables, $styles) = @_;
522cdf0e10cSrcweir
523cdf0e10cSrcweir	my $fileversion = "";
524cdf0e10cSrcweir
525cdf0e10cSrcweir	if ( $allvariables->{'USE_FILEVERSION'} )
526cdf0e10cSrcweir	{
527cdf0e10cSrcweir		if ( ! $allvariables->{'LIBRARYVERSION'} ) { installer::exiter::exit_program("ERROR: USE_FILEVERSION is set, but not LIBRARYVERSION", "get_fileversion"); }
528cdf0e10cSrcweir		my $libraryversion = $allvariables->{'LIBRARYVERSION'};
529cdf0e10cSrcweir		if ( $libraryversion =~ /^\s*(\d+)\.(\d+)\.(\d+)\s*$/ )
530cdf0e10cSrcweir		{
531cdf0e10cSrcweir			my $major = $1;
532cdf0e10cSrcweir			my $minor = $2;
533cdf0e10cSrcweir			my $micro = $3;
534cdf0e10cSrcweir			my $concat = 100 * $minor + $micro;
535cdf0e10cSrcweir			$libraryversion = $major . "\." . $concat;
536cdf0e10cSrcweir		}
537cdf0e10cSrcweir		my $vendornumber = 0;
538cdf0e10cSrcweir		if ( $allvariables->{'VENDORPATCHVERSION'} ) { $vendornumber = $allvariables->{'VENDORPATCHVERSION'}; }
539cdf0e10cSrcweir		$fileversion = $libraryversion . "\." . $installer::globals::buildid . "\." . $vendornumber;
540cdf0e10cSrcweir		if ( $onefile->{'FileVersion'} ) { $fileversion = $onefile->{'FileVersion'}; } # overriding FileVersion in scp
541cdf0e10cSrcweir
542cdf0e10cSrcweir		# if ( $styles =~ /\bFONT\b/ )
543cdf0e10cSrcweir		# {
544cdf0e10cSrcweir		#	my $newfileversion = installer::windows::font::get_font_version($onefile->{'sourcepath'});
545cdf0e10cSrcweir		#	if ( $newfileversion != 0 ) { $fileversion = $newfileversion; }
546cdf0e10cSrcweir		# }
547cdf0e10cSrcweir	}
548cdf0e10cSrcweir
549cdf0e10cSrcweir	if ( $installer::globals::prepare_winpatch ) { $fileversion = ""; } # Windows patches do not allow this version # -> who says so?
550cdf0e10cSrcweir
551cdf0e10cSrcweir	return $fileversion;
552cdf0e10cSrcweir}
553cdf0e10cSrcweir
554cdf0e10cSrcweir#############################################
555cdf0e10cSrcweir# Returning the Windows language of a file
556cdf0e10cSrcweir#############################################
557cdf0e10cSrcweir
558cdf0e10cSrcweirsub get_language_for_file
559cdf0e10cSrcweir{
560cdf0e10cSrcweir	my ($fileref) = @_;
561cdf0e10cSrcweir
562cdf0e10cSrcweir	my $language = "";
563cdf0e10cSrcweir
564cdf0e10cSrcweir	if ( $fileref->{'specificlanguage'} ) { $language = $fileref->{'specificlanguage'}; }
565cdf0e10cSrcweir
566cdf0e10cSrcweir	if ( $language eq "" )
567cdf0e10cSrcweir	{
568cdf0e10cSrcweir		$language = 0;  # language independent
569cdf0e10cSrcweir		# If this is not a font, the return value should be "0" (Check ICE 60)
570cdf0e10cSrcweir		my $styles = "";
571cdf0e10cSrcweir		if ( $fileref->{'Styles'} ) { $styles = $fileref->{'Styles'}; }
572cdf0e10cSrcweir		if ( $styles =~ /\bFONT\b/ ) { $language = ""; }
573cdf0e10cSrcweir	}
574cdf0e10cSrcweir	else
575cdf0e10cSrcweir	{
576cdf0e10cSrcweir		$language = installer::windows::language::get_windows_language($language);
577cdf0e10cSrcweir	}
578cdf0e10cSrcweir
579cdf0e10cSrcweir	return $language;
580cdf0e10cSrcweir}
581cdf0e10cSrcweir
582cdf0e10cSrcweir####################################################################
583cdf0e10cSrcweir# Creating a new KeyPath for components in TemplatesFolder.
584cdf0e10cSrcweir####################################################################
585cdf0e10cSrcweir
586cdf0e10cSrcweirsub generate_registry_keypath
587cdf0e10cSrcweir{
588cdf0e10cSrcweir	my ($onefile) = @_;
589cdf0e10cSrcweir
590cdf0e10cSrcweir	my $keypath = $onefile->{'Name'};
591cdf0e10cSrcweir	$keypath =~ s/\.//g;
592cdf0e10cSrcweir	$keypath = lc($keypath);
593cdf0e10cSrcweir	$keypath = "userreg_" . $keypath;
594cdf0e10cSrcweir
595cdf0e10cSrcweir	return $keypath;
596cdf0e10cSrcweir}
597cdf0e10cSrcweir
598cdf0e10cSrcweir###################################################################
599cdf0e10cSrcweir# Collecting further conditions for the component table.
600cdf0e10cSrcweir# This is used by multilayer products, to enable installation
601cdf0e10cSrcweir# of separate layers.
602cdf0e10cSrcweir###################################################################
603cdf0e10cSrcweir
604cdf0e10cSrcweirsub get_tree_condition_for_component
605cdf0e10cSrcweir{
606cdf0e10cSrcweir	my ($onefile, $componentname) = @_;
607cdf0e10cSrcweir
608cdf0e10cSrcweir	if ( $onefile->{'destination'} )
609cdf0e10cSrcweir	{
610cdf0e10cSrcweir		my $dest = $onefile->{'destination'};
611cdf0e10cSrcweir
612cdf0e10cSrcweir		# Comparing the destination path with
613cdf0e10cSrcweir		# $installer::globals::hostnametreestyles{$hostname} = $treestyle;
614cdf0e10cSrcweir		# (-> hostname is the key, the style the value!)
615cdf0e10cSrcweir
616cdf0e10cSrcweir		foreach my $hostname ( keys %installer::globals::hostnametreestyles )
617cdf0e10cSrcweir		{
618cdf0e10cSrcweir			if (( $dest eq $hostname ) || ( $dest =~ /^\s*\Q$hostname\E\\/ ))
619cdf0e10cSrcweir			{
620cdf0e10cSrcweir				# the value is the style
621cdf0e10cSrcweir				my $style = $installer::globals::hostnametreestyles{$hostname};
622cdf0e10cSrcweir				# the condition is saved in %installer::globals::treestyles
623cdf0e10cSrcweir				my $condition = $installer::globals::treestyles{$style};
624cdf0e10cSrcweir				# Saving condition to be added in table Property
625cdf0e10cSrcweir				$installer::globals::usedtreeconditions{$condition} = 1;
626cdf0e10cSrcweir				$condition = $condition . "=1";
627cdf0e10cSrcweir				# saving this condition
628cdf0e10cSrcweir				$installer::globals::treeconditions{$componentname} = $condition;
629cdf0e10cSrcweir
630cdf0e10cSrcweir				# saving also at the file, for usage in fileinfo
631cdf0e10cSrcweir				$onefile->{'layer'} = $installer::globals::treelayername{$style};
632cdf0e10cSrcweir			}
633cdf0e10cSrcweir		}
634cdf0e10cSrcweir	}
635cdf0e10cSrcweir}
636cdf0e10cSrcweir
637cdf0e10cSrcweir############################################
638cdf0e10cSrcweir# Collecting all short names, that are
639cdf0e10cSrcweir# already used by the old database
640cdf0e10cSrcweir############################################
641cdf0e10cSrcweir
642cdf0e10cSrcweirsub collect_shortnames_from_old_database
643cdf0e10cSrcweir{
644cdf0e10cSrcweir	my ($uniquefilenamehashref, $shortnameshashref) = @_;
645cdf0e10cSrcweir
646cdf0e10cSrcweir	foreach my $key ( keys %{$uniquefilenamehashref} )
647cdf0e10cSrcweir	{
648cdf0e10cSrcweir		my $value = $uniquefilenamehashref->{$key};  # syntax of $value: ($uniquename;$shortname)
649cdf0e10cSrcweir
650cdf0e10cSrcweir		if ( $value =~ /^\s*(.*?)\;\s*(.*?)\s*$/ )
651cdf0e10cSrcweir		{
652cdf0e10cSrcweir			my $shortstring = $2;
653cdf0e10cSrcweir			$shortnameshashref->{$shortstring} = 1;	# adding the shortname to the array of all shortnames
654cdf0e10cSrcweir		}
655cdf0e10cSrcweir	}
656cdf0e10cSrcweir}
657cdf0e10cSrcweir
658cdf0e10cSrcweir############################################
659cdf0e10cSrcweir# Creating the file File.idt dynamically
660cdf0e10cSrcweir############################################
661cdf0e10cSrcweir
662*dca4887fSAndre Fischersub create_files_table ($$$$)
663cdf0e10cSrcweir{
664*dca4887fSAndre Fischer	my ($filesref, $allfilecomponentsref, $basedir, $allvariables) = @_;
665cdf0e10cSrcweir
666b274bc22SAndre Fischer	$installer::logger::Lang->add_timestamp("Performance Info: File Table start");
667cdf0e10cSrcweir
668cdf0e10cSrcweir	# Structure of the files table:
669cdf0e10cSrcweir	# File Component_ FileName FileSize Version Language Attributes Sequence
670cdf0e10cSrcweir	# In this function, all components are created.
671cdf0e10cSrcweir	#
672cdf0e10cSrcweir	# $allfilecomponentsref is empty at the beginning
673cdf0e10cSrcweir
674cdf0e10cSrcweir	my $infoline;
675cdf0e10cSrcweir
676cdf0e10cSrcweir	my @allfiles = ();
677cdf0e10cSrcweir	my @filetable = ();
678cdf0e10cSrcweir	my @filehashtable = ();
679cdf0e10cSrcweir	my %allfilecomponents = ();
680cdf0e10cSrcweir	my $counter = 0;
681cdf0e10cSrcweir
682cdf0e10cSrcweir	if ( $^O =~ /cygwin/i ) { installer::worker::generate_cygwin_pathes($filesref); }
683cdf0e10cSrcweir
684cdf0e10cSrcweir	# The filenames must be collected because of uniqueness
685cdf0e10cSrcweir	# 01-44-~1.DAT, 01-44-~2.DAT, ...
686cdf0e10cSrcweir	# my @shortnames = ();
687cdf0e10cSrcweir	my %shortnames = ();
688cdf0e10cSrcweir
689cdf0e10cSrcweir	installer::windows::idtglobal::write_idt_header(\@filetable, "file");
690cdf0e10cSrcweir	installer::windows::idtglobal::write_idt_header(\@filehashtable, "filehash");
691cdf0e10cSrcweir
692cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$filesref}; $i++ )
693cdf0e10cSrcweir	{
694cdf0e10cSrcweir		my %file = ();
695cdf0e10cSrcweir
696cdf0e10cSrcweir		my $onefile = ${$filesref}[$i];
697cdf0e10cSrcweir
698cdf0e10cSrcweir		my $styles = "";
699cdf0e10cSrcweir		if ( $onefile->{'Styles'} ) { $styles = $onefile->{'Styles'}; }
700cdf0e10cSrcweir		if (( $styles =~ /\bJAVAFILE\b/ ) && ( ! ($allvariables->{'JAVAPRODUCT'} ))) { next; }
701cdf0e10cSrcweir
702cdf0e10cSrcweir		$file{'Component_'} = get_file_component_name($onefile, $filesref);
703*dca4887fSAndre Fischer		$file{'File'} = generate_unique_filename_for_filetable($onefile, $file{'Component_'});
704cdf0e10cSrcweir
705cdf0e10cSrcweir		$onefile->{'uniquename'} = $file{'File'};
706cdf0e10cSrcweir		$onefile->{'componentname'} = $file{'Component_'};
707cdf0e10cSrcweir
708cdf0e10cSrcweir		# Collecting all components
709cdf0e10cSrcweir		# if (!(installer::existence::exists_in_array($file{'Component_'}, $allfilecomponentsref))) { push(@{$allfilecomponentsref}, $file{'Component_'}); }
710cdf0e10cSrcweir
711cdf0e10cSrcweir		if ( ! exists($allfilecomponents{$file{'Component_'}}) ) { $allfilecomponents{$file{'Component_'}} = 1; }
712cdf0e10cSrcweir
713*dca4887fSAndre Fischer		$file{'FileName'} = generate_filename_for_filetable($onefile, \%shortnames);
714cdf0e10cSrcweir
715cdf0e10cSrcweir		$file{'FileSize'} = get_filesize($onefile);
716cdf0e10cSrcweir
717cdf0e10cSrcweir		$file{'Version'} = get_fileversion($onefile, $allvariables, $styles);
718cdf0e10cSrcweir
719cdf0e10cSrcweir		$file{'Language'} = get_language_for_file($onefile);
720cdf0e10cSrcweir
721cdf0e10cSrcweir		if ( $styles =~ /\bDONT_PACK\b/ ) { $file{'Attributes'} = "8192"; }
722cdf0e10cSrcweir		else { $file{'Attributes'} = "16384"; }
723cdf0e10cSrcweir
724cdf0e10cSrcweir		# $file{'Attributes'} = "16384"; 	# Sourcefile is packed
725cdf0e10cSrcweir		# $file{'Attributes'} = "8192"; 	# Sourcefile is unpacked
726cdf0e10cSrcweir
727cdf0e10cSrcweir		$installer::globals::insert_file_at_end = 0;
728cdf0e10cSrcweir		$counter++;
729f30bf281SAndre Fischer		$file{'Sequence'} = $counter;
730cdf0e10cSrcweir
731cdf0e10cSrcweir		$onefile->{'sequencenumber'} = $file{'Sequence'};
732cdf0e10cSrcweir
733cdf0e10cSrcweir		my $oneline = $file{'File'} . "\t" . $file{'Component_'} . "\t" . $file{'FileName'} . "\t"
734cdf0e10cSrcweir				. $file{'FileSize'} . "\t" . $file{'Version'} . "\t" . $file{'Language'} . "\t"
735cdf0e10cSrcweir				. $file{'Attributes'} . "\t" . $file{'Sequence'} . "\n";
736cdf0e10cSrcweir
737cdf0e10cSrcweir		push(@filetable, $oneline);
738cdf0e10cSrcweir
739cdf0e10cSrcweir		if ( ! $installer::globals::insert_file_at_end ) { push(@allfiles, $onefile); }
740cdf0e10cSrcweir
741cdf0e10cSrcweir		# Collecting all component conditions
742cdf0e10cSrcweir		if ( $onefile->{'ComponentCondition'} )
743cdf0e10cSrcweir		{
744cdf0e10cSrcweir			if ( ! exists($installer::globals::componentcondition{$file{'Component_'}}))
745cdf0e10cSrcweir			{
746cdf0e10cSrcweir				$installer::globals::componentcondition{$file{'Component_'}} = $onefile->{'ComponentCondition'};
747cdf0e10cSrcweir			}
748cdf0e10cSrcweir		}
749cdf0e10cSrcweir
750cdf0e10cSrcweir		# Collecting also all tree conditions for multilayer products
751cdf0e10cSrcweir		get_tree_condition_for_component($onefile, $file{'Component_'});
752cdf0e10cSrcweir
753cdf0e10cSrcweir		# Collecting all component names, that have flag VERSION_INDEPENDENT_COMP_ID
754cdf0e10cSrcweir		# This should be all components with constant API, for example URE
755cdf0e10cSrcweir		if ( $styles =~ /\bVERSION_INDEPENDENT_COMP_ID\b/ )
756cdf0e10cSrcweir		{
757cdf0e10cSrcweir			$installer::globals::base_independent_components{$onefile->{'componentname'}} = 1;
758cdf0e10cSrcweir		}
759cdf0e10cSrcweir
760cdf0e10cSrcweir		# Collecting all component ids, that are defined at files in scp project (should not be used anymore)
761cdf0e10cSrcweir		if ( $onefile->{'CompID'} )
762cdf0e10cSrcweir		{
763cdf0e10cSrcweir			if ( ! exists($installer::globals::componentid{$onefile->{'componentname'}}))
764cdf0e10cSrcweir			{
765cdf0e10cSrcweir				$installer::globals::componentid{$onefile->{'componentname'}} = $onefile->{'CompID'};
766cdf0e10cSrcweir			}
767cdf0e10cSrcweir			else
768cdf0e10cSrcweir			{
769cdf0e10cSrcweir				if ( $installer::globals::componentid{$onefile->{'componentname'}} ne $onefile->{'CompID'} )
770cdf0e10cSrcweir				{
771cdf0e10cSrcweir					installer::exiter::exit_program("ERROR: There is already a ComponentID for component \"$onefile->{'componentname'}\" : \"$installer::globals::componentid{$onefile->{'componentname'}}\" . File \"$onefile->{'gid'}\" uses \"$onefile->{'CompID'}\" !", "create_files_table");
772cdf0e10cSrcweir				}
773cdf0e10cSrcweir			}
774cdf0e10cSrcweir
775cdf0e10cSrcweir			# Also checking vice versa. Is this ComponentID already used? If yes, is the componentname the same?
776cdf0e10cSrcweir
777cdf0e10cSrcweir			if ( ! exists($installer::globals::comparecomponentname{$onefile->{'CompID'}}))
778cdf0e10cSrcweir			{
779cdf0e10cSrcweir				$installer::globals::comparecomponentname{$onefile->{'CompID'}} = $onefile->{'componentname'};
780cdf0e10cSrcweir			}
781cdf0e10cSrcweir			else
782cdf0e10cSrcweir			{
783cdf0e10cSrcweir				if ( $installer::globals::comparecomponentname{$onefile->{'CompID'}} ne $onefile->{'componentname'} )
784cdf0e10cSrcweir				{
785cdf0e10cSrcweir					installer::exiter::exit_program("ERROR: There is already a component for ComponentID \"$onefile->{'CompID'}\" : \"$installer::globals::comparecomponentname{$onefile->{'CompID'}}\" . File \"$onefile->{'gid'}\" has same component id but is included in component \"$onefile->{'componentname'}\" !", "create_files_table");
786cdf0e10cSrcweir				}
787cdf0e10cSrcweir			}
788cdf0e10cSrcweir		}
789cdf0e10cSrcweir
790cdf0e10cSrcweir		# Collecting all language specific conditions
791cdf0e10cSrcweir		# if ( $onefile->{'haslanguagemodule'} )
792cdf0e10cSrcweir		if ( $onefile->{'ismultilingual'} )
793cdf0e10cSrcweir		{
794cdf0e10cSrcweir			if ( $onefile->{'ComponentCondition'} ) { installer::exiter::exit_program("ERROR: Cannot set language condition. There is already another component condition for file $onefile->{'gid'}: \"$onefile->{'ComponentCondition'}\" !", "create_files_table"); }
795cdf0e10cSrcweir
796cdf0e10cSrcweir			if ( $onefile->{'specificlanguage'} eq "" ) { installer::exiter::exit_program("ERROR: There is no specific language for file at language module: $onefile->{'gid'} !", "create_files_table"); }
797cdf0e10cSrcweir			my $locallanguage = $onefile->{'specificlanguage'};
798cdf0e10cSrcweir			my $property = "IS" . $file{'Language'};
799cdf0e10cSrcweir			my $value = 1;
800cdf0e10cSrcweir			my $condition = $property . "=" . $value;
801cdf0e10cSrcweir
802cdf0e10cSrcweir			$onefile->{'ComponentCondition'} = $condition;
803cdf0e10cSrcweir
804cdf0e10cSrcweir			if ( exists($installer::globals::componentcondition{$file{'Component_'}}))
805cdf0e10cSrcweir			{
806cdf0e10cSrcweir				if ( $installer::globals::componentcondition{$file{'Component_'}} ne $condition ) { installer::exiter::exit_program("ERROR: There is already another component condition for file $onefile->{'gid'}: \"$installer::globals::componentcondition{$file{'Component_'}}\" and \"$condition\" !", "create_files_table"); }
807cdf0e10cSrcweir			}
808cdf0e10cSrcweir			else
809cdf0e10cSrcweir			{
810cdf0e10cSrcweir				$installer::globals::componentcondition{$file{'Component_'}} = $condition;
811cdf0e10cSrcweir			}
812cdf0e10cSrcweir
813cdf0e10cSrcweir			# collecting all properties for table Property
814cdf0e10cSrcweir			if ( ! exists($installer::globals::languageproperties{$property}) ) { $installer::globals::languageproperties{$property} = $value; }
815cdf0e10cSrcweir		}
816cdf0e10cSrcweir
817cdf0e10cSrcweir		if ( $installer::globals::prepare_winpatch )
818cdf0e10cSrcweir		{
819cdf0e10cSrcweir			my $path = $onefile->{'sourcepath'};
820cdf0e10cSrcweir			if ( $^O =~ /cygwin/i ) { $path = $onefile->{'cyg_sourcepath'}; }
821cdf0e10cSrcweir
822cdf0e10cSrcweir			open(FILE, $path) or die "ERROR: Can't open $path for creating file hash";
823cdf0e10cSrcweir			binmode(FILE);
824cdf0e10cSrcweir			my $hashinfo = pack("l", 20);
825cdf0e10cSrcweir			$hashinfo .= Digest::MD5->new->addfile(*FILE)->digest;
826cdf0e10cSrcweir
827cdf0e10cSrcweir			my @i = unpack ('x[l]l4', $hashinfo);
828cdf0e10cSrcweir			$oneline = $file{'File'} . "\t" .
829cdf0e10cSrcweir				"0" . "\t" .
830cdf0e10cSrcweir				$i[0] . "\t" .
831cdf0e10cSrcweir				$i[1] . "\t" .
832cdf0e10cSrcweir				$i[2] . "\t" .
833cdf0e10cSrcweir				$i[3] . "\n";
834cdf0e10cSrcweir			push (@filehashtable, $oneline);
835cdf0e10cSrcweir		}
836cdf0e10cSrcweir
837cdf0e10cSrcweir		# Saving the sequence number in a hash with uniquefilename as key.
838cdf0e10cSrcweir		# This is used for better performance in "save_packorder"
839cdf0e10cSrcweir		$installer::globals::uniquefilenamesequence{$onefile->{'uniquename'}} = $onefile->{'sequencenumber'};
840cdf0e10cSrcweir
841cdf0e10cSrcweir		# Special handling for files in PREDEFINED_OSSHELLNEWDIR. These components
842cdf0e10cSrcweir		# need as KeyPath a RegistryItem in HKCU
843cdf0e10cSrcweir		my $destdir = "";
844cdf0e10cSrcweir		if ( $onefile->{'Dir'} ) { $destdir = $onefile->{'Dir'}; }
845cdf0e10cSrcweir
846cdf0e10cSrcweir		if (( $destdir =~ /\bPREDEFINED_OSSHELLNEWDIR\b/ ) || ( $onefile->{'needs_user_registry_key'} ))
847cdf0e10cSrcweir		{
848cdf0e10cSrcweir			my $keypath = generate_registry_keypath($onefile);
849cdf0e10cSrcweir			$onefile->{'userregkeypath'} = $keypath;
850cdf0e10cSrcweir			push(@installer::globals::userregistrycollector, $onefile);
851cdf0e10cSrcweir			$installer::globals::addeduserregitrykeys = 1;
852cdf0e10cSrcweir		}
853cdf0e10cSrcweir	}
854cdf0e10cSrcweir
855cdf0e10cSrcweir	# putting content from %allfilecomponents to $allfilecomponentsref for later usage
856cdf0e10cSrcweir	foreach $localkey (keys %allfilecomponents ) { push( @{$allfilecomponentsref}, $localkey); }
857cdf0e10cSrcweir
858cdf0e10cSrcweir	my $filetablename = $basedir . $installer::globals::separator . "File.idt";
859cdf0e10cSrcweir	installer::files::save_file($filetablename ,\@filetable);
860b274bc22SAndre Fischer	$installer::logger::Lang->print("\n");
861b274bc22SAndre Fischer	$installer::logger::Lang->printf("Created idt file: %s\n", $filetablename);
862cdf0e10cSrcweir
863b274bc22SAndre Fischer	$installer::logger::Lang->add_timestamp("Performance Info: File Table end");
864cdf0e10cSrcweir
865cdf0e10cSrcweir	my $filehashtablename = $basedir . $installer::globals::separator . "MsiFileHash.idt";
866cdf0e10cSrcweir	installer::files::save_file($filehashtablename ,\@filehashtable);
867b274bc22SAndre Fischer	$installer::logger::Lang->print("\n");
868b274bc22SAndre Fischer	$installer::logger::Lang->printf("Created idt file: %s\n", $filehashtablename);
869cdf0e10cSrcweir
870cdf0e10cSrcweir	# Now the new files can be added to the files collector (only in update packaging processes)
871cdf0e10cSrcweir	if ( $installer::globals::newfilesexist )
872cdf0e10cSrcweir	{
873cdf0e10cSrcweir		foreach my $seq (sort keys %installer::globals::newfilescollector) { push(@allfiles, $installer::globals::newfilescollector{$seq}) }
874cdf0e10cSrcweir	}
875cdf0e10cSrcweir
876cdf0e10cSrcweir	return \@allfiles;
877cdf0e10cSrcweir}
878cdf0e10cSrcweir
879cdf0e10cSrcweir1;
880