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: directory.pm,v $
11 # $Revision: 1.30.126.1 $
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
::directory
;
34 use installer
::exiter
;
36 use installer
::globals
;
37 use installer
::pathanalyzer
;
38 use installer
::windows
::idtglobal
;
40 ##############################################################
41 # Collecting all directory trees in global hash
42 ##############################################################
44 sub collectdirectorytrees
46 my ( $directoryref ) = @_;
48 for ( my $i = 0; $i <= $#{$directoryref}; $i++ )
50 my $onedir = ${$directoryref}[$i];
52 if ( $onedir->{'Styles'} ) { $styles = $onedir->{'Styles'}; }
56 foreach my $treestyle ( keys %installer::globals
::treestyles
)
58 if ( $styles =~ /\b$treestyle\b/ )
60 my $hostname = $onedir->{'HostName'};
61 # -> hostname is the key, the style the value!
62 $installer::globals
::hostnametreestyles
{$hostname} = $treestyle;
69 ##############################################################
70 # Overwriting global programfilesfolder, if required
71 ##############################################################
73 sub overwrite_programfilesfolder
75 my ( $allvariables ) = @_;
77 if ( $allvariables->{'PROGRAMFILESFOLDERNAME'} )
79 $installer::globals
::programfilesfolder
= $allvariables->{'PROGRAMFILESFOLDERNAME'};
83 ##############################################################
84 # Adding unique directory names to the directory collection
85 ##############################################################
87 sub create_unique_directorynames
89 my ($directoryref) = @_;
91 $installer::globals
::officeinstalldirectoryset
= 0;
93 for ( my $i = 0; $i <= $#{$directoryref}; $i++ )
95 my $onedir = ${$directoryref}[$i];
96 my $uniquename = $onedir->{'HostName'};
98 if ( $onedir->{'Styles'} ) { $styles = $onedir->{'Styles'}; }
99 # get_path_from_fullqualifiedname(\$uniqueparentname);
100 # making /registry/schema/org/openoffice/VCL.xcs to VCL.xcs
102 $uniquename =~ s/^\s*//g; # removing beginning white spaces
103 $uniquename =~ s/\s*$//g; # removing ending white spaces
104 $uniquename =~ s/\s//g; # removing white spaces
105 $uniquename =~ s/\_//g; # removing existing underlines
106 $uniquename =~ s/\.//g; # removing dots in directoryname
107 $uniquename =~ s/\Q$installer::globals::separator\E/\_/g; # replacing slash and backslash with underline
109 my $uniqueparentname = $uniquename;
111 if ( $uniqueparentname =~ /^\s*(.*)\_(.*?)\s*$/ ) # the underline is now the separator
113 $uniqueparentname = $1;
117 $uniqueparentname = "INSTALLLOCATION";
120 if ( $styles =~ /\bPROGRAMFILESFOLDER\b/ ) { $uniqueparentname = $installer::globals
::programfilesfolder
; }
121 if ( $styles =~ /\bCOMMONFILESFOLDER\b/ ) { $uniqueparentname = $installer::globals
::commonfilesfolder
; }
122 if ( $styles =~ /\bCOMMONAPPDATAFOLDER\b/ ) { $uniqueparentname = $installer::globals
::commonappdatafolder
; }
123 if ( $styles =~ /\bLOCALAPPDATAFOLDER\b/ ) { $uniqueparentname = $installer::globals
::localappdatafolder
; }
125 if ( $styles =~ /\bSHAREPOINTPATH\b/ )
127 $uniqueparentname = "SHAREPOINTPATH";
128 $installer::globals
::usesharepointpath
= 1;
131 $uniquename =~ s/\-/\_/g; # making "-" to "_"
132 $uniqueparentname =~ s/\-/\_/g; # making "-" to "_"
134 $onedir->{'uniquename'} = $uniquename;
135 $onedir->{'uniqueparentname'} = $uniqueparentname;
137 # setting the office installation directory
138 if ( $styles =~ /\bOFFICEDIRECTORY\b/ )
140 if ( $installer::globals
::officeinstalldirectoryset
) { installer
::exiter
::exit_program
("ERROR: Directory with flag OFFICEDIRECTORY alread set: \"$installer::globals::officeinstalldirectory\".", "create_unique_directorynames"); }
141 $installer::globals
::officeinstalldirectory
= $uniquename;
142 $installer::globals
::officeinstalldirectoryset
= 1;
143 if ( $installer::globals
::officeinstalldirectory
=~ /sun_/i ) { $installer::globals
::sundirexists
= 1; }
146 # setting the bais installation directory
147 if ( $styles =~ /\bBASISDIRECTORY\b/ )
149 if ( $installer::globals
::basisinstalldirectoryset
) { installer
::exiter
::exit_program
("ERROR: Directory with flag BASISDIRECTORY alread set: \"$installer::globals::basisinstalldirectory\".", "create_unique_directorynames"); }
150 $installer::globals
::basisinstalldirectory
= $uniquename;
151 $installer::globals
::basisinstalldirectoryset
= 1;
154 # setting the ure installation directory
155 if ( $styles =~ /\bUREDIRECTORY\b/ )
157 if ( $installer::globals
::ureinstalldirectoryset
) { installer
::exiter
::exit_program
("ERROR: Directory with flag UREDIRECTORY alread set: \"$installer::globals::ureinstalldirectory\".", "create_unique_directorynames"); }
158 $installer::globals
::ureinstalldirectory
= $uniquename;
159 $installer::globals
::ureinstalldirectoryset
= 1;
164 #####################################################
165 # Getting the name of the top level directory. This
166 # can have only one letter
167 #####################################################
169 sub get_last_directory_name
171 my ($completepathref) = @_;
173 if ( $$completepathref =~ /^.*[\/\\](.+?
)\s
*$/ )
175 $$completepathref = $1;
179 #####################################################
180 # Creating the defaultdir for the file Director.idt
181 #####################################################
183 sub create_defaultdir_directorynames
185 my ($directoryref, $shortdirnamehashref) = @_;
188 if ( $installer::globals
::updatedatabase
) { @shortnames = values(%{$shortdirnamehashref}); }
189 elsif ( $installer::globals
::prepare_winpatch
) { @shortnames = values(%installer::globals
::saved83dirmapping
); }
191 for ( my $i = 0; $i <= $#{$directoryref}; $i++ )
193 my $onedir = ${$directoryref}[$i];
194 my $hostname = $onedir->{'HostName'};
196 $hostname =~ s/\Q$installer::globals::separator\E\s*$//;
197 get_last_directory_name
(\
$hostname);
198 # installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$hostname); # making program/classes to classes
199 my $uniquename = $onedir->{'uniquename'};
201 if (( $installer::globals
::updatedatabase
) && ( exists($shortdirnamehashref->{$uniquename}) ))
203 $shortstring = $shortdirnamehashref->{$uniquename};
205 elsif (( $installer::globals
::prepare_winpatch
) && ( exists($installer::globals
::saved83dirmapping
{$uniquename}) ))
207 $shortstring = $installer::globals
::saved83dirmapping
{$uniquename};
211 $shortstring = installer
::windows
::idtglobal
::make_eight_three_conform
($hostname, "dir", \
@shortnames);
216 if ( $shortstring eq $hostname )
218 $defaultdir = $hostname;
222 $defaultdir = $shortstring . "|" . $hostname;
225 $onedir->{'defaultdir'} = $defaultdir;
228 if ( $onedir->{'Dir'} ) { $fontdir = $onedir->{'Dir'}; }
230 my $fontdefaultdir = "";
231 if ( $onedir->{'defaultdir'} ) { $fontdefaultdir = $onedir->{'defaultdir'}; }
233 if (( $fontdir eq "PREDEFINED_OSSYSTEMFONTDIR" ) && ( $fontdefaultdir eq $installer::globals
::fontsdirhostname
))
235 $installer::globals
::fontsdirname
= $onedir->{'defaultdir'};
236 $installer::globals
::fontsdirparent
= $onedir->{'uniqueparentname'};
241 ###############################################
242 # Fill content into the directory table
243 ###############################################
245 sub create_directorytable_from_collection
247 my ($directorytableref, $directoryref) = @_;
249 for ( my $i = 0; $i <= $#{$directoryref}; $i++ )
251 my $onedir = ${$directoryref}[$i];
252 my $hostname = $onedir->{'HostName'};
255 if ( $onedir->{'Dir'} ) { $dir = $onedir->{'Dir'}; }
257 if (( $dir eq "PREDEFINED_PROGDIR" ) && ( $hostname eq "" )) { next; } # removing files from root directory
259 my $oneline = $onedir->{'uniquename'} . "\t" . $onedir->{'uniqueparentname'} . "\t" . $onedir->{'defaultdir'} . "\n";
261 push(@
{$directorytableref}, $oneline);
265 ###############################################
266 # Defining the root installation structure
267 ###############################################
269 sub add_root_directories
271 my ($directorytableref, $allvariableshashref) = @_;
273 my $oneline = "TARGETDIR\t\tSourceDir\n";
274 push(@
{$directorytableref}, $oneline);
276 $oneline = "WindowsFolder\tTARGETDIR\tWindows\n";
277 push(@
{$directorytableref}, $oneline);
279 $oneline = "WindowsShellNewFolder\tWindowsFolder\tShellNew\n";
280 push(@
{$directorytableref}, $oneline);
282 my $sourcediraddon = "";
283 if (($installer::globals
::addchildprojects
) ||
284 ($installer::globals
::patch
) ||
285 ($installer::globals
::languagepack
) ||
286 ($allvariableshashref->{'CHANGETARGETDIR'}))
288 $sourcediraddon = "\:\.";
291 if (!($installer::globals
::product
=~ /ada/i )) # the following directories not for ada products
293 $oneline = "$installer::globals::programfilesfolder\tTARGETDIR\t.\n";
294 push(@
{$directorytableref}, $oneline);
296 # my $manufacturer = $installer::globals::manufacturer;
297 # my $shortmanufacturer = installer::windows::idtglobal::make_eight_three_conform($manufacturer, "dir"); # third parameter not used
298 # $shortmanufacturer =~ s/\s/\_/g; # changing empty space to underline
300 my $productname = $allvariableshashref->{'PRODUCTNAME'};
301 my $productversion = $allvariableshashref->{'PRODUCTVERSION'};
302 my $baseproductversion = $productversion;
304 if (( $installer::globals
::prepare_winpatch
) && ( $allvariableshashref->{'BASEPRODUCTVERSION'} ))
306 $baseproductversion = $allvariableshashref->{'BASEPRODUCTVERSION'}; # for example "2.0" for OOo
309 my $realproductkey = $productname . " " . $productversion;
310 my $productkey = $productname . " " . $baseproductversion;
312 if (( $allvariableshashref->{'POSTVERSIONEXTENSION'} ) && ( ! $allvariableshashref->{'DONTUSEEXTENSIONINDEFAULTDIR'} ))
314 $productkey = $productkey . " " . $allvariableshashref->{'POSTVERSIONEXTENSION'};
315 $realproductkey = $realproductkey . " " . $allvariableshashref->{'POSTVERSIONEXTENSION'};
317 if ( $allvariableshashref->{'NOVERSIONINDIRNAME'} )
319 $productkey = $productname;
320 $realproductkey = $realproductname;
322 if ( $allvariableshashref->{'NOSPACEINDIRECTORYNAME'} )
324 $productkey =~ s/\ /\_/g;
325 $realproductkey =~ s/\ /\_/g;
328 my $shortproductkey = installer
::windows
::idtglobal
::make_eight_three_conform
($productkey, "dir"); # third parameter not used
329 $shortproductkey =~ s/\s/\_/g; # changing empty space to underline
331 if ( $allvariableshashref->{'SUNDIR'} )
333 $oneline = "sundirectory\t$installer::globals::programfilesfolder\t$installer::globals::sundirname$sourcediraddon\n";
334 push(@
{$directorytableref}, $oneline);
336 $oneline = "INSTALLLOCATION\tsundirectory\t$shortproductkey|$productkey$sourcediraddon\n";
337 push(@
{$directorytableref}, $oneline);
341 if ( $allvariableshashref->{'PROGRAMFILESROOT'} )
343 $oneline = "INSTALLLOCATION\t$installer::globals::programfilesfolder\t.\n";
347 $oneline = "INSTALLLOCATION\t$installer::globals::programfilesfolder\t$shortproductkey|$productkey$sourcediraddon\n";
350 push(@
{$directorytableref}, $oneline);
353 $oneline = "$installer::globals::programmenufolder\tTARGETDIR\t.\n";
354 push(@
{$directorytableref}, $oneline);
356 if (( ! $installer::globals
::patch
) && ( ! $installer::globals
::languagepack
) && ( ! $allvariableshashref->{'DONTUSESTARTMENUFOLDER'} ))
358 $oneline = "$installer::globals::officemenufolder\t$installer::globals::programmenufolder\t$shortproductkey|$realproductkey\n";
359 push(@
{$directorytableref}, $oneline);
362 $oneline = "$installer::globals::startupfolder\tTARGETDIR\t.\n";
363 push(@
{$directorytableref}, $oneline);
365 $oneline = "$installer::globals::desktopfolder\tTARGETDIR\t.\n";
366 push(@
{$directorytableref}, $oneline);
368 $oneline = "$installer::globals::startmenufolder\tTARGETDIR\t.\n";
369 push(@
{$directorytableref}, $oneline);
371 $oneline = "$installer::globals::commonfilesfolder\tTARGETDIR\t.\n";
372 push(@
{$directorytableref}, $oneline);
374 $oneline = "$installer::globals::commonappdatafolder\tTARGETDIR\t.\n";
375 push(@
{$directorytableref}, $oneline);
377 $oneline = "$installer::globals::localappdatafolder\tTARGETDIR\t.\n";
378 push(@
{$directorytableref}, $oneline);
380 if ( $installer::globals
::usesharepointpath
)
382 $oneline = "SHAREPOINTPATH\tTARGETDIR\t.\n";
383 push(@
{$directorytableref}, $oneline);
386 $oneline = "$installer::globals::systemfolder\tTARGETDIR\t.\n";
387 push(@
{$directorytableref}, $oneline);
389 my $localtemplatefoldername = $installer::globals
::templatefoldername
;
390 my $directorytableentry = $localtemplatefoldername;
391 my $shorttemplatefoldername = installer
::windows
::idtglobal
::make_eight_three_conform
($localtemplatefoldername, "dir");
392 if ( $shorttemplatefoldername ne $localtemplatefoldername ) { $directorytableentry = "$shorttemplatefoldername|$localtemplatefoldername"; }
393 $oneline = "$installer::globals::templatefolder\tTARGETDIR\t$directorytableentry\n";
394 push(@
{$directorytableref}, $oneline);
396 if ( $installer::globals
::fontsdirname
)
398 $oneline = "$installer::globals::fontsfolder\t$installer::globals::fontsdirparent\t$installer::globals::fontsfoldername\:$installer::globals::fontsdirname\n";
402 $oneline = "$installer::globals::fontsfolder\tTARGETDIR\t$installer::globals::fontsfoldername\n";
405 push(@
{$directorytableref}, $oneline);
410 ###############################################
411 # Creating the file Director.idt dynamically
412 ###############################################
414 sub create_directory_table
416 my ($directoryref, $basedir, $allvariableshashref, $shortdirnamehashref) = @_;
418 # Structure of the directory table:
419 # Directory Directory_Parent DefaultDir
420 # Directory is a unique identifier
421 # Directory_Parent is the unique identifier of the parent
422 # DefaultDir is .:APPLIC~1|Application Data with
423 # Before ":" : [sourcedir]:[destdir] (not programmed yet)
424 # After ":" : 8+3 and not 8+3 the destination directory name
426 my @directorytable = ();
429 overwrite_programfilesfolder
($allvariableshashref);
430 create_unique_directorynames
($directoryref);
431 create_defaultdir_directorynames
($directoryref, $shortdirnamehashref); # only destdir!
432 installer
::windows
::idtglobal
::write_idt_header
(\
@directorytable, "directory");
433 add_root_directories
(\
@directorytable, $allvariableshashref);
434 create_directorytable_from_collection
(\
@directorytable, $directoryref);
438 my $directorytablename = $basedir . $installer::globals
::separator
. "Director.idt";
439 installer
::files
::save_file
($directorytablename ,\
@directorytable);
440 $infoline = "Created idt file: $directorytablename\n";
441 push(@installer::globals
::logfileinfo
, $infoline);