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