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: files.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
::files
;
34 use installer
::exiter
;
35 use installer
::logger
;
37 ############################################
39 ############################################
45 if ( $installer::globals
::debug
) { installer
::logger
::debuginfo
("installer::files::check_file : $arg"); }
49 installer
::exiter
::exit_program
("ERROR: Cannot find file $arg", "check_file");
58 if ( $installer::globals
::debug
) { installer
::logger
::debuginfo
("installer::files::read_file : $localfile"); }
60 open( IN
, "<$localfile" ) || installer
::exiter
::exit_program
("ERROR: Cannot open file $localfile for reading", "read_file");
62 # Don't use "my @localfile = <IN>" here, because
63 # perl has a problem with the internal "large_and_huge_malloc" function
64 # when calling perl using MacOS 10.5 with a perl built with MacOS 10.4
65 while ( $line = <IN
> ) {
66 push @localfile, $line;
74 ###########################################
75 # Saving files, arrays and hashes
76 ###########################################
80 my ($savefile, $savecontent) = @_;
82 if ( $installer::globals
::debug
) { installer
::logger
::debuginfo
("installer::files::save_file : $savefile : $#{$savecontent}"); }
84 if ( open( OUT
, ">$savefile" ) )
86 print OUT @
{$savecontent};
91 # it is useless to save a log file, if there is no write access
93 if ( $savefile =~ /\.log/ )
95 print "\n*************************************************\n";
96 print "ERROR: Cannot write log file: $savefile";
97 print "\n*************************************************\n";
98 exit(-1); # exiting the program to avoid endless loops
101 installer
::exiter
::exit_program
("ERROR: Cannot open file $savefile for writing", "save_file");
107 my ($savefile, $hashref) = @_;
109 if ( $installer::globals
::debug
) { installer
::logger
::debuginfo
("installer::files::save_hash : $savefile"); }
111 my @printcontent = ();
115 foreach $itemkey ( keys %{$hashref} )
118 my $itemvalue = $hashref->{$itemkey};
119 $line = $itemkey . "=" . $itemvalue . "\n";
120 push(@printcontent, $line);
123 open( OUT
, ">$savefile" ) || installer
::exiter
::exit_program
("ERROR: Cannot open file $savefile for writing", "save_hash");
124 print OUT
@printcontent;
128 sub save_array_of_hashes
130 my ($savefile, $arrayref) = @_;
132 if ( $installer::globals
::debug
) { installer
::logger
::debuginfo
("installer::files::save_array_of_hashes : $savefile : $#{$arrayref}"); }
134 my @printcontent = ();
136 for ( my $i = 0; $i <= $#{$arrayref}; $i++ )
139 my $hashref = ${$arrayref}[$i];
142 foreach $itemkey ( keys %{$hashref} )
144 my $itemvalue = $hashref->{$itemkey};
145 $line = $line . $itemkey . "=" . $itemvalue . "\t";
148 $line = $line . "\n";
150 push(@printcontent, $line);
153 open( OUT
, ">$savefile" ) || installer
::exiter
::exit_program
("ERROR: Cannot open file $savefile for writing", "save_array_of_hashes");
154 print OUT
@printcontent;
158 sub save_array_of_hashes_modules
160 my ($savefile, $arrayref) = @_;
162 if ( $installer::globals
::debug
) { installer
::logger
::debuginfo
("installer::files::save_array_of_hashes : $savefile : $#{$arrayref}"); }
164 my @printcontent = ();
166 for ( my $i = 0; $i <= $#{$arrayref}; $i++ )
168 my $line = "***************************************************\n";
169 my $hashref = ${$arrayref}[$i];
172 foreach $itemkey ( keys %{$hashref} )
174 my $itemvalue = $hashref->{$itemkey};
175 $line = $line . $itemkey . "=" . $itemvalue . "\n";
178 $line = $line . "\n";
180 push(@printcontent, $line);
183 open( OUT
, ">$savefile" ) || installer
::exiter
::exit_program
("ERROR: Cannot open file $savefile for writing", "save_array_of_hashes");
184 print OUT
@printcontent;
188 ###########################################
189 # Binary file operations
190 ###########################################
196 if ( $installer::globals
::debug
) { installer
::logger
::debuginfo
("installer::files::read_binary_file : $filename"); }
200 open( IN
, "<$filename" ) || installer
::exiter
::exit_program
("ERROR: Cannot open file $filename for reading", "read_binary_file");
203 my $length = tell IN
;
205 read IN
, $file, $length;
213 my ($file, $filename) = @_;
215 if ( $installer::globals
::debug
) { installer
::logger
::debuginfo
("installer::files::save_binary_file : $filename"); }
217 open( OUT
, ">$filename" ) || installer
::exiter
::exit_program
("ERROR: Cannot open file $filename for writing", "save_binary_file");