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::idtglobal;
25
26use Cwd;
27use installer::converter;
28use installer::existence;
29use installer::exiter;
30use installer::files;
31use installer::globals;
32use installer::pathanalyzer;
33use installer::remover;
34use installer::scriptitems;
35use installer::systemactions;
36use installer::windows::language;
37
38##############################################################
39# Shorten the gid for a feature.
40# Attention: Maximum length is 38
41##############################################################
42
43sub shorten_feature_gid
44{
45	my ($stringref) = @_;
46
47	$$stringref =~ s/gid_Module_/gm_/;
48	$$stringref =~ s/_Extension_/_ex_/;
49	$$stringref =~ s/_Root_/_r_/;
50	$$stringref =~ s/_Prg_/_p_/;
51	$$stringref =~ s/_Optional_/_o_/;
52	$$stringref =~ s/_Tools_/_tl_/;
53	$$stringref =~ s/_Wrt_Flt_/_w_f_/;
54	$$stringref =~ s/_Javafilter_/_jf_/;
55	$$stringref =~ s/_Productivity_/_pr_/;
56	$$stringref =~ s/_Replacement_/_rpl_/;
57}
58
59############################################
60# Getting the next free number, that
61# can be added.
62# Sample: 01-44-~1.DAT, 01-44-~2.DAT, ...
63############################################
64
65sub get_next_free_number
66{
67	my ($name, $shortnamesref) = @_;
68
69	my $counter = 0;
70	my $dontsave = 0;
71	my $alreadyexists;
72	my ($newname, $shortname);
73
74	do
75	{
76		$alreadyexists = 0;
77		$counter++;
78		$newname = $name . $counter;
79
80		for ( my $i = 0; $i <= $#{$shortnamesref}; $i++ )
81		{
82			$shortname = ${$shortnamesref}[$i];
83
84			if ( uc($shortname) eq uc($newname) )	# case insensitive
85			{
86				$alreadyexists = 1;
87				last;
88			}
89		}
90	}
91	until (!($alreadyexists));
92
93	if (( $counter > 9 ) && ( length($name) > 6 )) { $dontsave = 1; }
94	if (( $counter > 99 ) && ( length($name) > 5 )) { $dontsave = 1; }
95
96	if (!($dontsave))
97	{
98		push(@{$shortnamesref}, $newname);	# adding the new shortname to the array of shortnames
99	}
100
101	return $counter
102}
103
104############################################
105# Getting the next free number, that
106# can be added.
107# Sample: 01-44-~1.DAT, 01-44-~2.DAT, ...
108############################################
109
110sub get_next_free_number_with_hash
111{
112	my ($name, $shortnamesref, $ext) = @_;
113
114	my $counter = 0;
115	my $dontsave = 0;
116	my $saved = 0;
117	my $alreadyexists;
118	my ($newname, $shortname);
119
120	do
121	{
122		$alreadyexists = 0;
123		$counter++;
124		$newname = $name . $counter;
125		$newname = uc($newname);	# case insensitive, always upper case
126		if ( exists($shortnamesref->{$newname}) ||
127		     exists($installer::globals::savedrev83mapping{$newname.$ext}) )
128		{
129			$alreadyexists = 1;
130		}
131	}
132	until (!($alreadyexists));
133
134	if (( $counter > 9 ) && ( length($name) > 6 )) { $dontsave = 1; }
135	if (( $counter > 99 ) && ( length($name) > 5 )) { $dontsave = 1; }
136
137	if (!($dontsave))
138	{
139		# push(@{$shortnamesref}, $newname);	# adding the new shortname to the array of shortnames
140		$shortnamesref->{$newname} = 1;	# adding the new shortname to the array of shortnames, always uppercase
141		$saved = 1;
142	}
143
144	return ( $counter, $saved )
145}
146
147#########################################
148# 8.3 for filenames and directories
149#########################################
150
151sub make_eight_three_conform
152{
153	my ($inputstring, $pattern, $shortnamesref) = @_;
154
155	# all shortnames are collected in $shortnamesref, because of uniqueness
156
157	my ($name, $namelength, $number);
158	my $conformstring = "";
159	my $changed = 0;
160
161	if (( $inputstring =~ /^\s*(.*?)\.(.*?)\s*$/ ) && ( $pattern eq "file" ))	# files with a dot
162	{
163		$name = $1;
164		my $extension = $2;
165
166		$namelength = length($name);
167		my $extensionlength = length($extension);
168
169		if ( $extensionlength > 3 )
170		{
171			# simply taking the first three letters
172			$extension = substr($extension, 0, 3);	# name, offset, length
173		}
174
175		# Attention: readme.html -> README~1.HTM
176
177		if (( $namelength > 8 ) || ( $extensionlength > 3 ))
178		{
179			# taking the first six letters
180			$name = substr($name, 0, 6);	# name, offset, length
181			$name =~ s/\s*$//; # removing ending whitespaces
182			$name = $name . "\~";
183			$number = get_next_free_number($name, $shortnamesref);
184
185			# if $number>9 the new name would be "abcdef~10.xyz", which is 9+3, and therefore not allowed
186
187			if ( $number > 9 )
188			{
189				$name = substr($name, 0, 5);	# name, offset, length
190				$name =~ s/\s*$//; # removing ending whitespaces
191				$name = $name . "\~";
192				$number = get_next_free_number($name, $shortnamesref);
193
194				if ( $number > 99 )
195				{
196					$name = substr($name, 0, 4);	# name, offset, length
197					$name =~ s/\s*$//; # removing ending whitespaces
198					$name = $name . "\~";
199					$number = get_next_free_number($name, $shortnamesref);
200				}
201			}
202
203			$name = $name . "$number";
204
205			$changed = 1;
206		}
207
208		$conformstring = $name . "\." . $extension;
209
210		if ( $changed ) { $conformstring= uc($conformstring); }
211	}
212	else 		# no dot in filename or directory (also used for shortcuts)
213	{
214		$name = $inputstring;
215		$namelength = length($name);
216
217		if ( $namelength > 8 )
218		{
219			# taking the first six letters
220			$name = substr($name, 0, 6);	# name, offset, length
221			$name =~ s/\s*$//; # removing ending whitespaces
222			$name = $name . "\~";
223			$number = get_next_free_number($name, $shortnamesref);
224
225			# if $number>9 the new name would be "abcdef~10.xyz", which is 9+3, and therefore not allowed
226
227			if ( $number > 9 )
228			{
229				$name = substr($name, 0, 5);	# name, offset, length
230				$name =~ s/\s*$//; # removing ending whitespaces
231				$name = $name . "\~";
232				$number = get_next_free_number($name, $shortnamesref);
233
234				if ( $number > 99 )
235				{
236					$name = substr($name, 0, 4);	# name, offset, length
237					$name =~ s/\s*$//; # removing ending whitespaces
238					$name = $name . "\~";
239					$number = get_next_free_number($name, $shortnamesref);
240				}
241			}
242
243			$name = $name . "$number";
244			$changed = 1;
245			if ( $pattern eq "dir" ) { $name =~ s/\./\_/g; }	# in directories replacing "." with "_"
246		}
247
248		$conformstring = $name;
249
250		if ( $changed ) { $conformstring = uc($name); }
251	}
252
253	return $conformstring;
254}
255
256#########################################
257# 8.3 for filenames and directories
258# $shortnamesref is a hash in this case
259# -> performance reasons
260#########################################
261
262sub make_eight_three_conform_with_hash
263{
264	my ($inputstring, $pattern, $shortnamesref) = @_;
265
266	# all shortnames are collected in $shortnamesref, because of uniqueness (a hash!)
267
268	my ($name, $namelength, $number);
269	my $conformstring = "";
270	my $changed = 0;
271	my $saved;
272
273	# if (( $inputstring =~ /^\s*(.*?)\.(.*?)\s*$/ ) && ( $pattern eq "file" ))	# files with a dot
274	if (( $inputstring =~ /^\s*(.*)\.(.*?)\s*$/ ) && ( $pattern eq "file" ))	# files with a dot
275	{
276		# extension has to be non-greedy, but name is. This is important to find the last dot in the filename
277		$name = $1;
278		my $extension = $2;
279
280		if ( $name =~ /^\s*(.*?)\s*$/ ) { $name = $1; } # now the name is also non-greedy
281		$name =~ s/\.//g; # no dots in 8+3 conform filename
282
283		$namelength = length($name);
284		my $extensionlength = length($extension);
285
286		if ( $extensionlength > 3 )
287		{
288			# simply taking the first three letters
289			$extension = substr($extension, 0, 3);	# name, offset, length
290			$changed = 1;
291		}
292
293		# Attention: readme.html -> README~1.HTM
294
295		if (( $namelength > 8 ) || ( $extensionlength > 3 ))
296		{
297			# taking the first six letters, if filename is longer than 6 characters
298			if ( $namelength > 6 )
299			{
300				$name = substr($name, 0, 6);	# name, offset, length
301				$name =~ s/\s*$//; # removing ending whitespaces
302				$name = $name . "\~";
303				($number, $saved) = get_next_free_number_with_hash($name, $shortnamesref, '.'.uc($extension));
304
305				# if $number>9 the new name would be "abcdef~10.xyz", which is 9+3, and therefore not allowed
306
307				if ( ! $saved )
308				{
309					$name = substr($name, 0, 5);	# name, offset, length
310					$name =~ s/\s*$//; # removing ending whitespaces
311					$name = $name . "\~";
312					($number, $saved) = get_next_free_number_with_hash($name, $shortnamesref, '.'.uc($extension));
313
314					# if $number>99 the new name would be "abcde~100.xyz", which is 9+3, and therefore not allowed
315
316					if ( ! $saved )
317					{
318						$name = substr($name, 0, 4);	# name, offset, length
319						$name =~ s/\s*$//; # removing ending whitespaces
320						$name = $name . "\~";
321						($number, $saved) = get_next_free_number_with_hash($name, $shortnamesref, '.'.uc($extension));
322
323						if ( ! $saved )
324						{
325							installer::exiter::exit_program("ERROR: Could not set 8+3 conform name for $inputstring !", "make_eight_three_conform_with_hash");
326						}
327					}
328				}
329
330				$name = $name . "$number";
331				$changed = 1;
332			}
333		}
334
335		$conformstring = $name . "\." . $extension;
336
337		if ( $changed ) { $conformstring= uc($conformstring); }
338	}
339	else 		# no dot in filename or directory (also used for shortcuts)
340	{
341		$name = $inputstring;
342		$namelength = length($name);
343
344		if ( $namelength > 8 )
345		{
346			# taking the first six letters
347			$name = substr($name, 0, 6);	# name, offset, length
348			$name =~ s/\s*$//; # removing ending whitespaces
349			$name = $name . "\~";
350			( $number, $saved ) = get_next_free_number_with_hash($name, $shortnamesref, '');
351
352			# if $number>9 the new name would be "abcdef~10", which is 9+0, and therefore not allowed
353
354			if ( ! $saved )
355			{
356				$name = substr($name, 0, 5);	# name, offset, length
357				$name =~ s/\s*$//; # removing ending whitespaces
358				$name = $name . "\~";
359				( $number, $saved ) = get_next_free_number_with_hash($name, $shortnamesref, '');
360
361				# if $number>99 the new name would be "abcde~100", which is 9+0, and therefore not allowed
362
363				if ( ! $saved )
364				{
365					$name = substr($name, 0, 4);	# name, offset, length
366					$name =~ s/\s*$//; # removing ending whitespaces
367					$name = $name . "\~";
368					( $number, $saved ) = get_next_free_number_with_hash($name, $shortnamesref, '');
369
370					if ( ! $saved ) { installer::exiter::exit_program("ERROR: Could not set 8+3 conform name for $inputstring !", "make_eight_three_conform_with_hash"); }
371				}
372			}
373
374			$name = $name . "$number";
375			$changed = 1;
376			if ( $pattern eq "dir" ) { $name =~ s/\./\_/g; }	# in directories replacing "." with "_"
377		}
378
379		$conformstring = $name;
380
381		if ( $changed ) { $conformstring = uc($name); }
382	}
383
384	return $conformstring;
385}
386
387#########################################
388# Writing the header for idt files
389#########################################
390
391sub write_idt_header
392{
393	my ($idtref, $definestring) = @_;
394
395	my $oneline;
396
397	if ( $definestring eq "file" )
398	{
399		$oneline = "File\tComponent_\tFileName\tFileSize\tVersion\tLanguage\tAttributes\tSequence\n";
400		push(@{$idtref}, $oneline);
401		$oneline = "s72\ts72\tl255\ti4\tS72\tS20\tI2\ti2\n";
402		push(@{$idtref}, $oneline);
403		$oneline = "File\tFile\n";
404		push(@{$idtref}, $oneline);
405	}
406
407	if ( $definestring eq "filehash" )
408	{
409		$oneline = "File_\tOptions\tHashPart1\tHashPart2\tHashPart3\tHashPart4\n";
410		push(@{$idtref}, $oneline);
411		$oneline = "s72\ti2\ti4\ti4\ti4\ti4\n";
412		push(@{$idtref}, $oneline);
413		$oneline = "MsiFileHash\tFile_\n";
414		push(@{$idtref}, $oneline);
415	}
416
417	if ( $definestring eq "directory" )
418	{
419		$oneline = "Directory\tDirectory_Parent\tDefaultDir\n";
420		push(@{$idtref}, $oneline);
421		$oneline = "s72\tS72\tl255\n";
422		push(@{$idtref}, $oneline);
423		$oneline = "Directory\tDirectory\n";
424		push(@{$idtref}, $oneline);
425	}
426
427	if ( $definestring eq "component" )
428	{
429		$oneline = "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n";
430		push(@{$idtref}, $oneline);
431		$oneline = "s72\tS38\ts72\ti2\tS255\tS72\n";
432		push(@{$idtref}, $oneline);
433		$oneline = "Component\tComponent\n";
434		push(@{$idtref}, $oneline);
435	}
436
437	if ( $definestring eq "feature" )
438	{
439		$oneline = "Feature\tFeature_Parent\tTitle\tDescription\tDisplay\tLevel\tDirectory_\tAttributes\n";
440		push(@{$idtref}, $oneline);
441		$oneline = "s38\tS38\tL64\tL255\tI2\ti2\tS72\ti2\n";
442		push(@{$idtref}, $oneline);
443		$oneline = "WINDOWSENCODINGTEMPLATE\tFeature\tFeature\n";
444		push(@{$idtref}, $oneline);
445	}
446
447	if ( $definestring eq "featurecomponent" )
448	{
449		$oneline = "Feature_\tComponent_\n";
450		push(@{$idtref}, $oneline);
451		$oneline = "s38\ts72\n";
452		push(@{$idtref}, $oneline);
453		$oneline = "FeatureComponents\tFeature_\tComponent_\n";
454		push(@{$idtref}, $oneline);
455	}
456
457	if ( $definestring eq "media" )
458	{
459		$oneline = "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n";
460		push(@{$idtref}, $oneline);
461		$oneline = "i2\ti2\tL64\tS255\tS32\tS72\n";
462		push(@{$idtref}, $oneline);
463		$oneline = "Media\tDiskId\n";
464		push(@{$idtref}, $oneline);
465	}
466
467	if ( $definestring eq "font" )
468	{
469		$oneline = "File_\tFontTitle\n";
470		push(@{$idtref}, $oneline);
471		$oneline = "s72\tS128\n";
472		push(@{$idtref}, $oneline);
473		$oneline = "Font\tFile_\n";
474		push(@{$idtref}, $oneline);
475	}
476
477	if ( $definestring eq "shortcut" )
478	{
479		$oneline = "Shortcut\tDirectory_\tName\tComponent_\tTarget\tArguments\tDescription\tHotkey\tIcon_\tIconIndex\tShowCmd\tWkDir\n";
480		push(@{$idtref}, $oneline);
481		$oneline = "s72\ts72\tl128\ts72\ts72\tS255\tL255\tI2\tS72\tI2\tI2\tS72\n";
482		push(@{$idtref}, $oneline);
483		$oneline = "WINDOWSENCODINGTEMPLATE\tShortcut\tShortcut\n";
484		push(@{$idtref}, $oneline);
485	}
486
487	if ( $definestring eq "registry" )
488	{
489		$oneline = "Registry\tRoot\tKey\tName\tValue\tComponent_\n";
490		push(@{$idtref}, $oneline);
491		$oneline = "s72\ti2\tl255\tL255\tL0\ts72\n";
492		push(@{$idtref}, $oneline);
493		$oneline = "Registry\tRegistry\n";
494		push(@{$idtref}, $oneline);
495	}
496
497	if ( $definestring eq "reg64" )
498	{
499		$oneline = "Registry\tRoot\tKey\tName\tValue\tComponent_\n";
500		push(@{$idtref}, $oneline);
501		$oneline = "s72\ti2\tl255\tL255\tL0\ts72\n";
502		push(@{$idtref}, $oneline);
503		$oneline = "Reg64\tRegistry\n";
504		push(@{$idtref}, $oneline);
505	}
506
507	if ( $definestring eq "createfolder" )
508	{
509		$oneline = "Directory_\tComponent_\n";
510		push(@{$idtref}, $oneline);
511		$oneline = "s72\ts72\n";
512		push(@{$idtref}, $oneline);
513		$oneline = "CreateFolder\tDirectory_\tComponent_\n";
514		push(@{$idtref}, $oneline);
515	}
516
517	if ( $definestring eq "removefile" )
518	{
519		$oneline = "FileKey\tComponent_\tFileName\tDirProperty\tInstallMode\n";
520		push(@{$idtref}, $oneline);
521		$oneline = "s72\ts72\tL255\ts72\ti2\n";
522		push(@{$idtref}, $oneline);
523		$oneline = "RemoveFile\tFileKey\n";
524		push(@{$idtref}, $oneline);
525	}
526
527	if ( $definestring eq "upgrade" )
528	{
529		$oneline = "UpgradeCode\tVersionMin\tVersionMax\tLanguage\tAttributes\tRemove\tActionProperty\n";
530		push(@{$idtref}, $oneline);
531		$oneline = "s38\tS20\tS20\tS255\ti4\tS255\ts72\n";
532		push(@{$idtref}, $oneline);
533		$oneline = "Upgrade\tUpgradeCode\tVersionMin\tVersionMax\tLanguage\tAttributes\n";
534		push(@{$idtref}, $oneline);
535	}
536
537	if ( $definestring eq "icon" )
538	{
539		$oneline = "Name\tData\n";
540		push(@{$idtref}, $oneline);
541		$oneline = "s72\tv0\n";
542		push(@{$idtref}, $oneline);
543		$oneline = "Icon\tName\n";
544		push(@{$idtref}, $oneline);
545	}
546
547	if ( $definestring eq "inifile" )
548	{
549		$oneline = "IniFile\tFileName\tDirProperty\tSection\tKey\tValue\tAction\tComponent_\n";
550		push(@{$idtref}, $oneline);
551		$oneline = "s72\tl255\tS72\tl96\tl128\tl255\ti2\ts72\n";
552		push(@{$idtref}, $oneline);
553		$oneline = "IniFile\tIniFile\n";
554		push(@{$idtref}, $oneline);
555	}
556
557	if ( $definestring eq "selfreg" )
558	{
559		$oneline = "File_\tCost\n";
560		push(@{$idtref}, $oneline);
561		$oneline = "s72\tI2\n";
562		push(@{$idtref}, $oneline);
563		$oneline = "SelfReg\tFile_\n";
564		push(@{$idtref}, $oneline);
565	}
566
567	if ( $definestring eq "msiassembly" )
568	{
569		$oneline = "Component_\tFeature_\tFile_Manifest\tFile_Application\tAttributes\n";
570		push(@{$idtref}, $oneline);
571		$oneline = "s72\ts38\tS72\tS72\tI2\n";
572		push(@{$idtref}, $oneline);
573		$oneline = "MsiAssembly\tComponent_\n";
574		push(@{$idtref}, $oneline);
575	}
576
577	if ( $definestring eq "msiassemblyname" )
578	{
579		$oneline = "Component_\tName\tValue\n";
580		push(@{$idtref}, $oneline);
581		$oneline = "s72\ts255\ts255\n";
582		push(@{$idtref}, $oneline);
583		$oneline = "MsiAssemblyName\tComponent_\tName\n";
584		push(@{$idtref}, $oneline);
585	}
586
587	if ( $definestring eq "appsearch" )
588	{
589		$oneline = "Property\tSignature_\n";
590		push(@{$idtref}, $oneline);
591		$oneline = "s72\ts72\n";
592		push(@{$idtref}, $oneline);
593		$oneline = "AppSearch\tProperty\tSignature_\n";
594		push(@{$idtref}, $oneline);
595	}
596
597	if ( $definestring eq "reglocat" )
598	{
599		$oneline = "Signature_\tRoot\tKey\tName\tType\n";
600		push(@{$idtref}, $oneline);
601		$oneline = "s72\ti2\ts255\tS255\tI2\n";
602		push(@{$idtref}, $oneline);
603		$oneline = "RegLocator\tSignature_\n";
604		push(@{$idtref}, $oneline);
605	}
606
607	if ( $definestring eq "signatur" )
608	{
609		$oneline = "Signature\tFileName\tMinVersion\tMaxVersion\tMinSize\tMaxSize\tMinDate\tMaxDate\tLanguages\n";
610		push(@{$idtref}, $oneline);
611		$oneline = "s72\ts255\tS20\tS20\tI4\tI4\tI4\tI4\tS255\n";
612		push(@{$idtref}, $oneline);
613		$oneline = "Signature\tSignature\n";
614		push(@{$idtref}, $oneline);
615	}
616
617}
618
619##############################################################
620# Returning the name of the rranslation file for a
621# given language.
622# Sample: "01" oder "en-US" -> "1033.txt"
623##############################################################
624
625sub get_languagefilename
626{
627	my ($idtfilename, $basedir) = @_;
628
629	# $idtfilename =~ s/\.idt/\.ulf/;
630	$idtfilename =~ s/\.idt/\.mlf/;
631
632	my $languagefilename = $basedir . $installer::globals::separator . $idtfilename;
633
634	return $languagefilename;
635}
636
637##############################################################
638# Returning the complete block in all languages
639# for a specified string
640##############################################################
641
642sub get_language_block_from_language_file
643{
644	my ($searchstring, $languagefile) = @_;
645
646	my @language_block = ();
647
648	for ( my $i = 0; $i <= $#{$languagefile}; $i++ )
649	{
650		if ( ${$languagefile}[$i] =~ /^\s*\[\s*$searchstring\s*\]\s*$/ )
651		{
652			my $counter = $i;
653
654			push(@language_block, ${$languagefile}[$counter]);
655			$counter++;
656
657			while (( $counter <= $#{$languagefile} ) && (!( ${$languagefile}[$counter] =~ /^\s*\[/ )))
658			{
659				push(@language_block, ${$languagefile}[$counter]);
660				$counter++;
661			}
662
663			last;
664		}
665	}
666
667	return \@language_block;
668}
669
670##############################################################
671# Returning a specific language string from the block
672# of all translations
673##############################################################
674
675sub get_language_string_from_language_block
676{
677	my ($language_block, $language, $oldstring) = @_;
678
679	my $newstring = "";
680
681	for ( my $i = 0; $i <= $#{$language_block}; $i++ )
682	{
683		if ( ${$language_block}[$i] =~ /^\s*$language\s*\=\s*\"(.*)\"\s*$/ )
684		{
685			$newstring = $1;
686			last;
687		}
688	}
689
690	if ( $newstring eq "" )
691	{
692		$language = "en-US"; 	# defaulting to english
693
694		for ( my $i = 0; $i <= $#{$language_block}; $i++ )
695		{
696			if ( ${$language_block}[$i] =~ /^\s*$language\s*\=\s*\"(.*)\"\s*$/ )
697			{
698				$newstring = $1;
699				last;
700			}
701		}
702	}
703
704	return $newstring;
705}
706
707##############################################################
708# Returning a specific code from the block
709# of all codes. No defaulting to english!
710##############################################################
711
712sub get_code_from_code_block
713{
714	my ($codeblock, $language) = @_;
715
716	my $newstring = "";
717
718	for ( my $i = 0; $i <= $#{$codeblock}; $i++ )
719	{
720		if ( ${$codeblock}[$i] =~ /^\s*$language\s*\=\s*\"(.*)\"\s*$/ )
721		{
722			$newstring = $1;
723			last;
724		}
725	}
726
727	return $newstring;
728}
729
730##############################################################
731# Translating an idt file
732##############################################################
733
734sub translate_idtfile
735{
736	my ($idtfile, $languagefile, $onelanguage) = @_;
737
738	for ( my $i = 0; $i <= $#{$idtfile}; $i++ )
739	{
740		my @allstrings = ();
741
742		my $oneline = ${$idtfile}[$i];
743
744		while ( $oneline =~ /\b(OOO_\w+)\b/ )
745		{
746			my $replacestring = $1;
747			push(@allstrings, $replacestring);
748			$oneline =~ s/$replacestring//;
749		}
750
751		my $oldstring;
752
753		foreach $oldstring (@allstrings)
754		{
755			my $language_block = get_language_block_from_language_file($oldstring, $languagefile);
756			my $newstring = get_language_string_from_language_block($language_block, $onelanguage, $oldstring);
757
758			# if (!( $newstring eq "" )) { ${$idtfile}[$i] =~ s/$oldstring/$newstring/; }
759			${$idtfile}[$i] =~ s/$oldstring/$newstring/;	# always substitute, even if $newstring eq "" (there are empty strings for control.idt)
760		}
761	}
762}
763
764##############################################################
765# Copying all needed files to create a msi database
766# into one language specific directory
767##############################################################
768
769sub prepare_language_idt_directory
770{
771	my ($destinationdir, $newidtdir, $onelanguage, $filesref, $iconfilecollector, $binarytablefiles, $allvariables) = @_;
772
773	# Copying all idt-files from the source $installer::globals::idttemplatepath to the destination $destinationdir
774	# Copying all files in the subdirectory "Binary"
775	# Copying all files in the subdirectory "Icon"
776
777	my $infoline = "";
778
779	installer::systemactions::copy_directory($installer::globals::idttemplatepath, $destinationdir);
780
781	if ( -d $installer::globals::idttemplatepath . $installer::globals::separator . "Binary")
782	{
783		installer::systemactions::create_directory($destinationdir . $installer::globals::separator . "Binary");
784		installer::systemactions::copy_directory($installer::globals::idttemplatepath . $installer::globals::separator . "Binary", $destinationdir . $installer::globals::separator . "Binary");
785
786		if ((( $installer::globals::patch ) && ( $allvariables->{'WINDOWSPATCHBITMAPDIRECTORY'} )) || ( $allvariables->{'WINDOWSBITMAPDIRECTORY'} ))
787		{
788			my $bitmapdir = "";
789			if ( $allvariables->{'WINDOWSPATCHBITMAPDIRECTORY'} ) { $bitmapdir = $allvariables->{'WINDOWSPATCHBITMAPDIRECTORY'}; }
790			if ( $allvariables->{'WINDOWSBITMAPDIRECTORY'} ) { $bitmapdir = $allvariables->{'WINDOWSBITMAPDIRECTORY'}; }
791
792			my $newsourcedir = $installer::globals::unpackpath . $installer::globals::separator . $bitmapdir; # path setting in list file dependent from unpackpath !?
793            $installer::logger::Lang->printf("\n");
794            $installer::logger::Lang->printf(
795                "Overwriting files in directory \"%s%sBinary\" with files from directory \"%s\".\n",
796                $destinationdir,
797                $installer::globals::separator,
798                $newsourcedir);
799			if ( ! -d $newsourcedir )
800			{
801				my $currentdir = cwd();
802				installer::exiter::exit_program("ERROR: Directory $newsourcedir does not exist! Current directory is: $currentdir", "prepare_language_idt_directory");
803			}
804			installer::systemactions::copy_directory($newsourcedir, $destinationdir . $installer::globals::separator . "Binary");
805		}
806	}
807
808	installer::systemactions::create_directory($destinationdir . $installer::globals::separator . "Icon");
809
810	if ( -d $installer::globals::idttemplatepath . $installer::globals::separator . "Icon")
811	{
812		installer::systemactions::copy_directory($installer::globals::idttemplatepath . $installer::globals::separator . "Icon", $destinationdir . $installer::globals::separator . "Icon");
813	}
814
815	# Copying all files in $iconfilecollector, that describe icons of folderitems
816
817	for ( my $i = 0; $i <= $#{$iconfilecollector}; $i++ )
818	{
819		my $iconfilename = ${$iconfilecollector}[$i];
820		installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$iconfilename);
821		installer::systemactions::copy_one_file(${$iconfilecollector}[$i], $destinationdir . $installer::globals::separator . "Icon" . $installer::globals::separator . $iconfilename);
822	}
823
824	# Copying all files in $binarytablefiles in the binary directory
825
826	for ( my $i = 0; $i <= $#{$binarytablefiles}; $i++ )
827	{
828		my $binaryfile = ${$binarytablefiles}[$i];
829		my $binaryfilepath = $binaryfile->{'sourcepath'};
830		my $binaryfilename = $binaryfilepath;
831		installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$binaryfilename);
832		installer::systemactions::copy_one_file($binaryfilepath, $destinationdir . $installer::globals::separator . "Binary" . $installer::globals::separator . $binaryfilename);
833	}
834
835	# Copying all new created and language independent idt-files to the destination $destinationdir.
836	# Example: "File.idt"
837
838	installer::systemactions::copy_directory_with_fileextension($newidtdir, $destinationdir, "idt");
839
840	# Copying all new created and language dependent idt-files to the destination $destinationdir.
841	# Example: "Feature.idt.01"
842
843	installer::systemactions::copy_directory_with_fileextension($newidtdir, $destinationdir, $onelanguage);
844	installer::systemactions::rename_files_with_fileextension($destinationdir, $onelanguage);
845
846}
847
848##############################################################
849# Returning the source path of the rtf licensefile for
850# a specified language
851##############################################################
852
853sub get_rtflicensefilesource
854{
855	my ($language, $includepatharrayref) = @_;
856
857	my $licensefilename = "license_" . $language . ".rtf";
858
859	my $sourcefileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$licensefilename, $includepatharrayref, 1);
860
861	if ($$sourcefileref eq "") { installer::exiter::exit_program("ERROR: Could not find $licensefilename!", "get_rtflicensefilesource"); }
862
863    $installer::logger::Lang->printf("Using licensefile: %s\n", $$sourcefileref);
864
865	return $$sourcefileref;
866}
867
868##############################################################
869# Returning the source path of the licensefile for
870# a specified language
871##############################################################
872
873sub get_licensefilesource
874{
875	my ($language, $filesref) = @_;
876
877	my $licensefilename = "license_" . $language . ".txt";
878	my $sourcepath = "";
879	my $foundlicensefile = 0;
880
881	for ( my $i = 0; $i <= $#{$filesref}; $i++ )
882	{
883		my $onefile = ${$filesref}[$i];
884		my $filename = $onefile->{'Name'};
885
886		if ($filename eq $licensefilename)
887		{
888			$sourcepath = $onefile->{'sourcepath'};
889			$foundlicensefile = 1;
890			last;
891		}
892	}
893
894	if ( ! $foundlicensefile ) { installer::exiter::exit_program("ERROR: Did not find file $licensefilename in file collector!", "get_licensefilesource"); }
895
896	return $sourcepath;
897}
898
899##############################################################
900# A simple converter to create the license text
901# in rtf format
902##############################################################
903
904sub get_rtf_licensetext
905{
906	my ($licensefile) = @_;
907
908	# A very simple rtf converter
909
910	# The static header
911
912	my $rtf_licensetext = '{\rtf1\ansi\deff0';
913	$rtf_licensetext = $rtf_licensetext . '{\fonttbl{\f0\froman\fprq2\fcharset0 Times New Roman;}}';
914	$rtf_licensetext = $rtf_licensetext . '{\colortbl\red0\green0\blue0;\red255\green255\blue255;\red128\green128\blue128;}';
915	$rtf_licensetext = $rtf_licensetext . '{\stylesheet{\s1\snext1 Standard;}}';
916	$rtf_licensetext = $rtf_licensetext . '{\info{\comment StarWriter}{\vern5690}}\deftab709';
917	$rtf_licensetext = $rtf_licensetext . '{\*\pgdsctbl';
918	$rtf_licensetext = $rtf_licensetext . '{\pgdsc0\pgdscuse195\pgwsxn11905\pghsxn16837\marglsxn1134\margrsxn1134\margtsxn1134\margbsxn1134\pgdscnxt0 Standard;}}';
919	$rtf_licensetext = $rtf_licensetext . '\paperh16837\paperw11905\margl1134\margr1134\margt1134\margb1134\sectd\sbknone\pgwsxn11905\pghsxn16837\marglsxn1134\margrsxn1134\margtsxn1134\margbsxn1134\ftnbj\ftnstart1\ftnrstcont\ftnnar\aenddoc\aftnrstcont\aftnstart1\aftnnrlc';
920	$rtf_licensetext = $rtf_licensetext . '\pard\plain \s1';
921
922	for ( my $i = 0; $i <= $#{$licensefile}; $i++ )
923	{
924		my $oneline = ${$licensefile}[$i];
925		# if  ( $oneline =~ /^\s*$/ ) { $oneline = '\par'; }	# empty lines
926
927		if ( $i == 0 ) { $oneline =~ s/^\W*//; }
928
929		$oneline =~ s/\t/    /g;		# no tabs allowed, converting to four spaces
930		$oneline =~ s/\n$//g;			# no newline at line end
931
932#		$oneline =~ s/�/\\\'e4/g;			# converting "�"
933#		$oneline =~ s/�/\\\'f6/g;			# converting "�"
934#		$oneline =~ s/�/\\\'fc/g;			# converting "�"
935#		$oneline =~ s/�/\\\'df/g;			# converting "�"
936
937		# german replacements
938
939		$oneline =~ s/\�\�/\\\'c4/g;		# converting "�"
940		$oneline =~ s/\�\�/\\\'d6/g;		# converting "�"
941		$oneline =~ s/\�\�/\\\'dc/g;		# converting "�"
942		$oneline =~ s/\�\�/\\\'e4/g;		# converting "�"
943		$oneline =~ s/\�\�/\\\'f6/g;		# converting "�"
944		$oneline =~ s/\�\�/\\\'fc/g;		# converting "�"
945		$oneline =~ s/\�\�/\\\'df/g;		# converting "�"
946
947		# french replacements
948
949		$oneline =~ s/\�\�/\\\'c9/g;
950		$oneline =~ s/\�\�/\\\'c0/g;
951		$oneline =~ s/\�\�/\\\'ab/g;
952		$oneline =~ s/\�\�/\\\'bb/g;
953		$oneline =~ s/\�\�/\\\'e9/g;
954		$oneline =~ s/\�\�/\\\'e8/g;
955		$oneline =~ s/\�\�/\\\'e0/g;
956		$oneline =~ s/\�\�/\\\'f4/g;
957		$oneline =~ s/\�\�/\\\'e7/g;
958		$oneline =~ s/\�\�/\\\'ea/g;
959		$oneline =~ s/\�\�/\\\'ca/g;
960		$oneline =~ s/\�\�/\\\'fb/g;
961		$oneline =~ s/\�\�/\\\'f9/g;
962		$oneline =~ s/\�\�/\\\'ee/g;
963
964		# quotation marks
965
966		$oneline =~ s/\�\�\�/\\\'84/g;
967		$oneline =~ s/\�\�\�/\\ldblquote/g;
968		$oneline =~ s/\�\�\�/\\rquote/g;
969
970
971		$oneline =~ s/\�\�/\\\~/g;
972
973		$oneline = '\par ' . $oneline;
974
975		$rtf_licensetext = $rtf_licensetext .  $oneline;
976	}
977
978	# and the end
979
980	$rtf_licensetext = $rtf_licensetext . '\par \par }';
981
982	return $rtf_licensetext;
983}
984
985##############################################################
986# A simple converter to create a license txt string from
987# the rtf format
988##############################################################
989
990sub make_string_licensetext
991{
992	my ($licensefile) = @_;
993
994	my $rtf_licensetext = "";
995
996	for ( my $i = 0; $i <= $#{$licensefile}; $i++ )
997	{
998		my $oneline = ${$licensefile}[$i];
999		$oneline =~ s/\s*$//g;		# no whitespace at line end
1000
1001		$rtf_licensetext = $rtf_licensetext .  $oneline . " ";
1002	}
1003
1004	return $rtf_licensetext;
1005}
1006
1007##############################################################
1008# Setting the path, where the soffice.exe is installed, into
1009# the CustomAction table
1010##############################################################
1011
1012sub add_officedir_to_database
1013{
1014	my ($basedir, $allvariables) = @_;
1015
1016	my $customactionfilename = $basedir . $installer::globals::separator . "CustomAc.idt";
1017
1018	my $customacfile = installer::files::read_file($customactionfilename);
1019
1020	my $found = 0;
1021
1022	# Updating the values
1023
1024	if ( $installer::globals::officeinstalldirectoryset )
1025	{
1026		$found = 0;
1027
1028		for ( my $i = 0; $i <= $#{$customacfile}; $i++ )
1029		{
1030			if ( ${$customacfile}[$i] =~ /\bOFFICEDIRECTORYGID\b/ )
1031			{
1032				${$customacfile}[$i] =~ s/\bOFFICEDIRECTORYGID\b/$installer::globals::officeinstalldirectory/;
1033				$found = 1;
1034			}
1035		}
1036
1037		if (( ! $found ) && ( ! $allvariables->{'IGNOREDIRECTORYLAYER'} ))
1038		{
1039			installer::exiter::exit_program("ERROR: \"OFFICEDIRECTORYGID\" not found in \"$customactionfilename\" !", "add_officedir_to_database");
1040		}
1041	}
1042
1043	# Saving the file
1044
1045	installer::files::save_file($customactionfilename ,$customacfile);
1046	my $infoline = "Updated idt file: $customactionfilename\n";
1047	$installer::logger::Lang->print($infoline);
1048
1049}
1050
1051##############################################################
1052# Including the license text into the table control.idt
1053##############################################################
1054
1055sub add_licensefile_to_database
1056{
1057	my ($licensefile, $controltable) = @_;
1058
1059	# Nine tabs before the license text and two tabs after it
1060	# The license text has to be included into the dialog
1061	# LicenseAgreement into the control Memo.
1062
1063	my $foundlicenseline = 0;
1064	my ($number, $line);
1065
1066	for ( my $i = 0; $i <= $#{$controltable}; $i++ )
1067	{
1068		$line = ${$controltable}[$i];
1069
1070		if ( $line =~ /^\s*\bLicenseAgreement\b\t\bMemo\t/ )
1071		{
1072			$foundlicenseline = 1;
1073			$number = $i;
1074			last;
1075		}
1076	}
1077
1078	if (!($foundlicenseline))
1079	{
1080		installer::exiter::exit_program("ERROR: Line for license file in Control.idt not found!", "add_licensefile_to_database");
1081	}
1082	else
1083	{
1084		my %control = ();
1085
1086		if ( $line =~ /^\s*(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\s*$/ )
1087		{
1088			$control{'Dialog_'} = $1;
1089			$control{'Control'} = $2;
1090			$control{'Type'} = $3;
1091			$control{'X'} = $4;
1092			$control{'Y'} = $5;
1093			$control{'Width'} = $6;
1094			$control{'Height'} = $7;
1095			$control{'Attributes'} = $8;
1096			$control{'Property'} = $9;
1097			$control{'Text'} = $10;
1098			$control{'Control_Next'} = $11;
1099			$control{'Help'} = $12;
1100		}
1101		else
1102		{
1103			installer::exiter::exit_program("ERROR: Could not split line correctly!", "add_licensefile_to_database");
1104		}
1105
1106		# my $licensetext = get_rtf_licensetext($licensefile);
1107		my $licensetext = make_string_licensetext($licensefile);
1108
1109		$control{'Text'} = $licensetext;
1110
1111		my $newline = $control{'Dialog_'} . "\t" . $control{'Control'} . "\t" . $control{'Type'} . "\t" .
1112						$control{'X'} . "\t" . $control{'Y'} . "\t" . $control{'Width'} . "\t" .
1113						$control{'Height'} . "\t" . $control{'Attributes'} . "\t" . $control{'Property'} . "\t" .
1114						$control{'Text'} . "\t" . $control{'Control_Next'} . "\t" . $control{'Help'} . "\n";
1115
1116		${$controltable}[$number] = $newline
1117	}
1118}
1119
1120################################################################################################
1121# Including the checkboxes for the language selection dialog
1122# into the table control.idt . This is only relevant for
1123# multilingual installation sets.
1124#
1125# old:
1126# LanguageSelection	CheckBox1	CheckBox	22	60	15	24	3	IS1033		CheckBox2
1127# LanguageSelection	Text1	Text	40	60	70	15	65539		OOO_CONTROL_LANG_1033
1128# LanguageSelection	CheckBox2	CheckBox	22	90	15	24	3	IS1031		Next
1129# LanguageSelection	Text2	Text	40	90	70	15	65539		OOO_CONTROL_LANG_1031
1130# new:
1131# LanguageSelection	CheckBox1	CheckBox	22	60	15	24	3	IS1033	Text	CheckBox2
1132# LanguageSelection	CheckBox2	CheckBox	22	90	15	24	3	IS1031	Text	Next
1133################################################################################################
1134
1135sub add_language_checkboxes_to_database
1136{
1137	my ($controltable, $languagesarrayref) = @_;
1138
1139	# for each language, two lines have to be inserted
1140
1141	for ( my $i = 0; $i <= $#{$languagesarrayref}; $i++ )
1142	{
1143		my $last = 0;
1144		if ( $i == $#{$languagesarrayref} ) { $last = 1; }		# special handling for the last
1145
1146		my $onelanguage = ${$languagesarrayref}[$i];
1147		my $windowslanguage = installer::windows::language::get_windows_language($onelanguage);
1148
1149		# my $is_english = 0;
1150		# if ( $windowslanguage eq "1033" ) { $is_english = 1; }
1151
1152		my $checkboxattribute = "3";
1153		# if ( $is_english ) { $checkboxattribute = "1"; }	# english is not deselectable
1154
1155		my $count = $i + 1;
1156		my $nextcount = $i + 2;
1157		my $checkboxcount = "CheckBox" . $count;
1158
1159		my $multiplier = 20;
1160		my $offset = 60;
1161		if ( $#{$languagesarrayref} > 7 )
1162		{
1163			$multiplier = 15;	# smaller differences for more than 7 languages
1164			$offset = 50;		# smaller offset for more than 7 languages
1165		}
1166
1167		my $yvalue = $offset + $i * $multiplier;
1168
1169		my $property = "IS" . $windowslanguage;
1170	#	if ( ! exists($installer::globals::languageproperties{$property}) ) { installer::exiter::exit_program("ERROR: Could not find property \"$property\" in the list of language properties!", "add_language_checkboxes_to_database"); }
1171
1172		my $controlnext = "";
1173		if ( $last ) { $controlnext = "Next"; }
1174		else { $controlnext = "CheckBox" . $nextcount; }
1175
1176		my $stringname = "OOO_CONTROL_LANG_" . $windowslanguage;
1177
1178		my $line1 = "LanguageSelection" . "\t" . $checkboxcount . "\t" . "CheckBox" . "\t" .
1179					"22" . "\t" . $yvalue . "\t" . "200" . "\t" . "15" . "\t" . $checkboxattribute . "\t" .
1180					$property . "\t" . $stringname . "\t" . $controlnext . "\t" . "\n";
1181
1182		push(@{$controltable}, $line1);
1183
1184	#	my $textcount = "Text" . $count;
1185	#	my $stringname = "OOO_CONTROL_LANG_" . $windowslanguage;
1186	#
1187	#	$yvalue = $yvalue + 2;		# text 2 pixel lower than checkbox
1188	#
1189	#	my $line2 = "LanguageSelection" . "\t" . $textcount . "\t" . "Text" . "\t" .
1190	#				"40" . "\t" . $yvalue . "\t" . "70" . "\t" . "15" . "\t" . "65539" . "\t" .
1191	#				"\t" . $stringname . "\t" . "\t" . "\n";
1192	#
1193	#	push(@{$controltable}, $line2);
1194	}
1195}
1196
1197###################################################################
1198# Determining the last position in a sequencetable
1199# into the tables CustomAc.idt and InstallE.idt.
1200###################################################################
1201
1202sub get_last_position_in_sequencetable
1203{
1204	my ($sequencetable) = @_;
1205
1206	my $position = 0;
1207
1208	for ( my $i = 0; $i <= $#{$sequencetable}; $i++ )
1209	{
1210		my $line = ${$sequencetable}[$i];
1211
1212		if ( $line =~ /^\s*\w+\t.*\t\s*(\d+)\s$/ )
1213		{
1214			my $newposition = $1;
1215			if ( $newposition > $position ) { $position = $newposition; }
1216		}
1217	}
1218
1219	return $position;
1220}
1221
1222#########################################################################
1223# Determining the position of a specified Action in the sequencetable
1224#########################################################################
1225
1226sub get_position_in_sequencetable
1227{
1228	my ($action, $sequencetable) = @_;
1229
1230	my $position = 0;
1231
1232	$action =~ s/^\s*behind_//;
1233
1234	for ( my $i = 0; $i <= $#{$sequencetable}; $i++ )
1235	{
1236		my $line = ${$sequencetable}[$i];
1237
1238		if ( $line =~ /^\s*(\w+)\t.*\t\s*(\d+)\s$/ )
1239		{
1240			my $compareaction = $1;
1241			$position = $2;
1242			if ( $compareaction eq $action ) { last; }
1243		}
1244	}
1245
1246	return $position;
1247}
1248
1249################################################################################################
1250# Including the CustomAction for the configuration
1251# into the tables CustomAc.idt and InstallE.idt.
1252#
1253# CustomAc.idt: ExecutePkgchk 82 pkgchk.exe -s
1254# InstallE.idt: ExecutePkgchk Not REMOVE="ALL" 3175
1255#
1256# CustomAc.idt: ExecuteQuickstart 82 install_quickstart.exe
1257# InstallE.idt: ExecuteQuickstart &gm_o_Quickstart=3 3200
1258#
1259# CustomAc.idt: ExecuteInstallRegsvrex 82 regsvrex.exe shlxthdl.dll
1260# InstallE.idt: ExecuteInstallRegsvrex Not REMOVE="ALL" 3225
1261#
1262# CustomAc.idt: ExecuteUninstallRegsvrex 82 regsvrex.exe /u shlxthdl.dll
1263# InstallE.idt: ExecuteUninstallRegsvrex REMOVE="ALL" 690
1264#
1265# CustomAc.idt: Regmsdocmsidll1 1 reg4msdocmsidll Reg4MsDocEntry
1266# InstallU.idt: Regmsdocmsidll1 Not REMOVE="ALL" 610
1267#
1268# CustomAc.idt: Regmsdocmsidll2 1 reg4msdocmsidll Reg4MsDocEntry
1269# InstallE.idt: Regmsdocmsidll2 Not REMOVE="ALL" 3160
1270################################################################################################
1271
1272sub set_custom_action
1273{
1274	my ($customactionidttable, $actionname, $actionflags, $exefilename, $actionparameter, $inbinarytable, $filesref, $customactionidttablename, $styles) = @_;
1275
1276	my $included_customaction = 0;
1277	my $infoline = "";
1278	my $customaction_exefilename = $exefilename;
1279	my $uniquename = "";
1280
1281    # when the style NO_FILE is set, no searching for the file is needed, no filtering is done, we can add that custom action
1282    if ( $styles =~ /\bNO_FILE\b/ )
1283    {
1284		my $line = $actionname . "\t" . $actionflags . "\t" . $customaction_exefilename . "\t" . $actionparameter . "\n";
1285		push(@{$customactionidttable}, $line);
1286
1287        $infoline = "Added $actionname CustomAction into table $customactionidttablename (NO_FILE has been set)\n";
1288        $installer::logger::Lang->print($infoline);
1289
1290		$included_customaction = 1;
1291        return $included_customaction;
1292	}
1293
1294	# is the $exefilename a library that is included into the binary table
1295
1296	if ( $inbinarytable ) { $customaction_exefilename =~ s/\.//; }	# this is the entry in the binary table ("abc.dll" -> "abcdll")
1297
1298	# is the $exefilename included into the product?
1299
1300	my $contains_file = 0;
1301
1302	# All files are located in $filesref and in @installer::globals::binarytableonlyfiles.
1303	# Both must be added together
1304	my $localfilesref = installer::converter::combine_arrays_from_references(\@installer::globals::binarytableonlyfiles, $filesref);
1305
1306	for ( my $i = 0; $i <= $#{$localfilesref}; $i++ )
1307	{
1308		my $onefile = ${$localfilesref}[$i];
1309		my $filename = "";
1310		if ( exists($onefile->{'Name'}) )
1311		{
1312			$filename = $onefile->{'Name'};
1313
1314			if ( $filename eq $exefilename )
1315			{
1316				$contains_file = 1;
1317				$uniquename = ${$localfilesref}[$i]->{'uniquename'};
1318				last;
1319			}
1320		}
1321		else
1322		{
1323			installer::exiter::exit_program("ERROR: Did not find \"Name\" for file \"$onefile->{'uniquename'}\" ($onefile->{'gid'})!", "set_custom_action");
1324		}
1325	}
1326
1327	if ( $contains_file )
1328	{
1329		# Now the CustomAction can be included into the CustomAc.idt
1330
1331		if ( ! $inbinarytable ) { $customaction_exefilename = $uniquename; }	# the unique file name has to be added to the custom action table
1332
1333		my $line = $actionname . "\t" . $actionflags . "\t" . $customaction_exefilename . "\t" . $actionparameter . "\n";
1334		push(@{$customactionidttable}, $line);
1335
1336		$included_customaction = 1;
1337	}
1338
1339	if ( $included_customaction ) { $infoline = "Added $actionname CustomAction into table $customactionidttablename\n"; }
1340	else { $infoline = "Did not add $actionname CustomAction into table $customactionidttablename\n"; }
1341	$installer::logger::Lang->print($infoline);
1342
1343	return $included_customaction;
1344}
1345
1346####################################################################
1347# Adding a Custom Action to InstallExecuteTable or InstallUITable
1348####################################################################
1349
1350sub add_custom_action_to_install_table
1351{
1352	my ($installtable, $exefilename, $actionname, $actioncondition, $position, $filesref, $installtablename, $styles) = @_;
1353
1354	my $included_customaction = 0;
1355	my $feature = "";
1356	my $infoline = "";
1357
1358    # when the style NO_FILE is set, no searching for the file is needed, no filtering is done, we can add that custom action
1359    if ( $styles =~ /\bNO_FILE\b/ )
1360    {
1361		# then the InstallE.idt.idt or InstallU.idt.idt
1362		$actioncondition =~ s/FEATURETEMPLATE/$feature/g;	# only execute Custom Action, if feature of the file is installed
1363
1364		my $actionposition = 0;
1365
1366		if ( $position eq "end" ) { $actionposition = get_last_position_in_sequencetable($installtable) + 25; }
1367		elsif ( $position =~ /^\s*behind_/ ) { $actionposition = get_position_in_sequencetable($position, $installtable) + 2; }
1368		else { $actionposition = get_position_in_sequencetable($position, $installtable) - 2; }
1369
1370		my $line = $actionname . "\t" . $actioncondition . "\t" . $actionposition . "\n";
1371		push(@{$installtable}, $line);
1372
1373        $infoline = "Added $actionname CustomAction into table $installtablename (NO_FILE has been set)\n";
1374    	$installer::logger::Lang->print($infoline);
1375        return;
1376	}
1377
1378	my $contains_file = 0;
1379
1380	# All files are located in $filesref and in @installer::globals::binarytableonlyfiles.
1381	# Both must be added together
1382	my $localfilesref = installer::converter::combine_arrays_from_references(\@installer::globals::binarytableonlyfiles, $filesref);
1383
1384	for ( my $i = 0; $i <= $#{$localfilesref}; $i++ )
1385	{
1386		my $filename = ${$localfilesref}[$i]->{'Name'};
1387
1388		if ( $filename eq $exefilename )
1389		{
1390			$contains_file = 1;
1391
1392			# Determining the feature of the file
1393
1394			if ( ${$localfilesref}[$i] ) { $feature = ${$localfilesref}[$i]->{'modules'}; }
1395
1396			# If modules contains a list of modules, only taking the first one.
1397			if ( $feature =~ /^\s*(.*?)\,/ ) { $feature = $1; }
1398			# Attention: Maximum feature length is 38!
1399			shorten_feature_gid(\$feature);
1400
1401			last;
1402		}
1403	}
1404
1405	if ( $contains_file )
1406	{
1407		# then the InstallE.idt.idt or InstallU.idt.idt
1408
1409		$actioncondition =~ s/FEATURETEMPLATE/$feature/g;	# only execute Custom Action, if feature of the file is installed
1410
1411#		my $actionposition = 0;
1412#		if ( $position eq "end" ) { $actionposition = get_last_position_in_sequencetable($installtable) + 25; }
1413#		elsif ( $position =~ /^\s*behind_/ ) { $actionposition = get_position_in_sequencetable($position, $installtable) + 2; }
1414#		else { $actionposition = get_position_in_sequencetable($position, $installtable) - 2; }
1415#		my $line = $actionname . "\t" . $actioncondition . "\t" . $actionposition . "\n";
1416
1417		my $positiontemplate = "";
1418		if ( $position =~ /^\s*\d+\s*$/ ) { $positiontemplate = $position; }	# setting the position directly, number defined in scp2
1419		else { $positiontemplate = "POSITIONTEMPLATE_" . $position; }
1420
1421		my $line = $actionname . "\t" . $actioncondition . "\t" . $positiontemplate . "\n";
1422		push(@{$installtable}, $line);
1423
1424		$included_customaction = 1;
1425	}
1426
1427	if ( $included_customaction ) { $infoline = "Added $actionname CustomAction into table $installtablename\n"; }
1428	else { $infoline = "Did not add $actionname CustomAction into table $installtablename\n"; }
1429	$installer::logger::Lang->print($infoline);
1430
1431}
1432
1433##################################################################
1434# A line in the table ControlEvent connects a Control
1435# with a Custom Action
1436#################################################################
1437
1438sub connect_custom_action_to_control
1439{
1440	my ( $table, $tablename, $dialog, $control, $event, $argument, $condition, $ordering) = @_;
1441
1442	my $line = $dialog . "\t" . $control. "\t" . $event. "\t" . $argument. "\t" . $condition. "\t" . $ordering . "\n";
1443
1444	push(@{$table}, $line);
1445
1446	$line =~ s/\s*$//g;
1447
1448	$infoline = "Added line \"$line\" into table $tablename\n";
1449	$installer::logger::Lang->print($infoline);
1450}
1451
1452##################################################################
1453# A line in the table ControlCondition connects a Control state
1454# with a condition
1455##################################################################
1456
1457sub connect_condition_to_control
1458{
1459	my ( $table, $tablename, $dialog, $control, $event, $condition) = @_;
1460
1461	my $line = $dialog . "\t" . $control. "\t" . $event. "\t" . $condition. "\n";
1462
1463	push(@{$table}, $line);
1464
1465	$line =~ s/\s*$//g;
1466
1467	$infoline = "Added line \"$line\" into table $tablename\n";
1468	$installer::logger::Lang->print($infoline);
1469}
1470
1471##################################################################
1472# Searching for a sequencenumber in InstallUISequence table
1473# "ExecuteAction" must be the last action
1474##################################################################
1475
1476sub get_free_number_in_uisequence_table
1477{
1478	my ( $installuitable ) = @_;
1479
1480	# determining the sequence of "ExecuteAction"
1481
1482	my $executeactionnumber = 0;
1483
1484	for ( my $i = 0; $i <= $#{$installuitable}; $i++ )
1485	{
1486		if ( ${$installuitable}[$i] =~ /^\s*(\w+)\t\w*\t(\d+)\s*$/ )
1487		{
1488			my $actionname = $1;
1489			my $actionnumber = $2;
1490
1491			if ( $actionname eq "ExecuteAction" )
1492			{
1493				$executeactionnumber = $actionnumber;
1494				last;
1495			}
1496		}
1497	}
1498
1499	if ( $executeactionnumber == 0 ) { installer::exiter::exit_program("ERROR: Did not find \"ExecuteAction\" in InstallUISequence table!", "get_free_number_in_uisequence_table"); }
1500
1501	# determining the sequence of the action before "ExecuteAction"
1502
1503	my $lastactionnumber = 0;
1504
1505	for ( my $i = 0; $i <= $#{$installuitable}; $i++ )
1506	{
1507		if ( ${$installuitable}[$i] =~ /^\s*\w+\t\w*\t(\d+)\s*$/ )
1508		{
1509			my $actionnumber = $1;
1510
1511			if (( $actionnumber > $lastactionnumber ) && ( $actionnumber != $executeactionnumber ))
1512			{
1513				$lastactionnumber = $actionnumber;
1514			}
1515		}
1516	}
1517
1518	# the new number can now be calculated
1519
1520	my $newnumber = 0;
1521
1522	if ((( $lastactionnumber + $executeactionnumber ) % 2 ) == 0 ) { $newnumber = ( $lastactionnumber + $executeactionnumber ) / 2; }
1523	else { $newnumber = ( $lastactionnumber + $executeactionnumber -1 ) / 2; }
1524
1525	return $newnumber;
1526}
1527
1528##################################################################
1529# Searching for a specified string in the feature table
1530##################################################################
1531
1532sub get_feature_name
1533{
1534	my ( $string, $featuretable ) = @_;
1535
1536	my $featurename = "";
1537
1538	for ( my $i = 0; $i <= $#{$featuretable}; $i++ )
1539	{
1540		if ( ${$featuretable}[$i] =~ /^\s*(\w+$string)\t/ )
1541		{
1542			$featurename = $1;
1543			last;
1544		}
1545	}
1546
1547	return $featurename;
1548}
1549
1550######################################################################
1551# Returning the toplevel directory name of one specific file
1552######################################################################
1553
1554sub get_directory_name_from_file
1555{
1556	my ($onefile) = @_;
1557
1558	my $destination = $onefile->{'destination'};
1559	my $name = $onefile->{'Name'};
1560
1561	$destination =~ s/\Q$name\E\s*$//;
1562	$destination =~ s/\Q$installer::globals::separator\E\s*$//;
1563
1564	my $path = "";
1565
1566	if ( $destination =~ /\Q$installer::globals::separator\E/ )
1567	{
1568		if ( $destination =~ /^\s*(\S.*\S\Q$installer::globals::separator\E)(\S.+\S?)/ )
1569		{
1570			$path = $2;
1571		}
1572	}
1573	else
1574	{
1575		$path = $destination;
1576	}
1577
1578	return $path;
1579}
1580
1581#############################################################
1582# Including the new subdir into the directory table
1583#############################################################
1584
1585sub include_subdirname_into_directory_table
1586{
1587	my ($dirname, $directorytable, $directorytablename, $onefile) = @_;
1588
1589	my $subdir = "";
1590	if ( $onefile->{'Subdir'} ) { $subdir = $onefile->{'Subdir'}; }
1591	if ( $subdir eq "" ) { installer::exiter::exit_program("ERROR: No \"Subdir\" defined for $onefile->{'Name'}", "include_subdirname_into_directory_table"); }
1592
1593	# program INSTALLLOCATION program -> subjava INSTALLLOCATION program:java
1594
1595	my $uniquename = "";
1596	my $parent = "";
1597	my $name = "";
1598
1599	my $includedline = 0;
1600
1601	my $newdir = "";
1602
1603	for ( my $i = 0; $i <= $#{$directorytable}; $i++ )
1604	{
1605
1606		if ( ${$directorytable}[$i] =~ /^\s*(.*?)\t(.*?)\t(.*?)\s*$/ )
1607		{
1608			$uniquename = $1;
1609			$parent = $2;
1610			$name = $3;
1611
1612			if ( $dirname eq $name )
1613			{
1614				my $newuniquename = "sub" . $subdir;
1615				$newdir = $newuniquename;
1616				# my $newparent = $parent;
1617				my $newparent = "INSTALLLOCATION";
1618				my $newname = $name . "\:" . $subdir;
1619				my $newline =
1620				$line = "$newuniquename\t$newparent\t$newname\n";
1621				push(@{$directorytable}, $line);
1622				installer::remover::remove_leading_and_ending_whitespaces(\$line);
1623				$infoline = "Added $line into directory table $directorytablename\n";
1624				$installer::logger::Lang->print($infoline);
1625
1626				$includedline = 1;
1627				last;
1628			}
1629		}
1630	}
1631
1632	if ( ! $includedline ) { installer::exiter::exit_program("ERROR: Could not include new subdirectory into directory table for file $onefile->{'Name'}!", "include_subdirname_into_directory_table"); }
1633
1634	return $newdir;
1635}
1636
1637##################################################################
1638# Including the new sub directory into the component table
1639##################################################################
1640
1641sub include_subdir_into_componenttable
1642{
1643	my ($subdir, $onefile, $componenttable) = @_;
1644
1645	my $componentname = $onefile->{'componentname'};
1646
1647	my $changeddirectory = 0;
1648
1649	for ( my $i = 0; $i <= $#{$componenttable}; $i++ )
1650	{
1651		if ( ${$componenttable}[$i] =~ /^\s*(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\s*$/ )
1652		{
1653			my $localcomponentname = $1;
1654			my $directory = $3;
1655
1656			if ( $componentname eq $localcomponentname )
1657			{
1658				my $oldvalue = ${$componenttable}[$i];
1659				${$componenttable}[$i] =~ s/\b\Q$directory\E\b/$subdir/;
1660				my $newvalue = ${$componenttable}[$i];
1661
1662				installer::remover::remove_leading_and_ending_whitespaces(\$oldvalue);
1663				installer::remover::remove_leading_and_ending_whitespaces(\$newvalue);
1664				$infoline = "Change in Component table: From \"$oldvalue\" to \"$newvalue\"\n";
1665				$installer::logger::Lang->print($infoline);
1666
1667				$changeddirectory = 1;
1668				last;
1669			}
1670		}
1671	}
1672
1673	if ( ! $changeddirectory ) { installer::exiter::exit_program("ERROR: Could not change directory for component: $onefile->{'Name'}!", "include_subdir_into_componenttable"); }
1674
1675}
1676
1677################################################################################################
1678# Including the content for the child installations
1679# into the tables:
1680# CustomAc.idt, InstallU.idt, Feature.idt
1681################################################################################################
1682
1683sub add_childprojects
1684{
1685	my ($languageidtdir, $filesref, $allvariables) = @_;
1686
1687	my $customactiontablename = $languageidtdir . $installer::globals::separator . "CustomAc.idt";
1688	my $customactiontable = installer::files::read_file($customactiontablename);
1689	my $installuitablename = $languageidtdir . $installer::globals::separator . "InstallU.idt";
1690	my $installuitable = installer::files::read_file($installuitablename);
1691	my $featuretablename = $languageidtdir . $installer::globals::separator . "Feature.idt";
1692	my $featuretable = installer::files::read_file($featuretablename);
1693	my $directorytablename = $languageidtdir . $installer::globals::separator . "Director.idt";
1694	my $directorytable = installer::files::read_file($directorytablename);
1695	my $componenttablename = $languageidtdir . $installer::globals::separator . "Componen.idt";
1696	my $componenttable = installer::files::read_file($componenttablename);
1697
1698	my $infoline = "";
1699	my $line = "";
1700
1701	$installer::globals::javafile = installer::worker::return_first_item_with_special_flag($filesref ,"JAVAFILE");
1702	$installer::globals::urefile = installer::worker::return_first_item_with_special_flag($filesref ,"UREFILE");
1703
1704	if (( $installer::globals::javafile eq "" ) && ( $allvariables->{'JAVAPRODUCT'} )) { installer::exiter::exit_program("ERROR: No JAVAFILE found in files collector!", "add_childprojects"); }
1705	if (( $installer::globals::urefile eq "" ) && ( $allvariables->{'UREPRODUCT'} )) { installer::exiter::exit_program("ERROR: No UREFILE found in files collector!", "add_childprojects"); }
1706
1707	# Content for Directory table
1708	# SystemFolder TARGETDIR .
1709
1710	my $contains_systemfolder = 0;
1711
1712	for ( my $i = 0; $i <= $#{$directorytable}; $i++ )
1713	{
1714		if ( ${$directorytable}[$i] =~ /^\s*SystemFolder\t/ )
1715		{
1716			$contains_systemfolder = 1;
1717			last;
1718		}
1719	}
1720
1721	if ( ! $contains_systemfolder )
1722	{
1723		$line = "SystemFolder\tTARGETDIR\t\.\n";
1724		push(@{$directorytable}, $line);
1725		installer::remover::remove_leading_and_ending_whitespaces(\$line);
1726		$infoline = "Added $line into table $directorytablename\n";
1727	}
1728	else
1729	{
1730		$infoline = "SystemFolder already exists in table $directorytablename\n";
1731	}
1732
1733	$installer::logger::Lang->print($infoline);
1734
1735	# Additional content for the directory table
1736	# subjava 	INSTALLLOCATION program:java
1737	# subure 	INSTALLLOCATION program:ure
1738
1739	my $dirname = "";
1740	my $subjavadir = "";
1741	my $suburedir = "";
1742
1743	if ( $allvariables->{'JAVAPRODUCT'} )
1744	{
1745		$dirname = get_directory_name_from_file($installer::globals::javafile);
1746		$subjavadir = include_subdirname_into_directory_table($dirname, $directorytable, $directorytablename, $installer::globals::javafile);
1747	}
1748
1749	if ( $allvariables->{'UREPRODUCT'} )
1750	{
1751		$dirname = get_directory_name_from_file($installer::globals::urefile);
1752		$suburedir = include_subdirname_into_directory_table($dirname, $directorytable, $directorytablename, $installer::globals::urefile);
1753	}
1754
1755	# Content for the Component table
1756	# The Java and Ada components have new directories
1757
1758	if ( $allvariables->{'JAVAPRODUCT'} ) { include_subdir_into_componenttable($subjavadir, $installer::globals::javafile, $componenttable); }
1759	if ( $allvariables->{'UREPRODUCT'} ) { include_subdir_into_componenttable($suburedir, $installer::globals::urefile, $componenttable); }
1760
1761	# Content for CustomAction table
1762
1763	if ( $allvariables->{'JAVAPRODUCT'} )
1764	{
1765		$line = "InstallJava\t98\tSystemFolder\t[SourceDir]$installer::globals::javafile->{'Subdir'}\\$installer::globals::javafile->{'Name'} \/qb REBOOT=Suppress SPONSORS=0 DISABLEAD=1\n";
1766		push(@{$customactiontable} ,$line);
1767		installer::remover::remove_leading_and_ending_whitespaces(\$line);
1768		$infoline = "Added $line into table $customactiontablename\n";
1769		$installer::logger::Lang->print($infoline);
1770	}
1771
1772	if ( $allvariables->{'UREPRODUCT'} )
1773	{
1774		$line = "InstallUre\t98\tSystemFolder\t$installer::globals::urefile->{'Subdir'}\\$installer::globals::urefile->{'Name'} /S\n";
1775		push(@{$customactiontable} ,$line);
1776		installer::remover::remove_leading_and_ending_whitespaces(\$line);
1777		$infoline = "Added $line into table $customactiontablename\n";
1778		$installer::logger::Lang->print($infoline);
1779	}
1780
1781	if ( $allvariables->{'JAVAPRODUCT'} )
1782	{
1783		$line = "MaintenanceJava\t82\t$installer::globals::javafile->{'uniquename'}\t\/qb REBOOT=Suppress SPONSORS=0 DISABLEAD=1\n";
1784		push(@{$customactiontable} ,$line);
1785		installer::remover::remove_leading_and_ending_whitespaces(\$line);
1786		$infoline = "Added $line into table $customactiontablename\n";
1787		$installer::logger::Lang->print($infoline);
1788	}
1789
1790	if ( $allvariables->{'UREPRODUCT'} )
1791	{
1792		$line = "MaintenanceUre\t82\t$installer::globals::urefile->{'uniquename'}\t\/S\n";
1793		push(@{$customactiontable} ,$line);
1794		installer::remover::remove_leading_and_ending_whitespaces(\$line);
1795		$infoline = "Added $line into table $customactiontablename\n";
1796		$installer::logger::Lang->print($infoline);
1797	}
1798
1799	# Content for InstallUISequence table
1800	# InstallAdabas &gm_o_Adabas=3 825
1801	# InstallJava &gm_o_Java=3 827
1802
1803	my $number = "";
1804	my $featurename = "";
1805
1806	if ( $allvariables->{'ADAPRODUCT'} )
1807	{
1808		$number = get_free_number_in_uisequence_table($installuitable);
1809		$featurename = get_feature_name("_Adabas", $featuretable);
1810		$line = "InstallAdabas\t\&$featurename\=3 And Not Installed And Not PATCH\t$number\n";
1811		push(@{$installuitable} ,$line);
1812		installer::remover::remove_leading_and_ending_whitespaces(\$line);
1813		$infoline = "Added $line into table $installuitablename\n";
1814		$installer::logger::Lang->print($infoline);
1815	}
1816
1817	if ( $allvariables->{'JAVAPRODUCT'} )
1818	{
1819		$number = get_free_number_in_uisequence_table($installuitable) + 2;
1820		$featurename = get_feature_name("_Java", $featuretable);
1821		if ( $featurename ) { $line = "InstallJava\t\&$featurename\=3 And Not Installed And JAVAPATH\=\"\" And Not PATCH\t$number\n"; }
1822		else { $line = "InstallJava\tNot Installed And JAVAPATH\=\"\" And Not PATCH\t$number\n"; } # feature belongs to root
1823		push(@{$installuitable} ,$line);
1824		installer::remover::remove_leading_and_ending_whitespaces(\$line);
1825		$infoline = "Added $line into table $installuitablename\n";
1826		$installer::logger::Lang->print($infoline);
1827	}
1828
1829	if ( $allvariables->{'ADAPRODUCT'} )
1830	{
1831		$number = get_free_number_in_uisequence_table($installuitable) + 4;
1832		$featurename = get_feature_name("_Adabas", $featuretable);
1833		$line = "MaintenanceAdabas\t\&$featurename\=3 And Installed And Not PATCH\t$number\n";
1834		push(@{$installuitable} ,$line);
1835		installer::remover::remove_leading_and_ending_whitespaces(\$line);
1836		$infoline = "Added $line into table $installuitablename\n";
1837		$installer::logger::Lang->print($infoline);
1838	}
1839
1840	if ( $allvariables->{'JAVAPRODUCT'} )
1841	{
1842		$number = get_free_number_in_uisequence_table($installuitable) + 6;
1843		$featurename = get_feature_name("_Java", $featuretable);
1844		if ( $featurename ) { $line = "MaintenanceJava\t\&$featurename\=3 And Installed And JAVAPATH\=\"\" And Not PATCH\t$number\n"; }
1845		else { $line = "MaintenanceJava\tInstalled And JAVAPATH\=\"\" And Not PATCH\t$number\n"; } # feature belongs to root
1846		push(@{$installuitable} ,$line);
1847		installer::remover::remove_leading_and_ending_whitespaces(\$line);
1848		$infoline = "Added $line into table $installuitablename\n";
1849		$installer::logger::Lang->print($infoline);
1850	}
1851
1852	if ( $allvariables->{'UREPRODUCT'} )
1853	{
1854		$number = get_free_number_in_uisequence_table($installuitable) + 8;
1855		$featurename = get_feature_name("_Ure", $featuretable);
1856		if ( $featurename ) { $line = "InstallUre\t\&$featurename\=3 And Not Installed\t$number\n"; }
1857		else { $line = "InstallUre\tNot Installed\t$number\n"; } # feature belongs to root
1858		push(@{$installuitable} ,$line);
1859		installer::remover::remove_leading_and_ending_whitespaces(\$line);
1860		$infoline = "Added $line into table $installuitablename\n";
1861		$installer::logger::Lang->print($infoline);
1862	}
1863
1864	if ( $allvariables->{'UREPRODUCT'} )
1865	{
1866		$number = get_free_number_in_uisequence_table($installuitable) + 10;
1867		$featurename = get_feature_name("_Ure", $featuretable);
1868		if ( $featurename ) { $line = "MaintenanceUre\t\&$featurename\=3 And Installed\t$number\n"; }
1869		else { $line = "MaintenanceUre\tInstalled\t$number\n"; } # feature belongs to root
1870		push(@{$installuitable} ,$line);
1871		installer::remover::remove_leading_and_ending_whitespaces(\$line);
1872		$infoline = "Added $line into table $installuitablename\n";
1873		$installer::logger::Lang->print($infoline);
1874	}
1875
1876	# Content for Feature table, better from scp (translation)
1877	# gm_o_java gm_optional Java 1.4.2 Description 2 200
1878
1879	installer::files::save_file($customactiontablename, $customactiontable);
1880	installer::files::save_file($installuitablename, $installuitable);
1881	installer::files::save_file($featuretablename, $featuretable);
1882	installer::files::save_file($directorytablename, $directorytable);
1883	installer::files::save_file($componenttablename, $componenttable);
1884}
1885
1886##################################################################
1887# Setting the encoding in all idt files. Replacing the
1888# variable WINDOWSENCODINGTEMPLATE
1889##################################################################
1890
1891sub setencoding
1892{
1893	my ( $languageidtdir, $onelanguage ) = @_;
1894
1895	my $encoding = installer::windows::language::get_windows_encoding($onelanguage);
1896
1897	# collecting all idt files in the directory $languageidtdir and substituting the string
1898
1899	my $idtfiles = installer::systemactions::find_file_with_file_extension("idt", $languageidtdir);
1900
1901	for ( my $i = 0; $i <= $#{$idtfiles}; $i++ )
1902	{
1903		my $onefilename = $languageidtdir . $installer::globals::separator . ${$idtfiles}[$i];
1904		my $onefile = installer::files::read_file($onefilename);
1905
1906		for ( my $j = 0; $j <= $#{$onefile}; $j++ )
1907		{
1908			${$onefile}[$j] =~ s/WINDOWSENCODINGTEMPLATE/$encoding/g;
1909		}
1910
1911		installer::files::save_file($onefilename, $onefile);
1912	}
1913}
1914
1915##################################################################
1916# Setting the condition, that at least one module is selected.
1917# All modules with flag SHOW_MULTILINGUAL_ONLY were already
1918# collected. In table ControlE.idt, the string
1919# LANGUAGECONDITIONINSTALL needs to be replaced.
1920# Also for APPLICATIONCONDITIONINSTALL for the applications
1921# with flag APPLICATIONMODULE.
1922##################################################################
1923
1924sub set_multilanguageonly_condition
1925{
1926	my ( $languageidtdir ) = @_;
1927
1928	my $onefilename = $languageidtdir . $installer::globals::separator . "ControlE.idt";
1929	my $onefile = installer::files::read_file($onefilename);
1930
1931	# Language modules
1932
1933	my $condition = "";
1934
1935	foreach my $module ( sort keys %installer::globals::multilingual_only_modules )
1936	{
1937		$condition = $condition . " &$module=3 Or";
1938	}
1939
1940	$condition =~ s/^\s*//;
1941	$condition =~ s/\s*Or\s*$//;	# removing the ending "Or"
1942
1943	if ( $condition eq "" ) { $condition = "1"; }
1944
1945	for ( my $j = 0; $j <= $#{$onefile}; $j++ )
1946	{
1947		${$onefile}[$j] =~ s/LANGUAGECONDITIONINSTALL/$condition/;
1948	}
1949
1950	# Application modules
1951
1952	$condition = "";
1953
1954	foreach my $module ( sort keys %installer::globals::application_modules )
1955	{
1956		$condition = $condition . " &$module=3 Or";
1957	}
1958
1959	$condition =~ s/^\s*//;
1960	$condition =~ s/\s*Or\s*$//;	# removing the ending "Or"
1961
1962	if ( $condition eq "" ) { $condition = "1"; }
1963
1964	for ( my $j = 0; $j <= $#{$onefile}; $j++ )
1965	{
1966		${$onefile}[$j] =~ s/APPLICATIONCONDITIONINSTALL/$condition/;
1967	}
1968
1969	installer::files::save_file($onefilename, $onefile);
1970}
1971
1972#############################################
1973# Putting array values into hash
1974#############################################
1975
1976sub fill_assignment_hash
1977{
1978	my ($gid, $name, $key, $assignmenthashref, $parameter, $tablename, $assignmentarray) = @_;
1979
1980	my $max = $parameter - 1;
1981
1982	if ( $max != $#{$assignmentarray} )
1983	{
1984		my $definedparameter = $#{$assignmentarray} + 1;
1985		installer::exiter::exit_program("ERROR: gid: $gid, key: $key ! Wrong parameter in scp. For table $tablename $parameter parameter are required ! You defined: $definedparameter", "fill_assignment_hash");
1986	}
1987
1988	for ( my $i = 0; $i <= $#{$assignmentarray}; $i++ )
1989	{
1990		my $counter = $i + 1;
1991		my $key = "parameter". $counter;
1992
1993		my $localvalue = ${$assignmentarray}[$i];
1994		installer::remover::remove_leading_and_ending_quotationmarks(\$localvalue);
1995		$localvalue =~ s/\\\"/\"/g;
1996		$localvalue =~ s/\\\!/\!/g;
1997		$localvalue =~ s/\\\&/\&/g;
1998		$localvalue =~ s/\\\</\</g;
1999		$localvalue =~ s/\\\>/\>/g;
2000		$assignmenthashref->{$key} = $localvalue;
2001	}
2002}
2003
2004##########################################################################
2005# Checking the assignment of a Windows CustomAction and putting it
2006# into a hash
2007##########################################################################
2008
2009sub create_customaction_assignment_hash
2010{
2011	my ($gid, $name, $key, $assignmentarray) = @_;
2012
2013	my %assignment = ();
2014	my $assignmenthashref = \%assignment;
2015
2016	my $tablename = ${$assignmentarray}[0];
2017	installer::remover::remove_leading_and_ending_quotationmarks(\$tablename);
2018
2019	my $tablename_defined = 0;
2020	my $parameter = 0;
2021
2022	if ( $tablename eq "InstallUISequence" )
2023	{
2024		$tablename_defined = 1;
2025		$parameter = 3;
2026		fill_assignment_hash($gid, $name, $key, $assignmenthashref, $parameter, $tablename, $assignmentarray);
2027	}
2028
2029	if ( $tablename eq "InstallExecuteSequence" )
2030	{
2031		$tablename_defined = 1;
2032		$parameter = 3;
2033		fill_assignment_hash($gid, $name, $key, $assignmenthashref, $parameter, $tablename, $assignmentarray);
2034	}
2035
2036	if ( $tablename eq "AdminExecuteSequence" )
2037	{
2038		$tablename_defined = 1;
2039		$parameter = 3;
2040		fill_assignment_hash($gid, $name, $key, $assignmenthashref, $parameter, $tablename, $assignmentarray);
2041	}
2042
2043	if ( $tablename eq "ControlEvent" )
2044	{
2045		$tablename_defined = 1;
2046		$parameter = 7;
2047		fill_assignment_hash($gid, $name, $key, $assignmenthashref, $parameter, $tablename, $assignmentarray);
2048	}
2049
2050	if ( $tablename eq "ControlCondition" )
2051	{
2052		$tablename_defined = 1;
2053		$parameter = 5;
2054		fill_assignment_hash($gid, $name, $key, $assignmenthashref, $parameter, $tablename, $assignmentarray);
2055	}
2056
2057	if ( ! $tablename_defined )
2058	{
2059		installer::exiter::exit_program("ERROR: gid: $gid, key: $key ! Unknown Windows CustomAction table: $tablename ! Currently supported: InstallUISequence, InstallExecuteSequence, ControlEvent, ControlCondition", "create_customaction_assignment_hash");
2060	}
2061
2062	return $assignmenthashref;
2063}
2064
2065##########################################################################
2066# Finding the position of a specified CustomAction.
2067# If the CustomAction is not found, the return value is "-1".
2068# If the CustomAction position is not defined yet,
2069# the return value is also "-1".
2070##########################################################################
2071
2072sub get_customaction_position
2073{
2074	my ($action, $sequencetable) = @_;
2075
2076	my $position = -1;
2077
2078	for ( my $i = 0; $i <= $#{$sequencetable}; $i++ )
2079	{
2080		my $line = ${$sequencetable}[$i];
2081
2082		if ( $line =~ /^\s*([\w\.]+)\t.*\t\s*(\d+)\s$/ )	# matching only, if position is a number!
2083		{
2084			my $compareaction = $1;
2085			my $localposition = $2;
2086
2087			if ( $compareaction eq $action )
2088			{
2089				$position = $localposition;
2090				last;
2091			}
2092		}
2093	}
2094
2095	return $position;
2096}
2097
2098##########################################################################
2099# Setting the position of CustomActions in sequence tables.
2100# Replacing all occurences of "POSITIONTEMPLATE_"
2101##########################################################################
2102
2103sub set_positions_in_table
2104{
2105	my ( $sequencetable, $tablename ) = @_;
2106
2107	$installer::logger::Lang->print("\n");
2108	$installer::logger::Lang->printf("Setting positions in table \"%s\".\n", $tablename);
2109
2110	# Step 1: Resolving all occurences of "POSITIONTEMPLATE_end"
2111
2112	my $lastposition = get_last_position_in_sequencetable($sequencetable);
2113
2114	for ( my $i = 0; $i <= $#{$sequencetable}; $i++ )
2115	{
2116		if ( ${$sequencetable}[$i] =~ /^\s*([\w\.]+)\t.*\t\s*POSITIONTEMPLATE_end\s*$/ )
2117		{
2118			my $customaction = $1;
2119			$lastposition = $lastposition + 25;
2120			${$sequencetable}[$i] =~ s/POSITIONTEMPLATE_end/$lastposition/;
2121			$infoline = "Setting position \"$lastposition\" for custom action \"$customaction\".\n";
2122			$installer::logger::Lang->print($infoline);
2123		}
2124	}
2125
2126	# Step 2: Resolving all occurences of "POSITIONTEMPLATE_abc" or "POSITIONTEMPLATE_behind_abc"
2127	# where abc is the name of the reference Custom Action.
2128	# This has to be done, until there is no more occurence of POSITIONTEMPLATE (success)
2129	# or there is no replacement in one circle (failure).
2130
2131	my $template_exists = 0;
2132	my $template_replaced = 0;
2133	my $counter = 0;
2134
2135	do
2136	{
2137		$template_exists = 0;
2138		$template_replaced = 0;
2139		$counter++;
2140
2141		for ( my $i = 0; $i <= $#{$sequencetable}; $i++ )
2142		{
2143			if ( ${$sequencetable}[$i] =~ /^\s*([\w\.]+)\t.*\t\s*(POSITIONTEMPLATE_.*?)\s*$/ )
2144			{
2145				my $onename = $1;
2146				my $templatename = $2;
2147				my $positionname = $templatename;
2148				my $customaction = $templatename;
2149				$customaction =~ s/POSITIONTEMPLATE_//;
2150				$template_exists = 1;
2151
2152				# Trying to find the correct number.
2153				# This can fail, if the custom action has no number
2154
2155				my $setbehind = 0;
2156				if ( $customaction =~ /^\s*behind_(.*?)\s*$/ )
2157				{
2158					$customaction = $1;
2159					$setbehind = 1;
2160				}
2161
2162				my $position = get_customaction_position($customaction, $sequencetable);
2163
2164				if ( $position >= 0 )	# Found CustomAction and is has a position. Otherwise return value is "-1".
2165				{
2166					my $newposition = 0;
2167					if ( $setbehind ) { $newposition = $position + 2; }
2168					else { $newposition = $position - 2; }
2169					${$sequencetable}[$i] =~ s/$templatename/$newposition/;
2170					$template_replaced = 1;
2171					$infoline = "Setting position \"$newposition\" for custom action \"$onename\" (scp: \"$positionname\" at position $position).\n";
2172					$installer::logger::Lang->print($infoline);
2173				}
2174				else
2175				{
2176					$infoline = "Could not assign position for custom action \"$onename\" yet (scp: \"$positionname\").\n";
2177					$installer::logger::Lang->print($infoline);
2178				}
2179			}
2180		}
2181	} while (( $template_exists ) && ( $template_replaced ));
2182
2183	# An error occured, because templates still exist, but could not be replaced.
2184	# Reason:
2185	# 1. Wrong name of CustomAction in scp2 (typo?)
2186	# 2. Circular dependencies of CustomActions (A after B and B after A)
2187
2188	# Problem: It is allowed, that a CustomAction is defined in scp2 in a library that is
2189	# part of product ABC, but this CustomAction is not used in this product
2190	# and the reference CustomAction is not part of this product.
2191	# Therefore this cannot be an error, but only produce a warning. The assigned number
2192	# must be the last sequence number.
2193
2194	if (( $template_exists ) && ( ! $template_replaced ))
2195	{
2196		# Giving a precise error message, collecting all unresolved templates
2197		# my $templatestring = "";
2198
2199		for ( my $i = 0; $i <= $#{$sequencetable}; $i++ )
2200		{
2201			if ( ${$sequencetable}[$i] =~ /^\s*([\w\.]+)\t.*\t\s*(POSITIONTEMPLATE_.*?)\s*$/ )
2202			{
2203				my $customactionname = $1;
2204				my $fulltemplate = $2;
2205				my $template = $fulltemplate;
2206				$template =~ s/POSITIONTEMPLATE_//;
2207				# my $newstring = $customactionname . " (" . $template . ")";
2208				# $templatestring = $templatestring . $newstring . ", ";
2209				# Setting at the end!
2210				$lastposition = $lastposition + 25;
2211				${$sequencetable}[$i] =~ s/$fulltemplate/$lastposition/;
2212				$infoline = "WARNING: Setting position \"$lastposition\" for custom action \"$customactionname\". Could not find CustomAction \"$template\".\n";
2213				$installer::logger::Lang->print($infoline);
2214			}
2215		}
2216		# $templatestring =~ s/,\s*$//;
2217
2218		# $infoline = "Error: Saving table \"$tablename\"\n";
2219		# $installer::logger::Lang->print($infoline);
2220		# print $infoline;
2221		# installer::files::save_file($tablename, $sequencetable);
2222		# installer::exiter::exit_program("ERROR: Unresolved positions in CustomActions in scp2: $templatestring", "set_positions_in_table");
2223	}
2224}
2225
2226##########################################################################
2227# Setting the Windows custom actions into different tables
2228# CustomAc.idt, InstallE.idt, InstallU.idt, ControlE.idt, ControlC.idt
2229##########################################################################
2230
2231sub addcustomactions
2232{
2233	my ($languageidtdir, $customactions, $filesarray) = @_;
2234
2235	$installer::logger::Lang->print("\n");
2236	$installer::logger::Lang->add_timestamp("Performance Info: addcustomactions start\n");
2237
2238	my $customactionidttablename = $languageidtdir . $installer::globals::separator . "CustomAc.idt";
2239	my $customactionidttable = installer::files::read_file($customactionidttablename);
2240	my $installexecutetablename = $languageidtdir . $installer::globals::separator . "InstallE.idt";
2241	my $installexecutetable = installer::files::read_file($installexecutetablename);
2242	my $adminexecutetablename = $languageidtdir . $installer::globals::separator . "AdminExe.idt";
2243	my $adminexecutetable = installer::files::read_file($adminexecutetablename);
2244	my $installuitablename = $languageidtdir . $installer::globals::separator . "InstallU.idt";
2245	my $installuitable = installer::files::read_file($installuitablename);
2246	my $controleventtablename = $languageidtdir . $installer::globals::separator . "ControlE.idt";
2247	my $controleventtable = installer::files::read_file($controleventtablename);
2248	my $controlconditiontablename = $languageidtdir . $installer::globals::separator . "ControlC.idt";
2249	my $controlconditiontable = installer::files::read_file($controlconditiontablename);
2250
2251	# Iterating over all Windows custom actions
2252
2253	for ( my $i = 0; $i <= $#{$customactions}; $i++ )
2254	{
2255		my $customaction = ${$customactions}[$i];
2256		my $name = $customaction->{'Name'};
2257		my $typ = $customaction->{'Typ'};
2258		my $source = $customaction->{'Source'};
2259		my $target = $customaction->{'Target'};
2260		my $inbinarytable = $customaction->{'Inbinarytable'};
2261		my $gid = $customaction->{'gid'};
2262
2263		my $styles = "";
2264		if ( $customaction->{'Styles'} ) { $styles = $customaction->{'Styles'}; }
2265
2266		my $added_customaction = set_custom_action($customactionidttable, $name, $typ, $source, $target, $inbinarytable, $filesarray, $customactionidttablename, $styles);
2267
2268		if ( $added_customaction )
2269		{
2270			# If the CustomAction was added into the CustomAc.idt, it can be connected to the installation.
2271			# There are currently two different ways for doing this:
2272			# 1. Using "add_custom_action_to_install_table", which adds the CustomAction to the install sequences,
2273			#    which are saved in InstallE.idt and InstallU.idt
2274			# 2. Using "connect_custom_action_to_control" and "connect_custom_action_to_control". The first method
2275			#    connects a CustomAction to a control in ControlE.idt. The second method sets a condition for a control,
2276			#    which might be influenced by the CustomAction. This happens in ControlC.idt.
2277
2278			# Any Windows CustomAction can have a lot of different assignments.
2279
2280			for ( my $j = 1; $j <= 50; $j++ )
2281			{
2282				my $key = "Assignment" . $j;
2283				my $value = "";
2284				if ( $customaction->{$key} )
2285				{
2286					$value = $customaction->{$key};
2287
2288					# in a patch the Assignment can be overwritten by a PatchAssignment
2289					if ( $installer::globals::patch )
2290					{
2291						$patchkey = "PatchAssignment" . $j;
2292						if ( $customaction->{$patchkey} )
2293						{
2294							$value = $customaction->{$patchkey};
2295							$key = $patchkey;
2296						}
2297					}
2298
2299				}
2300				else { last; }
2301
2302				# $value is now a comma separated list
2303				if ( $value =~ /^\s*\(\s*(.*)\s*\);?\s*$/ ) { $value = $1; }
2304				my $assignmentarray = installer::converter::convert_stringlist_into_array(\$value, ",");
2305				my $assignment = create_customaction_assignment_hash($gid, $name, $key, $assignmentarray);
2306
2307				if ( $assignment->{'parameter1'} eq "InstallExecuteSequence" )
2308				{
2309					add_custom_action_to_install_table($installexecutetable, $source, $name, $assignment->{'parameter2'}, $assignment->{'parameter3'}, $filesarray, $installexecutetablename, $styles);
2310				}
2311				elsif ( $assignment->{'parameter1'} eq "AdminExecuteSequence" )
2312				{
2313					add_custom_action_to_install_table($adminexecutetable, $source, $name, $assignment->{'parameter2'}, $assignment->{'parameter3'}, $filesarray, $adminexecutetablename, $styles);
2314				}
2315				elsif ( $assignment->{'parameter1'} eq "InstallUISequence" )
2316				{
2317					add_custom_action_to_install_table($installuitable, $source, $name, $assignment->{'parameter2'}, $assignment->{'parameter3'}, $filesarray, $installuitablename, $styles);
2318				}
2319				elsif ( $assignment->{'parameter1'} eq "ControlEvent" )
2320				{
2321					connect_custom_action_to_control($controleventtable, $controleventtablename, $assignment->{'parameter2'}, $assignment->{'parameter3'}, $assignment->{'parameter4'}, $assignment->{'parameter5'}, $assignment->{'parameter6'}, $assignment->{'parameter7'});
2322				}
2323				elsif ( $assignment->{'parameter1'} eq "ControlCondition" )
2324				{
2325					connect_condition_to_control($controlconditiontable, $controlconditiontablename, $assignment->{'parameter2'}, $assignment->{'parameter3'}, $assignment->{'parameter4'}, $assignment->{'parameter5'});
2326				}
2327				else
2328				{
2329					installer::exiter::exit_program("ERROR: gid: $gid, key: $key ! Unknown Windows CustomAction table: $assignmenthashref->{'parameter1'} ! Currently supported: InstallUISequence, InstallESequence, ControlEvent, ControlCondition", "addcustomactions");
2330				}
2331			}
2332		}
2333	}
2334
2335	# Setting the positions in the tables
2336
2337	set_positions_in_table($installexecutetable, $installexecutetablename);
2338	set_positions_in_table($installuitable, $installuitablename);
2339	set_positions_in_table($adminexecutetable, $adminexecutetablename);
2340
2341	# Saving the files
2342
2343	installer::files::save_file($customactionidttablename, $customactionidttable);
2344	installer::files::save_file($installexecutetablename, $installexecutetable);
2345	installer::files::save_file($adminexecutetablename, $adminexecutetable);
2346	installer::files::save_file($installuitablename, $installuitable);
2347	installer::files::save_file($controleventtablename, $controleventtable);
2348	installer::files::save_file($controlconditiontablename, $controlconditiontable);
2349
2350	my $infoline = "Updated idt file: $customactionidttablename\n";
2351	$installer::logger::Lang->print($infoline);
2352	$infoline = "Updated idt file: $installexecutetablename\n";
2353	$installer::logger::Lang->print($infoline);
2354	$infoline = "Updated idt file: $adminexecutetablename\n";
2355	$installer::logger::Lang->print($infoline);
2356	$infoline = "Updated idt file: $installuitablename\n";
2357	$installer::logger::Lang->print($infoline);
2358	$infoline = "Updated idt file: $controleventtablename\n";
2359	$installer::logger::Lang->print($infoline);
2360	$infoline = "Updated idt file: $controlconditiontablename\n";
2361	$installer::logger::Lang->print($infoline);
2362
2363	$installer::logger::Lang->print("\n");
2364	$installer::logger::Lang->add_timestamp("Performance Info: addcustomactions end\n");
2365}
2366
2367##########################################################################
2368# Setting bidi attributes in idt tables
2369##########################################################################
2370
2371sub setbidiattributes
2372{
2373	my ($languageidtdir, $onelanguage) = @_;
2374
2375	# Editing the files Dialog.idt and Control.idt
2376
2377	my $dialogfilename = $languageidtdir . $installer::globals::separator . "Dialog.idt";
2378	my $controlfilename = $languageidtdir . $installer::globals::separator . "Control.idt";
2379
2380	my $dialogfile = installer::files::read_file($dialogfilename);
2381	my $controlfile = installer::files::read_file($controlfilename);
2382
2383	# Searching attributes in Dialog.idt and adding "896".
2384	# Attributes are in column 6 (from 10).
2385
2386	my $bidiattribute = 896;
2387	for ( my $i = 0; $i <= $#{$dialogfile}; $i++ )
2388	{
2389		if ( $i < 3 ) { next; }
2390		if ( ${$dialogfile}[$i] =~ /^\s*(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\s*$/ )
2391		{
2392			my $one = $1;
2393			my $two = $2;
2394			my $three = $3;
2395			my $four = $4;
2396			my $five = $5;
2397			my $attribute = $6;
2398			my $seven = $7;
2399			my $eight = $8;
2400			$attribute = $attribute + $bidiattribute;
2401			${$dialogfile}[$i] = "$one\t$two\t$three\t$four\t$five\t$attribute\t$seven\t$eight\n";
2402		}
2403	}
2404
2405	# Searching attributes in Control.idt and adding "224".
2406	# Attributes are in column 8 (from 12).
2407
2408	$bidiattribute = 224;
2409	for ( my $i = 0; $i <= $#{$controlfile}; $i++ )
2410	{
2411		if ( $i < 3 ) { next; }
2412		if ( ${$controlfile}[$i] =~ /^\s*(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\s*$/ )
2413		{
2414			my $one = $1;
2415			my $two = $2;
2416			my $three = $3;
2417			my $four = $4;
2418			my $five = $5;
2419			my $six = $6;
2420			my $seven = $7;
2421			my $attribute = $8;
2422			my $nine = $9;
2423			my $ten = $10;
2424			my $eleven = $11;
2425			my $twelve = $12;
2426			$attribute = $attribute + $bidiattribute;
2427			${$controlfile}[$i] = "$one\t$two\t$three\t$four\t$five\t$six\t$seven\t$attribute\t$nine\t$ten\t$eleven\t$twelve\n";
2428		}
2429	}
2430
2431	# Saving the file
2432
2433	installer::files::save_file($dialogfilename, $dialogfile);
2434	$infoline = "Set bidi support in idt file \"$dialogfilename\" for language $onelanguage\n";
2435	$installer::logger::Lang->print($infoline);
2436
2437	installer::files::save_file($controlfilename, $controlfile);
2438	$infoline = "Set bidi support in idt file \"$controlfilename\" for language $onelanguage\n";
2439	$installer::logger::Lang->print($infoline);
2440}
2441
24421;
2443