Debian Codegraph @

solenv/bin/modules/installer/windows/idtglobal.pm

raw
1 #
2 # This file is part of the LibreOffice project.
3 #
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/.
7 #
8 # This file incorporates work covered by the following license notice:
9 #
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 .
17 #
18
19 package installer::windows::idtglobal;
20
21 use strict;
22 use warnings;
23
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;
34
35 ##############################################################
36 # Shorten the gid for a feature.
37 # Attention: Maximum length is 38
38 ##############################################################
39
40 sub shorten_feature_gid
41 {
42 my ($stringref) = @_;
43
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
53 }
54
55 ############################################
56 # Getting the next free number, that
57 # can be added.
58 # Sample: 01-44-~1.DAT, 01-44-~2.DAT, ...
59 ############################################
60
61 sub get_next_free_number
62 {
63 my ($name, $shortnamesref) = @_;
64
65 my $counter = 0;
66 my $dontsave = 0;
67 my $alreadyexists;
68 my ($newname, $shortname);
69
70 do
71 {
72 $alreadyexists = 0;
73 $counter++;
74 $newname = $name . $counter;
75
76 for ( my $i = 0; $i <= $#{$shortnamesref}; $i++ )
77 {
78 $shortname = ${$shortnamesref}[$i];
79
80 if ( uc($shortname) eq uc($newname) ) # case insensitive
81 {
82 $alreadyexists = 1;
83 last;
84 }
85 }
86 }
87 until (!($alreadyexists));
88
89 if (( $counter > 9 ) && ( length($name) > 6 )) { $dontsave = 1; }
90 if (( $counter > 99 ) && ( length($name) > 5 )) { $dontsave = 1; }
91
92 if (!($dontsave))
93 {
94 push(@{$shortnamesref}, $newname); # adding the new shortname to the array of shortnames
95 }
96
97 return $counter
98 }
99
100 ############################################
101 # Getting the next free number, that
102 # can be added.
103 # Sample: 01-44-~1.DAT, 01-44-~2.DAT, ...
104 ############################################
105
106 sub get_next_free_number_with_hash
107 {
108 my ($name, $shortnamesref, $ext) = @_;
109
110 my $counter = 0;
111 my $dontsave = 0;
112 my $saved = 0;
113 my $alreadyexists;
114 my ($newname, $shortname);
115
116 do
117 {
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}) )
124 {
125 $alreadyexists = 1;
126 }
127 }
128 until (!($alreadyexists));
129
130 if (( $counter > 9 ) && ( length($name) > 6 )) { $dontsave = 1; }
131 if (( $counter > 99 ) && ( length($name) > 5 )) { $dontsave = 1; }
132
133 if (!($dontsave))
134 {
135 $shortnamesref->{$newname} = 1; # adding the new shortname to the array of shortnames, always uppercase
136 $saved = 1;
137 }
138
139 return ( $counter, $saved )
140 }
141
142 #########################################
143 # 8.3 for filenames and directories
144 #########################################
145
146 sub make_eight_three_conform
147 {
148 my ($inputstring, $pattern, $shortnamesref) = @_;
149
150 # all shortnames are collected in $shortnamesref, because of uniqueness
151
152 my ($name, $namelength, $number);
153 my $conformstring = "";
154 my $changed = 0;
155
156 if (( $inputstring =~ /^\s*(.*?)\.(.*?)\s*$/ ) && ( $pattern eq "file" )) # files with a dot
157 {
158 $name = $1;
159 my $extension = $2;
160
161 $namelength = length($name);
162 my $extensionlength = length($extension);
163
164 if ( $extensionlength > 3 )
165 {
166 # simply taking the first three letters
167 $extension = substr($extension, 0, 3); # name, offset, length
168 }
169
170 # Attention: readme.html -> README~1.HTM
171
172 if (( $namelength > 8 ) || ( $extensionlength > 3 ))
173 {
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);
179
180 # if $number>9 the new name would be "abcdef~10.xyz", which is 9+3, and therefore not allowed
181
182 if ( $number > 9 )
183 {
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);
188
189 if ( $number > 99 )
190 {
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);
195 }
196 }
197
198 $name = $name . "$number";
199
200 $changed = 1;
201 }
202
203 $conformstring = $name . "\." . $extension;
204
205 if ( $changed ) { $conformstring= uc($conformstring); }
206 }
207 else # no dot in filename or directory (also used for shortcuts)
208 {
209 $name = $inputstring;
210 $namelength = length($name);
211
212 if ( $namelength > 8 )
213 {
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);
219
220 # if $number>9 the new name would be "abcdef~10.xyz", which is 9+3, and therefore not allowed
221
222 if ( $number > 9 )
223 {
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);
228
229 if ( $number > 99 )
230 {
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);
235 }
236 }
237
238 $name = $name . "$number";
239 $changed = 1;
240 if ( $pattern eq "dir" ) { $name =~ s/\./\_/g; } # in directories replacing "." with "_"
241 }
242
243 $conformstring = $name;
244
245 if ( $changed ) { $conformstring = uc($name); }
246 }
247
248 return $conformstring;
249 }
250
251 #########################################
252 # 8.3 for filenames and directories
253 # $shortnamesref is a hash in this case
254 # -> performance reasons
255 #########################################
256
257 sub make_eight_three_conform_with_hash
258 {
259 my ($inputstring, $pattern, $shortnamesref) = @_;
260
261 # all shortnames are collected in $shortnamesref, because of uniqueness (a hash!)
262
263 my ($name, $namelength, $number);
264 my $conformstring = "";
265 my $changed = 0;
266 my $saved;
267
268 if (( $inputstring =~ /^\s*(.*)\.(.*?)\s*$/ ) && ( $pattern eq "file" )) # files with a dot
269 {
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;
273
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
276
277 $namelength = length($name);
278 my $extensionlength = length($extension);
279
280 if ( $extensionlength > 3 )
281 {
282 # simply taking the first three letters
283 $extension = substr($extension, 0, 3); # name, offset, length
284 $changed = 1;
285 }
286
287 # Attention: readme.html -> README~1.HTM
288
289 if (( $namelength > 8 ) || ( $extensionlength > 3 ))
290 {
291 # taking the first six letters, if filename is longer than 6 characters
292 if ( $namelength > 6 )
293 {
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));
298
299 # if $number>9 the new name would be "abcdef~10.xyz", which is 9+3, and therefore not allowed
300
301 if ( ! $saved )
302 {
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));
307
308 # if $number>99 the new name would be "abcde~100.xyz", which is 9+3, and therefore not allowed
309
310 if ( ! $saved )
311 {
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));
316
317 if ( ! $saved )
318 {
319 installer::exiter::exit_program("ERROR: Could not set 8+3 conform name for $inputstring !", "make_eight_three_conform_with_hash");
320 }
321 }
322 }
323
324 $name = $name . "$number";
325 $changed = 1;
326 }
327 }
328
329 $conformstring = $name . "\." . $extension;
330
331 if ( $changed ) { $conformstring= uc($conformstring); }
332 }
333 else # no dot in filename or directory (also used for shortcuts)
334 {
335 $name = $inputstring;
336 $namelength = length($name);
337
338 if ( $namelength > 8 )
339 {
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, '');
345
346 # if $number>9 the new name would be "abcdef~10", which is 9+0, and therefore not allowed
347
348 if ( ! $saved )
349 {
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, '');
354
355 # if $number>99 the new name would be "abcde~100", which is 9+0, and therefore not allowed
356
357 if ( ! $saved )
358 {
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, '');
363
364 if ( ! $saved ) { installer::exiter::exit_program("ERROR: Could not set 8+3 conform name for $inputstring !", "make_eight_three_conform_with_hash"); }
365 }
366 }
367
368 $name = $name . "$number";
369 $changed = 1;
370 if ( $pattern eq "dir" ) { $name =~ s/\./\_/g; } # in directories replacing "." with "_"
371 }
372
373 $conformstring = $name;
374
375 if ( $changed ) { $conformstring = uc($name); }
376 }
377
378 return $conformstring;
379 }
380
381 #########################################
382 # Writing the header for idt files
383 #########################################
384
385 sub write_idt_header
386 {
387 my ($idtref, $definestring) = @_;
388
389 my $oneline;
390
391 if ( $definestring eq "file" )
392 {
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);
399 }
400
401 if ( $definestring eq "filehash" )
402 {
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);
409 }
410
411 if ( $definestring eq "directory" )
412 {
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);
419 }
420
421 if ( $definestring eq "component" )
422 {
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);
429 }
430
431 if ( $definestring eq "feature" )
432 {
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);
439 }
440
441 if ( $definestring eq "featurecomponent" )
442 {
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);
449 }
450
451 if ( $definestring eq "media" )
452 {
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);
459 }
460
461 if ( $definestring eq "font" )
462 {
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);
469 }
470
471 if ( $definestring eq "shortcut" )
472 {
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);
479 }
480
481 if ( $definestring eq "msishortcutproperty" )
482 {
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);
489 }
490
491 if ( $definestring eq "registry" )
492 {
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);
499 }
500
501 if ( $definestring eq "createfolder" )
502 {
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);
509 }
510
511 if ( $definestring eq "removefile" )
512 {
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);
519 }
520
521 if ( $definestring eq "upgrade" )
522 {
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);
529 }
530
531 if ( $definestring eq "icon" )
532 {
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);
539 }
540
541 if ( $definestring eq "inifile" )
542 {
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);
549 }
550
551 if ( $definestring eq "msiassembly" )
552 {
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);
559 }
560
561 if ( $definestring eq "msiassemblyname" )
562 {
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);
569 }
570
571 if ( $definestring eq "appsearch" )
572 {
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);
579 }
580
581 if ( $definestring eq "reglocat" )
582 {
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);
589 }
590
591 if ( $definestring eq "signatur" )
592 {
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);
599 }
600
601 }
602
603 ##############################################################
604 # Returning the name of the translation file for a
605 # given language.
606 # Sample: "01" order "en-US" -> "1033.txt"
607 ##############################################################
608
609 sub get_languagefilename
610 {
611 my ($idtfilename, $basedir) = @_;
612
613 $idtfilename =~ s/\.idt/\.ulf/;
614
615 my $languagefilename = $basedir . $installer::globals::separator . $idtfilename;
616
617 return $languagefilename;
618 }
619
620 ##############################################################
621 # Returning the complete block in all languages
622 # for a specified string
623 ##############################################################
624
625 sub get_language_block_from_language_file
626 {
627 my ($searchstring, $languagefile) = @_;
628
629 my @language_block = ();
630
631 for ( my $i = 0; $i <= $#{$languagefile}; $i++ )
632 {
633 if ( ${$languagefile}[$i] =~ /^\s*\[\s*$searchstring\s*\]\s*$/ )
634 {
635 my $counter = $i;
636
637 push(@language_block, ${$languagefile}[$counter]);
638 $counter++;
639
640 while (( $counter <= $#{$languagefile} ) && (!( ${$languagefile}[$counter] =~ /^\s*\[/ )))
641 {
642 push(@language_block, ${$languagefile}[$counter]);
643 $counter++;
644 }
645
646 last;
647 }
648 }
649
650 return \@language_block;
651 }
652
653 ##############################################################
654 # Returning a specific language string from the block
655 # of all translations
656 ##############################################################
657
658 sub get_language_string_from_language_block
659 {
660 my ($language_block, $language, $oldstring) = @_;
661
662 my $newstring = "";
663
664 for ( my $i = 0; $i <= $#{$language_block}; $i++ )
665 {
666 if ( ${$language_block}[$i] =~ /^\s*$language\s*\=\s*\"(.*)\"\s*$/ )
667 {
668 $newstring = $1;
669 $newstring =~ s/\\\"/\"/g; #un-escape quotes, fdo#59321
670 last;
671 }
672 }
673
674 if ( $newstring eq "" )
675 {
676 $language = "en-US"; # defaulting to english
677
678 for ( my $i = 0; $i <= $#{$language_block}; $i++ )
679 {
680 if ( ${$language_block}[$i] =~ /^\s*$language\s*\=\s*\"(.*)\"\s*$/ )
681 {
682 $newstring = $1;
683 last;
684 }
685 }
686 }
687
688 return $newstring;
689 }
690
691 ##############################################################
692 # Returning a specific code from the block
693 # of all codes. No defaulting to english!
694 ##############################################################
695
696 sub get_code_from_code_block
697 {
698 my ($codeblock, $language) = @_;
699
700 my $newstring = "";
701
702 for ( my $i = 0; $i <= $#{$codeblock}; $i++ )
703 {
704 if ( ${$codeblock}[$i] =~ /^\s*$language\s*\=\s*\"(.*)\"\s*$/ )
705 {
706 $newstring = $1;
707 last;
708 }
709 }
710
711 return $newstring;
712 }
713
714 ##############################################################
715 # Translating an idt file
716 ##############################################################
717
718 sub translate_idtfile
719 {
720 my ($idtfile, $languagefile, $onelanguage) = @_;
721
722 for ( my $i = 0; $i <= $#{$idtfile}; $i++ )
723 {
724 my @allstrings = ();
725
726 my $oneline = ${$idtfile}[$i];
727
728 while ( $oneline =~ /\b(OOO_\w+)\b/ )
729 {
730 my $replacestring = $1;
731 push(@allstrings, $replacestring);
732 $oneline =~ s/$replacestring//;
733 }
734
735 my $oldstring;
736
737 foreach $oldstring (@allstrings)
738 {
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);
741
742 ${$idtfile}[$i] =~ s/$oldstring/$newstring/; # always substitute, even if $newstring eq "" (there are empty strings for control.idt)
743 }
744 }
745 }
746
747 ##############################################################
748 # Copying all needed files to create a msi database
749 # into one language specific directory
750 ##############################################################
751
752 sub prepare_language_idt_directory
753 {
754 my ($destinationdir, $newidtdir, $onelanguage, $filesref, $iconfilecollector, $binarytablefiles, $allvariables) = @_;
755
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"
759
760 my $infoline = "";
761
762 installer::systemactions::copy_directory($installer::globals::idttemplatepath, $destinationdir);
763
764 if ( -d $installer::globals::idttemplatepath . $installer::globals::separator . "Binary")
765 {
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");
768 }
769
770 installer::systemactions::create_directory($destinationdir . $installer::globals::separator . "Icon");
771
772 if ( -d $installer::globals::idttemplatepath . $installer::globals::separator . "Icon")
773 {
774 installer::systemactions::copy_directory($installer::globals::idttemplatepath . $installer::globals::separator . "Icon", $destinationdir . $installer::globals::separator . "Icon");
775 }
776
777 # Copying all files in $iconfilecollector, that describe icons of folderitems
778
779 for ( my $i = 0; $i <= $#{$iconfilecollector}; $i++ )
780 {
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);
784 }
785
786 # Copying all files in $binarytablefiles in the binary directory
787
788 for ( my $i = 0; $i <= $#{$binarytablefiles}; $i++ )
789 {
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);
795 }
796
797 # Copying all new created and language independent idt-files to the destination $destinationdir.
798 # Example: "File.idt"
799
800 installer::systemactions::copy_directory_with_fileextension($newidtdir, $destinationdir, "idt");
801
802 # Copying all new created and language dependent idt-files to the destination $destinationdir.
803 # Example: "Feature.idt.01"
804
805 installer::systemactions::copy_directory_with_fileextension($newidtdir, $destinationdir, $onelanguage);
806 installer::systemactions::rename_files_with_fileextension($destinationdir, $onelanguage);
807
808 }
809
810 ##############################################################
811 # Returning the source path of the rtf licensefile for
812 # a specified language
813 ##############################################################
814
815 sub get_rtflicensefilesource
816 {
817 my ($language, $includepatharrayref) = @_;
818
819 my $licensefilename = "license_" . $language . ".rtf";
820
821 my $sourcefileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$licensefilename, $includepatharrayref, 1);
822
823 if ($$sourcefileref eq "") { installer::exiter::exit_program("ERROR: Could not find $licensefilename!", "get_rtflicensefilesource"); }
824
825 my $infoline = "Using licensefile: $$sourcefileref\n";
826 push( @installer::globals::logfileinfo, $infoline);
827
828 return $$sourcefileref;
829 }
830
831 ##############################################################
832 # A simple converter to create a license txt string from
833 # the rtf format
834 ##############################################################
835
836 sub make_string_licensetext
837 {
838 my ($licensefile) = @_;
839
840 my $rtf_licensetext = "";
841
842 for ( my $i = 0; $i <= $#{$licensefile}; $i++ )
843 {
844 my $oneline = ${$licensefile}[$i];
845 $oneline =~ s/\s*$//g; # no whitespace at line end
846
847 $rtf_licensetext = $rtf_licensetext . $oneline . " ";
848 }
849
850 return $rtf_licensetext;
851 }
852
853 ##############################################################
854 # Including the license text into the table control.idt
855 ##############################################################
856
857 sub add_licensefile_to_database
858 {
859 my ($licensefile, $controltable) = @_;
860
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.
864
865 my $foundlicenseline = 0;
866 my ($number, $line);
867
868 for ( my $i = 0; $i <= $#{$controltable}; $i++ )
869 {
870 $line = ${$controltable}[$i];
871
872 if ( $line =~ /^\s*\bLicenseAgreement\b\t\bMemo\t/ )
873 {
874 $foundlicenseline = 1;
875 $number = $i;
876 last;
877 }
878 }
879
880 if (!($foundlicenseline))
881 {
882 installer::exiter::exit_program("ERROR: Line for license file in Control.idt not found!", "add_licensefile_to_database");
883 }
884 else
885 {
886 my %control = ();
887
888 if ( $line =~ /^\s*(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\s*$/ )
889 {
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;
902 }
903 else
904 {
905 installer::exiter::exit_program("ERROR: Could not split line correctly!", "add_licensefile_to_database");
906 }
907
908 my $licensetext = make_string_licensetext($licensefile);
909
910 $control{'Text'} = $licensetext;
911
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";
916
917 ${$controltable}[$number] = $newline
918 }
919 }
920
921 ###################################################################
922 # Determining the last position in a sequencetable
923 # into the tables CustomAc.idt and InstallE.idt.
924 ###################################################################
925
926 sub get_last_position_in_sequencetable
927 {
928 my ($sequencetable) = @_;
929
930 my $position = 0;
931
932 for ( my $i = 0; $i <= $#{$sequencetable}; $i++ )
933 {
934 my $line = ${$sequencetable}[$i];
935
936 if ( $line =~ /^\s*\w+\t.*\t\s*(\d+)\s$/ )
937 {
938 my $newposition = $1;
939 if ( $newposition > $position ) { $position = $newposition; }
940 }
941 }
942
943 return $position;
944 }
945
946 #########################################################################
947 # Determining the position of a specified Action in the sequencetable
948 #########################################################################
949
950 sub get_position_in_sequencetable
951 {
952 my ($action, $sequencetable) = @_;
953
954 my $position = 0;
955
956 $action =~ s/^\s*behind_//;
957
958 for ( my $i = 0; $i <= $#{$sequencetable}; $i++ )
959 {
960 my $line = ${$sequencetable}[$i];
961
962 if ( $line =~ /^\s*(\w+)\t.*\t\s*(\d+)\s$/ )
963 {
964 my $compareaction = $1;
965 $position = $2;
966 if ( $compareaction eq $action ) { last; }
967 }
968 }
969
970 return $position;
971 }
972
973 ################################################################################################
974 # Including the CustomAction for the configuration
975 # into the tables CustomAc.idt and InstallE.idt.
976 #
977 # CustomAc.idt: ExecutePkgchk 82 pkgchk.exe -s
978 # InstallE.idt: ExecutePkgchk Not REMOVE="ALL" 3175
979 #
980 # CustomAc.idt: ExecuteQuickstart 82 install_quickstart.exe
981 # InstallE.idt: ExecuteQuickstart &gm_o_Quickstart=3 3200
982 #
983 # CustomAc.idt: ExecuteInstallRegsvrex 82 regsvrex.exe shlxthdl.dll
984 # InstallE.idt: ExecuteInstallRegsvrex Not REMOVE="ALL" 3225
985 #
986 # CustomAc.idt: ExecuteUninstallRegsvrex 82 regsvrex.exe /u shlxthdl.dll
987 # InstallE.idt: ExecuteUninstallRegsvrex REMOVE="ALL" 690
988 #
989 # CustomAc.idt: Regmsdocmsidll1 1 reg4msdocmsidll Reg4MsDocEntry
990 # InstallU.idt: Regmsdocmsidll1 Not REMOVE="ALL" 610
991 #
992 # CustomAc.idt: Regmsdocmsidll2 1 reg4msdocmsidll Reg4MsDocEntry
993 # InstallE.idt: Regmsdocmsidll2 Not REMOVE="ALL" 3160
994 ################################################################################################
995
996 sub set_custom_action
997 {
998 my ($customactionidttable, $actionname, $actionflags, $exefilename, $actionparameter, $inbinarytable, $filesref, $customactionidttablename, $styles) = @_;
999
1000 my $included_customaction = 0;
1001 my $infoline = "";
1002 my $customaction_exefilename = $exefilename;
1003 my $uniquename = "";
1004
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/ )
1007 {
1008 my $line = $actionname . "\t" . $actionflags . "\t" . $customaction_exefilename . "\t" . $actionparameter . "\t\n";
1009 push(@{$customactionidttable}, $line);
1010
1011 $infoline = "Added $actionname CustomAction into table $customactionidttablename (NO_FILE has been set)\n";
1012 push(@installer::globals::logfileinfo, $infoline);
1013
1014 $included_customaction = 1;
1015 return $included_customaction;
1016 }
1017
1018 # is the $exefilename a library that is included into the binary table
1019
1020 if ( $inbinarytable ) { $customaction_exefilename =~ s/\.//g; } # this is the entry in the binary table ("abc.dll" -> "abcdll")
1021
1022 # is the $exefilename included into the product?
1023
1024 my $contains_file = 0;
1025
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}];
1029
1030 for ( my $i = 0; $i <= $#{$localfilesref}; $i++ )
1031 {
1032 my $onefile = ${$localfilesref}[$i];
1033 my $filename = "";
1034 if ( exists($onefile->{'Name'}) )
1035 {
1036 $filename = $onefile->{'Name'};
1037
1038 if ( $filename eq $exefilename )
1039 {
1040 $contains_file = 1;
1041 $uniquename = ${$localfilesref}[$i]->{'uniquename'};
1042 last;
1043 }
1044 }
1045 else
1046 {
1047 installer::exiter::exit_program("ERROR: Did not find \"Name\" for file \"$onefile->{'uniquename'}\" ($onefile->{'gid'})!", "set_custom_action");
1048 }
1049 }
1050
1051 if ( $contains_file )
1052 {
1053 # Now the CustomAction can be included into the CustomAc.idt
1054
1055 if ( ! $inbinarytable ) { $customaction_exefilename = $uniquename; } # the unique file name has to be added to the custom action table
1056
1057 my $line = $actionname . "\t" . $actionflags . "\t" . $customaction_exefilename . "\t" . $actionparameter . "\t\n";
1058 push(@{$customactionidttable}, $line);
1059
1060 $included_customaction = 1;
1061 }
1062
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);
1066
1067 return $included_customaction;
1068 }
1069
1070 ####################################################################
1071 # Adding a Custom Action to InstallExecuteTable or InstallUITable
1072 ####################################################################
1073
1074 sub add_custom_action_to_install_table
1075 {
1076 my ($installtable, $exefilename, $actionname, $actioncondition, $position, $filesref, $installtablename, $styles) = @_;
1077
1078 my $included_customaction = 0;
1079 my $feature = "";
1080 my $infoline = "";
1081
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/ )
1084 {
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
1087
1088 my $actionposition = 0;
1089
1090 if ( $position =~ /^\s*\d+\s*$/ ) { $actionposition = $position; } # setting the position directly, number defined in scp2
1091 else { $actionposition = "POSITIONTEMPLATE_" . $position; }
1092
1093 my $line = $actionname . "\t" . $actioncondition . "\t" . $actionposition . "\n";
1094 push(@{$installtable}, $line);
1095
1096 $infoline = "Added $actionname CustomAction into table $installtablename (NO_FILE has been set)\n";
1097 push(@installer::globals::logfileinfo, $infoline);
1098 return;
1099 }
1100
1101 my $contains_file = 0;
1102
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}];
1106
1107 for ( my $i = 0; $i <= $#{$localfilesref}; $i++ )
1108 {
1109 my $filename = ${$localfilesref}[$i]->{'Name'};
1110
1111 if ( $filename eq $exefilename )
1112 {
1113 $contains_file = 1;
1114
1115 # Determining the feature of the file
1116
1117 if ( ${$localfilesref}[$i] ) { $feature = ${$localfilesref}[$i]->{'modules'}; }
1118
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);
1123
1124 last;
1125 }
1126 }
1127
1128 if ( $contains_file )
1129 {
1130 # then the InstallE.idt.idt or InstallU.idt.idt
1131
1132 $actioncondition =~ s/FEATURETEMPLATE/$feature/g; # only execute Custom Action, if feature of the file is installed
1133
1134 my $positiontemplate = "";
1135 if ( $position =~ /^\s*\d+\s*$/ ) { $positiontemplate = $position; } # setting the position directly, number defined in scp2
1136 else { $positiontemplate = "POSITIONTEMPLATE_" . $position; }
1137
1138 my $line = $actionname . "\t" . $actioncondition . "\t" . $positiontemplate . "\n";
1139 push(@{$installtable}, $line);
1140
1141 $included_customaction = 1;
1142 }
1143
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);
1147
1148 }
1149
1150 ##################################################################
1151 # A line in the table ControlEvent connects a Control
1152 # with a Custom Action
1153 #################################################################
1154
1155 sub connect_custom_action_to_control
1156 {
1157 my ( $table, $tablename, $dialog, $control, $event, $argument, $condition, $ordering) = @_;
1158
1159 my $line = $dialog . "\t" . $control. "\t" . $event. "\t" . $argument. "\t" . $condition. "\t" . $ordering . "\n";
1160
1161 push(@{$table}, $line);
1162
1163 $line =~ s/\s*$//g;
1164
1165 my $infoline = "Added line \"$line\" into table $tablename\n";
1166 push(@installer::globals::logfileinfo, $infoline);
1167 }
1168
1169 ##################################################################
1170 # A line in the table ControlCondition connects a Control state
1171 # with a condition
1172 ##################################################################
1173
1174 sub connect_condition_to_control
1175 {
1176 my ( $table, $tablename, $dialog, $control, $event, $condition) = @_;
1177
1178 my $line = $dialog . "\t" . $control. "\t" . $event. "\t" . $condition. "\n";
1179
1180 push(@{$table}, $line);
1181
1182 $line =~ s/\s*$//g;
1183
1184 my $infoline = "Added line \"$line\" into table $tablename\n";
1185 push(@installer::globals::logfileinfo, $infoline);
1186 }
1187
1188 ##################################################################
1189 # Searching for a sequencenumber in InstallUISequence table
1190 # "ExecuteAction" must be the last action
1191 ##################################################################
1192
1193 sub get_free_number_in_uisequence_table
1194 {
1195 my ( $installuitable ) = @_;
1196
1197 # determining the sequence of "ExecuteAction"
1198
1199 my $executeactionnumber = 0;
1200
1201 for ( my $i = 0; $i <= $#{$installuitable}; $i++ )
1202 {
1203 if ( ${$installuitable}[$i] =~ /^\s*(\w+)\t\w*\t(\d+)\s*$/ )
1204 {
1205 my $actionname = $1;
1206 my $actionnumber = $2;
1207
1208 if ( $actionname eq "ExecuteAction" )
1209 {
1210 $executeactionnumber = $actionnumber;
1211 last;
1212 }
1213 }
1214 }
1215
1216 if ( $executeactionnumber == 0 ) { installer::exiter::exit_program("ERROR: Did not find \"ExecuteAction\" in InstallUISequence table!", "get_free_number_in_uisequence_table"); }
1217
1218 # determining the sequence of the action before "ExecuteAction"
1219
1220 my $lastactionnumber = 0;
1221
1222 for ( my $i = 0; $i <= $#{$installuitable}; $i++ )
1223 {
1224 if ( ${$installuitable}[$i] =~ /^\s*\w+\t\w*\t(\d+)\s*$/ )
1225 {
1226 my $actionnumber = $1;
1227
1228 if (( $actionnumber > $lastactionnumber ) && ( $actionnumber != $executeactionnumber ))
1229 {
1230 $lastactionnumber = $actionnumber;
1231 }
1232 }
1233 }
1234
1235 # the new number can now be calculated
1236
1237 my $newnumber = 0;
1238
1239 if ((( $lastactionnumber + $executeactionnumber ) % 2 ) == 0 ) { $newnumber = ( $lastactionnumber + $executeactionnumber ) / 2; }
1240 else { $newnumber = ( $lastactionnumber + $executeactionnumber -1 ) / 2; }
1241
1242 return $newnumber;
1243 }
1244
1245 #############################################################
1246 # Including the new subdir into the directory table
1247 #############################################################
1248
1249 sub include_subdirname_into_directory_table
1250 {
1251 my ($dirname, $directorytable, $directorytablename, $onefile) = @_;
1252
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"); }
1256
1257 # program INSTALLLOCATION program -> subjava INSTALLLOCATION program:java
1258
1259 my $uniquename = "";
1260 my $parent = "";
1261 my $name = "";
1262
1263 my $includedline = 0;
1264
1265 my $newdir = "";
1266
1267 for ( my $i = 0; $i <= $#{$directorytable}; $i++ )
1268 {
1269
1270 if ( ${$directorytable}[$i] =~ /^\s*(.*?)\t(.*?)\t(.*?)\s*$/ )
1271 {
1272 $uniquename = $1;
1273 $parent = $2;
1274 $name = $3;
1275
1276 if ( $dirname eq $name )
1277 {
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);
1288
1289 $includedline = 1;
1290 last;
1291 }
1292 }
1293 }
1294
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"); }
1296
1297 return $newdir;
1298 }
1299
1300 ##################################################################
1301 # Including the new sub directory into the component table
1302 ##################################################################
1303
1304 sub include_subdir_into_componenttable
1305 {
1306 my ($subdir, $onefile, $componenttable) = @_;
1307
1308 my $componentname = $onefile->{'componentname'};
1309
1310 my $changeddirectory = 0;
1311
1312 for ( my $i = 0; $i <= $#{$componenttable}; $i++ )
1313 {
1314 if ( ${$componenttable}[$i] =~ /^\s*(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\s*$/ )
1315 {
1316 my $localcomponentname = $1;
1317 my $directory = $3;
1318
1319 if ( $componentname eq $localcomponentname )
1320 {
1321 my $oldvalue = ${$componenttable}[$i];
1322 ${$componenttable}[$i] =~ s/\b\Q$directory\E\b/$subdir/;
1323 my $newvalue = ${$componenttable}[$i];
1324
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);
1329
1330 $changeddirectory = 1;
1331 last;
1332 }
1333 }
1334 }
1335
1336 if ( ! $changeddirectory ) { installer::exiter::exit_program("ERROR: Could not change directory for component: $onefile->{'Name'}!", "include_subdir_into_componenttable"); }
1337
1338 }
1339
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 ##################################################################
1348
1349 sub set_multilanguageonly_condition
1350 {
1351 my ( $languageidtdir ) = @_;
1352
1353 my $onefilename = $languageidtdir . $installer::globals::separator . "ControlE.idt";
1354 my $onefile = installer::files::read_file($onefilename);
1355
1356 # Language modules
1357
1358 my $condition = "";
1359
1360 foreach my $module ( sort keys %installer::globals::multilingual_only_modules )
1361 {
1362 $condition = $condition . " &$module=3 Or";
1363 }
1364
1365 $condition =~ s/^\s*//;
1366 $condition =~ s/\s*Or\s*$//; # removing the ending "Or"
1367
1368 if ( $condition eq "" ) { $condition = "1"; }
1369
1370 for ( my $j = 0; $j <= $#{$onefile}; $j++ )
1371 {
1372 ${$onefile}[$j] =~ s/LANGUAGECONDITIONINSTALL/$condition/;
1373 }
1374
1375 # Application modules
1376
1377 $condition = "";
1378
1379 foreach my $module ( sort keys %installer::globals::application_modules )
1380 {
1381 $condition = $condition . " &$module=3 Or";
1382 }
1383
1384 $condition =~ s/^\s*//;
1385 $condition =~ s/\s*Or\s*$//; # removing the ending "Or"
1386
1387 if ( $condition eq "" ) { $condition = "1"; }
1388
1389 for ( my $j = 0; $j <= $#{$onefile}; $j++ )
1390 {
1391 ${$onefile}[$j] =~ s/APPLICATIONCONDITIONINSTALL/$condition/;
1392 }
1393
1394 installer::files::save_file($onefilename, $onefile);
1395 }
1396
1397 #############################################
1398 # Putting array values into hash
1399 #############################################
1400
1401 sub fill_assignment_hash
1402 {
1403 my ($gid, $name, $key, $assignmenthashref, $parameter, $tablename, $assignmentarray) = @_;
1404
1405 my $max = $parameter - 1;
1406
1407 if ( $max != $#{$assignmentarray} )
1408 {
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");
1411 }
1412
1413 for ( my $i = 0; $i <= $#{$assignmentarray}; $i++ )
1414 {
1415 my $counter = $i + 1;
1416 my $key = "parameter". $counter;
1417
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;
1426 }
1427 }
1428
1429 ##########################################################################
1430 # Checking the assignment of a Windows CustomAction and putting it
1431 # into a hash
1432 ##########################################################################
1433
1434 sub create_customaction_assignment_hash
1435 {
1436 my ($gid, $name, $key, $assignmentarray) = @_;
1437
1438 my %assignment = ();
1439 my $assignmenthashref = \%assignment;
1440
1441 my $tablename = ${$assignmentarray}[0];
1442 installer::remover::remove_leading_and_ending_quotationmarks(\$tablename);
1443
1444 my $tablename_defined = 0;
1445 my $parameter = 0;
1446
1447 if ( $tablename eq "InstallUISequence" )
1448 {
1449 $tablename_defined = 1;
1450 $parameter = 3;
1451 fill_assignment_hash($gid, $name, $key, $assignmenthashref, $parameter, $tablename, $assignmentarray);
1452 }
1453
1454 if ( $tablename eq "InstallExecuteSequence" )
1455 {
1456 $tablename_defined = 1;
1457 $parameter = 3;
1458 fill_assignment_hash($gid, $name, $key, $assignmenthashref, $parameter, $tablename, $assignmentarray);
1459 }
1460
1461 if ( $tablename eq "AdminExecuteSequence" )
1462 {
1463 $tablename_defined = 1;
1464 $parameter = 3;
1465 fill_assignment_hash($gid, $name, $key, $assignmenthashref, $parameter, $tablename, $assignmentarray);
1466 }
1467
1468 if ( $tablename eq "ControlEvent" )
1469 {
1470 $tablename_defined = 1;
1471 $parameter = 7;
1472 fill_assignment_hash($gid, $name, $key, $assignmenthashref, $parameter, $tablename, $assignmentarray);
1473 }
1474
1475 if ( $tablename eq "ControlCondition" )
1476 {
1477 $tablename_defined = 1;
1478 $parameter = 5;
1479 fill_assignment_hash($gid, $name, $key, $assignmenthashref, $parameter, $tablename, $assignmentarray);
1480 }
1481
1482 if ( ! $tablename_defined )
1483 {
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");
1485 }
1486
1487 return $assignmenthashref;
1488 }
1489
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 ##########################################################################
1496
1497 sub get_customaction_position
1498 {
1499 my ($action, $sequencetable) = @_;
1500
1501 my $position = -1;
1502
1503 for ( my $i = 0; $i <= $#{$sequencetable}; $i++ )
1504 {
1505 my $line = ${$sequencetable}[$i];
1506
1507 if ( $line =~ /^\s*([\w\.]+)\t.*\t\s*(\d+)\s$/ ) # matching only, if position is a number!
1508 {
1509 my $compareaction = $1;
1510 my $localposition = $2;
1511
1512 if ( $compareaction eq $action )
1513 {
1514 $position = $localposition;
1515 last;
1516 }
1517 }
1518 }
1519
1520 return $position;
1521 }
1522
1523 ##########################################################################
1524 # Setting the position of CustomActions in sequence tables.
1525 # Replacing all occurrences of "POSITIONTEMPLATE_"
1526 ##########################################################################
1527
1528 sub set_positions_in_table
1529 {
1530 my ( $sequencetable, $tablename ) = @_;
1531
1532 my $infoline = "\nSetting positions in table \"$tablename\".\n";
1533 push(@installer::globals::logfileinfo, $infoline);
1534
1535 # Step 1: Resolving all occurrences of "POSITIONTEMPLATE_end"
1536
1537 my $lastposition = get_last_position_in_sequencetable($sequencetable);
1538
1539 for ( my $i = 0; $i <= $#{$sequencetable}; $i++ )
1540 {
1541 if ( ${$sequencetable}[$i] =~ /^\s*([\w\.]+)\t.*\t\s*POSITIONTEMPLATE_end\s*$/ )
1542 {
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);
1548 }
1549 }
1550
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).
1555
1556 my $template_exists = 0;
1557 my $template_replaced = 0;
1558 my $counter = 0;
1559
1560 do
1561 {
1562 $template_exists = 0;
1563 $template_replaced = 0;
1564 $counter++;
1565
1566 for ( my $i = 0; $i <= $#{$sequencetable}; $i++ )
1567 {
1568 if ( ${$sequencetable}[$i] =~ /^\s*([\w\.]+)\t.*\t\s*(POSITIONTEMPLATE_.*?)\s*$/ )
1569 {
1570 my $onename = $1;
1571 my $templatename = $2;
1572 my $positionname = $templatename;
1573 my $customaction = $templatename;
1574 $customaction =~ s/POSITIONTEMPLATE_//;
1575 $template_exists = 1;
1576
1577 # Trying to find the correct number.
1578 # This can fail, if the custom action has no number
1579
1580 my $setbehind = 0;
1581 if ( $customaction =~ /^\s*behind_(.*?)\s*$/ )
1582 {
1583 $customaction = $1;
1584 $setbehind = 1;
1585 }
1586
1587 my $position = get_customaction_position($customaction, $sequencetable);
1588
1589 if ( $position >= 0 ) # Found CustomAction and is has a position. Otherwise return value is "-1".
1590 {
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);
1598 }
1599 else
1600 {
1601 $infoline = "Could not assign position for custom action \"$onename\" yet (scp: \"$positionname\").\n";
1602 push(@installer::globals::logfileinfo, $infoline);
1603 }
1604 }
1605 }
1606 } while (( $template_exists ) && ( $template_replaced ));
1607
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)
1612
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.
1618
1619 if (( $template_exists ) && ( ! $template_replaced ))
1620 {
1621 for ( my $i = 0; $i <= $#{$sequencetable}; $i++ )
1622 {
1623 if ( ${$sequencetable}[$i] =~ /^\s*([\w\.]+)\t.*\t\s*(POSITIONTEMPLATE_.*?)\s*$/ )
1624 {
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);
1633 }
1634 }
1635 }
1636 }
1637
1638 ##########################################################################
1639 # Setting the Windows custom actions into different tables
1640 # CustomAc.idt, InstallE.idt, InstallU.idt, ControlE.idt, ControlC.idt
1641 ##########################################################################
1642
1643 sub addcustomactions
1644 {
1645 my ($languageidtdir, $customactions, $filesarray) = @_;
1646
1647 installer::logger::include_timestamp_into_logfile("\nPerformance Info: addcustomactions start\n");
1648
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);
1661
1662 # Iterating over all Windows custom actions
1663
1664 for ( my $i = 0; $i <= $#{$customactions}; $i++ )
1665 {
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'};
1673
1674 my $styles = "";
1675 if ( $customaction->{'Styles'} ) { $styles = $customaction->{'Styles'}; }
1676
1677 my $added_customaction = set_custom_action($customactionidttable, $name, $typ, $source, $target, $inbinarytable, $filesarray, $customactionidttablename, $styles);
1678
1679 if ( $added_customaction )
1680 {
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.
1688
1689 # Any Windows CustomAction can have a lot of different assignments.
1690
1691 for ( my $j = 1; $j <= 50; $j++ )
1692 {
1693 my $key = "Assignment" . $j;
1694 my $value = "";
1695 if ( $customaction->{$key} )
1696 {
1697 $value = $customaction->{$key};
1698 }
1699 else { last; }
1700
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);
1705
1706 if ( $assignment->{'parameter1'} eq "InstallExecuteSequence" )
1707 {
1708 add_custom_action_to_install_table($installexecutetable, $source, $name, $assignment->{'parameter2'}, $assignment->{'parameter3'}, $filesarray, $installexecutetablename, $styles);
1709 }
1710 elsif ( $assignment->{'parameter1'} eq "AdminExecuteSequence" )
1711 {
1712 add_custom_action_to_install_table($adminexecutetable, $source, $name, $assignment->{'parameter2'}, $assignment->{'parameter3'}, $filesarray, $adminexecutetablename, $styles);
1713 }
1714 elsif ( $assignment->{'parameter1'} eq "InstallUISequence" )
1715 {
1716 add_custom_action_to_install_table($installuitable, $source, $name, $assignment->{'parameter2'}, $assignment->{'parameter3'}, $filesarray, $installuitablename, $styles);
1717 }
1718 elsif ( $assignment->{'parameter1'} eq "ControlEvent" )
1719 {
1720 connect_custom_action_to_control($controleventtable, $controleventtablename, $assignment->{'parameter2'}, $assignment->{'parameter3'}, $assignment->{'parameter4'}, $assignment->{'parameter5'}, $assignment->{'parameter6'}, $assignment->{'parameter7'});
1721 }
1722 elsif ( $assignment->{'parameter1'} eq "ControlCondition" )
1723 {
1724 connect_condition_to_control($controlconditiontable, $controlconditiontablename, $assignment->{'parameter2'}, $assignment->{'parameter3'}, $assignment->{'parameter4'}, $assignment->{'parameter5'});
1725 }
1726 else
1727 {
1728 installer::exiter::exit_program("ERROR: gid: $gid, key: $key ! Unknown Windows CustomAction table: $assignment->{'parameter1'} ! Currently supported: InstallUISequence, InstallESequence, ControlEvent, ControlCondition", "addcustomactions");
1729 }
1730 }
1731 }
1732 }
1733
1734 # Setting the positions in the tables
1735
1736 set_positions_in_table($installexecutetable, $installexecutetablename);
1737 set_positions_in_table($installuitable, $installuitablename);
1738 set_positions_in_table($adminexecutetable, $adminexecutetablename);
1739
1740 # Saving the files
1741
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);
1748
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);
1761
1762 installer::logger::include_timestamp_into_logfile("\nPerformance Info: addcustomactions end\n");
1763 }
1764
1765 ##########################################################################
1766 # Setting bidi attributes in idt tables
1767 ##########################################################################
1768
1769 sub setbidiattributes
1770 {
1771 my ($languageidtdir, $onelanguage) = @_;
1772
1773 # Editing the files Dialog.idt and Control.idt
1774
1775 my $dialogfilename = $languageidtdir . $installer::globals::separator . "Dialog.idt";
1776 my $controlfilename = $languageidtdir . $installer::globals::separator . "Control.idt";
1777
1778 my $dialogfile = installer::files::read_file($dialogfilename);
1779 my $controlfile = installer::files::read_file($controlfilename);
1780
1781 # Searching attributes in Dialog.idt and adding "896".
1782 # Attributes are in column 6 (from 10).
1783
1784 my $bidiattribute = 896;
1785 for ( my $i = 0; $i <= $#{$dialogfile}; $i++ )
1786 {
1787 if ( $i < 3 ) { next; }
1788 if ( ${$dialogfile}[$i] =~ /^\s*(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\s*$/ )
1789 {
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";
1800 }
1801 }
1802
1803 # Searching attributes in Control.idt and adding "224".
1804 # Attributes are in column 8 (from 12).
1805
1806 $bidiattribute = 224;
1807 for ( my $i = 0; $i <= $#{$controlfile}; $i++ )
1808 {
1809 if ( $i < 3 ) { next; }
1810 if ( ${$controlfile}[$i] =~ /^\s*(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\s*$/ )
1811 {
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";
1826 }
1827 }
1828
1829 # Saving the file
1830
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);
1834
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);
1838 }
1839
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 ###############################################
1847
1848 sub emit_custom_action_for_standard_directory
1849 {
1850 my ($dir, $var) = @_;
1851 my %action = ();
1852
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")';
1861
1862 return \%action;
1863 }
1864
1865 1;