#663: fgadmin not working properly (with latest Fltk)
Some things about fltk seem changed, which broke fgadmin: fl_filename_list could return negative number instead of 0. fl_filename_list now has a "/" appended to every reported directory name. free( list ) now caused a segfault - use fltk's method to free memory. fgadmin should now work with new and old Fltk.
This commit is contained in:
parent
f6c3a41b92
commit
7c657dfa71
1 changed files with 24 additions and 14 deletions
|
@ -48,6 +48,18 @@ extern string def_scenery_dest;
|
||||||
static const float min_progress = 0.0;
|
static const float min_progress = 0.0;
|
||||||
static const float max_progress = 5000.0;
|
static const float max_progress = 5000.0;
|
||||||
|
|
||||||
|
/** Strip a single trailing '/' or '\\' */
|
||||||
|
static char* stripSlash(char* str)
|
||||||
|
{
|
||||||
|
int l = strlen(str);
|
||||||
|
if ((l>0)&&
|
||||||
|
((str[l-1]=='/')||(str[l-1]=='\\')))
|
||||||
|
{
|
||||||
|
str[l-1] = 0;
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
// destructor
|
// destructor
|
||||||
FGAdminUI::~FGAdminUI() {
|
FGAdminUI::~FGAdminUI() {
|
||||||
delete prefs;
|
delete prefs;
|
||||||
|
@ -147,6 +159,7 @@ void FGAdminUI::update_install_box() {
|
||||||
// find base name of archive file
|
// find base name of archive file
|
||||||
char base[FL_PATH_MAX];
|
char base[FL_PATH_MAX];
|
||||||
dirent *ent = list[i];
|
dirent *ent = list[i];
|
||||||
|
stripSlash(ent->d_name);
|
||||||
strncpy( base, ent->d_name, FL_PATH_MAX );
|
strncpy( base, ent->d_name, FL_PATH_MAX );
|
||||||
const char *p = fl_filename_ext( base );
|
const char *p = fl_filename_ext( base );
|
||||||
int offset;
|
int offset;
|
||||||
|
@ -187,9 +200,8 @@ void FGAdminUI::update_install_box() {
|
||||||
// cout << install.str() << " exists." << endl;
|
// cout << install.str() << " exists." << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free( ent );
|
|
||||||
}
|
}
|
||||||
free( list );
|
fl_filename_free_list(&list, nb);
|
||||||
|
|
||||||
for ( set<string>::iterator it = file_list.begin(); it != file_list.end(); ++it ) {
|
for ( set<string>::iterator it = file_list.begin(); it != file_list.end(); ++it ) {
|
||||||
install_box->add( it->c_str() );
|
install_box->add( it->c_str() );
|
||||||
|
@ -223,14 +235,14 @@ void FGAdminUI::update_remove_box() {
|
||||||
int nb = fl_filename_list( path[i].c_str(), &list );
|
int nb = fl_filename_list( path[i].c_str(), &list );
|
||||||
for ( int i = 0; i < nb; ++i ) {
|
for ( int i = 0; i < nb; ++i ) {
|
||||||
dirent *ent = list[i];
|
dirent *ent = list[i];
|
||||||
|
stripSlash(ent->d_name);
|
||||||
if ( strlen(ent->d_name) == 7 &&
|
if ( strlen(ent->d_name) == 7 &&
|
||||||
( ent->d_name[0] == 'e' || ent->d_name[0] == 'w' ) &&
|
( ent->d_name[0] == 'e' || ent->d_name[0] == 'w' ) &&
|
||||||
( ent->d_name[4] == 'n' || ent->d_name[4] == 's' ) ) {
|
( ent->d_name[4] == 'n' || ent->d_name[4] == 's' ) ) {
|
||||||
dir_list.insert( ent->d_name );
|
dir_list.insert( ent->d_name );
|
||||||
}
|
}
|
||||||
free( ent );
|
|
||||||
}
|
}
|
||||||
free( list );
|
fl_filename_free_list(&list, nb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,6 +304,7 @@ static unsigned long count_dir( const char *dir_name, bool top = true ) {
|
||||||
if ( nb != 0 ) {
|
if ( nb != 0 ) {
|
||||||
for ( int i = 0; i < nb; ++i ) {
|
for ( int i = 0; i < nb; ++i ) {
|
||||||
dirent *ent = list[i];
|
dirent *ent = list[i];
|
||||||
|
stripSlash(ent->d_name);
|
||||||
if ( strcmp( ent->d_name, "." ) == 0 ) {
|
if ( strcmp( ent->d_name, "." ) == 0 ) {
|
||||||
// ignore "."
|
// ignore "."
|
||||||
} else if ( strcmp( ent->d_name, ".." ) == 0 ) {
|
} else if ( strcmp( ent->d_name, ".." ) == 0 ) {
|
||||||
|
@ -303,9 +316,8 @@ static unsigned long count_dir( const char *dir_name, bool top = true ) {
|
||||||
} else {
|
} else {
|
||||||
cnt += 1;
|
cnt += 1;
|
||||||
}
|
}
|
||||||
free( ent );
|
|
||||||
}
|
}
|
||||||
free( list );
|
fl_filename_free_list(&list, nb);
|
||||||
} else if ( top ) {
|
} else if ( top ) {
|
||||||
string base = dir_name;
|
string base = dir_name;
|
||||||
size_t pos = base.rfind('/');
|
size_t pos = base.rfind('/');
|
||||||
|
@ -322,26 +334,24 @@ static unsigned long count_dir( const char *dir_name, bool top = true ) {
|
||||||
static void remove_dir( const char *dir_name, void (*step)(void*,int), void *data, bool top = true ) {
|
static void remove_dir( const char *dir_name, void (*step)(void*,int), void *data, bool top = true ) {
|
||||||
dirent **list;
|
dirent **list;
|
||||||
int nb = fl_filename_list( dir_name, &list );
|
int nb = fl_filename_list( dir_name, &list );
|
||||||
if ( nb != 0 ) {
|
if ( nb > 0 ) {
|
||||||
for ( int i = 0; i < nb; ++i ) {
|
for ( int i = 0; i < nb; ++i ) {
|
||||||
dirent *ent = list[i];
|
dirent *ent = list[i];
|
||||||
|
SGPath child( dir_name );
|
||||||
|
child.append( ent->d_name );
|
||||||
|
stripSlash(ent->d_name);
|
||||||
if ( strcmp( ent->d_name, "." ) == 0 ) {
|
if ( strcmp( ent->d_name, "." ) == 0 ) {
|
||||||
// ignore "."
|
// ignore "."
|
||||||
} else if ( strcmp( ent->d_name, ".." ) == 0 ) {
|
} else if ( strcmp( ent->d_name, ".." ) == 0 ) {
|
||||||
// ignore ".."
|
// ignore ".."
|
||||||
} else if ( fl_filename_isdir( ent->d_name ) ) {
|
} else if ( child.isDir() ) {
|
||||||
SGPath child( dir_name );
|
|
||||||
child.append( ent->d_name );
|
|
||||||
remove_dir( child.c_str(), step, data, false );
|
remove_dir( child.c_str(), step, data, false );
|
||||||
} else {
|
} else {
|
||||||
SGPath child( dir_name );
|
|
||||||
child.append( ent->d_name );
|
|
||||||
unlink( child.c_str() );
|
unlink( child.c_str() );
|
||||||
if (step) step( data, 1 );
|
if (step) step( data, 1 );
|
||||||
}
|
}
|
||||||
free( ent );
|
|
||||||
}
|
}
|
||||||
free( list );
|
fl_filename_free_list(&list, nb);
|
||||||
rmdir( dir_name );
|
rmdir( dir_name );
|
||||||
} else if ( top ) {
|
} else if ( top ) {
|
||||||
string base = dir_name;
|
string base = dir_name;
|
||||||
|
|
Loading…
Add table
Reference in a new issue