1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # $RCSfile: shortcut.pm,v $
13 # This file is part of OpenOffice.org.
15 # OpenOffice.org is free software: you can redistribute it and/or modify
16 # it under the terms of the GNU Lesser General Public License version 3
17 # only, as published by the Free Software Foundation.
19 # OpenOffice.org is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU Lesser General Public License version 3 for more details
23 # (a copy is included in the LICENSE file that accompanied this code).
25 # You should have received a copy of the GNU Lesser General Public License
26 # version 3 along with OpenOffice.org. If not, see
27 # <http://www.openoffice.org/license.html>
28 # for a copy of the LGPLv3 License.
30 #*************************************************************************
32 package installer
::windows
::shortcut
;
34 use installer
::existence
;
35 use installer
::exiter
;
37 use installer
::globals
;
38 use installer
::windows
::idtglobal
;
40 ##############################################################
41 # Returning the file object for the msiassembly table.
42 ##############################################################
46 my ( $filesref, $filename ) = @_;
51 for ( my $i = 0; $i <= $#{$filesref}; $i++ )
53 $onefile = ${$filesref}[$i];
54 my $name = $onefile->{'Name'};
56 if ( $name eq $filename )
63 if (! $foundfile ) { $onefile = ""; }
68 ##############################################################
69 # Returning identifier for shortcut table.
70 ##############################################################
72 sub get_shortcut_identifier
76 my $identifier = $shortcut->{'gid'};
81 ##############################################################
82 # Returning directory for shortcut table.
83 ##############################################################
85 sub get_shortcut_directory
87 my ($shortcut, $dirref) = @_;
89 # For shortcuts it is easy to convert the gid_Dir_Abc into the unique name in
90 # the directory table, for instance help_en_simpressidx.
91 # For files (components) this is not so easy, because files can be included
92 # in zip files with subdirectories that are not defined in scp.
95 my $shortcutdirectory = $shortcut->{'Dir'};
99 for ( my $i = 0; $i <= $#{$dirref}; $i++ )
101 $onedir = ${$dirref}[$i];
102 my $directorygid = $onedir->{'Dir'};
104 if ( $directorygid eq $shortcutdirectory )
113 installer
::exiter
::exit_program
("ERROR: Did not find DirectoryID $shortcutdirectory in directory collection for shortcut", "get_shortcut_directory");
116 $directory = $onedir->{'uniquename'};
118 if ($directory eq "") { $directory = "OFFICEINSTALLLOCATION"; } # Shortcuts in the root directory
123 ##############################################################
124 # Returning name for shortcut table.
125 ##############################################################
127 sub get_shortcut_name
129 my ($shortcut, $shortnamesref, $onelanguage) = @_;
133 my $name = $shortcut->{'Name'};
135 my $shortstring = installer
::windows
::idtglobal
::make_eight_three_conform
($name, "shortcut", $shortnamesref);
136 $shortstring =~ s/\s/\_/g; # replacing white spaces with underline
138 if ( $shortstring eq $name ) { $returnstring = $name; } # nothing changed
139 else {$returnstring = $shortstring . "\|" . $name; }
141 return $returnstring;
144 ##############################################################
145 # Returning component for shortcut table.
146 ##############################################################
148 sub get_shortcut_component
150 my ($shortcut, $filesref) = @_;
155 my $shortcut_fileid = $shortcut->{'FileID'};
157 my $absolute_filename = 0;
158 if ( $shortcut->{'Styles'} ) { $styles = $shortcut->{'Styles'}; }
159 if ( $styles =~ /\bABSOLUTE_FILENAME\b/ ) { $absolute_filename = 1; } # FileID contains an absolute filename
160 if ( $styles =~ /\bUSE_HELPER_FILENAME\b/ ) { $absolute_filename = 1; } # ComponentIDFile contains id of a helper file
162 # if the FileID contains an absolute filename, therefore the entry for "ComponentIDFile" has to be used.
163 if ( $absolute_filename ) { $shortcut_fileid = $shortcut->{'ComponentIDFile'}; }
165 for ( my $i = 0; $i <= $#{$filesref}; $i++ )
167 $onefile = ${$filesref}[$i];
168 my $filegid = $onefile->{'gid'};
170 if ( $filegid eq $shortcut_fileid )
179 installer
::exiter
::exit_program
("ERROR: Did not find FileID $shortcut_fileid in file collection for shortcut", "get_shortcut_component");
182 $component = $onefile->{'componentname'};
184 # finally saving the componentname in the folderitem collector
186 $shortcut->{'component'} = $component;
191 ##############################################################
192 # Returning target for shortcut table.
193 ##############################################################
195 sub get_shortcut_target
197 my ($shortcut, $filesref) = @_;
201 my $shortcut_fileid = $shortcut->{'FileID'};
204 for ( my $i = 0; $i <= $#{$filesref}; $i++ )
206 $onefile = ${$filesref}[$i];
207 my $filegid = $onefile->{'gid'};
209 if ( $filegid eq $shortcut_fileid )
218 installer
::exiter
::exit_program
("ERROR: Did not find FileID $shortcut_fileid in file collection for shortcut", "get_shortcut_target");
221 if ( $onefile->{'Name'} )
223 $target = $onefile->{'Name'};
226 $target = "\[\#" . $target . "\]"; # format for Non-Advertised shortcuts
231 ##############################################################
232 # Returning arguments for shortcut table.
233 ##############################################################
235 sub get_shortcut_arguments
242 ##############################################################
243 # Returning the localized description for shortcut table.
244 ##############################################################
246 sub get_shortcut_description
248 my ($shortcut, $onelanguage) = @_;
250 my $description = "";
251 if ( $shortcut->{'Tooltip'} ) { $description = $shortcut->{'Tooltip'}; }
256 ##############################################################
257 # Returning hotkey for shortcut table.
258 ##############################################################
260 sub get_shortcut_hotkey
267 ##############################################################
268 # Returning icon for shortcut table.
269 ##############################################################
271 sub get_shortcut_icon
278 ##############################################################
279 # Returning iconindex for shortcut table.
280 ##############################################################
282 sub get_shortcut_iconindex
289 ##############################################################
290 # Returning show command for shortcut table.
291 ##############################################################
293 sub get_shortcut_showcmd
300 ##############################################################
301 # Returning working directory for shortcut table.
302 ##############################################################
304 sub get_shortcut_wkdir
311 ####################################################################
312 # Returning working directory for shortcut table for FolderItems.
313 ####################################################################
315 sub get_folderitem_wkdir
317 my ($onelink, $dirref) = @_;
319 # For shortcuts it is easy to convert the gid_Dir_Abc into the unique name in
320 # the directory table, for instance help_en_simpressidx.
323 my $workingdirectory = "";
324 if ( $onelink->{'WkDir'} ) { $workingdirectory = $onelink->{'WkDir'}; }
327 if ( $workingdirectory )
331 for ( my $i = 0; $i <= $#{$dirref}; $i++ )
333 $onedir = ${$dirref}[$i];
334 my $directorygid = $onedir->{'Dir'};
336 if ( $directorygid eq $workingdirectory )
345 installer
::exiter
::exit_program
("ERROR: Did not find DirectoryID $workingdirectory in directory collection for FolderItem", "get_folderitem_wkdir");
348 $directory = $onedir->{'uniquename'};
350 if ($directory eq "") { $directory = "OFFICEINSTALLLOCATION"; }
356 ###################################################################
357 # Returning the directory for a folderitem for shortcut table.
358 ###################################################################
360 sub get_folderitem_directory
364 # my $directory = "$installer::globals::programmenufolder"; # default
365 my $directory = "$installer::globals::officemenufolder"; # default
367 # The value $installer::globals::programmenufolder is not correct for the
368 # PREDEFINED folders, like PREDEFINED_AUTOSTART
370 if ( $shortcut->{'FolderID'} eq "PREDEFINED_AUTOSTART" )
372 $directory = $installer::globals
::startupfolder
;
375 if ( $shortcut->{'FolderID'} eq "PREDEFINED_DESKTOP" )
377 $directory = $installer::globals
::desktopfolder
;
378 $installer::globals
::desktoplinkexists
= 1;
381 if ( $shortcut->{'FolderID'} eq "PREDEFINED_STARTMENU" )
383 $directory = $installer::globals
::startmenufolder
;
386 # saving the directory in the folderitems collector
388 $shortcut->{'directory'} = $directory;
393 ########################################################################
394 # Returning the target (feature) for a folderitem for shortcut table.
395 # For non-advertised shortcuts this is a formatted string.
396 ########################################################################
398 sub get_folderitem_target
400 my ($shortcut, $filesref) = @_;
405 my $shortcut_fileid = $shortcut->{'FileID'};
408 my $nonadvertised = 0;
409 my $absolute_filename = 0;
410 if ( $shortcut->{'Styles'} ) { $styles = $shortcut->{'Styles'}; }
411 if ( $styles =~ /\bNON_ADVERTISED\b/ ) { $nonadvertised = 1; } # this is a non-advertised shortcut
412 if ( $styles =~ /\bABSOLUTE_FILENAME\b/ ) { $absolute_filename = 1; } # FileID contains an absolute filename
414 # if the FileID contains an absolute filename this can simply be returned as target for the shortcut table.
415 if ( $absolute_filename )
417 $shortcut->{'target'} = $shortcut_fileid;
418 return $shortcut_fileid;
421 for ( my $i = 0; $i <= $#{$filesref}; $i++ )
423 $onefile = ${$filesref}[$i];
424 my $filegid = $onefile->{'gid'};
426 if ( $filegid eq $shortcut_fileid )
435 installer
::exiter
::exit_program
("ERROR: Did not find FileID $shortcut_fileid in file collection for folderitem", "get_folderitem_target");
438 # Non advertised shortcuts do not return the feature, but the path to the file
439 if ( $nonadvertised )
441 $target = "\[" . $onefile->{'uniquedirname'} . "\]" . "\\" . $onefile->{'Name'};
442 $shortcut->{'target'} = $target;
446 # the rest only for advertised shortcuts, which contain the feature in the shortcut table.
448 if ( $onefile->{'modules'} ) { $target = $onefile->{'modules'}; }
450 # If modules contains a list of modules, only taking the first one.
451 # But this should never be needed
453 if ( $target =~ /^\s*(.*?)\,/ ) { $target = $1; }
455 # Attention: Maximum feature length is 38!
456 installer
::windows
::idtglobal
::shorten_feature_gid
(\
$target);
458 # and finally saving the target in the folderitems collector
460 $shortcut->{'target'} = $target;
465 ########################################################################
466 # Returning the arguments for a folderitem for shortcut table.
467 ########################################################################
469 sub get_folderitem_arguments
475 if ( $shortcut->{'Parameter'} ) { $parameter = $shortcut->{'Parameter'}; }
480 ########################################################################
481 # Returning the icon for a folderitem for shortcut table.
482 # The returned value has to be defined in the icon table.
483 ########################################################################
485 sub get_folderitem_icon
487 my ($shortcut, $filesref, $iconfilecollector) = @_;
490 if ( $shortcut->{'Styles'} ) { $styles = $shortcut->{'Styles'}; }
491 if ( $styles =~ /\bNON_ADVERTISED\b/ ) { return ""; } # no icon for non-advertised shortcuts
493 my $iconfilegid = "";
495 if ( $shortcut->{'IconFile'} ) { $iconfilegid = $shortcut->{'IconFile'}; }
496 else { $iconfilegid = $shortcut->{'FileID'}; }
501 for ( my $i = 0; $i <= $#{$filesref}; $i++ )
503 $onefile = ${$filesref}[$i];
504 my $filegid = $onefile->{'gid'};
506 if ( $filegid eq $iconfilegid )
515 installer
::exiter
::exit_program
("ERROR: Did not find FileID $iconfilegid in file collection", "get_folderitem_icon");
518 $iconfile = $onefile->{'Name'};
520 # collecting all icon files to copy them into the icon directory
522 my $sourcepath = $onefile->{'sourcepath'};
524 if (! installer
::existence
::exists_in_array
($sourcepath, $iconfilecollector))
526 push(@
{$iconfilecollector}, $sourcepath);
532 ########################################################################
533 # Returning the iconindex for a folderitem for shortcut table.
534 ########################################################################
536 sub get_folderitem_iconindex
541 if ( $shortcut->{'Styles'} ) { $styles = $shortcut->{'Styles'}; }
542 if ( $styles =~ /\bNON_ADVERTISED\b/ ) { return ""; } # no iconindex for non-advertised shortcuts
546 if ( $shortcut->{'IconID'} ) { $iconid = $shortcut->{'IconID'}; }
551 ########################################################################
552 # Returning the show command for a folderitem for shortcut table.
553 ########################################################################
555 sub get_folderitem_showcmd
562 ###########################################################################################################
563 # Creating the file Shortcut.idt dynamically
565 # Shortcut Directory_ Name Component_ Target Arguments Description Hotkey Icon_ IconIndex ShowCmd WkDir
566 ###########################################################################################################
568 sub create_shortcut_table
570 my ($filesref, $linksref, $folderref, $folderitemsref, $dirref, $basedir, $languagesarrayref, $includepatharrayref, $iconfilecollector) = @_;
572 for ( my $m = 0; $m <= $#{$languagesarrayref}; $m++ )
574 my $onelanguage = ${$languagesarrayref}[$m];
576 my @shortcuttable = ();
578 my @shortnames = (); # to collect all short names
580 installer
::windows
::idtglobal
::write_idt_header
(\
@shortcuttable, "shortcut");
582 # First the links, defined in scp as ShortCut
584 for ( my $i = 0; $i <= $#{$linksref}; $i++ )
586 my $onelink = ${$linksref}[$i];
588 # Controlling the language!
589 # Only language independent folderitems or folderitems with the correct language
590 # will be included into the table
592 if (! (!(( $onelink->{'ismultilingual'} )) || ( $onelink->{'specificlanguage'} eq $onelanguage )) ) { next; }
596 $shortcut{'Shortcut'} = get_shortcut_identifier
($onelink);
597 $shortcut{'Directory_'} = get_shortcut_directory
($onelink, $dirref);
598 $shortcut{'Name'} = get_shortcut_name
($onelink, \
@shortnames, $onelanguage); # localized name
599 $shortcut{'Component_'} = get_shortcut_component
($onelink, $filesref);
600 $shortcut{'Target'} = get_shortcut_target
($onelink, $filesref);
601 $shortcut{'Arguments'} = get_shortcut_arguments
($onelink);
602 $shortcut{'Description'} = get_shortcut_description
($onelink, $onelanguage); # localized description
603 $shortcut{'Hotkey'} = get_shortcut_hotkey
($onelink);
604 $shortcut{'Icon_'} = get_shortcut_icon
($onelink);
605 $shortcut{'IconIndex'} = get_shortcut_iconindex
($onelink);
606 $shortcut{'ShowCmd'} = get_shortcut_showcmd
($onelink);
607 $shortcut{'WkDir'} = get_shortcut_wkdir
($onelink);
609 my $oneline = $shortcut{'Shortcut'} . "\t" . $shortcut{'Directory_'} . "\t" . $shortcut{'Name'} . "\t"
610 . $shortcut{'Component_'} . "\t" . $shortcut{'Target'} . "\t" . $shortcut{'Arguments'} . "\t"
611 . $shortcut{'Description'} . "\t" . $shortcut{'Hotkey'} . "\t" . $shortcut{'Icon_'} . "\t"
612 . $shortcut{'IconIndex'} . "\t" . $shortcut{'ShowCmd'} . "\t" . $shortcut{'WkDir'} . "\n";
614 push(@shortcuttable, $oneline);
617 # Second the entries into the start menu, defined in scp as Folder and Folderitem
618 # These shortcuts will fill the icons table.
620 for ( my $i = 0; $i <= $#{$folderref}; $i++ )
622 my $foldergid = ${$folderref}[$i]->{'gid'};
624 # iterating over all folderitems for this folder
626 for ( my $j = 0; $j <= $#{$folderitemsref}; $j++ )
628 my $onelink = ${$folderitemsref}[$j];
630 # Controlling the language!
631 # Only language independent folderitems or folderitems with the correct language
632 # will be included into the table
634 if (! (!(( $onelink->{'ismultilingual'} )) || ( $onelink->{'specificlanguage'} eq $onelanguage )) ) { next; }
636 # controlling the folder
640 if ( $onelink->{'used'} ) { $localused = $onelink->{'used'}; }
642 if (!($localused == 1)) { $onelink->{'used'} = "0"; } # no resetting
644 if (!( $onelink->{'FolderID'} eq $foldergid )) { next; }
646 $onelink->{'used'} = "1";
650 $shortcut{'Shortcut'} = get_shortcut_identifier
($onelink);
651 $shortcut{'Directory_'} = get_folderitem_directory
($onelink);
652 $shortcut{'Name'} = get_shortcut_name
($onelink, \
@shortnames, $onelanguage); # localized name
653 $shortcut{'Component_'} = get_shortcut_component
($onelink, $filesref);
654 $shortcut{'Target'} = get_folderitem_target
($onelink, $filesref);
655 $shortcut{'Arguments'} = get_folderitem_arguments
($onelink);
656 $shortcut{'Description'} = get_shortcut_description
($onelink, $onelanguage); # localized description
657 $shortcut{'Hotkey'} = get_shortcut_hotkey
($onelink);
658 $shortcut{'Icon_'} = get_folderitem_icon
($onelink, $filesref, $iconfilecollector);
659 $shortcut{'IconIndex'} = get_folderitem_iconindex
($onelink);
660 $shortcut{'ShowCmd'} = get_folderitem_showcmd
($onelink);
661 $shortcut{'WkDir'} = get_folderitem_wkdir
($onelink, $dirref);
663 my $oneline = $shortcut{'Shortcut'} . "\t" . $shortcut{'Directory_'} . "\t" . $shortcut{'Name'} . "\t"
664 . $shortcut{'Component_'} . "\t" . $shortcut{'Target'} . "\t" . $shortcut{'Arguments'} . "\t"
665 . $shortcut{'Description'} . "\t" . $shortcut{'Hotkey'} . "\t" . $shortcut{'Icon_'} . "\t"
666 . $shortcut{'IconIndex'} . "\t" . $shortcut{'ShowCmd'} . "\t" . $shortcut{'WkDir'} . "\n";
668 push(@shortcuttable, $oneline);
672 # if it is part of the product, the soffice.exe has to be included into the icon table
673 # as icon for the ARP applet
675 my $sofficefile = "soffice.exe";
676 my $onefile = get_file_by_name
($filesref, $sofficefile);
678 if ( $onefile ne "" )
680 my $sourcepath = $onefile->{'sourcepath'};
681 if (! installer
::existence
::exists_in_array
($sourcepath, $iconfilecollector))
683 unshift(@
{$iconfilecollector}, $sourcepath);
684 $installer::globals
::sofficeiconadded
= 1;
688 # For language packs and patches the soffice.exe has to be included, even if it is not part of the product.
689 # Also as part of the ARP applet (no substitution needed for ProductName, because the file is not installed!)
691 if (( $onefile eq "" ) && (( $installer::globals
::languagepack
) || ( $installer::globals
::patch
)))
693 my $sourcepathref = installer
::scriptitems
::get_sourcepath_from_filename_and_includepath
(\
$sofficefile, $includepatharrayref, 1);
694 if ($$sourcepathref eq "") { installer
::exiter
::exit_program
("ERROR: Could not find $sofficefile as icon in language pack!", "create_shortcut_table"); }
696 if (! installer
::existence
::exists_in_array
($$sourcepathref, $iconfilecollector))
698 unshift(@
{$iconfilecollector}, $$sourcepathref);
699 $installer::globals
::sofficeiconadded
= 1;
702 my $localinfoline = "Added icon file $$sourcepathref for language pack into icon file collector.\n";
703 push(@installer::globals
::logfileinfo
, $localinfoline);
708 my $shortcuttablename = $basedir . $installer::globals
::separator
. "Shortcut.idt" . "." . $onelanguage;
709 installer
::files
::save_file
($shortcuttablename ,\
@shortcuttable);
710 my $infoline = "Created idt file: $shortcuttablename\n";
711 push(@installer::globals
::logfileinfo
, $infoline);