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