cid#1607171 Data race condition
[LibreOffice.git] / solenv / bin / modules / installer / windows / idtglobal.pm
blobba3af1ab48d7b9ebfd2372ee8d9e3a3f5194169f
2 # This file is part of the LibreOffice project.
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 # This file incorporates work covered by the following license notice:
10 # Licensed to the Apache Software Foundation (ASF) under one or more
11 # contributor license agreements. See the NOTICE file distributed
12 # with this work for additional information regarding copyright
13 # ownership. The ASF licenses this file to you under the Apache
14 # License, Version 2.0 (the "License"); you may not use this file
15 # except in compliance with the License. You may obtain a copy of
16 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package installer::windows::idtglobal;
21 use strict;
22 use warnings;
24 use Cwd;
25 use installer::converter;
26 use installer::exiter;
27 use installer::files;
28 use installer::globals;
29 use installer::pathanalyzer;
30 use installer::remover;
31 use installer::scriptitems;
32 use installer::systemactions;
33 use installer::windows::language;
35 ##############################################################
36 # Shorten the gid for a feature.
37 # Attention: Maximum length is 38
38 ##############################################################
40 sub shorten_feature_gid
42 my ($stringref) = @_;
44 $$stringref =~ s/gid_Module_/gm_/;
45 $$stringref =~ s/_Extension_/_ex_/;
46 $$stringref =~ s/_Root_/_r_/;
47 $$stringref =~ s/_Prg_/_p_/;
48 $$stringref =~ s/_Optional_/_o_/;
49 $$stringref =~ s/_Tools_/_tl_/;
50 $$stringref =~ s/_Wrt_Flt_/_w_f_/;
51 $$stringref =~ s/_Productivity_/_pr_/;
52 # $$stringref =~ s/_Replacement_/_rpl_/; # native373 fix
55 ############################################
56 # Getting the next free number, that
57 # can be added.
58 # Sample: 01-44-~1.DAT, 01-44-~2.DAT, ...
59 ############################################
61 sub get_next_free_number
63 my ($name, $shortnamesref) = @_;
65 my $counter = 0;
66 my $dontsave = 0;
67 my $alreadyexists;
68 my ($newname, $shortname);
72 $alreadyexists = 0;
73 $counter++;
74 $newname = $name . $counter;
76 for ( my $i = 0; $i <= $#{$shortnamesref}; $i++ )
78 $shortname = ${$shortnamesref}[$i];
80 if ( uc($shortname) eq uc($newname) ) # case insensitive
82 $alreadyexists = 1;
83 last;
87 until (!($alreadyexists));
89 if (( $counter > 9 ) && ( length($name) > 6 )) { $dontsave = 1; }
90 if (( $counter > 99 ) && ( length($name) > 5 )) { $dontsave = 1; }
92 if (!($dontsave))
94 push(@{$shortnamesref}, $newname); # adding the new shortname to the array of shortnames
97 return $counter
100 ############################################
101 # Getting the next free number, that
102 # can be added.
103 # Sample: 01-44-~1.DAT, 01-44-~2.DAT, ...
104 ############################################
106 sub get_next_free_number_with_hash
108 my ($name, $shortnamesref, $ext) = @_;
110 my $counter = 0;
111 my $dontsave = 0;
112 my $saved = 0;
113 my $alreadyexists;
114 my ($newname, $shortname);
118 $alreadyexists = 0;
119 $counter++;
120 $newname = $name . $counter;
121 $newname = uc($newname); # case insensitive, always upper case
122 if ( exists($shortnamesref->{$newname}) ||
123 exists($installer::globals::savedrev83mapping{$newname.$ext}) )
125 $alreadyexists = 1;
128 until (!($alreadyexists));
130 if (( $counter > 9 ) && ( length($name) > 6 )) { $dontsave = 1; }
131 if (( $counter > 99 ) && ( length($name) > 5 )) { $dontsave = 1; }
133 if (!($dontsave))
135 $shortnamesref->{$newname} = 1; # adding the new shortname to the array of shortnames, always uppercase
136 $saved = 1;
139 return ( $counter, $saved )
142 #########################################
143 # 8.3 for filenames and directories
144 #########################################
146 sub make_eight_three_conform
148 my ($inputstring, $pattern, $shortnamesref) = @_;
150 # all shortnames are collected in $shortnamesref, because of uniqueness
152 my ($name, $namelength, $number);
153 my $conformstring = "";
154 my $changed = 0;
156 if (( $inputstring =~ /^\s*(.*?)\.(.*?)\s*$/ ) && ( $pattern eq "file" )) # files with a dot
158 $name = $1;
159 my $extension = $2;
161 $namelength = length($name);
162 my $extensionlength = length($extension);
164 if ( $extensionlength > 3 )
166 # simply taking the first three letters
167 $extension = substr($extension, 0, 3); # name, offset, length
170 # Attention: readme.html -> README~1.HTM
172 if (( $namelength > 8 ) || ( $extensionlength > 3 ))
174 # taking the first six letters
175 $name = substr($name, 0, 6); # name, offset, length
176 $name =~ s/\s*$//; # removing ending whitespaces
177 $name = $name . "\~";
178 $number = get_next_free_number($name, $shortnamesref);
180 # if $number>9 the new name would be "abcdef~10.xyz", which is 9+3, and therefore not allowed
182 if ( $number > 9 )
184 $name = substr($name, 0, 5); # name, offset, length
185 $name =~ s/\s*$//; # removing ending whitespaces
186 $name = $name . "\~";
187 $number = get_next_free_number($name, $shortnamesref);
189 if ( $number > 99 )
191 $name = substr($name, 0, 4); # name, offset, length
192 $name =~ s/\s*$//; # removing ending whitespaces
193 $name = $name . "\~";
194 $number = get_next_free_number($name, $shortnamesref);
198 $name = $name . "$number";
200 $changed = 1;
203 $conformstring = $name . "\." . $extension;
205 if ( $changed ) { $conformstring= uc($conformstring); }
207 else # no dot in filename or directory (also used for shortcuts)
209 $name = $inputstring;
210 $namelength = length($name);
212 if ( $namelength > 8 )
214 # taking the first six letters
215 $name = substr($name, 0, 6); # name, offset, length
216 $name =~ s/\s*$//; # removing ending whitespaces
217 $name = $name . "\~";
218 $number = get_next_free_number($name, $shortnamesref);
220 # if $number>9 the new name would be "abcdef~10.xyz", which is 9+3, and therefore not allowed
222 if ( $number > 9 )
224 $name = substr($name, 0, 5); # name, offset, length
225 $name =~ s/\s*$//; # removing ending whitespaces
226 $name = $name . "\~";
227 $number = get_next_free_number($name, $shortnamesref);
229 if ( $number > 99 )
231 $name = substr($name, 0, 4); # name, offset, length
232 $name =~ s/\s*$//; # removing ending whitespaces
233 $name = $name . "\~";
234 $number = get_next_free_number($name, $shortnamesref);
238 $name = $name . "$number";
239 $changed = 1;
240 if ( $pattern eq "dir" ) { $name =~ s/\./\_/g; } # in directories replacing "." with "_"
243 $conformstring = $name;
245 if ( $changed ) { $conformstring = uc($name); }
248 return $conformstring;
251 #########################################
252 # 8.3 for filenames and directories
253 # $shortnamesref is a hash in this case
254 # -> performance reasons
255 #########################################
257 sub make_eight_three_conform_with_hash
259 my ($inputstring, $pattern, $shortnamesref) = @_;
261 # all shortnames are collected in $shortnamesref, because of uniqueness (a hash!)
263 my ($name, $namelength, $number);
264 my $conformstring = "";
265 my $changed = 0;
266 my $saved;
268 if (( $inputstring =~ /^\s*(.*)\.(.*?)\s*$/ ) && ( $pattern eq "file" )) # files with a dot
270 # extension has to be non-greedy, but name is. This is important to find the last dot in the filename
271 $name = $1;
272 my $extension = $2;
274 if ( $name =~ /^\s*(.*?)\s*$/ ) { $name = $1; } # now the name is also non-greedy
275 $name =~ s/\.//g; # no dots in 8+3 conform filename
277 $namelength = length($name);
278 my $extensionlength = length($extension);
280 if ( $extensionlength > 3 )
282 # simply taking the first three letters
283 $extension = substr($extension, 0, 3); # name, offset, length
284 $changed = 1;
287 # Attention: readme.html -> README~1.HTM
289 if (( $namelength > 8 ) || ( $extensionlength > 3 ))
291 # taking the first six letters, if filename is longer than 6 characters
292 if ( $namelength > 6 )
294 $name = substr($name, 0, 6); # name, offset, length
295 $name =~ s/\s*$//; # removing ending whitespaces
296 $name = $name . "\~";
297 ($number, $saved) = get_next_free_number_with_hash($name, $shortnamesref, '.'.uc($extension));
299 # if $number>9 the new name would be "abcdef~10.xyz", which is 9+3, and therefore not allowed
301 if ( ! $saved )
303 $name = substr($name, 0, 5); # 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));
308 # if $number>99 the new name would be "abcde~100.xyz", which is 9+3, and therefore not allowed
310 if ( ! $saved )
312 $name = substr($name, 0, 4); # 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));
317 if ( ! $saved )
319 installer::exiter::exit_program("ERROR: Could not set 8+3 conform name for $inputstring !", "make_eight_three_conform_with_hash");
324 $name = $name . "$number";
325 $changed = 1;
329 $conformstring = $name . "\." . $extension;
331 if ( $changed ) { $conformstring= uc($conformstring); }
333 else # no dot in filename or directory (also used for shortcuts)
335 $name = $inputstring;
336 $namelength = length($name);
338 if ( $namelength > 8 )
340 # taking the first six letters
341 $name = substr($name, 0, 6); # name, offset, length
342 $name =~ s/\s*$//; # removing ending whitespaces
343 $name = $name . "\~";
344 ( $number, $saved ) = get_next_free_number_with_hash($name, $shortnamesref, '');
346 # if $number>9 the new name would be "abcdef~10", which is 9+0, and therefore not allowed
348 if ( ! $saved )
350 $name = substr($name, 0, 5); # name, offset, length
351 $name =~ s/\s*$//; # removing ending whitespaces
352 $name = $name . "\~";
353 ( $number, $saved ) = get_next_free_number_with_hash($name, $shortnamesref, '');
355 # if $number>99 the new name would be "abcde~100", which is 9+0, and therefore not allowed
357 if ( ! $saved )
359 $name = substr($name, 0, 4); # name, offset, length
360 $name =~ s/\s*$//; # removing ending whitespaces
361 $name = $name . "\~";
362 ( $number, $saved ) = get_next_free_number_with_hash($name, $shortnamesref, '');
364 if ( ! $saved ) { installer::exiter::exit_program("ERROR: Could not set 8+3 conform name for $inputstring !", "make_eight_three_conform_with_hash"); }
368 $name = $name . "$number";
369 $changed = 1;
370 if ( $pattern eq "dir" ) { $name =~ s/\./\_/g; } # in directories replacing "." with "_"
373 $conformstring = $name;
375 if ( $changed ) { $conformstring = uc($name); }
378 return $conformstring;
381 #########################################
382 # Writing the header for idt files
383 #########################################
385 sub write_idt_header
387 my ($idtref, $definestring) = @_;
389 my $oneline;
391 if ( $definestring eq "file" )
393 $oneline = "File\tComponent_\tFileName\tFileSize\tVersion\tLanguage\tAttributes\tSequence\n";
394 push(@{$idtref}, $oneline);
395 $oneline = "s72\ts72\tl255\ti4\tS72\tS20\tI2\ti4\n";
396 push(@{$idtref}, $oneline);
397 $oneline = "File\tFile\n";
398 push(@{$idtref}, $oneline);
401 if ( $definestring eq "filehash" )
403 $oneline = "File_\tOptions\tHashPart1\tHashPart2\tHashPart3\tHashPart4\n";
404 push(@{$idtref}, $oneline);
405 $oneline = "s72\ti2\ti4\ti4\ti4\ti4\n";
406 push(@{$idtref}, $oneline);
407 $oneline = "MsiFileHash\tFile_\n";
408 push(@{$idtref}, $oneline);
411 if ( $definestring eq "directory" )
413 $oneline = "Directory\tDirectory_Parent\tDefaultDir\n";
414 push(@{$idtref}, $oneline);
415 $oneline = "s72\tS72\tl255\n";
416 push(@{$idtref}, $oneline);
417 $oneline = "Directory\tDirectory\n";
418 push(@{$idtref}, $oneline);
421 if ( $definestring eq "component" )
423 $oneline = "Component\tComponentId\tDirectory_\tAttributes\tCondition\tKeyPath\n";
424 push(@{$idtref}, $oneline);
425 $oneline = "s72\tS38\ts72\ti2\tS255\tS72\n";
426 push(@{$idtref}, $oneline);
427 $oneline = "Component\tComponent\n";
428 push(@{$idtref}, $oneline);
431 if ( $definestring eq "feature" )
433 $oneline = "Feature\tFeature_Parent\tTitle\tDescription\tDisplay\tLevel\tDirectory_\tAttributes\n";
434 push(@{$idtref}, $oneline);
435 $oneline = "s38\tS38\tL64\tL255\tI2\ti2\tS72\ti2\n";
436 push(@{$idtref}, $oneline);
437 $oneline = "65001\tFeature\tFeature\n";
438 push(@{$idtref}, $oneline);
441 if ( $definestring eq "featurecomponent" )
443 $oneline = "Feature_\tComponent_\n";
444 push(@{$idtref}, $oneline);
445 $oneline = "s38\ts72\n";
446 push(@{$idtref}, $oneline);
447 $oneline = "FeatureComponents\tFeature_\tComponent_\n";
448 push(@{$idtref}, $oneline);
451 if ( $definestring eq "media" )
453 $oneline = "DiskId\tLastSequence\tDiskPrompt\tCabinet\tVolumeLabel\tSource\n";
454 push(@{$idtref}, $oneline);
455 $oneline = "i2\ti4\tL64\tS255\tS32\tS72\n";
456 push(@{$idtref}, $oneline);
457 $oneline = "Media\tDiskId\n";
458 push(@{$idtref}, $oneline);
461 if ( $definestring eq "font" )
463 $oneline = "File_\tFontTitle\n";
464 push(@{$idtref}, $oneline);
465 $oneline = "s72\tS128\n";
466 push(@{$idtref}, $oneline);
467 $oneline = "Font\tFile_\n";
468 push(@{$idtref}, $oneline);
471 if ( $definestring eq "shortcut" )
473 $oneline = "Shortcut\tDirectory_\tName\tComponent_\tTarget\tArguments\tDescription\tHotkey\tIcon_\tIconIndex\tShowCmd\tWkDir\n";
474 push(@{$idtref}, $oneline);
475 $oneline = "s72\ts72\tl128\ts72\ts72\tS255\tL255\tI2\tS72\tI2\tI2\tS72\n";
476 push(@{$idtref}, $oneline);
477 $oneline = "65001\tShortcut\tShortcut\n";
478 push(@{$idtref}, $oneline);
481 if ( $definestring eq "msishortcutproperty" )
483 $oneline = "MsiShortcutProperty\tShortcut_\tPropertyKey\tPropVariantValue\n";
484 push(@{$idtref}, $oneline);
485 $oneline = "s72\ts72\ts255\ts255\n";
486 push(@{$idtref}, $oneline);
487 $oneline = "MsiShortcutProperty\tMsiShortcutProperty\n";
488 push(@{$idtref}, $oneline);
491 if ( $definestring eq "registry" )
493 $oneline = "Registry\tRoot\tKey\tName\tValue\tComponent_\n";
494 push(@{$idtref}, $oneline);
495 $oneline = "s72\ti2\tl255\tL255\tL0\ts72\n";
496 push(@{$idtref}, $oneline);
497 $oneline = "Registry\tRegistry\n";
498 push(@{$idtref}, $oneline);
501 if ( $definestring eq "createfolder" )
503 $oneline = "Directory_\tComponent_\n";
504 push(@{$idtref}, $oneline);
505 $oneline = "s72\ts72\n";
506 push(@{$idtref}, $oneline);
507 $oneline = "CreateFolder\tDirectory_\tComponent_\n";
508 push(@{$idtref}, $oneline);
511 if ( $definestring eq "removefile" )
513 $oneline = "FileKey\tComponent_\tFileName\tDirProperty\tInstallMode\n";
514 push(@{$idtref}, $oneline);
515 $oneline = "s72\ts72\tL255\ts72\ti2\n";
516 push(@{$idtref}, $oneline);
517 $oneline = "RemoveFile\tFileKey\n";
518 push(@{$idtref}, $oneline);
521 if ( $definestring eq "upgrade" )
523 $oneline = "UpgradeCode\tVersionMin\tVersionMax\tLanguage\tAttributes\tRemove\tActionProperty\n";
524 push(@{$idtref}, $oneline);
525 $oneline = "s38\tS20\tS20\tS255\ti4\tS255\ts72\n";
526 push(@{$idtref}, $oneline);
527 $oneline = "Upgrade\tUpgradeCode\tVersionMin\tVersionMax\tLanguage\tAttributes\n";
528 push(@{$idtref}, $oneline);
531 if ( $definestring eq "icon" )
533 $oneline = "Name\tData\n";
534 push(@{$idtref}, $oneline);
535 $oneline = "s72\tv0\n";
536 push(@{$idtref}, $oneline);
537 $oneline = "Icon\tName\n";
538 push(@{$idtref}, $oneline);
541 if ( $definestring eq "inifile" )
543 $oneline = "IniFile\tFileName\tDirProperty\tSection\tKey\tValue\tAction\tComponent_\n";
544 push(@{$idtref}, $oneline);
545 $oneline = "s72\tl255\tS72\tl96\tl128\tl255\ti2\ts72\n";
546 push(@{$idtref}, $oneline);
547 $oneline = "IniFile\tIniFile\n";
548 push(@{$idtref}, $oneline);
551 if ( $definestring eq "msiassembly" )
553 $oneline = "Component_\tFeature_\tFile_Manifest\tFile_Application\tAttributes\n";
554 push(@{$idtref}, $oneline);
555 $oneline = "s72\ts38\tS72\tS72\tI2\n";
556 push(@{$idtref}, $oneline);
557 $oneline = "MsiAssembly\tComponent_\n";
558 push(@{$idtref}, $oneline);
561 if ( $definestring eq "msiassemblyname" )
563 $oneline = "Component_\tName\tValue\n";
564 push(@{$idtref}, $oneline);
565 $oneline = "s72\ts255\ts255\n";
566 push(@{$idtref}, $oneline);
567 $oneline = "MsiAssemblyName\tComponent_\tName\n";
568 push(@{$idtref}, $oneline);
571 if ( $definestring eq "appsearch" )
573 $oneline = "Property\tSignature_\n";
574 push(@{$idtref}, $oneline);
575 $oneline = "s72\ts72\n";
576 push(@{$idtref}, $oneline);
577 $oneline = "AppSearch\tProperty\tSignature_\n";
578 push(@{$idtref}, $oneline);
581 if ( $definestring eq "reglocat" )
583 $oneline = "Signature_\tRoot\tKey\tName\tType\n";
584 push(@{$idtref}, $oneline);
585 $oneline = "s72\ti2\ts255\tS255\tI2\n";
586 push(@{$idtref}, $oneline);
587 $oneline = "RegLocator\tSignature_\n";
588 push(@{$idtref}, $oneline);
591 if ( $definestring eq "signatur" )
593 $oneline = "Signature\tFileName\tMinVersion\tMaxVersion\tMinSize\tMaxSize\tMinDate\tMaxDate\tLanguages\n";
594 push(@{$idtref}, $oneline);
595 $oneline = "s72\ts255\tS20\tS20\tI4\tI4\tI4\tI4\tS255\n";
596 push(@{$idtref}, $oneline);
597 $oneline = "Signature\tSignature\n";
598 push(@{$idtref}, $oneline);
603 ##############################################################
604 # Returning the name of the translation file for a
605 # given language.
606 # Sample: "01" order "en-US" -> "1033.txt"
607 ##############################################################
609 sub get_languagefilename
611 my ($idtfilename, $basedir) = @_;
613 $idtfilename =~ s/\.idt/\.ulf/;
615 my $languagefilename = $basedir . $installer::globals::separator . $idtfilename;
617 return $languagefilename;
620 ##############################################################
621 # Returning the complete block in all languages
622 # for a specified string
623 ##############################################################
625 sub get_language_block_from_language_file
627 my ($searchstring, $languagefile) = @_;
629 my @language_block = ();
631 for ( my $i = 0; $i <= $#{$languagefile}; $i++ )
633 if ( ${$languagefile}[$i] =~ /^\s*\[\s*$searchstring\s*\]\s*$/ )
635 my $counter = $i;
637 push(@language_block, ${$languagefile}[$counter]);
638 $counter++;
640 while (( $counter <= $#{$languagefile} ) && (!( ${$languagefile}[$counter] =~ /^\s*\[/ )))
642 push(@language_block, ${$languagefile}[$counter]);
643 $counter++;
646 last;
650 return \@language_block;
653 ##############################################################
654 # Returning a specific language string from the block
655 # of all translations
656 ##############################################################
658 sub get_language_string_from_language_block
660 my ($language_block, $language, $oldstring) = @_;
662 my $newstring = "";
664 for ( my $i = 0; $i <= $#{$language_block}; $i++ )
666 if ( ${$language_block}[$i] =~ /^\s*$language\s*\=\s*\"(.*)\"\s*$/ )
668 $newstring = $1;
669 $newstring =~ s/\\\"/\"/g; #un-escape quotes, fdo#59321
670 last;
674 if ( $newstring eq "" )
676 $language = "en-US"; # defaulting to english
678 for ( my $i = 0; $i <= $#{$language_block}; $i++ )
680 if ( ${$language_block}[$i] =~ /^\s*$language\s*\=\s*\"(.*)\"\s*$/ )
682 $newstring = $1;
683 last;
688 return $newstring;
691 ##############################################################
692 # Returning a specific code from the block
693 # of all codes. No defaulting to english!
694 ##############################################################
696 sub get_code_from_code_block
698 my ($codeblock, $language) = @_;
700 my $newstring = "";
702 for ( my $i = 0; $i <= $#{$codeblock}; $i++ )
704 if ( ${$codeblock}[$i] =~ /^\s*$language\s*\=\s*\"(.*)\"\s*$/ )
706 $newstring = $1;
707 last;
711 return $newstring;
714 ##############################################################
715 # Translating an idt file
716 ##############################################################
718 sub translate_idtfile
720 my ($idtfile, $languagefile, $onelanguage) = @_;
722 for ( my $i = 0; $i <= $#{$idtfile}; $i++ )
724 my @allstrings = ();
726 my $oneline = ${$idtfile}[$i];
728 while ( $oneline =~ /\b(OOO_\w+)\b/ )
730 my $replacestring = $1;
731 push(@allstrings, $replacestring);
732 $oneline =~ s/$replacestring//;
735 my $oldstring;
737 foreach $oldstring (@allstrings)
739 my $language_block = get_language_block_from_language_file($oldstring, $languagefile);
740 my $newstring = get_language_string_from_language_block($language_block, $onelanguage, $oldstring);
742 ${$idtfile}[$i] =~ s/$oldstring/$newstring/; # always substitute, even if $newstring eq "" (there are empty strings for control.idt)
747 ##############################################################
748 # Copying all needed files to create a msi database
749 # into one language specific directory
750 ##############################################################
752 sub prepare_language_idt_directory
754 my ($destinationdir, $newidtdir, $onelanguage, $filesref, $iconfilecollector, $binarytablefiles, $allvariables) = @_;
756 # Copying all idt-files from the source $installer::globals::idttemplatepath to the destination $destinationdir
757 # Copying all files in the subdirectory "Binary"
758 # Copying all files in the subdirectory "Icon"
760 my $infoline = "";
762 installer::systemactions::copy_directory($installer::globals::idttemplatepath, $destinationdir);
764 if ( -d $installer::globals::idttemplatepath . $installer::globals::separator . "Binary")
766 installer::systemactions::create_directory($destinationdir . $installer::globals::separator . "Binary");
767 installer::systemactions::copy_directory($installer::globals::idttemplatepath . $installer::globals::separator . "Binary", $destinationdir . $installer::globals::separator . "Binary");
770 installer::systemactions::create_directory($destinationdir . $installer::globals::separator . "Icon");
772 if ( -d $installer::globals::idttemplatepath . $installer::globals::separator . "Icon")
774 installer::systemactions::copy_directory($installer::globals::idttemplatepath . $installer::globals::separator . "Icon", $destinationdir . $installer::globals::separator . "Icon");
777 # Copying all files in $iconfilecollector, that describe icons of folderitems
779 for ( my $i = 0; $i <= $#{$iconfilecollector}; $i++ )
781 my $iconfilename = ${$iconfilecollector}[$i];
782 installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$iconfilename);
783 installer::systemactions::copy_one_file(${$iconfilecollector}[$i], $destinationdir . $installer::globals::separator . "Icon" . $installer::globals::separator . $iconfilename);
786 # Copying all files in $binarytablefiles in the binary directory
788 for ( my $i = 0; $i <= $#{$binarytablefiles}; $i++ )
790 my $binaryfile = ${$binarytablefiles}[$i];
791 my $binaryfilepath = $binaryfile->{'sourcepath'};
792 my $binaryfilename = $binaryfilepath;
793 installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$binaryfilename);
794 installer::systemactions::copy_one_file($binaryfilepath, $destinationdir . $installer::globals::separator . "Binary" . $installer::globals::separator . $binaryfilename);
797 # Copying all new created and language independent idt-files to the destination $destinationdir.
798 # Example: "File.idt"
800 installer::systemactions::copy_directory_with_fileextension($newidtdir, $destinationdir, "idt");
802 # Copying all new created and language dependent idt-files to the destination $destinationdir.
803 # Example: "Feature.idt.01"
805 installer::systemactions::copy_directory_with_fileextension($newidtdir, $destinationdir, $onelanguage);
806 installer::systemactions::rename_files_with_fileextension($destinationdir, $onelanguage);
810 ##############################################################
811 # Returning the source path of the rtf licensefile for
812 # a specified language
813 ##############################################################
815 sub get_rtflicensefilesource
817 my ($language, $includepatharrayref) = @_;
819 my $licensefilename = "license_" . $language . ".rtf";
821 my $sourcefileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$licensefilename, $includepatharrayref, 1);
823 if ($$sourcefileref eq "") { installer::exiter::exit_program("ERROR: Could not find $licensefilename!", "get_rtflicensefilesource"); }
825 my $infoline = "Using licensefile: $$sourcefileref\n";
826 push( @installer::globals::logfileinfo, $infoline);
828 return $$sourcefileref;
831 ##############################################################
832 # A simple converter to create a license txt string from
833 # the rtf format
834 ##############################################################
836 sub make_string_licensetext
838 my ($licensefile) = @_;
840 my $rtf_licensetext = "";
842 for ( my $i = 0; $i <= $#{$licensefile}; $i++ )
844 my $oneline = ${$licensefile}[$i];
845 $oneline =~ s/\s*$//g; # no whitespace at line end
847 $rtf_licensetext = $rtf_licensetext . $oneline . " ";
850 return $rtf_licensetext;
853 ##############################################################
854 # Including the license text into the table control.idt
855 ##############################################################
857 sub add_licensefile_to_database
859 my ($licensefile, $controltable) = @_;
861 # Nine tabs before the license text and two tabs after it
862 # The license text has to be included into the dialog
863 # LicenseAgreement into the control Memo.
865 my $foundlicenseline = 0;
866 my ($number, $line);
868 for ( my $i = 0; $i <= $#{$controltable}; $i++ )
870 $line = ${$controltable}[$i];
872 if ( $line =~ /^\s*\bLicenseAgreement\b\t\bMemo\t/ )
874 $foundlicenseline = 1;
875 $number = $i;
876 last;
880 if (!($foundlicenseline))
882 installer::exiter::exit_program("ERROR: Line for license file in Control.idt not found!", "add_licensefile_to_database");
884 else
886 my %control = ();
888 if ( $line =~ /^\s*(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\s*$/ )
890 $control{'Dialog_'} = $1;
891 $control{'Control'} = $2;
892 $control{'Type'} = $3;
893 $control{'X'} = $4;
894 $control{'Y'} = $5;
895 $control{'Width'} = $6;
896 $control{'Height'} = $7;
897 $control{'Attributes'} = $8;
898 $control{'Property'} = $9;
899 $control{'Text'} = $10;
900 $control{'Control_Next'} = $11;
901 $control{'Help'} = $12;
903 else
905 installer::exiter::exit_program("ERROR: Could not split line correctly!", "add_licensefile_to_database");
908 my $licensetext = make_string_licensetext($licensefile);
910 $control{'Text'} = $licensetext;
912 my $newline = $control{'Dialog_'} . "\t" . $control{'Control'} . "\t" . $control{'Type'} . "\t" .
913 $control{'X'} . "\t" . $control{'Y'} . "\t" . $control{'Width'} . "\t" .
914 $control{'Height'} . "\t" . $control{'Attributes'} . "\t" . $control{'Property'} . "\t" .
915 $control{'Text'} . "\t" . $control{'Control_Next'} . "\t" . $control{'Help'} . "\n";
917 ${$controltable}[$number] = $newline
921 ###################################################################
922 # Determining the last position in a sequencetable
923 # into the tables CustomAc.idt and InstallE.idt.
924 ###################################################################
926 sub get_last_position_in_sequencetable
928 my ($sequencetable) = @_;
930 my $position = 0;
932 for ( my $i = 0; $i <= $#{$sequencetable}; $i++ )
934 my $line = ${$sequencetable}[$i];
936 if ( $line =~ /^\s*\w+\t.*\t\s*(\d+)\s$/ )
938 my $newposition = $1;
939 if ( $newposition > $position ) { $position = $newposition; }
943 return $position;
946 #########################################################################
947 # Determining the position of a specified Action in the sequencetable
948 #########################################################################
950 sub get_position_in_sequencetable
952 my ($action, $sequencetable) = @_;
954 my $position = 0;
956 $action =~ s/^\s*behind_//;
958 for ( my $i = 0; $i <= $#{$sequencetable}; $i++ )
960 my $line = ${$sequencetable}[$i];
962 if ( $line =~ /^\s*(\w+)\t.*\t\s*(\d+)\s$/ )
964 my $compareaction = $1;
965 $position = $2;
966 if ( $compareaction eq $action ) { last; }
970 return $position;
973 ################################################################################################
974 # Including the CustomAction for the configuration
975 # into the tables CustomAc.idt and InstallE.idt.
977 # CustomAc.idt: ExecutePkgchk 82 pkgchk.exe -s
978 # InstallE.idt: ExecutePkgchk Not REMOVE="ALL" 3175
980 # CustomAc.idt: ExecuteQuickstart 82 install_quickstart.exe
981 # InstallE.idt: ExecuteQuickstart &gm_o_Quickstart=3 3200
983 # CustomAc.idt: ExecuteInstallRegsvrex 82 regsvrex.exe shlxthdl.dll
984 # InstallE.idt: ExecuteInstallRegsvrex Not REMOVE="ALL" 3225
986 # CustomAc.idt: ExecuteUninstallRegsvrex 82 regsvrex.exe /u shlxthdl.dll
987 # InstallE.idt: ExecuteUninstallRegsvrex REMOVE="ALL" 690
989 # CustomAc.idt: Regmsdocmsidll1 1 reg4msdocmsidll Reg4MsDocEntry
990 # InstallU.idt: Regmsdocmsidll1 Not REMOVE="ALL" 610
992 # CustomAc.idt: Regmsdocmsidll2 1 reg4msdocmsidll Reg4MsDocEntry
993 # InstallE.idt: Regmsdocmsidll2 Not REMOVE="ALL" 3160
994 ################################################################################################
996 sub set_custom_action
998 my ($customactionidttable, $actionname, $actionflags, $exefilename, $actionparameter, $inbinarytable, $filesref, $customactionidttablename, $styles) = @_;
1000 my $included_customaction = 0;
1001 my $infoline = "";
1002 my $customaction_exefilename = $exefilename;
1003 my $uniquename = "";
1005 # when the style NO_FILE is set, no searching for the file is needed, no filtering is done, we can add that custom action
1006 if ( $styles =~ /\bNO_FILE\b/ )
1008 my $line = $actionname . "\t" . $actionflags . "\t" . $customaction_exefilename . "\t" . $actionparameter . "\t\n";
1009 push(@{$customactionidttable}, $line);
1011 $infoline = "Added $actionname CustomAction into table $customactionidttablename (NO_FILE has been set)\n";
1012 push(@installer::globals::logfileinfo, $infoline);
1014 $included_customaction = 1;
1015 return $included_customaction;
1018 # is the $exefilename a library that is included into the binary table
1020 if ( $inbinarytable ) { $customaction_exefilename =~ s/\.//g; } # this is the entry in the binary table ("abc.dll" -> "abcdll")
1022 # is the $exefilename included into the product?
1024 my $contains_file = 0;
1026 # All files are located in $filesref and in @installer::globals::binarytableonlyfiles.
1027 # Both must be added together
1028 my $localfilesref = [@installer::globals::binarytableonlyfiles, @{$filesref}];
1030 for ( my $i = 0; $i <= $#{$localfilesref}; $i++ )
1032 my $onefile = ${$localfilesref}[$i];
1033 my $filename = "";
1034 if ( exists($onefile->{'Name'}) )
1036 $filename = $onefile->{'Name'};
1038 if ( $filename eq $exefilename )
1040 $contains_file = 1;
1041 $uniquename = ${$localfilesref}[$i]->{'uniquename'};
1042 last;
1045 else
1047 installer::exiter::exit_program("ERROR: Did not find \"Name\" for file \"$onefile->{'uniquename'}\" ($onefile->{'gid'})!", "set_custom_action");
1051 if ( $contains_file )
1053 # Now the CustomAction can be included into the CustomAc.idt
1055 if ( ! $inbinarytable ) { $customaction_exefilename = $uniquename; } # the unique file name has to be added to the custom action table
1057 my $line = $actionname . "\t" . $actionflags . "\t" . $customaction_exefilename . "\t" . $actionparameter . "\t\n";
1058 push(@{$customactionidttable}, $line);
1060 $included_customaction = 1;
1063 if ( $included_customaction ) { $infoline = "Added $actionname CustomAction into table $customactionidttablename\n"; }
1064 else { $infoline = "Did not add $actionname CustomAction into table $customactionidttablename\n"; }
1065 push(@installer::globals::logfileinfo, $infoline);
1067 return $included_customaction;
1070 ####################################################################
1071 # Adding a Custom Action to InstallExecuteTable or InstallUITable
1072 ####################################################################
1074 sub add_custom_action_to_install_table
1076 my ($installtable, $exefilename, $actionname, $actioncondition, $position, $filesref, $installtablename, $styles) = @_;
1078 my $included_customaction = 0;
1079 my $feature = "";
1080 my $infoline = "";
1082 # when the style NO_FILE is set, no searching for the file is needed, no filtering is done, we can add that custom action
1083 if ( $styles =~ /\bNO_FILE\b/ )
1085 # then the InstallE.idt.idt or InstallU.idt.idt
1086 $actioncondition =~ s/FEATURETEMPLATE/$feature/g; # only execute Custom Action, if feature of the file is installed
1088 my $actionposition = 0;
1090 if ( $position =~ /^\s*\d+\s*$/ ) { $actionposition = $position; } # setting the position directly, number defined in scp2
1091 else { $actionposition = "POSITIONTEMPLATE_" . $position; }
1093 my $line = $actionname . "\t" . $actioncondition . "\t" . $actionposition . "\n";
1094 push(@{$installtable}, $line);
1096 $infoline = "Added $actionname CustomAction into table $installtablename (NO_FILE has been set)\n";
1097 push(@installer::globals::logfileinfo, $infoline);
1098 return;
1101 my $contains_file = 0;
1103 # All files are located in $filesref and in @installer::globals::binarytableonlyfiles.
1104 # Both must be added together
1105 my $localfilesref = [@installer::globals::binarytableonlyfiles, @{$filesref}];
1107 for ( my $i = 0; $i <= $#{$localfilesref}; $i++ )
1109 my $filename = ${$localfilesref}[$i]->{'Name'};
1111 if ( $filename eq $exefilename )
1113 $contains_file = 1;
1115 # Determining the feature of the file
1117 if ( ${$localfilesref}[$i] ) { $feature = ${$localfilesref}[$i]->{'modules'}; }
1119 # If modules contains a list of modules, only taking the first one.
1120 if ( $feature =~ /^\s*(.*?)\,/ ) { $feature = $1; }
1121 # Attention: Maximum feature length is 38!
1122 shorten_feature_gid(\$feature);
1124 last;
1128 if ( $contains_file )
1130 # then the InstallE.idt.idt or InstallU.idt.idt
1132 $actioncondition =~ s/FEATURETEMPLATE/$feature/g; # only execute Custom Action, if feature of the file is installed
1134 my $positiontemplate = "";
1135 if ( $position =~ /^\s*\d+\s*$/ ) { $positiontemplate = $position; } # setting the position directly, number defined in scp2
1136 else { $positiontemplate = "POSITIONTEMPLATE_" . $position; }
1138 my $line = $actionname . "\t" . $actioncondition . "\t" . $positiontemplate . "\n";
1139 push(@{$installtable}, $line);
1141 $included_customaction = 1;
1144 if ( $included_customaction ) { $infoline = "Added $actionname CustomAction into table $installtablename\n"; }
1145 else { $infoline = "Did not add $actionname CustomAction into table $installtablename\n"; }
1146 push(@installer::globals::logfileinfo, $infoline);
1150 ##################################################################
1151 # A line in the table ControlEvent connects a Control
1152 # with a Custom Action
1153 #################################################################
1155 sub connect_custom_action_to_control
1157 my ( $table, $tablename, $dialog, $control, $event, $argument, $condition, $ordering) = @_;
1159 my $line = $dialog . "\t" . $control. "\t" . $event. "\t" . $argument. "\t" . $condition. "\t" . $ordering . "\n";
1161 push(@{$table}, $line);
1163 $line =~ s/\s*$//g;
1165 my $infoline = "Added line \"$line\" into table $tablename\n";
1166 push(@installer::globals::logfileinfo, $infoline);
1169 ##################################################################
1170 # A line in the table ControlCondition connects a Control state
1171 # with a condition
1172 ##################################################################
1174 sub connect_condition_to_control
1176 my ( $table, $tablename, $dialog, $control, $event, $condition) = @_;
1178 my $line = $dialog . "\t" . $control. "\t" . $event. "\t" . $condition. "\n";
1180 push(@{$table}, $line);
1182 $line =~ s/\s*$//g;
1184 my $infoline = "Added line \"$line\" into table $tablename\n";
1185 push(@installer::globals::logfileinfo, $infoline);
1188 ##################################################################
1189 # Searching for a sequencenumber in InstallUISequence table
1190 # "ExecuteAction" must be the last action
1191 ##################################################################
1193 sub get_free_number_in_uisequence_table
1195 my ( $installuitable ) = @_;
1197 # determining the sequence of "ExecuteAction"
1199 my $executeactionnumber = 0;
1201 for ( my $i = 0; $i <= $#{$installuitable}; $i++ )
1203 if ( ${$installuitable}[$i] =~ /^\s*(\w+)\t\w*\t(\d+)\s*$/ )
1205 my $actionname = $1;
1206 my $actionnumber = $2;
1208 if ( $actionname eq "ExecuteAction" )
1210 $executeactionnumber = $actionnumber;
1211 last;
1216 if ( $executeactionnumber == 0 ) { installer::exiter::exit_program("ERROR: Did not find \"ExecuteAction\" in InstallUISequence table!", "get_free_number_in_uisequence_table"); }
1218 # determining the sequence of the action before "ExecuteAction"
1220 my $lastactionnumber = 0;
1222 for ( my $i = 0; $i <= $#{$installuitable}; $i++ )
1224 if ( ${$installuitable}[$i] =~ /^\s*\w+\t\w*\t(\d+)\s*$/ )
1226 my $actionnumber = $1;
1228 if (( $actionnumber > $lastactionnumber ) && ( $actionnumber != $executeactionnumber ))
1230 $lastactionnumber = $actionnumber;
1235 # the new number can now be calculated
1237 my $newnumber = 0;
1239 if ((( $lastactionnumber + $executeactionnumber ) % 2 ) == 0 ) { $newnumber = ( $lastactionnumber + $executeactionnumber ) / 2; }
1240 else { $newnumber = ( $lastactionnumber + $executeactionnumber -1 ) / 2; }
1242 return $newnumber;
1245 #############################################################
1246 # Including the new subdir into the directory table
1247 #############################################################
1249 sub include_subdirname_into_directory_table
1251 my ($dirname, $directorytable, $directorytablename, $onefile) = @_;
1253 my $subdir = "";
1254 if ( $onefile->{'Subdir'} ) { $subdir = $onefile->{'Subdir'}; }
1255 if ( $subdir eq "" ) { installer::exiter::exit_program("ERROR: No \"Subdir\" defined for $onefile->{'Name'}", "include_subdirname_into_directory_table"); }
1257 # program INSTALLLOCATION program -> subjava INSTALLLOCATION program:java
1259 my $uniquename = "";
1260 my $parent = "";
1261 my $name = "";
1263 my $includedline = 0;
1265 my $newdir = "";
1267 for ( my $i = 0; $i <= $#{$directorytable}; $i++ )
1270 if ( ${$directorytable}[$i] =~ /^\s*(.*?)\t(.*?)\t(.*?)\s*$/ )
1272 $uniquename = $1;
1273 $parent = $2;
1274 $name = $3;
1276 if ( $dirname eq $name )
1278 my $newuniquename = "sub" . $subdir;
1279 $newdir = $newuniquename;
1280 my $newparent = "INSTALLLOCATION";
1281 my $newname = $name . "\:" . $subdir;
1282 my $newline =
1283 my $line = "$newuniquename\t$newparent\t$newname\n";
1284 push(@{$directorytable}, $line);
1285 installer::remover::remove_leading_and_ending_whitespaces(\$line);
1286 my $infoline = "Added $line into directory table $directorytablename\n";
1287 push(@installer::globals::logfileinfo, $infoline);
1289 $includedline = 1;
1290 last;
1295 if ( ! $includedline ) { installer::exiter::exit_program("ERROR: Could not include new subdirectory into directory table for file $onefile->{'Name'}!", "include_subdirname_into_directory_table"); }
1297 return $newdir;
1300 ##################################################################
1301 # Including the new sub directory into the component table
1302 ##################################################################
1304 sub include_subdir_into_componenttable
1306 my ($subdir, $onefile, $componenttable) = @_;
1308 my $componentname = $onefile->{'componentname'};
1310 my $changeddirectory = 0;
1312 for ( my $i = 0; $i <= $#{$componenttable}; $i++ )
1314 if ( ${$componenttable}[$i] =~ /^\s*(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\s*$/ )
1316 my $localcomponentname = $1;
1317 my $directory = $3;
1319 if ( $componentname eq $localcomponentname )
1321 my $oldvalue = ${$componenttable}[$i];
1322 ${$componenttable}[$i] =~ s/\b\Q$directory\E\b/$subdir/;
1323 my $newvalue = ${$componenttable}[$i];
1325 installer::remover::remove_leading_and_ending_whitespaces(\$oldvalue);
1326 installer::remover::remove_leading_and_ending_whitespaces(\$newvalue);
1327 my $infoline = "Change in Component table: From \"$oldvalue\" to \"$newvalue\"\n";
1328 push(@installer::globals::logfileinfo, $infoline);
1330 $changeddirectory = 1;
1331 last;
1336 if ( ! $changeddirectory ) { installer::exiter::exit_program("ERROR: Could not change directory for component: $onefile->{'Name'}!", "include_subdir_into_componenttable"); }
1340 ##################################################################
1341 # Setting the condition, that at least one module is selected.
1342 # All modules with flag SHOW_MULTILINGUAL_ONLY were already
1343 # collected. In table ControlE.idt, the string
1344 # LANGUAGECONDITIONINSTALL needs to be replaced.
1345 # Also for APPLICATIONCONDITIONINSTALL for the applications
1346 # with flag APPLICATIONMODULE.
1347 ##################################################################
1349 sub set_multilanguageonly_condition
1351 my ( $languageidtdir ) = @_;
1353 my $onefilename = $languageidtdir . $installer::globals::separator . "ControlE.idt";
1354 my $onefile = installer::files::read_file($onefilename);
1356 # Language modules
1358 my $condition = "";
1360 foreach my $module ( sort keys %installer::globals::multilingual_only_modules )
1362 $condition = $condition . " &$module=3 Or";
1365 $condition =~ s/^\s*//;
1366 $condition =~ s/\s*Or\s*$//; # removing the ending "Or"
1368 if ( $condition eq "" ) { $condition = "1"; }
1370 for ( my $j = 0; $j <= $#{$onefile}; $j++ )
1372 ${$onefile}[$j] =~ s/LANGUAGECONDITIONINSTALL/$condition/;
1375 # Application modules
1377 $condition = "";
1379 foreach my $module ( sort keys %installer::globals::application_modules )
1381 $condition = $condition . " &$module=3 Or";
1384 $condition =~ s/^\s*//;
1385 $condition =~ s/\s*Or\s*$//; # removing the ending "Or"
1387 if ( $condition eq "" ) { $condition = "1"; }
1389 for ( my $j = 0; $j <= $#{$onefile}; $j++ )
1391 ${$onefile}[$j] =~ s/APPLICATIONCONDITIONINSTALL/$condition/;
1394 installer::files::save_file($onefilename, $onefile);
1397 #############################################
1398 # Putting array values into hash
1399 #############################################
1401 sub fill_assignment_hash
1403 my ($gid, $name, $key, $assignmenthashref, $parameter, $tablename, $assignmentarray) = @_;
1405 my $max = $parameter - 1;
1407 if ( $max != $#{$assignmentarray} )
1409 my $definedparameter = $#{$assignmentarray} + 1;
1410 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");
1413 for ( my $i = 0; $i <= $#{$assignmentarray}; $i++ )
1415 my $counter = $i + 1;
1416 my $key = "parameter". $counter;
1418 my $localvalue = ${$assignmentarray}[$i];
1419 installer::remover::remove_leading_and_ending_quotationmarks(\$localvalue);
1420 $localvalue =~ s/\\\"/\"/g;
1421 $localvalue =~ s/\\\!/\!/g;
1422 $localvalue =~ s/\\\&/\&/g;
1423 $localvalue =~ s/\\\</\</g;
1424 $localvalue =~ s/\\\>/\>/g;
1425 $assignmenthashref->{$key} = $localvalue;
1429 ##########################################################################
1430 # Checking the assignment of a Windows CustomAction and putting it
1431 # into a hash
1432 ##########################################################################
1434 sub create_customaction_assignment_hash
1436 my ($gid, $name, $key, $assignmentarray) = @_;
1438 my %assignment = ();
1439 my $assignmenthashref = \%assignment;
1441 my $tablename = ${$assignmentarray}[0];
1442 installer::remover::remove_leading_and_ending_quotationmarks(\$tablename);
1444 my $tablename_defined = 0;
1445 my $parameter = 0;
1447 if ( $tablename eq "InstallUISequence" )
1449 $tablename_defined = 1;
1450 $parameter = 3;
1451 fill_assignment_hash($gid, $name, $key, $assignmenthashref, $parameter, $tablename, $assignmentarray);
1454 if ( $tablename eq "InstallExecuteSequence" )
1456 $tablename_defined = 1;
1457 $parameter = 3;
1458 fill_assignment_hash($gid, $name, $key, $assignmenthashref, $parameter, $tablename, $assignmentarray);
1461 if ( $tablename eq "AdminExecuteSequence" )
1463 $tablename_defined = 1;
1464 $parameter = 3;
1465 fill_assignment_hash($gid, $name, $key, $assignmenthashref, $parameter, $tablename, $assignmentarray);
1468 if ( $tablename eq "ControlEvent" )
1470 $tablename_defined = 1;
1471 $parameter = 7;
1472 fill_assignment_hash($gid, $name, $key, $assignmenthashref, $parameter, $tablename, $assignmentarray);
1475 if ( $tablename eq "ControlCondition" )
1477 $tablename_defined = 1;
1478 $parameter = 5;
1479 fill_assignment_hash($gid, $name, $key, $assignmenthashref, $parameter, $tablename, $assignmentarray);
1482 if ( ! $tablename_defined )
1484 installer::exiter::exit_program("ERROR: gid: $gid, key: $key ! Unknown Windows CustomAction table: $tablename ! Currently supported: InstallUISequence, InstallExecuteSequence, ControlEvent, ControlCondition", "create_customaction_assignment_hash");
1487 return $assignmenthashref;
1490 ##########################################################################
1491 # Finding the position of a specified CustomAction.
1492 # If the CustomAction is not found, the return value is "-1".
1493 # If the CustomAction position is not defined yet,
1494 # the return value is also "-1".
1495 ##########################################################################
1497 sub get_customaction_position
1499 my ($action, $sequencetable) = @_;
1501 my $position = -1;
1503 for ( my $i = 0; $i <= $#{$sequencetable}; $i++ )
1505 my $line = ${$sequencetable}[$i];
1507 if ( $line =~ /^\s*([\w\.]+)\t.*\t\s*(\d+)\s$/ ) # matching only, if position is a number!
1509 my $compareaction = $1;
1510 my $localposition = $2;
1512 if ( $compareaction eq $action )
1514 $position = $localposition;
1515 last;
1520 return $position;
1523 ##########################################################################
1524 # Setting the position of CustomActions in sequence tables.
1525 # Replacing all occurrences of "POSITIONTEMPLATE_"
1526 ##########################################################################
1528 sub set_positions_in_table
1530 my ( $sequencetable, $tablename ) = @_;
1532 my $infoline = "\nSetting positions in table \"$tablename\".\n";
1533 push(@installer::globals::logfileinfo, $infoline);
1535 # Step 1: Resolving all occurrences of "POSITIONTEMPLATE_end"
1537 my $lastposition = get_last_position_in_sequencetable($sequencetable);
1539 for ( my $i = 0; $i <= $#{$sequencetable}; $i++ )
1541 if ( ${$sequencetable}[$i] =~ /^\s*([\w\.]+)\t.*\t\s*POSITIONTEMPLATE_end\s*$/ )
1543 my $customaction = $1;
1544 $lastposition = $lastposition + 25;
1545 ${$sequencetable}[$i] =~ s/POSITIONTEMPLATE_end/$lastposition/;
1546 $infoline = "Setting position \"$lastposition\" for custom action \"$customaction\".\n";
1547 push(@installer::globals::logfileinfo, $infoline);
1551 # Step 2: Resolving all occurrences of "POSITIONTEMPLATE_abc" or "POSITIONTEMPLATE_behind_abc"
1552 # where abc is the name of the reference Custom Action.
1553 # This has to be done, until there is no more occurrence of POSITIONTEMPLATE (success)
1554 # or there is no replacement in one circle (failure).
1556 my $template_exists = 0;
1557 my $template_replaced = 0;
1558 my $counter = 0;
1562 $template_exists = 0;
1563 $template_replaced = 0;
1564 $counter++;
1566 for ( my $i = 0; $i <= $#{$sequencetable}; $i++ )
1568 if ( ${$sequencetable}[$i] =~ /^\s*([\w\.]+)\t.*\t\s*(POSITIONTEMPLATE_.*?)\s*$/ )
1570 my $onename = $1;
1571 my $templatename = $2;
1572 my $positionname = $templatename;
1573 my $customaction = $templatename;
1574 $customaction =~ s/POSITIONTEMPLATE_//;
1575 $template_exists = 1;
1577 # Trying to find the correct number.
1578 # This can fail, if the custom action has no number
1580 my $setbehind = 0;
1581 if ( $customaction =~ /^\s*behind_(.*?)\s*$/ )
1583 $customaction = $1;
1584 $setbehind = 1;
1587 my $position = get_customaction_position($customaction, $sequencetable);
1589 if ( $position >= 0 ) # Found CustomAction and is has a position. Otherwise return value is "-1".
1591 my $newposition = 0;
1592 if ( $setbehind ) { $newposition = $position + 2; }
1593 else { $newposition = $position - 2; }
1594 ${$sequencetable}[$i] =~ s/$templatename/$newposition/;
1595 $template_replaced = 1;
1596 $infoline = "Setting position \"$newposition\" for custom action \"$onename\" (scp: \"$positionname\" at position $position).\n";
1597 push(@installer::globals::logfileinfo, $infoline);
1599 else
1601 $infoline = "Could not assign position for custom action \"$onename\" yet (scp: \"$positionname\").\n";
1602 push(@installer::globals::logfileinfo, $infoline);
1606 } while (( $template_exists ) && ( $template_replaced ));
1608 # An error occurred, because templates still exist, but could not be replaced.
1609 # Reason:
1610 # 1. Wrong name of CustomAction in scp2 (typo?)
1611 # 2. Circular dependencies of CustomActions (A after B and B after A)
1613 # Problem: It is allowed, that a CustomAction is defined in scp2 in a library that is
1614 # part of product ABC, but this CustomAction is not used in this product
1615 # and the reference CustomAction is not part of this product.
1616 # Therefore this cannot be an error, but only produce a warning. The assigned number
1617 # must be the last sequence number.
1619 if (( $template_exists ) && ( ! $template_replaced ))
1621 for ( my $i = 0; $i <= $#{$sequencetable}; $i++ )
1623 if ( ${$sequencetable}[$i] =~ /^\s*([\w\.]+)\t.*\t\s*(POSITIONTEMPLATE_.*?)\s*$/ )
1625 my $customactionname = $1;
1626 my $fulltemplate = $2;
1627 my $template = $fulltemplate;
1628 $template =~ s/POSITIONTEMPLATE_//;
1629 $lastposition = $lastposition + 25;
1630 ${$sequencetable}[$i] =~ s/$fulltemplate/$lastposition/;
1631 $infoline = "WARNING: Setting position \"$lastposition\" for custom action \"$customactionname\". Could not find CustomAction \"$template\".\n";
1632 push(@installer::globals::logfileinfo, $infoline);
1638 ##########################################################################
1639 # Setting the Windows custom actions into different tables
1640 # CustomAc.idt, InstallE.idt, InstallU.idt, ControlE.idt, ControlC.idt
1641 ##########################################################################
1643 sub addcustomactions
1645 my ($languageidtdir, $customactions, $filesarray) = @_;
1647 installer::logger::include_timestamp_into_logfile("\nPerformance Info: addcustomactions start\n");
1649 my $customactionidttablename = $languageidtdir . $installer::globals::separator . "CustomAc.idt";
1650 my $customactionidttable = installer::files::read_file($customactionidttablename);
1651 my $installexecutetablename = $languageidtdir . $installer::globals::separator . "InstallE.idt";
1652 my $installexecutetable = installer::files::read_file($installexecutetablename);
1653 my $adminexecutetablename = $languageidtdir . $installer::globals::separator . "AdminExe.idt";
1654 my $adminexecutetable = installer::files::read_file($adminexecutetablename);
1655 my $installuitablename = $languageidtdir . $installer::globals::separator . "InstallU.idt";
1656 my $installuitable = installer::files::read_file($installuitablename);
1657 my $controleventtablename = $languageidtdir . $installer::globals::separator . "ControlE.idt";
1658 my $controleventtable = installer::files::read_file($controleventtablename);
1659 my $controlconditiontablename = $languageidtdir . $installer::globals::separator . "ControlC.idt";
1660 my $controlconditiontable = installer::files::read_file($controlconditiontablename);
1662 # Iterating over all Windows custom actions
1664 for ( my $i = 0; $i <= $#{$customactions}; $i++ )
1666 my $customaction = ${$customactions}[$i];
1667 my $name = $customaction->{'Name'};
1668 my $typ = $customaction->{'Typ'};
1669 my $source = $customaction->{'Source'};
1670 my $target = $customaction->{'Target'};
1671 my $inbinarytable = $customaction->{'Inbinarytable'};
1672 my $gid = $customaction->{'gid'};
1674 my $styles = "";
1675 if ( $customaction->{'Styles'} ) { $styles = $customaction->{'Styles'}; }
1677 my $added_customaction = set_custom_action($customactionidttable, $name, $typ, $source, $target, $inbinarytable, $filesarray, $customactionidttablename, $styles);
1679 if ( $added_customaction )
1681 # If the CustomAction was added into the CustomAc.idt, it can be connected to the installation.
1682 # There are currently two different ways for doing this:
1683 # 1. Using "add_custom_action_to_install_table", which adds the CustomAction to the install sequences,
1684 # which are saved in InstallE.idt and InstallU.idt
1685 # 2. Using "connect_custom_action_to_control" and "connect_custom_action_to_control". The first method
1686 # connects a CustomAction to a control in ControlE.idt. The second method sets a condition for a control,
1687 # which might be influenced by the CustomAction. This happens in ControlC.idt.
1689 # Any Windows CustomAction can have a lot of different assignments.
1691 for ( my $j = 1; $j <= 50; $j++ )
1693 my $key = "Assignment" . $j;
1694 my $value = "";
1695 if ( $customaction->{$key} )
1697 $value = $customaction->{$key};
1699 else { last; }
1701 # $value is now a comma separated list
1702 if ( $value =~ /^\s*\(\s*(.*)\s*\);?\s*$/ ) { $value = $1; }
1703 my $assignmentarray = installer::converter::convert_stringlist_into_array(\$value, ",");
1704 my $assignment = create_customaction_assignment_hash($gid, $name, $key, $assignmentarray);
1706 if ( $assignment->{'parameter1'} eq "InstallExecuteSequence" )
1708 add_custom_action_to_install_table($installexecutetable, $source, $name, $assignment->{'parameter2'}, $assignment->{'parameter3'}, $filesarray, $installexecutetablename, $styles);
1710 elsif ( $assignment->{'parameter1'} eq "AdminExecuteSequence" )
1712 add_custom_action_to_install_table($adminexecutetable, $source, $name, $assignment->{'parameter2'}, $assignment->{'parameter3'}, $filesarray, $adminexecutetablename, $styles);
1714 elsif ( $assignment->{'parameter1'} eq "InstallUISequence" )
1716 add_custom_action_to_install_table($installuitable, $source, $name, $assignment->{'parameter2'}, $assignment->{'parameter3'}, $filesarray, $installuitablename, $styles);
1718 elsif ( $assignment->{'parameter1'} eq "ControlEvent" )
1720 connect_custom_action_to_control($controleventtable, $controleventtablename, $assignment->{'parameter2'}, $assignment->{'parameter3'}, $assignment->{'parameter4'}, $assignment->{'parameter5'}, $assignment->{'parameter6'}, $assignment->{'parameter7'});
1722 elsif ( $assignment->{'parameter1'} eq "ControlCondition" )
1724 connect_condition_to_control($controlconditiontable, $controlconditiontablename, $assignment->{'parameter2'}, $assignment->{'parameter3'}, $assignment->{'parameter4'}, $assignment->{'parameter5'});
1726 else
1728 installer::exiter::exit_program("ERROR: gid: $gid, key: $key ! Unknown Windows CustomAction table: $assignment->{'parameter1'} ! Currently supported: InstallUISequence, InstallESequence, ControlEvent, ControlCondition", "addcustomactions");
1734 # Setting the positions in the tables
1736 set_positions_in_table($installexecutetable, $installexecutetablename);
1737 set_positions_in_table($installuitable, $installuitablename);
1738 set_positions_in_table($adminexecutetable, $adminexecutetablename);
1740 # Saving the files
1742 installer::files::save_file($customactionidttablename, $customactionidttable);
1743 installer::files::save_file($installexecutetablename, $installexecutetable);
1744 installer::files::save_file($adminexecutetablename, $adminexecutetable);
1745 installer::files::save_file($installuitablename, $installuitable);
1746 installer::files::save_file($controleventtablename, $controleventtable);
1747 installer::files::save_file($controlconditiontablename, $controlconditiontable);
1749 my $infoline = "Updated idt file: $customactionidttablename\n";
1750 push(@installer::globals::logfileinfo, $infoline);
1751 $infoline = "Updated idt file: $installexecutetablename\n";
1752 push(@installer::globals::logfileinfo, $infoline);
1753 $infoline = "Updated idt file: $adminexecutetablename\n";
1754 push(@installer::globals::logfileinfo, $infoline);
1755 $infoline = "Updated idt file: $installuitablename\n";
1756 push(@installer::globals::logfileinfo, $infoline);
1757 $infoline = "Updated idt file: $controleventtablename\n";
1758 push(@installer::globals::logfileinfo, $infoline);
1759 $infoline = "Updated idt file: $controlconditiontablename\n";
1760 push(@installer::globals::logfileinfo, $infoline);
1762 installer::logger::include_timestamp_into_logfile("\nPerformance Info: addcustomactions end\n");
1765 ##########################################################################
1766 # Setting bidi attributes in idt tables
1767 ##########################################################################
1769 sub setbidiattributes
1771 my ($languageidtdir, $onelanguage) = @_;
1773 # Editing the files Dialog.idt and Control.idt
1775 my $dialogfilename = $languageidtdir . $installer::globals::separator . "Dialog.idt";
1776 my $controlfilename = $languageidtdir . $installer::globals::separator . "Control.idt";
1778 my $dialogfile = installer::files::read_file($dialogfilename);
1779 my $controlfile = installer::files::read_file($controlfilename);
1781 # Searching attributes in Dialog.idt and adding "896".
1782 # Attributes are in column 6 (from 10).
1784 my $bidiattribute = 896;
1785 for ( my $i = 0; $i <= $#{$dialogfile}; $i++ )
1787 if ( $i < 3 ) { next; }
1788 if ( ${$dialogfile}[$i] =~ /^\s*(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\s*$/ )
1790 my $one = $1;
1791 my $two = $2;
1792 my $three = $3;
1793 my $four = $4;
1794 my $five = $5;
1795 my $attribute = $6;
1796 my $seven = $7;
1797 my $eight = $8;
1798 $attribute = $attribute + $bidiattribute;
1799 ${$dialogfile}[$i] = "$one\t$two\t$three\t$four\t$five\t$attribute\t$seven\t$eight\n";
1803 # Searching attributes in Control.idt and adding "224".
1804 # Attributes are in column 8 (from 12).
1806 $bidiattribute = 224;
1807 for ( my $i = 0; $i <= $#{$controlfile}; $i++ )
1809 if ( $i < 3 ) { next; }
1810 if ( ${$controlfile}[$i] =~ /^\s*(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\s*$/ )
1812 my $one = $1;
1813 my $two = $2;
1814 my $three = $3;
1815 my $four = $4;
1816 my $five = $5;
1817 my $six = $6;
1818 my $seven = $7;
1819 my $attribute = $8;
1820 my $nine = $9;
1821 my $ten = $10;
1822 my $eleven = $11;
1823 my $twelve = $12;
1824 $attribute = $attribute + $bidiattribute;
1825 ${$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";
1829 # Saving the file
1831 installer::files::save_file($dialogfilename, $dialogfile);
1832 my $infoline = "Set bidi support in idt file \"$dialogfilename\" for language $onelanguage\n";
1833 push(@installer::globals::logfileinfo, $infoline);
1835 installer::files::save_file($controlfilename, $controlfile);
1836 $infoline = "Set bidi support in idt file \"$controlfilename\" for language $onelanguage\n";
1837 push(@installer::globals::logfileinfo, $infoline);
1840 ###############################################
1841 # Emit custom action 51 for setting standard
1842 # directory variable. Reference to a hash is
1843 # returned, represented the custom action.
1844 # This can be passed in to addcustomaction
1845 # method.
1846 ###############################################
1848 sub emit_custom_action_for_standard_directory
1850 my ($dir, $var) = @_;
1851 my %action = ();
1853 $action{'Name'} = $dir;
1854 $action{'Typ'} = "51";
1855 $action{'Source'} = $dir;
1856 $action{'Target'} = "[$var]";
1857 $action{'Styles'} = "NO_FILE";
1858 $action{'Assignment1'} = '("AdminExecuteSequence", "", "CostInitialize")';
1859 $action{'Assignment2'} = '("InstallExecuteSequence", "", "CostInitialize")';
1860 $action{'Assignment3'} = '("InstallUISequence", "", "CostInitialize")';
1862 return \%action;