1#*************************************************************************
2#
3# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4#
5# Copyright 2000, 2010 Oracle and/or its affiliates.
6#
7# OpenOffice.org - a multi-platform office productivity suite
8#
9# This file is part of OpenOffice.org.
10#
11# OpenOffice.org is free software: you can redistribute it and/or modify
12# it under the terms of the GNU Lesser General Public License version 3
13# only, as published by the Free Software Foundation.
14#
15# OpenOffice.org is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18# GNU Lesser General Public License version 3 for more details
19# (a copy is included in the LICENSE file that accompanied this code).
20#
21# You should have received a copy of the GNU Lesser General Public License
22# version 3 along with OpenOffice.org.  If not, see
23# <http://www.openoffice.org/license.html>
24# for a copy of the LGPLv3 License.
25#
26#*************************************************************************
27
28package installer::windows::idtglobal;
29
30use Cwd;
31use installer::converter;
32use installer::existence;
33use installer::exiter;
34use installer::files;
35use installer::globals;
36use installer::pathanalyzer;
37use installer::remover;
38use installer::scriptitems;
39use installer::systemactions;
40use installer::windows::language;
41
42##############################################################
43# Shorten the gid for a feature.
44# Attention: Maximum length is 38
45##############################################################
46
47sub shorten_feature_gid
48{
49	my ($stringref) = @_;
50
51	$$stringref =~ s/gid_Module_/gm_/;
52	$$stringref =~ s/_Extension_/_ex_/;
53	$$stringref =~ s/_Root_/_r_/;
54	$$stringref =~ s/_Prg_/_p_/;
55	$$stringref =~ s/_Optional_/_o_/;
56	$$stringref =~ s/_Tools_/_tl_/;
57	$$stringref =~ s/_Wrt_Flt_/_w_f_/;
58	$$stringref =~ s/_Javafilter_/_jf_/;
59	$$stringref =~ s/_Productivity_/_pr_/;
60}
61
62############################################
63# Getting the next free number, that
64# can be added.
65# Sample: 01-44-~1.DAT, 01-44-~2.DAT, ...
66############################################
67
68sub get_next_free_number
69{
70	my ($name, $shortnamesref) = @_;
71
72	my $counter = 0;
73	my $dontsave = 0;
74	my $alreadyexists;
75	my ($newname, $shortname);
76
77	do
78	{
79		$alreadyexists = 0;
80		$counter++;
81		$newname = $name . $counter;
82
83		for ( my $i = 0; $i <= $#{$shortnamesref}; $i++ )
84		{
85			$shortname = ${$shortnamesref}[$i];
86
87			if ( uc($shortname) eq uc($newname) )	# case insensitive
88			{
89				$alreadyexists = 1;
90				last;
91			}
92		}
93	}
94	until (!($alreadyexists));
95
96	if (( $counter > 9 ) && ( length($name) > 6 )) { $dontsave = 1; }
97	if (( $counter > 99 ) && ( length($name) > 5 )) { $dontsave = 1; }
98
99	if (!($dontsave))
100	{
101		push(@{$shortnamesref}, $newname);	# adding the new shortname to the array of shortnames
102	}
103
104	return $counter
105}
106
107############################################
108# Getting the next free number, that
109# can be added.
110# Sample: 01-44-~1.DAT, 01-44-~2.DAT, ...
111############################################
112
113sub get_next_free_number_with_hash
114{
115	my ($name, $shortnamesref, $ext) = @_;
116
117	my $counter = 0;
118	my $dontsave = 0;
119	my $saved = 0;
120	my $alreadyexists;
121	my ($newname, $shortname);
122
123	do
124	{
125		$alreadyexists = 0;
126		$counter++;
127		$newname = $name . $counter;
128		$newname = uc($newname);	# case insensitive, always upper case
129		if ( exists($shortnamesref->{$newname}) ||
130		     exists($installer::globals::savedrev83mapping{$newname.$ext}) )
131		{
132			$alreadyexists = 1;
133		}
134	}
135	until (!($alreadyexists));
136
137	if (( $counter > 9 ) && ( length($name) > 6 )) { $dontsave = 1; }
138	if (( $counter > 99 ) && ( length($name) > 5 )) { $dontsave = 1; }
139
140	if (!($dontsave))
141	{
142		# push(@{$shortnamesref}, $newname);	# adding the new shortname to the array of shortnames
143		$shortnamesref->{$newname} = 1;	# adding the new shortname to the array of shortnames, always uppercase
144		$saved = 1;
145	}
146
147	return ( $counter, $saved )
148}
149
150#########################################
151# 8.3 for filenames and directories
152#########################################
153
154sub make_eight_three_conform
155{
156	my ($inputstring, $pattern, $shortnamesref) = @_;
157
158	# all shortnames are collected in $shortnamesref, because of uniqueness
159
160	my ($name, $namelength, $number);
161	my $conformstring = "";
162	my $changed = 0;
163
164	if (( $inputstring =~ /^\s*(.*?)\.(.*?)\s*$/ ) && ( $pattern eq "file" ))	# files with a dot
165	{
166		$name = $1;
167		my $extension = $2;
168
169		$namelength = length($name);
170		my $extensionlength = length($extension);
171
172		if ( $extensionlength > 3 )
173		{
174			# simply taking the first three letters
175			$extension = substr($extension, 0, 3);	# name, offset, length
176		}
177
178		# Attention: readme.html -> README~1.HTM
179
180		if (( $namelength > 8 ) || ( $extensionlength > 3 ))
181		{
182			# taking the first six letters
183			$name = substr($name, 0, 6);	# name, offset, length
184			$name =~ s/\s*$//; # removing ending whitespaces
185			$name = $name . "\~";
186			$number = get_next_free_number($name, $shortnamesref);
187
188			# if $number>9 the new name would be "abcdef~10.xyz", which is 9+3, and therefore not allowed
189
190			if ( $number > 9 )
191			{
192				$name = substr($name, 0, 5);	# name, offset, length
193				$name =~ s/\s*$//; # removing ending whitespaces
194				$name = $name . "\~";
195				$number = get_next_free_number($name, $shortnamesref);
196
197				if ( $number > 99 )
198				{
199					$name = substr($name, 0, 4);	# name, offset, length
200					$name =~ s/\s*$//; # removing ending whitespaces
201					$name = $name . "\~";
202					$number = get_next_free_number($name, $shortnamesref);
203				}
204			}
205
206			$name = $name . "$number";
207
208			$changed = 1;
209		}
210
211		$conformstring = $name . "\." . $extension;
212
213		if ( $changed ) { $conformstring= uc($conformstring); }
214	}
215	else 		# no dot in filename or directory (also used for shortcuts)
216	{
217		$name = $inputstring;
218		$namelength = length($name);
219
220		if ( $namelength > 8 )
221		{
222			# taking the first six letters
223			$name = substr($name, 0, 6);	# name, offset, length
224			$name =~ s/\s*$//; # removing ending whitespaces
225			$name = $name . "\~";
226			$number = get_next_free_number($name, $shortnamesref);
227
228			# if $number>9 the new name would be "abcdef~10.xyz", which is 9+3, and therefore not allowed
229
230			if ( $number > 9 )
231			{
232				$name = substr($name, 0, 5);	# name, offset, length
233				$name =~ s/\s*$//; # removing ending whitespaces
234				$name = $name . "\~";
235				$number = get_next_free_number($name, $shortnamesref);
236
237				if ( $number > 99 )
238				{
239					$name = substr($name, 0, 4);	# name, offset, length
240					$name =~ s/\s*$//; # removing ending whitespaces
241					$name = $name . "\~";
242					$number = get_next_free_number($name, $shortnamesref);
243				}
244			}
245
246			$name = $name . "$number";
247			$changed = 1;
248			if ( $pattern eq "dir" ) { $name =~ s/\./\_/g; }	# in directories replacing "." with "_"
249		}
250
251		$conformstring = $name;
252
253		if ( $changed ) { $conformstring = uc($name); }
254	}
255
256	return $conformstring;
257}
258
259#########################################
260# 8.3 for filenames and directories
261# $shortnamesref is a hash in this case
262# -> performance reasons
263#########################################
264
265sub make_eight_three_conform_with_hash
266{
267	my ($inputstring, $pattern, $shortnamesref) = @_;
268
269	# all shortnames are collected in $shortnamesref, because of uniqueness (a hash!)
270
271	my ($name, $namelength, $number);
272	my $conformstring = "";
273	my $changed = 0;
274	my $saved;
275
276	# if (( $inputstring =~ /^\s*(.*?)\.(.*?)\s*$/ ) && ( $pattern eq "file" ))	# files with a dot
277	if (( $inputstring =~ /^\s*(.*)\.(.*?)\s*$/ ) && ( $pattern eq "file" ))	# files with a dot
278	{
279		# extension has to be non-greedy, but name is. This is important to find the last dot in the filename
280		$name = $1;
281		my $extension = $2;
282
283		if ( $name =~ /^\s*(.*?)\s*$/ ) { $name = $1; } # now the name is also non-greedy
284		$name =~ s/\.//g; # no dots in 8+3 conform filename
285
286		$namelength = length($name);
287		my $extensionlength = length($extension);
288
289		if ( $extensionlength > 3 )
290		{
291			# simply taking the first three letters
292			$extension = substr($extension, 0, 3);	# name, offset, length
293			$changed = 1;
294		}
295
296		# Attention: readme.html -> README~1.HTM
297
298		if (( $namelength > 8 ) || ( $extensionlength > 3 ))
299		{
300			# taking the first six letters, if filename is longer than 6 characters
301			if ( $namelength > 6 )
302			{
303				$name = substr($name, 0, 6);	# name, offset, length
304				$name =~ s/\s*$//; # removing ending whitespaces
305				$name = $name . "\~";
306				($number, $saved) = get_next_free_number_with_hash($name, $shortnamesref, '.'.uc($extension));
307
308				# if $number>9 the new name would be "abcdef~10.xyz", which is 9+3, and therefore not allowed
309
310				if ( ! $saved )
311				{
312					$name = substr($name, 0, 5);	# name, offset, length
313					$name =~ s/\s*$//; # removing ending whitespaces
314					$name = $name . "\~";
315					($number, $saved) = get_next_free_number_with_hash($name, $shortnamesref, '.'.uc($extension));
316
317					# if $number>99 the new name would be "abcde~100.xyz", which is 9+3, and therefore not allowed
318
319					if ( ! $saved )
320					{
321						$name = substr($name, 0, 4);	# name, offset, length
322						$name =~ s/\s*$//; # removing ending whitespaces
323						$name = $name . "\~";
324						($number, $saved) = get_next_free_number_with_hash($name, $shortnamesref, '.'.uc($extension));
325
326						if ( ! $saved )
327						{
328							installer::exiter::exit_program("ERROR: Could not set 8+3 conform name for $inputstring !", "make_eight_three_conform_with_hash");
329						}
330					}
331				}
332
333				$name = $name . "$number";
334				$changed = 1;
335			}
336		}
337
338		$conformstring = $name . "\." . $extension;
339
340		if ( $changed ) { $conformstring= uc($conformstring); }
341	}
342	else 		# no dot in filename or directory (also used for shortcuts)
343	{
344		$name = $inputstring;
345		$namelength = length($name);
346
347		if ( $namelength > 8 )
348		{
349			# taking the first six letters
350			$name = substr($name, 0, 6);	# name, offset, length
351			$name =~ s/\s*$//; # removing ending whitespaces
352			$name = $name . "\~";
353			( $number, $saved ) = get_next_free_number_with_hash($name, $shortnamesref, '');
354
355			# if $number>9 the new name would be "abcdef~10", which is 9+0, and therefore not allowed
356
357			if ( ! $saved )
358			{
359				$name = substr($name, 0, 5);	# name, offset, length
360				$name =~ s/\s*$//; # removing ending whitespaces
361				$name = $name . "\~";
362				( $number, $saved ) = get_next_free_number_with_hash($name, $shortnamesref, '');
363
364				# if $number>99 the new name would be "abcde~100", which is 9+0, and therefore not allowed
365
366				if ( ! $saved )
367				{
368					$name = substr($name, 0, 4);	# name, offset, length
369					$name =~ s/\s*$//; # removing ending whitespaces
370					$name = $name . "\~";
371					( $number, $saved ) = get_next_free_number_with_hash($name, $shortnamesref, '');
372
373					if ( ! $saved ) { installer::exiter::exit_program("ERROR: Could not set 8+3 conform name for $inputstring !", "make_eight_three_conform_with_hash"); }
374				}
375			}
376
377			$name = $name . "$number";
378			$changed = 1;
379			if ( $pattern eq "dir" ) { $name =~ s/\./\_/g; }	# in directories replacing "." with "_"
380		}
381
382		$conformstring = $name;
383
384		if ( $changed ) { $conformstring = uc($name); }
385	}
386
387	return $conformstring;
388}
389
390#########################################
391# Writing the header for idt files
392#########################################
393
394sub write_idt_header
395{
396	my ($idtref, $definestring) = @_;
397
398	my $oneline;
399
400	if ( $definestring eq "file" )
401	{
402		$oneline = "File\tComponent_\tFileName\tFileSize\tVersion\tLanguage\tAttributes\tSequence\n";
403		push(@{$idtref}, $oneline);
404		$oneline = "s72\ts72\tl255\ti4\tS72\tS20\tI2\ti2\n";
405		push(@{$idtref}, $oneline);
406		$oneline = "File\tFile\n";
407		push(@{$idtref}, $oneline);
408	}
409
410	if ( $definestring eq "filehash" )
411	{
412		$oneline = "File_\tOptions\tHashPart1\tHashPart2\tHashPart3\tHashPart4\n";
413		push(@{$idtref}, $oneline);
414		$oneline = "s72\ti2\ti4\ti4\ti4\ti4\n";
415		push(@{$idtref}, $oneline);
416		$oneline = "MsiFileHash\tFile_\n";
417		push(@{$idtref}, $oneline);
418	}
419
420	if ( $definestring eq "directory" )
421	{
422		$oneline = "Directory\tDirectory_Parent\tDefaultDir\n";
423		push(@{$idtref}, $oneline);
424		$oneline = "s72\tS72\tl255\n";
425		push(@{$idtref}, $oneline);
426		$oneline = "Directory\tDirectory\n";
427		push(@{$idtref}, $oneline);
428	}
429
430	if ( $definestring eq "component" )
431	{
432		$oneline = "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n";
433		push(@{$idtref}, $oneline);
434		$oneline = "s72\tS38\ts72\ti2\tS255\tS72\n";
435		push(@{$idtref}, $oneline);
436		$oneline = "Component\tComponent\n";
437		push(@{$idtref}, $oneline);
438	}
439
440	if ( $definestring eq "feature" )
441	{
442		$oneline = "Feature\tFeature_Parent\tTitle\tDescription\tDisplay\tLevel\tDirectory_\tAttributes\n";
443		push(@{$idtref}, $oneline);
444		$oneline = "s38\tS38\tL64\tL255\tI2\ti2\tS72\ti2\n";
445		push(@{$idtref}, $oneline);
446		$oneline = "WINDOWSENCODINGTEMPLATE\tFeature\tFeature\n";
447		push(@{$idtref}, $oneline);
448	}
449
450	if ( $definestring eq "featurecomponent" )
451	{
452		$oneline = "Feature_\tComponent_\n";
453		push(@{$idtref}, $oneline);
454		$oneline = "s38\ts72\n";
455		push(@{$idtref}, $oneline);
456		$oneline = "FeatureComponents\tFeature_\tComponent_\n";
457		push(@{$idtref}, $oneline);
458	}
459
460	if ( $definestring eq "media" )
461	{
462		$oneline = "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n";
463		push(@{$idtref}, $oneline);
464		$oneline = "i2\ti2\tL64\tS255\tS32\tS72\n";
465		push(@{$idtref}, $oneline);
466		$oneline = "Media\tDiskId\n";
467		push(@{$idtref}, $oneline);
468	}
469
470	if ( $definestring eq "font" )
471	{
472		$oneline = "File_\tFontTitle\n";
473		push(@{$idtref}, $oneline);
474		$oneline = "s72\tS128\n";
475		push(@{$idtref}, $oneline);
476		$oneline = "Font\tFile_\n";
477		push(@{$idtref}, $oneline);
478	}
479
480	if ( $definestring eq "shortcut" )
481	{
482		$oneline = "Shortcut\tDirectory_\tName\tComponent_\tTarget\tArguments\tDescription\tHotkey\tIcon_\tIconIndex\tShowCmd\tWkDir\n";
483		push(@{$idtref}, $oneline);
484		$oneline = "s72\ts72\tl128\ts72\ts72\tS255\tL255\tI2\tS72\tI2\tI2\tS72\n";
485		push(@{$idtref}, $oneline);
486		$oneline = "WINDOWSENCODINGTEMPLATE\tShortcut\tShortcut\n";
487		push(@{$idtref}, $oneline);
488	}
489
490	if ( $definestring eq "registry" )
491	{
492		$oneline = "Registry\tRoot\tKey\tName\tValue\tComponent_\n";
493		push(@{$idtref}, $oneline);
494		$oneline = "s72\ti2\tl255\tL255\tL0\ts72\n";
495		push(@{$idtref}, $oneline);
496		$oneline = "Registry\tRegistry\n";
497		push(@{$idtref}, $oneline);
498	}
499
500	if ( $definestring eq "reg64" )
501	{
502		$oneline = "Registry\tRoot\tKey\tName\tValue\tComponent_\n";
503		push(@{$idtref}, $oneline);
504		$oneline = "s72\ti2\tl255\tL255\tL0\ts72\n";
505		push(@{$idtref}, $oneline);
506		$oneline = "Reg64\tRegistry\n";
507		push(@{$idtref}, $oneline);
508	}
509
510	if ( $definestring eq "createfolder" )
511	{
512		$oneline = "Directory_\tComponent_\n";
513		push(@{$idtref}, $oneline);
514		$oneline = "s72\ts72\n";
515		push(@{$idtref}, $oneline);
516		$oneline = "CreateFolder\tDirectory_\tComponent_\n";
517		push(@{$idtref}, $oneline);
518	}
519
520	if ( $definestring eq "removefile" )
521	{
522		$oneline = "FileKey\tComponent_\tFileName\tDirProperty\tInstallMode\n";
523		push(@{$idtref}, $oneline);
524		$oneline = "s72\ts72\tL255\ts72\ti2\n";
525		push(@{$idtref}, $oneline);
526		$oneline = "RemoveFile\tFileKey\n";
527		push(@{$idtref}, $oneline);
528	}
529
530	if ( $definestring eq "upgrade" )
531	{
532		$oneline = "UpgradeCode\tVersionMin\tVersionMax\tLanguage\tAttributes\tRemove\tActionProperty\n";
533		push(@{$idtref}, $oneline);
534		$oneline = "s38\tS20\tS20\tS255\ti4\tS255\ts72\n";
535		push(@{$idtref}, $oneline);
536		$oneline = "Upgrade\tUpgradeCode\tVersionMin\tVersionMax\tLanguage\tAttributes\n";
537		push(@{$idtref}, $oneline);
538	}
539
540	if ( $definestring eq "icon" )
541	{
542		$oneline = "Name\tData\n";
543		push(@{$idtref}, $oneline);
544		$oneline = "s72\tv0\n";
545		push(@{$idtref}, $oneline);
546		$oneline = "Icon\tName\n";
547		push(@{$idtref}, $oneline);
548	}
549
550	if ( $definestring eq "inifile" )
551	{
552		$oneline = "IniFile\tFileName\tDirProperty\tSection\tKey\tValue\tAction\tComponent_\n";
553		push(@{$idtref}, $oneline);
554		$oneline = "s72\tl255\tS72\tl96\tl128\tl255\ti2\ts72\n";
555		push(@{$idtref}, $oneline);
556		$oneline = "IniFile\tIniFile\n";
557		push(@{$idtref}, $oneline);
558	}
559
560	if ( $definestring eq "selfreg" )
561	{
562		$oneline = "File_\tCost\n";
563		push(@{$idtref}, $oneline);
564		$oneline = "s72\tI2\n";
565		push(@{$idtref}, $oneline);
566		$oneline = "SelfReg\tFile_\n";
567		push(@{$idtref}, $oneline);
568	}
569
570	if ( $definestring eq "msiassembly" )
571	{
572		$oneline = "Component_\tFeature_\tFile_Manifest\tFile_Application\tAttributes\n";
573		push(@{$idtref}, $oneline);
574		$oneline = "s72\ts38\tS72\tS72\tI2\n";
575		push(@{$idtref}, $oneline);
576		$oneline = "MsiAssembly\tComponent_\n";
577		push(@{$idtref}, $oneline);
578	}
579
580	if ( $definestring eq "msiassemblyname" )
581	{
582		$oneline = "Component_\tName\tValue\n";
583		push(@{$idtref}, $oneline);
584		$oneline = "s72\ts255\ts255\n";
585		push(@{$idtref}, $oneline);
586		$oneline = "MsiAssemblyName\tComponent_\tName\n";
587		push(@{$idtref}, $oneline);
588	}
589
590	if ( $definestring eq "appsearch" )
591	{
592		$oneline = "Property\tSignature_\n";
593		push(@{$idtref}, $oneline);
594		$oneline = "s72\ts72\n";
595		push(@{$idtref}, $oneline);
596		$oneline = "AppSearch\tProperty\tSignature_\n";
597		push(@{$idtref}, $oneline);
598	}
599
600	if ( $definestring eq "reglocat" )
601	{
602		$oneline = "Signature_\tRoot\tKey\tName\tType\n";
603		push(@{$idtref}, $oneline);
604		$oneline = "s72\ti2\ts255\tS255\tI2\n";
605		push(@{$idtref}, $oneline);
606		$oneline = "RegLocator\tSignature_\n";
607		push(@{$idtref}, $oneline);
608	}
609
610	if ( $definestring eq "signatur" )
611	{
612		$oneline = "Signature\tFileName\tMinVersion\tMaxVersion\tMinSize\tMaxSize\tMinDate\tMaxDate\tLanguages\n";
613		push(@{$idtref}, $oneline);
614		$oneline = "s72\ts255\tS20\tS20\tI4\tI4\tI4\tI4\tS255\n";
615		push(@{$idtref}, $oneline);
616		$oneline = "Signature\tSignature\n";
617		push(@{$idtref}, $oneline);
618	}
619
620}
621
622##############################################################
623# Returning the name of the rranslation file for a
624# given language.
625# Sample: "01" oder "en-US" -> "1033.txt"
626##############################################################
627
628sub get_languagefilename
629{
630	my ($idtfilename, $basedir) = @_;
631
632	# $idtfilename =~ s/\.idt/\.ulf/;
633	$idtfilename =~ s/\.idt/\.mlf/;
634
635	my $languagefilename = $basedir . $installer::globals::separator . $idtfilename;
636
637	return $languagefilename;
638}
639
640##############################################################
641# Returning the complete block in all languages
642# for a specified string
643##############################################################
644
645sub get_language_block_from_language_file
646{
647	my ($searchstring, $languagefile) = @_;
648
649	my @language_block = ();
650
651	for ( my $i = 0; $i <= $#{$languagefile}; $i++ )
652	{
653		if ( ${$languagefile}[$i] =~ /^\s*\[\s*$searchstring\s*\]\s*$/ )
654		{
655			my $counter = $i;
656
657			push(@language_block, ${$languagefile}[$counter]);
658			$counter++;
659
660			while (( $counter <= $#{$languagefile} ) && (!( ${$languagefile}[$counter] =~ /^\s*\[/ )))
661			{
662				push(@language_block, ${$languagefile}[$counter]);
663				$counter++;
664			}
665
666			last;
667		}
668	}
669
670	return \@language_block;
671}
672
673##############################################################
674# Returning a specific language string from the block
675# of all translations
676##############################################################
677
678sub get_language_string_from_language_block
679{
680	my ($language_block, $language, $oldstring) = @_;
681
682	my $newstring = "";
683
684	for ( my $i = 0; $i <= $#{$language_block}; $i++ )
685	{
686		if ( ${$language_block}[$i] =~ /^\s*$language\s*\=\s*\"(.*)\"\s*$/ )
687		{
688			$newstring = $1;
689			last;
690		}
691	}
692
693	if ( $newstring eq "" )
694	{
695		$language = "en-US"; 	# defaulting to english
696
697		for ( my $i = 0; $i <= $#{$language_block}; $i++ )
698		{
699			if ( ${$language_block}[$i] =~ /^\s*$language\s*\=\s*\"(.*)\"\s*$/ )
700			{
701				$newstring = $1;
702				last;
703			}
704		}
705	}
706
707	return $newstring;
708}
709
710##############################################################
711# Returning a specific code from the block
712# of all codes. No defaulting to english!
713##############################################################
714
715sub get_code_from_code_block
716{
717	my ($codeblock, $language) = @_;
718
719	my $newstring = "";
720
721	for ( my $i = 0; $i <= $#{$codeblock}; $i++ )
722	{
723		if ( ${$codeblock}[$i] =~ /^\s*$language\s*\=\s*\"(.*)\"\s*$/ )
724		{
725			$newstring = $1;
726			last;
727		}
728	}
729
730	return $newstring;
731}
732
733##############################################################
734# Translating an idt file
735##############################################################
736
737sub translate_idtfile
738{
739	my ($idtfile, $languagefile, $onelanguage) = @_;
740
741	for ( my $i = 0; $i <= $#{$idtfile}; $i++ )
742	{
743		my @allstrings = ();
744
745		my $oneline = ${$idtfile}[$i];
746
747		while ( $oneline =~ /\b(OOO_\w+)\b/ )
748		{
749			my $replacestring = $1;
750			push(@allstrings, $replacestring);
751			$oneline =~ s/$replacestring//;
752		}
753
754		my $oldstring;
755
756		foreach $oldstring (@allstrings)
757		{
758			my $language_block = get_language_block_from_language_file($oldstring, $languagefile);
759			my $newstring = get_language_string_from_language_block($language_block, $onelanguage, $oldstring);
760
761			# if (!( $newstring eq "" )) { ${$idtfile}[$i] =~ s/$oldstring/$newstring/; }
762			${$idtfile}[$i] =~ s/$oldstring/$newstring/;	# always substitute, even if $newstring eq "" (there are empty strings for control.idt)
763		}
764	}
765}
766
767##############################################################
768# Copying all needed files to create a msi database
769# into one language specific directory
770##############################################################
771
772sub prepare_language_idt_directory
773{
774	my ($destinationdir, $newidtdir, $onelanguage, $filesref, $iconfilecollector, $binarytablefiles, $allvariables) = @_;
775
776	# Copying all idt-files from the source $installer::globals::idttemplatepath to the destination $destinationdir
777	# Copying all files in the subdirectory "Binary"
778	# Copying all files in the subdirectory "Icon"
779
780	my $infoline = "";
781
782	installer::systemactions::copy_directory($installer::globals::idttemplatepath, $destinationdir);
783
784	if ( -d $installer::globals::idttemplatepath . $installer::globals::separator . "Binary")
785	{
786		installer::systemactions::create_directory($destinationdir . $installer::globals::separator . "Binary");
787		installer::systemactions::copy_directory($installer::globals::idttemplatepath . $installer::globals::separator . "Binary", $destinationdir . $installer::globals::separator . "Binary");
788
789		if ((( $installer::globals::patch ) && ( $allvariables->{'WINDOWSPATCHBITMAPDIRECTORY'} )) || ( $allvariables->{'WINDOWSBITMAPDIRECTORY'} ))
790		{
791			my $bitmapdir = "";
792			if ( $allvariables->{'WINDOWSPATCHBITMAPDIRECTORY'} ) { $bitmapdir = $allvariables->{'WINDOWSPATCHBITMAPDIRECTORY'}; }
793			if ( $allvariables->{'WINDOWSBITMAPDIRECTORY'} ) { $bitmapdir = $allvariables->{'WINDOWSBITMAPDIRECTORY'}; }
794
795			my $newsourcedir = $installer::globals::unpackpath . $installer::globals::separator . $bitmapdir; # path setting in list file dependent from unpackpath !?
796			$infoline = "\nOverwriting files in directory \"" . $destinationdir . $installer::globals::separator . "Binary" . "\" with files from directory \"" . $newsourcedir . "\".\n";
797			push( @installer::globals::logfileinfo, $infoline);
798			if ( ! -d $newsourcedir )
799			{
800				my $currentdir = cwd();
801				installer::exiter::exit_program("ERROR: Directory $newsourcedir does not exist! Current directory is: $currentdir", "prepare_language_idt_directory");
802			}
803			installer::systemactions::copy_directory($newsourcedir, $destinationdir . $installer::globals::separator . "Binary");
804		}
805	}
806
807	installer::systemactions::create_directory($destinationdir . $installer::globals::separator . "Icon");
808
809	if ( -d $installer::globals::idttemplatepath . $installer::globals::separator . "Icon")
810	{
811		installer::systemactions::copy_directory($installer::globals::idttemplatepath . $installer::globals::separator . "Icon", $destinationdir . $installer::globals::separator . "Icon");
812	}
813
814	# Copying all files in $iconfilecollector, that describe icons of folderitems
815
816	for ( my $i = 0; $i <= $#{$iconfilecollector}; $i++ )
817	{
818		my $iconfilename = ${$iconfilecollector}[$i];
819		installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$iconfilename);
820		installer::systemactions::copy_one_file(${$iconfilecollector}[$i], $destinationdir . $installer::globals::separator . "Icon" . $installer::globals::separator . $iconfilename);
821	}
822
823	# Copying all files in $binarytablefiles in the binary directory
824
825	for ( my $i = 0; $i <= $#{$binarytablefiles}; $i++ )
826	{
827		my $binaryfile = ${$binarytablefiles}[$i];
828		my $binaryfilepath = $binaryfile->{'sourcepath'};
829		my $binaryfilename = $binaryfilepath;
830		installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$binaryfilename);
831		installer::systemactions::copy_one_file($binaryfilepath, $destinationdir . $installer::globals::separator . "Binary" . $installer::globals::separator . $binaryfilename);
832	}
833
834	# Copying all new created and language independent idt-files to the destination $destinationdir.
835	# Example: "File.idt"
836
837	installer::systemactions::copy_directory_with_fileextension($newidtdir, $destinationdir, "idt");
838
839	# Copying all new created and language dependent idt-files to the destination $destinationdir.
840	# Example: "Feature.idt.01"
841
842	installer::systemactions::copy_directory_with_fileextension($newidtdir, $destinationdir, $onelanguage);
843	installer::systemactions::rename_files_with_fileextension($destinationdir, $onelanguage);
844
845}
846
847##############################################################
848# Returning the source path of the rtf licensefile for
849# a specified language
850##############################################################
851
852sub get_rtflicensefilesource
853{
854	my ($language, $includepatharrayref) = @_;
855
856	my $licensefilename = "license_" . $language . ".rtf";
857
858	my $sourcefileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$licensefilename, $includepatharrayref, 1);
859
860	if ($$sourcefileref eq "") { installer::exiter::exit_program("ERROR: Could not find $licensefilename!", "get_rtflicensefilesource"); }
861
862	my $infoline = "Using licensefile: $$sourcefileref\n";
863	push( @installer::globals::logfileinfo, $infoline);
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	push(@installer::globals::logfileinfo, $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        push(@installer::globals::logfileinfo, $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	push(@installer::globals::logfileinfo, $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    	push(@installer::globals::logfileinfo, $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	push(@installer::globals::logfileinfo, $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	push(@installer::globals::logfileinfo, $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	push(@installer::globals::logfileinfo, $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				push(@installer::globals::logfileinfo, $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				push(@installer::globals::logfileinfo, $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	push(@installer::globals::logfileinfo, $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		push(@installer::globals::logfileinfo, $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		push(@installer::globals::logfileinfo, $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		push(@installer::globals::logfileinfo, $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		push(@installer::globals::logfileinfo, $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		push(@installer::globals::logfileinfo, $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		push(@installer::globals::logfileinfo, $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		push(@installer::globals::logfileinfo, $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		push(@installer::globals::logfileinfo, $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		push(@installer::globals::logfileinfo, $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		push(@installer::globals::logfileinfo, $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	my $infoline = "\nSetting positions in table \"$tablename\".\n";
2108	push(@installer::globals::logfileinfo, $infoline);
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			push(@installer::globals::logfileinfo, $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					push(@installer::globals::logfileinfo, $infoline);
2173				}
2174				else
2175				{
2176					$infoline = "Could not assign position for custom action \"$onename\" yet (scp: \"$positionname\").\n";
2177					push(@installer::globals::logfileinfo, $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				push(@installer::globals::logfileinfo, $infoline);
2214			}
2215		}
2216		# $templatestring =~ s/,\s*$//;
2217
2218		# $infoline = "Error: Saving table \"$tablename\"\n";
2219		# push(@installer::globals::logfileinfo, $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::include_timestamp_into_logfile("\nPerformance Info: addcustomactions start\n");
2236
2237	my $customactionidttablename = $languageidtdir . $installer::globals::separator . "CustomAc.idt";
2238	my $customactionidttable = installer::files::read_file($customactionidttablename);
2239	my $installexecutetablename = $languageidtdir . $installer::globals::separator . "InstallE.idt";
2240	my $installexecutetable = installer::files::read_file($installexecutetablename);
2241	my $adminexecutetablename = $languageidtdir . $installer::globals::separator . "AdminExe.idt";
2242	my $adminexecutetable = installer::files::read_file($adminexecutetablename);
2243	my $installuitablename = $languageidtdir . $installer::globals::separator . "InstallU.idt";
2244	my $installuitable = installer::files::read_file($installuitablename);
2245	my $controleventtablename = $languageidtdir . $installer::globals::separator . "ControlE.idt";
2246	my $controleventtable = installer::files::read_file($controleventtablename);
2247	my $controlconditiontablename = $languageidtdir . $installer::globals::separator . "ControlC.idt";
2248	my $controlconditiontable = installer::files::read_file($controlconditiontablename);
2249
2250	# Iterating over all Windows custom actions
2251
2252	for ( my $i = 0; $i <= $#{$customactions}; $i++ )
2253	{
2254		my $customaction = ${$customactions}[$i];
2255		my $name = $customaction->{'Name'};
2256		my $typ = $customaction->{'Typ'};
2257		my $source = $customaction->{'Source'};
2258		my $target = $customaction->{'Target'};
2259		my $inbinarytable = $customaction->{'Inbinarytable'};
2260		my $gid = $customaction->{'gid'};
2261
2262		my $styles = "";
2263		if ( $customaction->{'Styles'} ) { $styles = $customaction->{'Styles'}; }
2264
2265		my $added_customaction = set_custom_action($customactionidttable, $name, $typ, $source, $target, $inbinarytable, $filesarray, $customactionidttablename, $styles);
2266
2267		if ( $added_customaction )
2268		{
2269			# If the CustomAction was added into the CustomAc.idt, it can be connected to the installation.
2270			# There are currently two different ways for doing this:
2271			# 1. Using "add_custom_action_to_install_table", which adds the CustomAction to the install sequences,
2272			#    which are saved in InstallE.idt and InstallU.idt
2273			# 2. Using "connect_custom_action_to_control" and "connect_custom_action_to_control". The first method
2274			#    connects a CustomAction to a control in ControlE.idt. The second method sets a condition for a control,
2275			#    which might be influenced by the CustomAction. This happens in ControlC.idt.
2276
2277			# Any Windows CustomAction can have a lot of different assignments.
2278
2279			for ( my $j = 1; $j <= 50; $j++ )
2280			{
2281				my $key = "Assignment" . $j;
2282				my $value = "";
2283				if ( $customaction->{$key} )
2284				{
2285					$value = $customaction->{$key};
2286
2287					# in a patch the Assignment can be overwritten by a PatchAssignment
2288					if ( $installer::globals::patch )
2289					{
2290						$patchkey = "PatchAssignment" . $j;
2291						if ( $customaction->{$patchkey} )
2292						{
2293							$value = $customaction->{$patchkey};
2294							$key = $patchkey;
2295						}
2296					}
2297
2298				}
2299				else { last; }
2300
2301				# $value is now a comma separated list
2302				if ( $value =~ /^\s*\(\s*(.*)\s*\);?\s*$/ ) { $value = $1; }
2303				my $assignmentarray = installer::converter::convert_stringlist_into_array(\$value, ",");
2304				my $assignment = create_customaction_assignment_hash($gid, $name, $key, $assignmentarray);
2305
2306				if ( $assignment->{'parameter1'} eq "InstallExecuteSequence" )
2307				{
2308					add_custom_action_to_install_table($installexecutetable, $source, $name, $assignment->{'parameter2'}, $assignment->{'parameter3'}, $filesarray, $installexecutetablename, $styles);
2309				}
2310				elsif ( $assignment->{'parameter1'} eq "AdminExecuteSequence" )
2311				{
2312					add_custom_action_to_install_table($adminexecutetable, $source, $name, $assignment->{'parameter2'}, $assignment->{'parameter3'}, $filesarray, $adminexecutetablename, $styles);
2313				}
2314				elsif ( $assignment->{'parameter1'} eq "InstallUISequence" )
2315				{
2316					add_custom_action_to_install_table($installuitable, $source, $name, $assignment->{'parameter2'}, $assignment->{'parameter3'}, $filesarray, $installuitablename, $styles);
2317				}
2318				elsif ( $assignment->{'parameter1'} eq "ControlEvent" )
2319				{
2320					connect_custom_action_to_control($controleventtable, $controleventtablename, $assignment->{'parameter2'}, $assignment->{'parameter3'}, $assignment->{'parameter4'}, $assignment->{'parameter5'}, $assignment->{'parameter6'}, $assignment->{'parameter7'});
2321				}
2322				elsif ( $assignment->{'parameter1'} eq "ControlCondition" )
2323				{
2324					connect_condition_to_control($controlconditiontable, $controlconditiontablename, $assignment->{'parameter2'}, $assignment->{'parameter3'}, $assignment->{'parameter4'}, $assignment->{'parameter5'});
2325				}
2326				else
2327				{
2328					installer::exiter::exit_program("ERROR: gid: $gid, key: $key ! Unknown Windows CustomAction table: $assignmenthashref->{'parameter1'} ! Currently supported: InstallUISequence, InstallESequence, ControlEvent, ControlCondition", "addcustomactions");
2329				}
2330			}
2331		}
2332	}
2333
2334	# Setting the positions in the tables
2335
2336	set_positions_in_table($installexecutetable, $installexecutetablename);
2337	set_positions_in_table($installuitable, $installuitablename);
2338	set_positions_in_table($adminexecutetable, $adminexecutetablename);
2339
2340	# Saving the files
2341
2342	installer::files::save_file($customactionidttablename, $customactionidttable);
2343	installer::files::save_file($installexecutetablename, $installexecutetable);
2344	installer::files::save_file($adminexecutetablename, $adminexecutetable);
2345	installer::files::save_file($installuitablename, $installuitable);
2346	installer::files::save_file($controleventtablename, $controleventtable);
2347	installer::files::save_file($controlconditiontablename, $controlconditiontable);
2348
2349	my $infoline = "Updated idt file: $customactionidttablename\n";
2350	push(@installer::globals::logfileinfo, $infoline);
2351	$infoline = "Updated idt file: $installexecutetablename\n";
2352	push(@installer::globals::logfileinfo, $infoline);
2353	$infoline = "Updated idt file: $adminexecutetablename\n";
2354	push(@installer::globals::logfileinfo, $infoline);
2355	$infoline = "Updated idt file: $installuitablename\n";
2356	push(@installer::globals::logfileinfo, $infoline);
2357	$infoline = "Updated idt file: $controleventtablename\n";
2358	push(@installer::globals::logfileinfo, $infoline);
2359	$infoline = "Updated idt file: $controlconditiontablename\n";
2360	push(@installer::globals::logfileinfo, $infoline);
2361
2362	installer::logger::include_timestamp_into_logfile("\nPerformance Info: addcustomactions end\n");
2363}
2364
2365##########################################################################
2366# Setting bidi attributes in idt tables
2367##########################################################################
2368
2369sub setbidiattributes
2370{
2371	my ($languageidtdir, $onelanguage) = @_;
2372
2373	# Editing the files Dialog.idt and Control.idt
2374
2375	my $dialogfilename = $languageidtdir . $installer::globals::separator . "Dialog.idt";
2376	my $controlfilename = $languageidtdir . $installer::globals::separator . "Control.idt";
2377
2378	my $dialogfile = installer::files::read_file($dialogfilename);
2379	my $controlfile = installer::files::read_file($controlfilename);
2380
2381	# Searching attributes in Dialog.idt and adding "896".
2382	# Attributes are in column 6 (from 10).
2383
2384	my $bidiattribute = 896;
2385	for ( my $i = 0; $i <= $#{$dialogfile}; $i++ )
2386	{
2387		if ( $i < 3 ) { next; }
2388		if ( ${$dialogfile}[$i] =~ /^\s*(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\s*$/ )
2389		{
2390			my $one = $1;
2391			my $two = $2;
2392			my $three = $3;
2393			my $four = $4;
2394			my $five = $5;
2395			my $attribute = $6;
2396			my $seven = $7;
2397			my $eight = $8;
2398			$attribute = $attribute + $bidiattribute;
2399			${$dialogfile}[$i] = "$one\t$two\t$three\t$four\t$five\t$attribute\t$seven\t$eight\n";
2400		}
2401	}
2402
2403	# Searching attributes in Control.idt and adding "224".
2404	# Attributes are in column 8 (from 12).
2405
2406	$bidiattribute = 224;
2407	for ( my $i = 0; $i <= $#{$controlfile}; $i++ )
2408	{
2409		if ( $i < 3 ) { next; }
2410		if ( ${$controlfile}[$i] =~ /^\s*(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\s*$/ )
2411		{
2412			my $one = $1;
2413			my $two = $2;
2414			my $three = $3;
2415			my $four = $4;
2416			my $five = $5;
2417			my $six = $6;
2418			my $seven = $7;
2419			my $attribute = $8;
2420			my $nine = $9;
2421			my $ten = $10;
2422			my $eleven = $11;
2423			my $twelve = $12;
2424			$attribute = $attribute + $bidiattribute;
2425			${$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";
2426		}
2427	}
2428
2429	# Saving the file
2430
2431	installer::files::save_file($dialogfilename, $dialogfile);
2432	$infoline = "Set bidi support in idt file \"$dialogfilename\" for language $onelanguage\n";
2433	push(@installer::globals::logfileinfo, $infoline);
2434
2435	installer::files::save_file($controlfilename, $controlfile);
2436	$infoline = "Set bidi support in idt file \"$controlfilename\" for language $onelanguage\n";
2437	push(@installer::globals::logfileinfo, $infoline);
2438}
2439
24401;
2441