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::directory;
25cdf0e10cSrcweir
26cdf0e10cSrcweiruse installer::exiter;
27cdf0e10cSrcweiruse installer::files;
28cdf0e10cSrcweiruse installer::globals;
29cdf0e10cSrcweiruse installer::pathanalyzer;
30cdf0e10cSrcweiruse installer::windows::idtglobal;
3119d58b3aSEike Rathkeuse installer::windows::msiglobal;
32cdf0e10cSrcweir
33*1ba1fd99SAndre Fischeruse strict;
34*1ba1fd99SAndre Fischer
35cdf0e10cSrcweir##############################################################
36cdf0e10cSrcweir# Collecting all directory trees in global hash
37cdf0e10cSrcweir##############################################################
38cdf0e10cSrcweir
39cdf0e10cSrcweirsub collectdirectorytrees
40cdf0e10cSrcweir{
41cdf0e10cSrcweir	my ( $directoryref ) = @_;
42cdf0e10cSrcweir
43cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$directoryref}; $i++ )
44cdf0e10cSrcweir	{
45cdf0e10cSrcweir		my $onedir = ${$directoryref}[$i];
46cdf0e10cSrcweir		my $styles = "";
47cdf0e10cSrcweir		if ( $onedir->{'Styles'} ) { $styles = $onedir->{'Styles'}; }
48cdf0e10cSrcweir
49cdf0e10cSrcweir		if ( $styles ne "" )
50cdf0e10cSrcweir		{
51cdf0e10cSrcweir			foreach my $treestyle ( keys %installer::globals::treestyles )
52cdf0e10cSrcweir			{
53cdf0e10cSrcweir				if ( $styles =~ /\b$treestyle\b/ )
54cdf0e10cSrcweir				{
55cdf0e10cSrcweir					my $hostname = $onedir->{'HostName'};
56cdf0e10cSrcweir					# -> hostname is the key, the style the value!
57cdf0e10cSrcweir					$installer::globals::hostnametreestyles{$hostname} = $treestyle;
58cdf0e10cSrcweir				}
59cdf0e10cSrcweir			}
60cdf0e10cSrcweir		}
61cdf0e10cSrcweir	}
62cdf0e10cSrcweir}
63cdf0e10cSrcweir
64cdf0e10cSrcweir##############################################################
65cdf0e10cSrcweir# Overwriting global programfilesfolder, if required
66cdf0e10cSrcweir##############################################################
67cdf0e10cSrcweir
68cdf0e10cSrcweirsub overwrite_programfilesfolder
69cdf0e10cSrcweir{
70cdf0e10cSrcweir	my ( $allvariables ) = @_;
71cdf0e10cSrcweir
72cdf0e10cSrcweir	if ( $allvariables->{'PROGRAMFILESFOLDERNAME'} )
73cdf0e10cSrcweir	{
74cdf0e10cSrcweir		$installer::globals::programfilesfolder = $allvariables->{'PROGRAMFILESFOLDERNAME'};
75cdf0e10cSrcweir	}
76cdf0e10cSrcweir}
77cdf0e10cSrcweir
78cdf0e10cSrcweir
79*1ba1fd99SAndre Fischer
80*1ba1fd99SAndre Fischer
81*1ba1fd99SAndre Fischer=head2 make_short_dir_version($longstring)
82*1ba1fd99SAndre Fischer
83*1ba1fd99SAndre Fischer    Transform the given string into one that is at most 70 characters long.
84*1ba1fd99SAndre Fischer    That is done in two steps:
85*1ba1fd99SAndre Fischer    - Cut all parts separated by '_' or '-' down to a length of 5.
86*1ba1fd99SAndre Fischer    - Cut down the result to a length of 60 and fill it up to length 70
87*1ba1fd99SAndre Fischer      with the MD5 checksum.
88*1ba1fd99SAndre Fischer
89*1ba1fd99SAndre Fischer    This transform always returns the same result for the same string.
90*1ba1fd99SAndre Fischer    There is no counter and reference to a global set of names to make the string unique.
91*1ba1fd99SAndre Fischer
92*1ba1fd99SAndre Fischer=cut
93*1ba1fd99SAndre Fischersub make_short_dir_version ($)
94cdf0e10cSrcweir{
9519d58b3aSEike Rathke	my ($longstring) = @_;
96cdf0e10cSrcweir
97cdf0e10cSrcweir	my $shortstring = "";
9819d58b3aSEike Rathke	my $cutlength = 60;
9919d58b3aSEike Rathke	my $length = 5; # So the directory can still be recognized
10019d58b3aSEike Rathke	my $longstring_save = $longstring;
101cdf0e10cSrcweir
102cdf0e10cSrcweir	# Splitting the string at each "underline" and allowing only $length characters per directory name.
103cdf0e10cSrcweir	# Checking also uniqueness and length.
104cdf0e10cSrcweir
105*1ba1fd99SAndre Fischer	my @outer_parts = split(/_/, $longstring);
106*1ba1fd99SAndre Fischer	foreach my $onestring (@outer_parts)
107cdf0e10cSrcweir	{
108cdf0e10cSrcweir		my $partstring = "";
109cdf0e10cSrcweir
110cdf0e10cSrcweir		if ( $onestring =~ /\-/ )
111cdf0e10cSrcweir		{
112*1ba1fd99SAndre Fischer			my @inner_parts = split(/-/, $onestring);
113*1ba1fd99SAndre Fischer            @inner_parts = map {substr($_,0,$length)} @inner_parts;
114*1ba1fd99SAndre Fischer            $partstring = join("-", @inner_parts);
115cdf0e10cSrcweir			$partstring =~ s/^\s*\-//;
116cdf0e10cSrcweir		}
117cdf0e10cSrcweir		else
118cdf0e10cSrcweir		{
119*1ba1fd99SAndre Fischer			$partstring = substr($onestring, 0, $length);
120cdf0e10cSrcweir		}
121cdf0e10cSrcweir
122*1ba1fd99SAndre Fischer		$shortstring .= "_" . $partstring;
123cdf0e10cSrcweir	}
124cdf0e10cSrcweir
125cdf0e10cSrcweir	$shortstring =~ s/^\s*\_//;
126cdf0e10cSrcweir
12719d58b3aSEike Rathke	# Setting unique ID to each directory
12819d58b3aSEike Rathke	# No counter allowed, process must be absolute reproducable due to patch creation process.
12919d58b3aSEike Rathke
13019d58b3aSEike Rathke	my $subid = installer::windows::msiglobal::calculate_id($longstring_save, 9); # taking only the first 9 digits
131*1ba1fd99SAndre Fischer	$shortstring = substr($shortstring, 0, $cutlength) . "_" . $subid;
132cdf0e10cSrcweir
133cdf0e10cSrcweir	return $shortstring;
134cdf0e10cSrcweir}
135cdf0e10cSrcweir
136cdf0e10cSrcweir##############################################################
137cdf0e10cSrcweir# Adding unique directory names to the directory collection
138cdf0e10cSrcweir##############################################################
139cdf0e10cSrcweir
140cdf0e10cSrcweirsub create_unique_directorynames
141cdf0e10cSrcweir{
142cdf0e10cSrcweir	my ($directoryref, $allvariables) = @_;
143cdf0e10cSrcweir
144cdf0e10cSrcweir	$installer::globals::officeinstalldirectoryset = 0;
14519d58b3aSEike Rathke
14619d58b3aSEike Rathke	my %completedirhashstep1 = ();
14719d58b3aSEike Rathke	my %shortdirhash = ();
14819d58b3aSEike Rathke	my %shortdirhashreverse = ();
149cdf0e10cSrcweir	my $infoline = "";
150cdf0e10cSrcweir	my $errorcount = 0;
151cdf0e10cSrcweir
152cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$directoryref}; $i++ )
153cdf0e10cSrcweir	{
154cdf0e10cSrcweir		my $onedir = ${$directoryref}[$i];
15519d58b3aSEike Rathke		my $uniquename = $onedir->{'HostName'};
156cdf0e10cSrcweir
157cdf0e10cSrcweir		my $styles = "";
158cdf0e10cSrcweir		if ( $onedir->{'Styles'} ) { $styles = $onedir->{'Styles'}; }
159cdf0e10cSrcweir
160cdf0e10cSrcweir		$uniquename =~ s/^\s*//g;				# removing beginning white spaces
161cdf0e10cSrcweir		$uniquename =~ s/\s*$//g;				# removing ending white spaces
162cdf0e10cSrcweir		$uniquename =~ s/\s//g;					# removing white spaces
163cdf0e10cSrcweir		$uniquename =~ s/\_//g;					# removing existing underlines
164cdf0e10cSrcweir		$uniquename =~ s/\.//g;					# removing dots in directoryname
165cdf0e10cSrcweir		$uniquename =~ s/OpenOffice/OO/g;
16619d58b3aSEike Rathke
16719d58b3aSEike Rathke		$uniquename =~ s/\Q$installer::globals::separator\E/\_/g;	# replacing slash and backslash with underline
16819d58b3aSEike Rathke
169cdf0e10cSrcweir		$uniquename =~ s/_registry/_rgy/g;
170cdf0e10cSrcweir		$uniquename =~ s/_registration/_rgn/g;
171cdf0e10cSrcweir		$uniquename =~ s/_extension/_ext/g;
172cdf0e10cSrcweir		$uniquename =~ s/_frame/_frm/g;
173cdf0e10cSrcweir		$uniquename =~ s/_table/_tbl/g;
174cdf0e10cSrcweir		$uniquename =~ s/_chart/_crt/g;
175cdf0e10cSrcweir
17619d58b3aSEike Rathke		# The names after this small changes must still be unique!
17719d58b3aSEike Rathke		if ( exists($completedirhashstep1{$uniquename}) ) { installer::exiter::exit_program("ERROR: Error in packaging process. Unallowed modification of directory name, not unique (step 1): \"$uniquename\".", "create_unique_directorynames"); }
17819d58b3aSEike Rathke		$completedirhashstep1{$uniquename} = 1;
179cdf0e10cSrcweir
18019d58b3aSEike Rathke		# Starting to make unique name for the parent and its directory
18119d58b3aSEike Rathke		my $originaluniquename = $uniquename;
18219d58b3aSEike Rathke
18319d58b3aSEike Rathke		$uniquename = make_short_dir_version($uniquename);
18419d58b3aSEike Rathke
18519d58b3aSEike Rathke		# Checking if the same directory already exists, but has another short version.
18619d58b3aSEike Rathke		if (( exists($shortdirhash{$originaluniquename}) ) && ( $shortdirhash{$originaluniquename} ne $uniquename )) { installer::exiter::exit_program("ERROR: Error in packaging process. Unallowed modification of directory name, not unique (step 2A): \"$uniquename\".", "create_unique_directorynames"); }
18719d58b3aSEike Rathke
18819d58b3aSEike Rathke		# Also checking vice versa
18919d58b3aSEike Rathke		# Checking if the same short directory already exists, but has another long version.
19019d58b3aSEike Rathke		if (( exists($shortdirhashreverse{$uniquename}) ) && ( $shortdirhashreverse{$uniquename} ne $originaluniquename )) { installer::exiter::exit_program("ERROR: Error in packaging process. Unallowed modification of directory name, not unique (step 2B): \"$uniquename\".", "create_unique_directorynames"); }
191cdf0e10cSrcweir
19219d58b3aSEike Rathke		# Creating assignment from long to short directory names
19319d58b3aSEike Rathke		$shortdirhash{$originaluniquename} = $uniquename;
19419d58b3aSEike Rathke		$shortdirhashreverse{$uniquename} = $originaluniquename;
195cdf0e10cSrcweir
19619d58b3aSEike Rathke		# Important: The unique parent is generated from the string $originaluniquename (with the use of underlines).
197cdf0e10cSrcweir
19819d58b3aSEike Rathke		my $uniqueparentname = $originaluniquename;
19919d58b3aSEike Rathke		my $keepparent = 1;
200cdf0e10cSrcweir
201cdf0e10cSrcweir		if ( $uniqueparentname =~ /^\s*(.*)\_(.*?)\s*$/ )	# the underline is now the separator
202cdf0e10cSrcweir		{
203cdf0e10cSrcweir			$uniqueparentname = $1;
20419d58b3aSEike Rathke			$keepparent = 0;
205cdf0e10cSrcweir		}
206cdf0e10cSrcweir		else
207cdf0e10cSrcweir		{
208cdf0e10cSrcweir			$uniqueparentname = $installer::globals::programfilesfolder;
20919d58b3aSEike Rathke			$keepparent = 1;
210cdf0e10cSrcweir		}
211cdf0e10cSrcweir
21219d58b3aSEike Rathke		if ( $styles =~ /\bPROGRAMFILESFOLDER\b/ )
21319d58b3aSEike Rathke		{
21419d58b3aSEike Rathke			$uniqueparentname = $installer::globals::programfilesfolder;
21519d58b3aSEike Rathke			$keepparent = 1;
21619d58b3aSEike Rathke		}
21719d58b3aSEike Rathke		if ( $styles =~ /\bCOMMONFILESFOLDER\b/ )
21819d58b3aSEike Rathke		{
21919d58b3aSEike Rathke			$uniqueparentname = $installer::globals::commonfilesfolder;
22019d58b3aSEike Rathke			$keepparent = 1;
22119d58b3aSEike Rathke		}
22219d58b3aSEike Rathke		if ( $styles =~ /\bCOMMONAPPDATAFOLDER\b/ )
22319d58b3aSEike Rathke		{
22419d58b3aSEike Rathke			$uniqueparentname = $installer::globals::commonappdatafolder;
22519d58b3aSEike Rathke			$keepparent = 1;
22619d58b3aSEike Rathke		}
22719d58b3aSEike Rathke		if ( $styles =~ /\bLOCALAPPDATAFOLDER\b/ )
22819d58b3aSEike Rathke		{
22919d58b3aSEike Rathke			$uniqueparentname = $installer::globals::localappdatafolder;
23019d58b3aSEike Rathke			$keepparent = 1;
23119d58b3aSEike Rathke		}
232cdf0e10cSrcweir
233cdf0e10cSrcweir		if ( $styles =~ /\bSHAREPOINTPATH\b/ )
234cdf0e10cSrcweir		{
235cdf0e10cSrcweir			$uniqueparentname = "SHAREPOINTPATH";
236cdf0e10cSrcweir			$installer::globals::usesharepointpath = 1;
23719d58b3aSEike Rathke			$keepparent = 1;
238cdf0e10cSrcweir		}
239cdf0e10cSrcweir
24019d58b3aSEike Rathke		# also setting short directory name for the parent
24119d58b3aSEike Rathke
24219d58b3aSEike Rathke		my $originaluniqueparentname = $uniqueparentname;
24319d58b3aSEike Rathke
24419d58b3aSEike Rathke		if ( ! $keepparent )
24519d58b3aSEike Rathke		{
24619d58b3aSEike Rathke			$uniqueparentname = make_short_dir_version($uniqueparentname);
24719d58b3aSEike Rathke		}
24819d58b3aSEike Rathke
24919d58b3aSEike Rathke		# Again checking if the same directory already exists, but has another short version.
25019d58b3aSEike Rathke		if (( exists($shortdirhash{$originaluniqueparentname}) ) && ( $shortdirhash{$originaluniqueparentname} ne $uniqueparentname )) { installer::exiter::exit_program("ERROR: Error in packaging process. Unallowed modification of directory name, not unique (step 3A): \"$uniqueparentname\".", "create_unique_directorynames"); }
25119d58b3aSEike Rathke
25219d58b3aSEike Rathke		# Also checking vice versa
25319d58b3aSEike Rathke		# Checking if the same short directory already exists, but has another long version.
25419d58b3aSEike Rathke		if (( exists($shortdirhashreverse{$uniqueparentname}) ) && ( $shortdirhashreverse{$uniqueparentname} ne $originaluniqueparentname )) { installer::exiter::exit_program("ERROR: Error in packaging process. Unallowed modification of directory name, not unique (step 3B): \"$uniqueparentname\".", "create_unique_directorynames"); }
25519d58b3aSEike Rathke
25619d58b3aSEike Rathke		$shortdirhash{$originaluniqueparentname} = $uniqueparentname;
25719d58b3aSEike Rathke		$shortdirhashreverse{$uniqueparentname} = $originaluniqueparentname;
25819d58b3aSEike Rathke
25919d58b3aSEike Rathke		# Hyphen not allowed in database
260cdf0e10cSrcweir		$uniquename =~ s/\-/\_/g;			# making "-" to "_"
261cdf0e10cSrcweir		$uniqueparentname =~ s/\-/\_/g;		# making "-" to "_"
262cdf0e10cSrcweir
26319d58b3aSEike Rathke		# And finally setting the values for the directories
264cdf0e10cSrcweir		$onedir->{'uniquename'} = $uniquename;
265cdf0e10cSrcweir		$onedir->{'uniqueparentname'} = $uniqueparentname;
266cdf0e10cSrcweir
267cdf0e10cSrcweir		# setting the installlocation directory
268cdf0e10cSrcweir		if ( $styles =~ /\bISINSTALLLOCATION\b/ )
269cdf0e10cSrcweir		{
270cdf0e10cSrcweir			if ( $installer::globals::installlocationdirectoryset ) { installer::exiter::exit_program("ERROR: Directory with flag ISINSTALLLOCATION alread set: \"$installer::globals::installlocationdirectory\".", "create_unique_directorynames"); }
271cdf0e10cSrcweir			$installer::globals::installlocationdirectory = $uniquename;
272cdf0e10cSrcweir			$installer::globals::installlocationdirectoryset = 1;
273cdf0e10cSrcweir		}
274cdf0e10cSrcweir
275cdf0e10cSrcweir		# setting the sundirectory
276cdf0e10cSrcweir		if ( $styles =~ /\bSUNDIRECTORY\b/ )
277cdf0e10cSrcweir		{
278cdf0e10cSrcweir			if ( $installer::globals::vendordirectoryset ) { installer::exiter::exit_program("ERROR: Directory with flag SUNDIRECTORY alread set: \"$installer::globals::vendordirectory\".", "create_unique_directorynames"); }
279cdf0e10cSrcweir			$installer::globals::vendordirectory = $uniquename;
280cdf0e10cSrcweir			$installer::globals::vendordirectoryset = 1;
281cdf0e10cSrcweir		}
28219d58b3aSEike Rathke	}
283cdf0e10cSrcweir}
284cdf0e10cSrcweir
285cdf0e10cSrcweir#####################################################
286cdf0e10cSrcweir# Adding ":." to selected default directory names
287cdf0e10cSrcweir#####################################################
288cdf0e10cSrcweir
289cdf0e10cSrcweirsub check_sourcedir_addon
290cdf0e10cSrcweir{
291cdf0e10cSrcweir	my ( $onedir, $allvariableshashref ) = @_;
292cdf0e10cSrcweir
293cdf0e10cSrcweir	if (($installer::globals::addchildprojects) ||
294cdf0e10cSrcweir		($installer::globals::patch) ||
295cdf0e10cSrcweir		($installer::globals::languagepack) ||
296cdf0e10cSrcweir		($allvariableshashref->{'CHANGETARGETDIR'}))
297cdf0e10cSrcweir	{
298cdf0e10cSrcweir		my $sourcediraddon = "\:\.";
299cdf0e10cSrcweir		$onedir->{'defaultdir'} = $onedir->{'defaultdir'} . $sourcediraddon;
300cdf0e10cSrcweir	}
301cdf0e10cSrcweir
302cdf0e10cSrcweir}
303cdf0e10cSrcweir
304cdf0e10cSrcweir#####################################################
305cdf0e10cSrcweir# The directory with the style ISINSTALLLOCATION
306cdf0e10cSrcweir# will be replaced by INSTALLLOCATION
307cdf0e10cSrcweir#####################################################
308cdf0e10cSrcweir
309cdf0e10cSrcweirsub set_installlocation_directory
310cdf0e10cSrcweir{
311cdf0e10cSrcweir	my ( $directoryref, $allvariableshashref ) = @_;
312cdf0e10cSrcweir
313cdf0e10cSrcweir	if ( ! $installer::globals::installlocationdirectoryset ) { installer::exiter::exit_program("ERROR: Directory with flag ISINSTALLLOCATION not set!", "set_installlocation_directory"); }
314cdf0e10cSrcweir
315cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$directoryref}; $i++ )
316cdf0e10cSrcweir	{
317cdf0e10cSrcweir		my $onedir = ${$directoryref}[$i];
318cdf0e10cSrcweir
319cdf0e10cSrcweir		if ( $onedir->{'uniquename'} eq $installer::globals::installlocationdirectory )
320cdf0e10cSrcweir		{
321cdf0e10cSrcweir			$onedir->{'uniquename'} = "INSTALLLOCATION";
322cdf0e10cSrcweir			check_sourcedir_addon($onedir, $allvariableshashref);
323cdf0e10cSrcweir		}
324cdf0e10cSrcweir
325cdf0e10cSrcweir		if ( $onedir->{'uniquename'} eq $installer::globals::vendordirectory )
326cdf0e10cSrcweir		{
327cdf0e10cSrcweir			check_sourcedir_addon($onedir, $allvariableshashref);
328cdf0e10cSrcweir		}
329cdf0e10cSrcweir
330cdf0e10cSrcweir		if ( $onedir->{'uniqueparentname'} eq $installer::globals::installlocationdirectory )
331cdf0e10cSrcweir		{
332cdf0e10cSrcweir			$onedir->{'uniqueparentname'} = "INSTALLLOCATION";
333cdf0e10cSrcweir		}
334cdf0e10cSrcweir	}
335cdf0e10cSrcweir}
336cdf0e10cSrcweir
337cdf0e10cSrcweir#####################################################
338cdf0e10cSrcweir# Getting the name of the top level directory. This
339cdf0e10cSrcweir# can have only one letter
340cdf0e10cSrcweir#####################################################
341cdf0e10cSrcweir
342cdf0e10cSrcweirsub get_last_directory_name
343cdf0e10cSrcweir{
344cdf0e10cSrcweir	my ($completepathref) = @_;
345cdf0e10cSrcweir
346cdf0e10cSrcweir	if ( $$completepathref =~ /^.*[\/\\](.+?)\s*$/ )
347cdf0e10cSrcweir	{
348cdf0e10cSrcweir		$$completepathref = $1;
349cdf0e10cSrcweir	}
350cdf0e10cSrcweir}
351cdf0e10cSrcweir
352cdf0e10cSrcweir#####################################################
353cdf0e10cSrcweir# Creating the defaultdir for the file Director.idt
354cdf0e10cSrcweir#####################################################
355cdf0e10cSrcweir
356dca4887fSAndre Fischersub create_defaultdir_directorynames ($)
357cdf0e10cSrcweir{
358dca4887fSAndre Fischer	my ($directoryref) = @_;
359cdf0e10cSrcweir
360cdf0e10cSrcweir	my @shortnames = ();
361f30bf281SAndre Fischer	if ( $installer::globals::prepare_winpatch ) { @shortnames = values(%installer::globals::saved83dirmapping); }
362cdf0e10cSrcweir
363cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$directoryref}; $i++ )
364cdf0e10cSrcweir	{
365cdf0e10cSrcweir		my $onedir = ${$directoryref}[$i];
366cdf0e10cSrcweir		my $hostname = $onedir->{'HostName'};
367cdf0e10cSrcweir
368cdf0e10cSrcweir		$hostname =~ s/\Q$installer::globals::separator\E\s*$//;
369cdf0e10cSrcweir		get_last_directory_name(\$hostname);
370cdf0e10cSrcweir		# installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$hostname);	# making program/classes to classes
371cdf0e10cSrcweir		my $uniquename = $onedir->{'uniquename'};
372cdf0e10cSrcweir		my $shortstring;
373f30bf281SAndre Fischer		if (( $installer::globals::prepare_winpatch ) && ( exists($installer::globals::saved83dirmapping{$uniquename}) ))
374cdf0e10cSrcweir		{
375cdf0e10cSrcweir			$shortstring = $installer::globals::saved83dirmapping{$uniquename};
376cdf0e10cSrcweir		}
377cdf0e10cSrcweir		else
378cdf0e10cSrcweir		{
379cdf0e10cSrcweir			$shortstring = installer::windows::idtglobal::make_eight_three_conform($hostname, "dir", \@shortnames);
380cdf0e10cSrcweir		}
381cdf0e10cSrcweir
382cdf0e10cSrcweir		my $defaultdir;
383cdf0e10cSrcweir
384cdf0e10cSrcweir		if ( $shortstring eq $hostname )
385cdf0e10cSrcweir		{
386cdf0e10cSrcweir			$defaultdir = $hostname;
387cdf0e10cSrcweir		}
388cdf0e10cSrcweir		else
389cdf0e10cSrcweir		{
390cdf0e10cSrcweir			$defaultdir = $shortstring . "|" . $hostname;
391cdf0e10cSrcweir		}
392cdf0e10cSrcweir
393cdf0e10cSrcweir		$onedir->{'defaultdir'} = $defaultdir;
394cdf0e10cSrcweir
395cdf0e10cSrcweir		my $fontdir = "";
396cdf0e10cSrcweir		if ( $onedir->{'Dir'} ) { $fontdir = $onedir->{'Dir'}; }
397cdf0e10cSrcweir
398cdf0e10cSrcweir		my $fontdefaultdir = "";
399cdf0e10cSrcweir		if ( $onedir->{'defaultdir'} ) { $fontdefaultdir = $onedir->{'defaultdir'}; }
400cdf0e10cSrcweir
401cdf0e10cSrcweir		if (( $fontdir eq "PREDEFINED_OSSYSTEMFONTDIR" ) && ( $fontdefaultdir eq $installer::globals::fontsdirhostname ))
402cdf0e10cSrcweir		{
403cdf0e10cSrcweir			$installer::globals::fontsdirname = $onedir->{'defaultdir'};
404cdf0e10cSrcweir			$installer::globals::fontsdirparent = $onedir->{'uniqueparentname'};
405cdf0e10cSrcweir		}
406cdf0e10cSrcweir	}
407cdf0e10cSrcweir}
408cdf0e10cSrcweir
409cdf0e10cSrcweir###############################################
410cdf0e10cSrcweir# Fill content into the directory table
411cdf0e10cSrcweir###############################################
412cdf0e10cSrcweir
413cdf0e10cSrcweirsub create_directorytable_from_collection
414cdf0e10cSrcweir{
415cdf0e10cSrcweir	my ($directorytableref, $directoryref) = @_;
416cdf0e10cSrcweir
417cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$directoryref}; $i++ )
418cdf0e10cSrcweir	{
419cdf0e10cSrcweir		my $onedir = ${$directoryref}[$i];
420cdf0e10cSrcweir		my $hostname = $onedir->{'HostName'};
421cdf0e10cSrcweir		my $dir = "";
422cdf0e10cSrcweir
423cdf0e10cSrcweir		if ( $onedir->{'Dir'} ) { $dir = $onedir->{'Dir'}; }
424cdf0e10cSrcweir
425cdf0e10cSrcweir		if (( $dir eq "PREDEFINED_PROGDIR" ) && ( $hostname eq "" )) { next; }	# removing files from root directory
426cdf0e10cSrcweir
427cdf0e10cSrcweir		my $oneline = $onedir->{'uniquename'} . "\t" . $onedir->{'uniqueparentname'} . "\t" . $onedir->{'defaultdir'} . "\n";
428cdf0e10cSrcweir
429cdf0e10cSrcweir		push(@{$directorytableref}, $oneline);
430cdf0e10cSrcweir	}
431cdf0e10cSrcweir}
432cdf0e10cSrcweir
433cdf0e10cSrcweir###############################################
434cdf0e10cSrcweir# Defining the root installation structure
435cdf0e10cSrcweir###############################################
436cdf0e10cSrcweir
437cdf0e10cSrcweirsub add_root_directories
438cdf0e10cSrcweir{
439cdf0e10cSrcweir	my ($directorytableref, $allvariableshashref) = @_;
440cdf0e10cSrcweir
441cdf0e10cSrcweir#	my $sourcediraddon = "";
442cdf0e10cSrcweir#	if (($installer::globals::addchildprojects) ||
443cdf0e10cSrcweir#		($installer::globals::patch) ||
444cdf0e10cSrcweir#		($installer::globals::languagepack) ||
445cdf0e10cSrcweir#		($allvariableshashref->{'CHANGETARGETDIR'}))
446cdf0e10cSrcweir#	{
447cdf0e10cSrcweir#		$sourcediraddon = "\:\.";
448cdf0e10cSrcweir#	}
449cdf0e10cSrcweir
450cdf0e10cSrcweir	my $oneline = "";
451cdf0e10cSrcweir
452cdf0e10cSrcweir	if (( ! $installer::globals::patch ) && ( ! $installer::globals::languagepack ) && ( ! $allvariableshashref->{'DONTUSESTARTMENUFOLDER'} ))
453cdf0e10cSrcweir	{
454cdf0e10cSrcweir		my $productname = $allvariableshashref->{'PRODUCTNAME'};
455cdf0e10cSrcweir		my $productversion = $allvariableshashref->{'PRODUCTVERSION'};
456cdf0e10cSrcweir		my $baseproductversion = $productversion;
457cdf0e10cSrcweir
458cdf0e10cSrcweir		if (( $installer::globals::prepare_winpatch ) && ( $allvariableshashref->{'BASEPRODUCTVERSION'} ))
459cdf0e10cSrcweir		{
460cdf0e10cSrcweir			$baseproductversion = $allvariableshashref->{'BASEPRODUCTVERSION'};  # for example "2.0" for OOo
461cdf0e10cSrcweir		}
462cdf0e10cSrcweir
463cdf0e10cSrcweir		my $realproductkey = $productname . " " . $productversion;
464cdf0e10cSrcweir		my $productkey = $productname . " " . $baseproductversion;
465cdf0e10cSrcweir
466cdf0e10cSrcweir		if (( $allvariableshashref->{'POSTVERSIONEXTENSION'} ) && ( ! $allvariableshashref->{'DONTUSEEXTENSIONINDEFAULTDIR'} ))
467cdf0e10cSrcweir		{
468cdf0e10cSrcweir			$productkey = $productkey . " " . $allvariableshashref->{'POSTVERSIONEXTENSION'};
469cdf0e10cSrcweir			$realproductkey = $realproductkey . " " . $allvariableshashref->{'POSTVERSIONEXTENSION'};
470cdf0e10cSrcweir		}
471cdf0e10cSrcweir		if ( $allvariableshashref->{'NOSPACEINDIRECTORYNAME'} )
472cdf0e10cSrcweir		{
473cdf0e10cSrcweir			$productkey =~ s/\ /\_/g;
474cdf0e10cSrcweir			$realproductkey =~ s/\ /\_/g;
475cdf0e10cSrcweir		}
476cdf0e10cSrcweir
477cdf0e10cSrcweir		my $shortproductkey = installer::windows::idtglobal::make_eight_three_conform($productkey, "dir");		# third parameter not used
478cdf0e10cSrcweir		$shortproductkey =~ s/\s/\_/g;									# changing empty space to underline
479cdf0e10cSrcweir
480cdf0e10cSrcweir		$oneline = "$installer::globals::officemenufolder\t$installer::globals::programmenufolder\t$shortproductkey|$realproductkey\n";
481cdf0e10cSrcweir		push(@{$directorytableref}, $oneline);
482cdf0e10cSrcweir	}
483cdf0e10cSrcweir
484cdf0e10cSrcweir	$oneline = "TARGETDIR\t\tSourceDir\n";
485cdf0e10cSrcweir	push(@{$directorytableref}, $oneline);
486cdf0e10cSrcweir
487cdf0e10cSrcweir	$oneline = "$installer::globals::programfilesfolder\tTARGETDIR\t.\n";
488cdf0e10cSrcweir	push(@{$directorytableref}, $oneline);
489cdf0e10cSrcweir
490cdf0e10cSrcweir	$oneline = "$installer::globals::programmenufolder\tTARGETDIR\t.\n";
491cdf0e10cSrcweir	push(@{$directorytableref}, $oneline);
492cdf0e10cSrcweir
493cdf0e10cSrcweir	$oneline = "$installer::globals::startupfolder\tTARGETDIR\t.\n";
494cdf0e10cSrcweir	push(@{$directorytableref}, $oneline);
495cdf0e10cSrcweir
496cdf0e10cSrcweir	$oneline = "$installer::globals::desktopfolder\tTARGETDIR\t.\n";
497cdf0e10cSrcweir	push(@{$directorytableref}, $oneline);
498cdf0e10cSrcweir
499cdf0e10cSrcweir	$oneline = "$installer::globals::startmenufolder\tTARGETDIR\t.\n";
500cdf0e10cSrcweir	push(@{$directorytableref}, $oneline);
501cdf0e10cSrcweir
502cdf0e10cSrcweir	$oneline = "$installer::globals::commonfilesfolder\tTARGETDIR\t.\n";
503cdf0e10cSrcweir	push(@{$directorytableref}, $oneline);
504cdf0e10cSrcweir
505cdf0e10cSrcweir	$oneline = "$installer::globals::commonappdatafolder\tTARGETDIR\t.\n";
506cdf0e10cSrcweir	push(@{$directorytableref}, $oneline);
507cdf0e10cSrcweir
508cdf0e10cSrcweir	$oneline = "$installer::globals::localappdatafolder\tTARGETDIR\t.\n";
509cdf0e10cSrcweir	push(@{$directorytableref}, $oneline);
510cdf0e10cSrcweir
511cdf0e10cSrcweir	if ( $installer::globals::usesharepointpath )
512cdf0e10cSrcweir	{
513cdf0e10cSrcweir		$oneline = "SHAREPOINTPATH\tTARGETDIR\t.\n";
514cdf0e10cSrcweir		push(@{$directorytableref}, $oneline);
515cdf0e10cSrcweir	}
516cdf0e10cSrcweir
517cdf0e10cSrcweir	$oneline = "$installer::globals::systemfolder\tTARGETDIR\t.\n";
518cdf0e10cSrcweir	push(@{$directorytableref}, $oneline);
519cdf0e10cSrcweir
520cdf0e10cSrcweir	my $localtemplatefoldername = $installer::globals::templatefoldername;
521cdf0e10cSrcweir	my $directorytableentry = $localtemplatefoldername;
522cdf0e10cSrcweir	my $shorttemplatefoldername = installer::windows::idtglobal::make_eight_three_conform($localtemplatefoldername, "dir");
523cdf0e10cSrcweir	if ( $shorttemplatefoldername ne $localtemplatefoldername ) { $directorytableentry = "$shorttemplatefoldername|$localtemplatefoldername"; }
524cdf0e10cSrcweir	$oneline = "$installer::globals::templatefolder\tTARGETDIR\t$directorytableentry\n";
525cdf0e10cSrcweir	push(@{$directorytableref}, $oneline);
526cdf0e10cSrcweir
527cdf0e10cSrcweir	if ( $installer::globals::fontsdirname )
528cdf0e10cSrcweir	{
529cdf0e10cSrcweir		$oneline = "$installer::globals::fontsfolder\t$installer::globals::fontsdirparent\t$installer::globals::fontsfoldername\:$installer::globals::fontsdirname\n";
530cdf0e10cSrcweir	}
531cdf0e10cSrcweir	else
532cdf0e10cSrcweir	{
533cdf0e10cSrcweir		$oneline = "$installer::globals::fontsfolder\tTARGETDIR\t$installer::globals::fontsfoldername\n";
534cdf0e10cSrcweir	}
535cdf0e10cSrcweir
536cdf0e10cSrcweir	push(@{$directorytableref}, $oneline);
537cdf0e10cSrcweir
538cdf0e10cSrcweir}
539cdf0e10cSrcweir
540cdf0e10cSrcweir###############################################
541cdf0e10cSrcweir# Creating the file Director.idt dynamically
542cdf0e10cSrcweir###############################################
543cdf0e10cSrcweir
544dca4887fSAndre Fischersub create_directory_table ($$$$)
545cdf0e10cSrcweir{
546dca4887fSAndre Fischer	my ($directoryref, $basedir, $allvariableshashref, $loggingdir) = @_;
547cdf0e10cSrcweir
548cdf0e10cSrcweir	# Structure of the directory table:
549cdf0e10cSrcweir	# Directory Directory_Parent DefaultDir
550cdf0e10cSrcweir	# Directory is a unique identifier
551cdf0e10cSrcweir	# Directory_Parent is the unique identifier of the parent
552cdf0e10cSrcweir	# DefaultDir is .:APPLIC~1|Application Data with
553cdf0e10cSrcweir	# Before ":" : [sourcedir]:[destdir] (not programmed yet)
554cdf0e10cSrcweir	# After ":" : 8+3 and not 8+3 the destination directory name
55519d58b3aSEike Rathke
556b274bc22SAndre Fischer	$installer::logger::Lang->add_timestamp("Performance Info: Directory Table start");
557cdf0e10cSrcweir
558cdf0e10cSrcweir	my @directorytable = ();
559cdf0e10cSrcweir	my $infoline;
560cdf0e10cSrcweir
561cdf0e10cSrcweir	overwrite_programfilesfolder($allvariableshashref);
562cdf0e10cSrcweir	create_unique_directorynames($directoryref, $allvariableshashref);
563dca4887fSAndre Fischer	create_defaultdir_directorynames($directoryref);	# only destdir!
564cdf0e10cSrcweir	set_installlocation_directory($directoryref, $allvariableshashref);
565cdf0e10cSrcweir	installer::windows::idtglobal::write_idt_header(\@directorytable, "directory");
566cdf0e10cSrcweir	add_root_directories(\@directorytable, $allvariableshashref);
567cdf0e10cSrcweir	create_directorytable_from_collection(\@directorytable, $directoryref);
568cdf0e10cSrcweir
569cdf0e10cSrcweir	# Saving the file
570cdf0e10cSrcweir
571cdf0e10cSrcweir	my $directorytablename = $basedir . $installer::globals::separator . "Director.idt";
572cdf0e10cSrcweir	installer::files::save_file($directorytablename ,\@directorytable);
573b274bc22SAndre Fischer    $installer::logger::Lang->printf("Created idt file: %s\n", $directorytablename);
57419d58b3aSEike Rathke
575b274bc22SAndre Fischer	$installer::logger::Lang->add_timestamp("Performance Info: Directory Table end");
576cdf0e10cSrcweir}
577cdf0e10cSrcweir
578cdf0e10cSrcweir1;
579