19780544fSAndrew Rist#**************************************************************
29780544fSAndrew Rist#
39780544fSAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
49780544fSAndrew Rist#  or more contributor license agreements.  See the NOTICE file
59780544fSAndrew Rist#  distributed with this work for additional information
69780544fSAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
79780544fSAndrew Rist#  to you under the Apache License, Version 2.0 (the
89780544fSAndrew Rist#  "License"); you may not use this file except in compliance
99780544fSAndrew Rist#  with the License.  You may obtain a copy of the License at
109780544fSAndrew Rist#
119780544fSAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
129780544fSAndrew Rist#
139780544fSAndrew Rist#  Unless required by applicable law or agreed to in writing,
149780544fSAndrew Rist#  software distributed under the License is distributed on an
159780544fSAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169780544fSAndrew Rist#  KIND, either express or implied.  See the License for the
179780544fSAndrew Rist#  specific language governing permissions and limitations
189780544fSAndrew Rist#  under the License.
199780544fSAndrew Rist#
209780544fSAndrew Rist#**************************************************************
219780544fSAndrew Rist
229780544fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweirpackage installer::windows::shortcut;
25cdf0e10cSrcweir
26cdf0e10cSrcweiruse installer::existence;
27cdf0e10cSrcweiruse installer::exiter;
28cdf0e10cSrcweiruse installer::files;
29cdf0e10cSrcweiruse installer::globals;
30cdf0e10cSrcweiruse installer::windows::idtglobal;
31cdf0e10cSrcweir
32cdf0e10cSrcweir##############################################################
33cdf0e10cSrcweir# Returning the file object for the msiassembly table.
34cdf0e10cSrcweir##############################################################
35cdf0e10cSrcweir
36cdf0e10cSrcweirsub get_file_by_name
37cdf0e10cSrcweir{
38cdf0e10cSrcweir	my ( $filesref, $filename ) = @_;
39cdf0e10cSrcweir
40cdf0e10cSrcweir	my $foundfile = 0;
41cdf0e10cSrcweir	my $onefile;
42cdf0e10cSrcweir
43cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$filesref}; $i++ )
44cdf0e10cSrcweir	{
45cdf0e10cSrcweir		$onefile = ${$filesref}[$i];
46cdf0e10cSrcweir		my $name = $onefile->{'Name'};
47cdf0e10cSrcweir
48cdf0e10cSrcweir		if ( $name eq $filename )
49cdf0e10cSrcweir		{
50cdf0e10cSrcweir			$foundfile = 1;
51cdf0e10cSrcweir			last;
52cdf0e10cSrcweir		}
53cdf0e10cSrcweir	}
54cdf0e10cSrcweir
55cdf0e10cSrcweir	if (! $foundfile ) { $onefile  = ""; }
56cdf0e10cSrcweir
57cdf0e10cSrcweir	return $onefile;
58cdf0e10cSrcweir}
59cdf0e10cSrcweir
60cdf0e10cSrcweir##############################################################
61cdf0e10cSrcweir# Returning identifier for shortcut table.
62cdf0e10cSrcweir##############################################################
63cdf0e10cSrcweir
64cdf0e10cSrcweirsub get_shortcut_identifier
65cdf0e10cSrcweir{
66cdf0e10cSrcweir	my ($shortcut) = @_;
67cdf0e10cSrcweir
68cdf0e10cSrcweir	my $identifier = $shortcut->{'gid'};
69cdf0e10cSrcweir
70cdf0e10cSrcweir	return $identifier;
71cdf0e10cSrcweir}
72cdf0e10cSrcweir
73cdf0e10cSrcweir##############################################################
74cdf0e10cSrcweir# Returning directory for shortcut table.
75cdf0e10cSrcweir##############################################################
76cdf0e10cSrcweir
77cdf0e10cSrcweirsub get_shortcut_directory
78cdf0e10cSrcweir{
79cdf0e10cSrcweir	my ($shortcut, $dirref) = @_;
80cdf0e10cSrcweir
81cdf0e10cSrcweir	# For shortcuts it is easy to convert the gid_Dir_Abc into the unique name in
82cdf0e10cSrcweir	# the directory table, for instance help_en_simpressidx.
83cdf0e10cSrcweir	# For files (components) this is not so easy, because files can be included
84cdf0e10cSrcweir	# in zip files with subdirectories that are not defined in scp.
85cdf0e10cSrcweir
86cdf0e10cSrcweir	my $onedir;
87cdf0e10cSrcweir	my $shortcutdirectory = $shortcut->{'Dir'};
88cdf0e10cSrcweir	my $directory = "";
89cdf0e10cSrcweir	my $found = 0;
90cdf0e10cSrcweir
91cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$dirref}; $i++ )
92cdf0e10cSrcweir	{
93cdf0e10cSrcweir		$onedir = ${$dirref}[$i];
94cdf0e10cSrcweir		my $directorygid = $onedir->{'Dir'};
95cdf0e10cSrcweir
96cdf0e10cSrcweir		if ( $directorygid eq $shortcutdirectory )
97cdf0e10cSrcweir		{
98cdf0e10cSrcweir			$found = 1;
99cdf0e10cSrcweir			last;
100cdf0e10cSrcweir		}
101cdf0e10cSrcweir	}
102cdf0e10cSrcweir
103cdf0e10cSrcweir	if (!($found))
104cdf0e10cSrcweir	{
105cdf0e10cSrcweir		installer::exiter::exit_program("ERROR: Did not find DirectoryID $shortcutdirectory in directory collection for shortcut", "get_shortcut_directory");
106cdf0e10cSrcweir	}
107cdf0e10cSrcweir
108cdf0e10cSrcweir	$directory = $onedir->{'uniquename'};
109cdf0e10cSrcweir
110cdf0e10cSrcweir	if ($directory eq "") { $directory = "INSTALLLOCATION"; }		# Shortcuts in the root directory
111cdf0e10cSrcweir
112cdf0e10cSrcweir	return $directory;
113cdf0e10cSrcweir}
114cdf0e10cSrcweir
115cdf0e10cSrcweir##############################################################
116cdf0e10cSrcweir# Returning name for shortcut table.
117cdf0e10cSrcweir##############################################################
118cdf0e10cSrcweir
119cdf0e10cSrcweirsub get_shortcut_name
120cdf0e10cSrcweir{
121cdf0e10cSrcweir	my ($shortcut, $shortnamesref, $onelanguage) = @_;
122cdf0e10cSrcweir
123cdf0e10cSrcweir	my $returnstring;
124cdf0e10cSrcweir
125cdf0e10cSrcweir	my $name = $shortcut->{'Name'};
126cdf0e10cSrcweir
127cdf0e10cSrcweir	my $shortstring = installer::windows::idtglobal::make_eight_three_conform($name, "shortcut", $shortnamesref);
128cdf0e10cSrcweir	$shortstring =~ s/\s/\_/g;	# replacing white spaces with underline
129cdf0e10cSrcweir
130cdf0e10cSrcweir	if ( $shortstring eq $name ) { $returnstring = $name; }	# nothing changed
131cdf0e10cSrcweir	else {$returnstring = $shortstring . "\|" . $name; }
132cdf0e10cSrcweir
133cdf0e10cSrcweir	return $returnstring;
134cdf0e10cSrcweir}
135cdf0e10cSrcweir
136cdf0e10cSrcweir##############################################################
137cdf0e10cSrcweir# Returning component for shortcut table.
138cdf0e10cSrcweir##############################################################
139cdf0e10cSrcweir
140cdf0e10cSrcweirsub get_shortcut_component
141cdf0e10cSrcweir{
142cdf0e10cSrcweir	my ($shortcut, $filesref) = @_;
143cdf0e10cSrcweir
144cdf0e10cSrcweir	my $onefile;
145cdf0e10cSrcweir	my $component = "";
146cdf0e10cSrcweir	my $found = 0;
147cdf0e10cSrcweir	my $shortcut_fileid = $shortcut->{'FileID'};
148cdf0e10cSrcweir
149cdf0e10cSrcweir	my $absolute_filename = 0;
150cdf0e10cSrcweir	if ( $shortcut->{'Styles'} ) { $styles = $shortcut->{'Styles'}; }
151cdf0e10cSrcweir	if ( $styles =~ /\bABSOLUTE_FILENAME\b/ ) { $absolute_filename = 1; }	# FileID contains an absolute filename
152cdf0e10cSrcweir	if ( $styles =~ /\bUSE_HELPER_FILENAME\b/ ) { $absolute_filename = 1; }	# ComponentIDFile contains id of a helper file
153cdf0e10cSrcweir
154cdf0e10cSrcweir	# if the FileID contains an absolute filename, therefore the entry for "ComponentIDFile" has to be used.
155cdf0e10cSrcweir	if ( $absolute_filename ) { $shortcut_fileid = $shortcut->{'ComponentIDFile'}; }
156cdf0e10cSrcweir
157cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$filesref}; $i++ )
158cdf0e10cSrcweir	{
159cdf0e10cSrcweir		$onefile = ${$filesref}[$i];
160cdf0e10cSrcweir		my $filegid = $onefile->{'gid'};
161cdf0e10cSrcweir
162cdf0e10cSrcweir		if ( $filegid eq $shortcut_fileid )
163cdf0e10cSrcweir		{
164cdf0e10cSrcweir			$found = 1;
165cdf0e10cSrcweir			last;
166cdf0e10cSrcweir		}
167cdf0e10cSrcweir	}
168cdf0e10cSrcweir
169cdf0e10cSrcweir	if (!($found))
170cdf0e10cSrcweir	{
171cdf0e10cSrcweir		installer::exiter::exit_program("ERROR: Did not find FileID $shortcut_fileid in file collection for shortcut", "get_shortcut_component");
172cdf0e10cSrcweir	}
173cdf0e10cSrcweir
174cdf0e10cSrcweir	$component = $onefile->{'componentname'};
175cdf0e10cSrcweir
176cdf0e10cSrcweir	# finally saving the componentname in the folderitem collector
177cdf0e10cSrcweir
178cdf0e10cSrcweir	$shortcut->{'component'} = $component;
179cdf0e10cSrcweir
180cdf0e10cSrcweir	return $component;
181cdf0e10cSrcweir}
182cdf0e10cSrcweir
183cdf0e10cSrcweir##############################################################
184cdf0e10cSrcweir# Returning target for shortcut table.
185cdf0e10cSrcweir##############################################################
186cdf0e10cSrcweir
187cdf0e10cSrcweirsub get_shortcut_target
188cdf0e10cSrcweir{
189cdf0e10cSrcweir	my ($shortcut, $filesref) = @_;
190cdf0e10cSrcweir
191cdf0e10cSrcweir	my $target = "";
192cdf0e10cSrcweir	my $found = 0;
193cdf0e10cSrcweir	my $shortcut_fileid = $shortcut->{'FileID'};
194cdf0e10cSrcweir	my $onefile;
195cdf0e10cSrcweir
196cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$filesref}; $i++ )
197cdf0e10cSrcweir	{
198cdf0e10cSrcweir		$onefile = ${$filesref}[$i];
199cdf0e10cSrcweir		my $filegid = $onefile->{'gid'};
200cdf0e10cSrcweir
201cdf0e10cSrcweir		if ( $filegid eq $shortcut_fileid )
202cdf0e10cSrcweir		{
203cdf0e10cSrcweir			$found = 1;
204cdf0e10cSrcweir			last;
205cdf0e10cSrcweir		}
206cdf0e10cSrcweir	}
207cdf0e10cSrcweir
208cdf0e10cSrcweir	if (!($found))
209cdf0e10cSrcweir	{
210cdf0e10cSrcweir		installer::exiter::exit_program("ERROR: Did not find FileID $shortcut_fileid in file collection for shortcut", "get_shortcut_target");
211cdf0e10cSrcweir	}
212cdf0e10cSrcweir
213cdf0e10cSrcweir	if ( $onefile->{'Name'} )
214cdf0e10cSrcweir	{
215cdf0e10cSrcweir		$target = $onefile->{'Name'};
216cdf0e10cSrcweir	}
217cdf0e10cSrcweir
218cdf0e10cSrcweir	$target = "\[\#" . $target . "\]";	# format for Non-Advertised shortcuts
219cdf0e10cSrcweir
220cdf0e10cSrcweir	return $target;
221cdf0e10cSrcweir}
222cdf0e10cSrcweir
223cdf0e10cSrcweir##############################################################
224cdf0e10cSrcweir# Returning arguments for shortcut table.
225cdf0e10cSrcweir##############################################################
226cdf0e10cSrcweir
227cdf0e10cSrcweirsub get_shortcut_arguments
228cdf0e10cSrcweir{
229cdf0e10cSrcweir	my ($shortcut) = @_;
230cdf0e10cSrcweir
231cdf0e10cSrcweir	return "";
232cdf0e10cSrcweir}
233cdf0e10cSrcweir
234cdf0e10cSrcweir##############################################################
235cdf0e10cSrcweir# Returning the localized description for shortcut table.
236cdf0e10cSrcweir##############################################################
237cdf0e10cSrcweir
238cdf0e10cSrcweirsub get_shortcut_description
239cdf0e10cSrcweir{
240cdf0e10cSrcweir	my ($shortcut, $onelanguage) = @_;
241cdf0e10cSrcweir
242cdf0e10cSrcweir	my $description = "";
243cdf0e10cSrcweir	if ( $shortcut->{'Tooltip'} ) { $description = $shortcut->{'Tooltip'}; }
244cdf0e10cSrcweir
245cdf0e10cSrcweir	return $description;
246cdf0e10cSrcweir}
247cdf0e10cSrcweir
248cdf0e10cSrcweir##############################################################
249cdf0e10cSrcweir# Returning hotkey for shortcut table.
250cdf0e10cSrcweir##############################################################
251cdf0e10cSrcweir
252cdf0e10cSrcweirsub get_shortcut_hotkey
253cdf0e10cSrcweir{
254cdf0e10cSrcweir	my ($shortcut) = @_;
255cdf0e10cSrcweir
256cdf0e10cSrcweir	return "";
257cdf0e10cSrcweir}
258cdf0e10cSrcweir
259cdf0e10cSrcweir##############################################################
260cdf0e10cSrcweir# Returning icon for shortcut table.
261cdf0e10cSrcweir##############################################################
262cdf0e10cSrcweir
263cdf0e10cSrcweirsub get_shortcut_icon
264cdf0e10cSrcweir{
265cdf0e10cSrcweir	my ($shortcut) = @_;
266cdf0e10cSrcweir
267cdf0e10cSrcweir	return "";
268cdf0e10cSrcweir}
269cdf0e10cSrcweir
270cdf0e10cSrcweir##############################################################
271cdf0e10cSrcweir# Returning iconindex for shortcut table.
272cdf0e10cSrcweir##############################################################
273cdf0e10cSrcweir
274cdf0e10cSrcweirsub get_shortcut_iconindex
275cdf0e10cSrcweir{
276cdf0e10cSrcweir	my ($shortcut) = @_;
277cdf0e10cSrcweir
278cdf0e10cSrcweir	return "";
279cdf0e10cSrcweir}
280cdf0e10cSrcweir
281cdf0e10cSrcweir##############################################################
282cdf0e10cSrcweir# Returning show command for shortcut table.
283cdf0e10cSrcweir##############################################################
284cdf0e10cSrcweir
285cdf0e10cSrcweirsub get_shortcut_showcmd
286cdf0e10cSrcweir{
287cdf0e10cSrcweir	my ($shortcut) = @_;
288cdf0e10cSrcweir
289cdf0e10cSrcweir	return "";
290cdf0e10cSrcweir}
291cdf0e10cSrcweir
292cdf0e10cSrcweir##############################################################
293cdf0e10cSrcweir# Returning working directory for shortcut table.
294cdf0e10cSrcweir##############################################################
295cdf0e10cSrcweir
296cdf0e10cSrcweirsub get_shortcut_wkdir
297cdf0e10cSrcweir{
298cdf0e10cSrcweir	my ($shortcut) = @_;
299cdf0e10cSrcweir
300cdf0e10cSrcweir	return "";
301cdf0e10cSrcweir}
302cdf0e10cSrcweir
303cdf0e10cSrcweir####################################################################
304cdf0e10cSrcweir# Returning working directory for shortcut table for FolderItems.
305cdf0e10cSrcweir####################################################################
306cdf0e10cSrcweir
307cdf0e10cSrcweirsub get_folderitem_wkdir
308cdf0e10cSrcweir{
309cdf0e10cSrcweir	my ($onelink, $dirref) = @_;
310cdf0e10cSrcweir
311cdf0e10cSrcweir	# For shortcuts it is easy to convert the gid_Dir_Abc into the unique name in
312cdf0e10cSrcweir	# the directory table, for instance help_en_simpressidx.
313cdf0e10cSrcweir
314cdf0e10cSrcweir	my $onedir;
315cdf0e10cSrcweir	my $workingdirectory = "";
316cdf0e10cSrcweir	if ( $onelink->{'WkDir'} ) { $workingdirectory = $onelink->{'WkDir'}; }
317cdf0e10cSrcweir	my $directory = "";
318cdf0e10cSrcweir
319cdf0e10cSrcweir	if ( $workingdirectory )
320cdf0e10cSrcweir	{
321cdf0e10cSrcweir		my $found = 0;
322cdf0e10cSrcweir
323cdf0e10cSrcweir		for ( my $i = 0; $i <= $#{$dirref}; $i++ )
324cdf0e10cSrcweir		{
325cdf0e10cSrcweir			$onedir = ${$dirref}[$i];
326cdf0e10cSrcweir			my $directorygid = $onedir->{'Dir'};
327cdf0e10cSrcweir
328cdf0e10cSrcweir			if ( $directorygid eq $workingdirectory )
329cdf0e10cSrcweir			{
330cdf0e10cSrcweir				$found = 1;
331cdf0e10cSrcweir				last;
332cdf0e10cSrcweir			}
333cdf0e10cSrcweir		}
334cdf0e10cSrcweir
335cdf0e10cSrcweir		if (!($found))
336cdf0e10cSrcweir		{
337cdf0e10cSrcweir			installer::exiter::exit_program("ERROR: Did not find DirectoryID $workingdirectory in directory collection for FolderItem", "get_folderitem_wkdir");
338cdf0e10cSrcweir		}
339cdf0e10cSrcweir
340cdf0e10cSrcweir		$directory = $onedir->{'uniquename'};
341cdf0e10cSrcweir
342cdf0e10cSrcweir		if ($directory eq "") { $directory = "INSTALLLOCATION"; }
343cdf0e10cSrcweir	}
344cdf0e10cSrcweir
345cdf0e10cSrcweir	return $directory;
346cdf0e10cSrcweir}
347cdf0e10cSrcweir
348cdf0e10cSrcweir###################################################################
349cdf0e10cSrcweir# Returning the directory for a folderitem for shortcut table.
350cdf0e10cSrcweir###################################################################
351cdf0e10cSrcweir
352cdf0e10cSrcweirsub get_folderitem_directory
353cdf0e10cSrcweir{
354cdf0e10cSrcweir	my ($shortcut) = @_;
355cdf0e10cSrcweir
356cdf0e10cSrcweir	# my $directory = "$installer::globals::programmenufolder";	 # default
357cdf0e10cSrcweir	my $directory = "$installer::globals::officemenufolder";	 # default
358cdf0e10cSrcweir
359cdf0e10cSrcweir	# The value $installer::globals::programmenufolder is not correct for the
360cdf0e10cSrcweir	# PREDEFINED folders, like PREDEFINED_AUTOSTART
361cdf0e10cSrcweir
362cdf0e10cSrcweir	if ( $shortcut->{'FolderID'} eq "PREDEFINED_AUTOSTART" )
363cdf0e10cSrcweir	{
364cdf0e10cSrcweir		$directory = $installer::globals::startupfolder;
365cdf0e10cSrcweir	}
366cdf0e10cSrcweir
367cdf0e10cSrcweir	if ( $shortcut->{'FolderID'} eq "PREDEFINED_DESKTOP" )
368cdf0e10cSrcweir	{
369cdf0e10cSrcweir		$directory = $installer::globals::desktopfolder;
370cdf0e10cSrcweir		$installer::globals::desktoplinkexists = 1;
371cdf0e10cSrcweir	}
372cdf0e10cSrcweir
373cdf0e10cSrcweir	if ( $shortcut->{'FolderID'} eq "PREDEFINED_STARTMENU" )
374cdf0e10cSrcweir	{
375cdf0e10cSrcweir		$directory = $installer::globals::startmenufolder;
376cdf0e10cSrcweir	}
377cdf0e10cSrcweir
378cdf0e10cSrcweir	# saving the directory in the folderitems collector
379cdf0e10cSrcweir
380cdf0e10cSrcweir	$shortcut->{'directory'} = $directory;
381cdf0e10cSrcweir
382cdf0e10cSrcweir	return $directory;
383cdf0e10cSrcweir}
384cdf0e10cSrcweir
385cdf0e10cSrcweir########################################################################
386cdf0e10cSrcweir# Returning the target (feature) for a folderitem for shortcut table.
387cdf0e10cSrcweir# For non-advertised shortcuts this is a formatted string.
388cdf0e10cSrcweir########################################################################
389cdf0e10cSrcweir
390cdf0e10cSrcweirsub get_folderitem_target
391cdf0e10cSrcweir{
392cdf0e10cSrcweir	my ($shortcut, $filesref) = @_;
393cdf0e10cSrcweir
394cdf0e10cSrcweir	my $onefile;
395cdf0e10cSrcweir	my $target = "";
396cdf0e10cSrcweir	my $found = 0;
397cdf0e10cSrcweir	my $shortcut_fileid = $shortcut->{'FileID'};
398cdf0e10cSrcweir
399cdf0e10cSrcweir	my $styles = "";
400cdf0e10cSrcweir	my $nonadvertised = 0;
401cdf0e10cSrcweir	my $absolute_filename = 0;
402cdf0e10cSrcweir	if ( $shortcut->{'Styles'} ) { $styles = $shortcut->{'Styles'}; }
403cdf0e10cSrcweir	if ( $styles =~ /\bNON_ADVERTISED\b/ ) { $nonadvertised = 1; }	# this is a non-advertised shortcut
404cdf0e10cSrcweir	if ( $styles =~ /\bABSOLUTE_FILENAME\b/ ) { $absolute_filename = 1; }	# FileID contains an absolute filename
405cdf0e10cSrcweir
406cdf0e10cSrcweir	# if the FileID contains an absolute filename this can simply be returned as target for the shortcut table.
407cdf0e10cSrcweir	if ( $absolute_filename )
408cdf0e10cSrcweir	{
409cdf0e10cSrcweir		$shortcut->{'target'} = $shortcut_fileid;
410cdf0e10cSrcweir		return $shortcut_fileid;
411cdf0e10cSrcweir	}
412cdf0e10cSrcweir
413cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$filesref}; $i++ )
414cdf0e10cSrcweir	{
415cdf0e10cSrcweir		$onefile = ${$filesref}[$i];
416cdf0e10cSrcweir		my $filegid = $onefile->{'gid'};
417cdf0e10cSrcweir
418cdf0e10cSrcweir		if ( $filegid eq $shortcut_fileid )
419cdf0e10cSrcweir		{
420cdf0e10cSrcweir			$found = 1;
421cdf0e10cSrcweir			last;
422cdf0e10cSrcweir		}
423cdf0e10cSrcweir	}
424cdf0e10cSrcweir
425cdf0e10cSrcweir	if (!($found))
426cdf0e10cSrcweir	{
427cdf0e10cSrcweir		installer::exiter::exit_program("ERROR: Did not find FileID $shortcut_fileid in file collection for folderitem", "get_folderitem_target");
428cdf0e10cSrcweir	}
429cdf0e10cSrcweir
430cdf0e10cSrcweir	# Non advertised shortcuts do not return the feature, but the path to the file
431cdf0e10cSrcweir	if ( $nonadvertised )
432cdf0e10cSrcweir	{
433cdf0e10cSrcweir		$target = "\[" . $onefile->{'uniquedirname'} . "\]" . "\\" . $onefile->{'Name'};
434cdf0e10cSrcweir		$shortcut->{'target'} = $target;
435cdf0e10cSrcweir		return $target;
436cdf0e10cSrcweir	}
437cdf0e10cSrcweir
438cdf0e10cSrcweir	# the rest only for advertised shortcuts, which contain the feature in the shortcut table.
439cdf0e10cSrcweir
440cdf0e10cSrcweir	if ( $onefile->{'modules'} ) { $target = $onefile->{'modules'}; }
441cdf0e10cSrcweir
442cdf0e10cSrcweir	# If modules contains a list of modules, only taking the first one.
443cdf0e10cSrcweir	# But this should never be needed
444cdf0e10cSrcweir
445cdf0e10cSrcweir	if ( $target =~ /^\s*(.*?)\,/ ) { $target = $1; }
446cdf0e10cSrcweir
447cdf0e10cSrcweir	# Attention: Maximum feature length is 38!
448cdf0e10cSrcweir	installer::windows::idtglobal::shorten_feature_gid(\$target);
449cdf0e10cSrcweir
450cdf0e10cSrcweir	# and finally saving the target in the folderitems collector
451cdf0e10cSrcweir
452cdf0e10cSrcweir	$shortcut->{'target'} = $target;
453cdf0e10cSrcweir
454cdf0e10cSrcweir	return $target;
455cdf0e10cSrcweir}
456cdf0e10cSrcweir
457cdf0e10cSrcweir########################################################################
458cdf0e10cSrcweir# Returning the arguments for a folderitem for shortcut table.
459cdf0e10cSrcweir########################################################################
460cdf0e10cSrcweir
461cdf0e10cSrcweirsub get_folderitem_arguments
462cdf0e10cSrcweir{
463cdf0e10cSrcweir	my ($shortcut) = @_;
464cdf0e10cSrcweir
465cdf0e10cSrcweir	my $parameter = "";
466cdf0e10cSrcweir
467cdf0e10cSrcweir	if ( $shortcut->{'Parameter'} ) { $parameter = $shortcut->{'Parameter'}; }
468cdf0e10cSrcweir
469cdf0e10cSrcweir	return $parameter;
470cdf0e10cSrcweir}
471cdf0e10cSrcweir
472cdf0e10cSrcweir########################################################################
473cdf0e10cSrcweir# Returning the icon for a folderitem for shortcut table.
474cdf0e10cSrcweir# The returned value has to be defined in the icon table.
475cdf0e10cSrcweir########################################################################
476cdf0e10cSrcweir
477cdf0e10cSrcweirsub get_folderitem_icon
478cdf0e10cSrcweir{
479cdf0e10cSrcweir	my ($shortcut, $filesref, $iconfilecollector) = @_;
480cdf0e10cSrcweir
481cdf0e10cSrcweir	my $styles = "";
482cdf0e10cSrcweir	if ( $shortcut->{'Styles'} ) { $styles = $shortcut->{'Styles'}; }
483cdf0e10cSrcweir	if ( $styles =~ /\bNON_ADVERTISED\b/ ) { return ""; }	# no icon for non-advertised shortcuts
484cdf0e10cSrcweir
485cdf0e10cSrcweir	my $iconfilegid = "";
486cdf0e10cSrcweir
487cdf0e10cSrcweir	if ( $shortcut->{'IconFile'} ) { $iconfilegid = $shortcut->{'IconFile'}; }
488cdf0e10cSrcweir	else { $iconfilegid = $shortcut->{'FileID'}; }
489cdf0e10cSrcweir
490cdf0e10cSrcweir	my $onefile;
491cdf0e10cSrcweir	my $found = 0;
492cdf0e10cSrcweir
493cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$filesref}; $i++ )
494cdf0e10cSrcweir	{
495cdf0e10cSrcweir		$onefile = ${$filesref}[$i];
496cdf0e10cSrcweir		my $filegid = $onefile->{'gid'};
497cdf0e10cSrcweir
498cdf0e10cSrcweir		if ( $filegid eq $iconfilegid )
499cdf0e10cSrcweir		{
500cdf0e10cSrcweir			$found = 1;
501cdf0e10cSrcweir			last;
502cdf0e10cSrcweir		}
503cdf0e10cSrcweir	}
504cdf0e10cSrcweir
505cdf0e10cSrcweir	if (!($found))
506cdf0e10cSrcweir	{
507cdf0e10cSrcweir		installer::exiter::exit_program("ERROR: Did not find FileID $iconfilegid in file collection", "get_folderitem_icon");
508cdf0e10cSrcweir	}
509cdf0e10cSrcweir
510cdf0e10cSrcweir	$iconfile = $onefile->{'Name'};
511cdf0e10cSrcweir
512cdf0e10cSrcweir	# collecting all icon files to copy them into the icon directory
513cdf0e10cSrcweir
514cdf0e10cSrcweir	my $sourcepath = $onefile->{'sourcepath'};
515cdf0e10cSrcweir
516cdf0e10cSrcweir	if (! installer::existence::exists_in_array($sourcepath, $iconfilecollector))
517cdf0e10cSrcweir	{
518cdf0e10cSrcweir		push(@{$iconfilecollector}, $sourcepath);
519cdf0e10cSrcweir	}
520cdf0e10cSrcweir
521cdf0e10cSrcweir	return $iconfile;
522cdf0e10cSrcweir}
523cdf0e10cSrcweir
524cdf0e10cSrcweir########################################################################
525cdf0e10cSrcweir# Returning the iconindex for a folderitem for shortcut table.
526cdf0e10cSrcweir########################################################################
527cdf0e10cSrcweir
528cdf0e10cSrcweirsub get_folderitem_iconindex
529cdf0e10cSrcweir{
530cdf0e10cSrcweir	my ($shortcut) = @_;
531cdf0e10cSrcweir
532cdf0e10cSrcweir	my $styles = "";
533cdf0e10cSrcweir	if ( $shortcut->{'Styles'} ) { $styles = $shortcut->{'Styles'}; }
534cdf0e10cSrcweir	if ( $styles =~ /\bNON_ADVERTISED\b/ ) { return ""; }	# no iconindex for non-advertised shortcuts
535cdf0e10cSrcweir
536cdf0e10cSrcweir	my $iconid = 0;
537cdf0e10cSrcweir
538cdf0e10cSrcweir	if ( $shortcut->{'IconID'} ) { $iconid = $shortcut->{'IconID'}; }
539cdf0e10cSrcweir
540cdf0e10cSrcweir	return $iconid;
541cdf0e10cSrcweir}
542cdf0e10cSrcweir
543cdf0e10cSrcweir########################################################################
544cdf0e10cSrcweir# Returning the show command for a folderitem for shortcut table.
545cdf0e10cSrcweir########################################################################
546cdf0e10cSrcweir
547cdf0e10cSrcweirsub get_folderitem_showcmd
548cdf0e10cSrcweir{
549cdf0e10cSrcweir	my ($shortcut) = @_;
550cdf0e10cSrcweir
551cdf0e10cSrcweir	return "1";
552cdf0e10cSrcweir}
553cdf0e10cSrcweir
554cdf0e10cSrcweir###########################################################################################################
555cdf0e10cSrcweir# Creating the file Shortcut.idt dynamically
556cdf0e10cSrcweir# Content:
557cdf0e10cSrcweir# Shortcut Directory_ Name Component_ Target Arguments Description Hotkey Icon_ IconIndex ShowCmd WkDir
558cdf0e10cSrcweir###########################################################################################################
559cdf0e10cSrcweir
560cdf0e10cSrcweirsub create_shortcut_table
561cdf0e10cSrcweir{
562cdf0e10cSrcweir	my ($filesref, $linksref, $folderref, $folderitemsref, $dirref, $basedir, $languagesarrayref, $includepatharrayref, $iconfilecollector) = @_;
563cdf0e10cSrcweir
564cdf0e10cSrcweir	for ( my $m = 0; $m <= $#{$languagesarrayref}; $m++ )
565cdf0e10cSrcweir	{
566cdf0e10cSrcweir		my $onelanguage = ${$languagesarrayref}[$m];
567cdf0e10cSrcweir
568cdf0e10cSrcweir		my @shortcuttable = ();
569cdf0e10cSrcweir
570cdf0e10cSrcweir		my @shortnames = ();	# to collect all short names
571cdf0e10cSrcweir
572cdf0e10cSrcweir		installer::windows::idtglobal::write_idt_header(\@shortcuttable, "shortcut");
573cdf0e10cSrcweir
574cdf0e10cSrcweir		# First the links, defined in scp as ShortCut
575cdf0e10cSrcweir
576cdf0e10cSrcweir		for ( my $i = 0; $i <= $#{$linksref}; $i++ )
577cdf0e10cSrcweir		{
578cdf0e10cSrcweir			my $onelink = ${$linksref}[$i];
579cdf0e10cSrcweir
580cdf0e10cSrcweir			# Controlling the language!
581cdf0e10cSrcweir			# Only language independent folderitems or folderitems with the correct language
582cdf0e10cSrcweir			# will be included into the table
583cdf0e10cSrcweir
584cdf0e10cSrcweir			if (! (!(( $onelink->{'ismultilingual'} )) || ( $onelink->{'specificlanguage'} eq $onelanguage )) )  { next; }
585cdf0e10cSrcweir
586cdf0e10cSrcweir			my %shortcut = ();
587cdf0e10cSrcweir
588cdf0e10cSrcweir			$shortcut{'Shortcut'} = get_shortcut_identifier($onelink);
589cdf0e10cSrcweir			$shortcut{'Directory_'} = get_shortcut_directory($onelink, $dirref);
590cdf0e10cSrcweir			$shortcut{'Name'} = get_shortcut_name($onelink, \@shortnames, $onelanguage);	# localized name
591cdf0e10cSrcweir			$shortcut{'Component_'} = get_shortcut_component($onelink, $filesref);
592cdf0e10cSrcweir			$shortcut{'Target'} = get_shortcut_target($onelink, $filesref);
593cdf0e10cSrcweir			$shortcut{'Arguments'} = get_shortcut_arguments($onelink);
594cdf0e10cSrcweir			$shortcut{'Description'} = get_shortcut_description($onelink, $onelanguage); 	# localized description
595cdf0e10cSrcweir			$shortcut{'Hotkey'} = get_shortcut_hotkey($onelink);
596cdf0e10cSrcweir			$shortcut{'Icon_'} = get_shortcut_icon($onelink);
597cdf0e10cSrcweir			$shortcut{'IconIndex'} = get_shortcut_iconindex($onelink);
598cdf0e10cSrcweir			$shortcut{'ShowCmd'} = get_shortcut_showcmd($onelink);
599cdf0e10cSrcweir			$shortcut{'WkDir'} = get_shortcut_wkdir($onelink);
600cdf0e10cSrcweir
601cdf0e10cSrcweir			my $oneline = $shortcut{'Shortcut'} . "\t" . $shortcut{'Directory_'} . "\t" . $shortcut{'Name'} . "\t"
602cdf0e10cSrcweir						. $shortcut{'Component_'} . "\t" . $shortcut{'Target'} . "\t" . $shortcut{'Arguments'} . "\t"
603cdf0e10cSrcweir						. $shortcut{'Description'} . "\t" . $shortcut{'Hotkey'} . "\t" . $shortcut{'Icon_'} . "\t"
604cdf0e10cSrcweir						. $shortcut{'IconIndex'} . "\t" . $shortcut{'ShowCmd'} . "\t" . $shortcut{'WkDir'} . "\n";
605cdf0e10cSrcweir
606cdf0e10cSrcweir			push(@shortcuttable, $oneline);
607cdf0e10cSrcweir		}
608cdf0e10cSrcweir
609cdf0e10cSrcweir		# Second the entries into the start menu, defined in scp as Folder and Folderitem
610cdf0e10cSrcweir		# These shortcuts will fill the icons table.
611cdf0e10cSrcweir
612cdf0e10cSrcweir		for ( my $i = 0; $i <= $#{$folderref}; $i++ )
613cdf0e10cSrcweir		{
614cdf0e10cSrcweir			my $foldergid = ${$folderref}[$i]->{'gid'};
615cdf0e10cSrcweir
616cdf0e10cSrcweir			# iterating over all folderitems for this folder
617cdf0e10cSrcweir
618cdf0e10cSrcweir			for ( my $j = 0; $j <= $#{$folderitemsref}; $j++ )
619cdf0e10cSrcweir			{
620cdf0e10cSrcweir				my $onelink = ${$folderitemsref}[$j];
621cdf0e10cSrcweir
622cdf0e10cSrcweir				# Controlling the language!
623cdf0e10cSrcweir				# Only language independent folderitems or folderitems with the correct language
624cdf0e10cSrcweir				# will be included into the table
625cdf0e10cSrcweir
626cdf0e10cSrcweir				if (! (!(( $onelink->{'ismultilingual'} )) || ( $onelink->{'specificlanguage'} eq $onelanguage )) )  { next; }
627cdf0e10cSrcweir
628cdf0e10cSrcweir				# controlling the folder
629cdf0e10cSrcweir
630cdf0e10cSrcweir				my $localused = 0;
631cdf0e10cSrcweir
632cdf0e10cSrcweir				if ( $onelink->{'used'} ) { $localused = $onelink->{'used'}; }
633cdf0e10cSrcweir
634cdf0e10cSrcweir				if (!($localused == 1)) { $onelink->{'used'} = "0"; }		# no resetting
635cdf0e10cSrcweir
636cdf0e10cSrcweir				if (!( $onelink->{'FolderID'} eq $foldergid )) { next; }
637cdf0e10cSrcweir
638cdf0e10cSrcweir				$onelink->{'used'} = "1";
639cdf0e10cSrcweir
640cdf0e10cSrcweir				my %shortcut = ();
641cdf0e10cSrcweir
642cdf0e10cSrcweir				$shortcut{'Shortcut'} = get_shortcut_identifier($onelink);
643cdf0e10cSrcweir				$shortcut{'Directory_'} = get_folderitem_directory($onelink);
644cdf0e10cSrcweir				$shortcut{'Name'} = get_shortcut_name($onelink, \@shortnames, $onelanguage);	# localized name
645cdf0e10cSrcweir				$shortcut{'Component_'} = get_shortcut_component($onelink, $filesref);
646cdf0e10cSrcweir				$shortcut{'Target'} = get_folderitem_target($onelink, $filesref);
647cdf0e10cSrcweir				$shortcut{'Arguments'} = get_folderitem_arguments($onelink);
648cdf0e10cSrcweir				$shortcut{'Description'} = get_shortcut_description($onelink, $onelanguage);	# localized description
649cdf0e10cSrcweir				$shortcut{'Hotkey'} = get_shortcut_hotkey($onelink);
650cdf0e10cSrcweir				$shortcut{'Icon_'} = get_folderitem_icon($onelink, $filesref, $iconfilecollector);
651cdf0e10cSrcweir				$shortcut{'IconIndex'} = get_folderitem_iconindex($onelink);
652cdf0e10cSrcweir				$shortcut{'ShowCmd'} = get_folderitem_showcmd($onelink);
653cdf0e10cSrcweir				$shortcut{'WkDir'} = get_folderitem_wkdir($onelink, $dirref);
654cdf0e10cSrcweir
655cdf0e10cSrcweir				my $oneline = $shortcut{'Shortcut'} . "\t" . $shortcut{'Directory_'} . "\t" . $shortcut{'Name'} . "\t"
656cdf0e10cSrcweir							. $shortcut{'Component_'} . "\t" . $shortcut{'Target'} . "\t" . $shortcut{'Arguments'} . "\t"
657cdf0e10cSrcweir							. $shortcut{'Description'} . "\t" . $shortcut{'Hotkey'} . "\t" . $shortcut{'Icon_'} . "\t"
658cdf0e10cSrcweir							. $shortcut{'IconIndex'} . "\t" . $shortcut{'ShowCmd'} . "\t" . $shortcut{'WkDir'} . "\n";
659cdf0e10cSrcweir
660cdf0e10cSrcweir				push(@shortcuttable, $oneline);
661cdf0e10cSrcweir			}
662cdf0e10cSrcweir		}
663cdf0e10cSrcweir
664cdf0e10cSrcweir		# The soffice.ico has to be included into the icon table
665cdf0e10cSrcweir		# as icon for the ARP applet
666cdf0e10cSrcweir
667cdf0e10cSrcweir		my $onefile = "";
668cdf0e10cSrcweir		my $sofficefile = "soffice.ico";
669cdf0e10cSrcweir
670cdf0e10cSrcweir		my $sourcepathref = installer::scriptitems::get_sourcepath_from_filename_and_includepath_classic(\$sofficefile, $includepatharrayref, 0);
671cdf0e10cSrcweir
672cdf0e10cSrcweir		if ($$sourcepathref eq "") { installer::exiter::exit_program("ERROR: Could not find $sofficefile as icon!", "create_shortcut_table"); }
673cdf0e10cSrcweir
674cdf0e10cSrcweir		if (! installer::existence::exists_in_array($$sourcepathref, $iconfilecollector))
675cdf0e10cSrcweir		{
676cdf0e10cSrcweir			unshift(@{$iconfilecollector}, $$sourcepathref);
677cdf0e10cSrcweir			$installer::globals::sofficeiconadded = 1;
678cdf0e10cSrcweir		}
679cdf0e10cSrcweir
680*b274bc22SAndre Fischer        $installer::logger::Lang->printf(
681*b274bc22SAndre Fischer            "Added icon file %s for language pack into icon file collector.\n", $$sourcepathref);
682cdf0e10cSrcweir
683cdf0e10cSrcweir		# Saving the file
684cdf0e10cSrcweir
685cdf0e10cSrcweir		my $shortcuttablename = $basedir . $installer::globals::separator . "Shortcut.idt" . "." . $onelanguage;
686cdf0e10cSrcweir		installer::files::save_file($shortcuttablename ,\@shortcuttable);
687*b274bc22SAndre Fischer        $installer::logger::Lang->printf("Created idt file: %s\n", $shortcuttablename);
688cdf0e10cSrcweir	}
689cdf0e10cSrcweir}
690cdf0e10cSrcweir
691cdf0e10cSrcweir
692*b274bc22SAndre Fischer1;
693