1
0
Fork 0

More portable way to deal with ZIP files

This commit is contained in:
Frederic Bouvier 2009-02-15 17:55:43 +01:00 committed by Ralf Gerlich
parent 0166015c4d
commit 1bca4c11e2
2 changed files with 13 additions and 6 deletions

View file

@ -36,6 +36,10 @@
# include <errno.h>
#endif
#ifdef _MSC_VER
# include <direct.h>
#endif
#include <simgear/constants.h>
#include <simgear/io/lowlevel.hxx>
@ -83,9 +87,12 @@ TGHgt::open ( const SGPath &f ) {
if ( file_name.extension() == "zip" ) {
// extract the .zip file to /tmp and point the file name
// to the extracted file
cout << "Extracting " << file_name.str() << " to /tmp" << endl;
string command = "unzip -d /tmp " + file_name.base();
system( command.c_str() );
SGPath tmp_dir = tempnam( 0, "hgt" );
tmp_dir.append( "dummy" );
tmp_dir.create_dir( 0700 );
cout << "Extracting " << file_name.str() << " to " << tmp_dir.dir() << endl;
string command = "unzip -d \"" + tmp_dir.dir() + "\" " + file_name.base();
system( command.c_str() );
SGPath full_name = file_name.base();
file_name.set( "/tmp" );
@ -135,8 +142,8 @@ TGHgt::close () {
gzclose(fd);
if ( remove_tmp_file ) {
string command = "/bin/rm " + remove_file_name;
system( command.c_str() );
unlink( remove_file_name.c_str() );
rmdir( remove_file_name.dir().c_str() );
}
return true;

View file

@ -63,7 +63,7 @@ private:
int hgt_resolution;
bool remove_tmp_file;
std::string remove_file_name;
SGPath remove_file_name;
public: