Implement a portable way to use ZIP files
This commit is contained in:
parent
00b8658b99
commit
814007e06c
1 changed files with 36 additions and 9 deletions
|
@ -94,26 +94,37 @@ TGHgt::open ( const SGPath &f ) {
|
||||||
string command = "unzip -d \"" + tmp_dir.dir() + "\" " + file_name.base();
|
string command = "unzip -d \"" + tmp_dir.dir() + "\" " + file_name.base();
|
||||||
system( command.c_str() );
|
system( command.c_str() );
|
||||||
|
|
||||||
SGPath full_name = file_name.base();
|
file_name = tmp_dir.dir();
|
||||||
file_name.set( "/tmp" );
|
ulDir *dir = ulOpenDir( tmp_dir.dir().c_str() );
|
||||||
if ( full_name.file().empty() ) {
|
if ( dir ) {
|
||||||
file_name.append( full_name.str() );
|
ulDirEnt *de;
|
||||||
} else {
|
while ( ( de = ulReadDir( dir ) ) != 0 ) {
|
||||||
file_name.append( full_name.file() );
|
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_tmp_file = true;
|
||||||
remove_file_name = file_name.str();
|
remove_file_name = file_name.str();
|
||||||
|
|
||||||
cout << "Proceeding with " << file_name.str() << endl;
|
cout << "Proceeding with " << file_name.str() << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << "Loading HGT data file: " << file_name.str() << endl;
|
cout << "Loading HGT data file: " << file_name.str() << endl;
|
||||||
if ( (fd = gzopen( file_name.c_str(), "rb" )) == NULL ) {
|
if ( (fd = gzopen( file_name.c_str(), "rb" )) == NULL ) {
|
||||||
SGPath file_name_gz = file_name;
|
SGPath file_name_gz = file_name;
|
||||||
file_name_gz.append( ".gz" );
|
file_name_gz.append( ".gz" );
|
||||||
if ( (fd = gzopen( file_name_gz.c_str(), "rb" )) == NULL ) {
|
if ( (fd = gzopen( file_name_gz.c_str(), "rb" )) == NULL ) {
|
||||||
cout << "ERROR: opening " << file_name.str() << " or "
|
cout << "ERROR: opening " << file_name.str() << " or "
|
||||||
<< file_name_gz.str() << "for reading!" << endl;
|
<< file_name_gz.str() << " for reading!" << endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -188,4 +199,20 @@ TGHgt::~TGHgt() {
|
||||||
// printf("class TGSrtmBase DEstructor called.\n");
|
// printf("class TGSrtmBase DEstructor called.\n");
|
||||||
delete [] data;
|
delete [] data;
|
||||||
delete [] output_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() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue