1
0
Fork 0

Implement a portable way to use ZIP files

This commit is contained in:
Frederic Bouvier 2009-02-23 09:16:22 +01:00 committed by Ralf Gerlich
parent 00b8658b99
commit 814007e06c

View file

@ -94,13 +94,24 @@ TGHgt::open ( const SGPath &f ) {
string command = "unzip -d \"" + tmp_dir.dir() + "\" " + file_name.base();
system( command.c_str() );
SGPath full_name = file_name.base();
file_name.set( "/tmp" );
if ( full_name.file().empty() ) {
file_name.append( full_name.str() );
} else {
file_name.append( full_name.file() );
file_name = tmp_dir.dir();
ulDir *dir = ulOpenDir( tmp_dir.dir().c_str() );
if ( dir ) {
ulDirEnt *de;
while ( ( de = ulReadDir( dir ) ) != 0 ) {
if ( !strcmp(de->d_name,".") || !strcmp(de->d_name,"..") || de->d_isdir ) {
continue;
}
SGPath file( de->d_name );
string ext = file.extension();
if ( ext == "HGT" || ext == "hgt" ) {
file_name.append( de->d_name );
break;
}
}
ulCloseDir( dir );
}
remove_tmp_file = true;
remove_file_name = file_name.str();
@ -188,4 +199,20 @@ TGHgt::~TGHgt() {
// printf("class TGSrtmBase DEstructor called.\n");
delete [] data;
delete [] output_data;
if ( remove_tmp_file ) {
ulDir *dir = ulOpenDir( remove_file_name.dir().c_str() );
if ( dir ) {
ulDirEnt *de;
while ( ( de = ulReadDir( dir ) ) != 0 ) {
if ( !strcmp(de->d_name,".") || !strcmp(de->d_name,"..") || de->d_isdir ) {
continue;
}
SGPath file( remove_file_name.dir() );
file.append( de->d_name );
unlink( file.c_str() );
}
ulCloseDir( dir );
}
rmdir( remove_file_name.dir().c_str() );
}
}