From 2513d066338514b0114fbdb40773d8545eb4ffa8 Mon Sep 17 00:00:00 2001 From: curt Date: Mon, 16 Feb 2004 14:08:20 +0000 Subject: [PATCH] Updates from Fred to add a progress bar and fix visual glitches. Tweaks by Curt to progress bar, plus sanity checks on included uninstall box entries. --- utils/fgadmin/src/fgadmin.cxx | 6 +- utils/fgadmin/src/fgadmin.fl | 11 +++- utils/fgadmin/src/fgadmin.h | 3 + utils/fgadmin/src/fgadmin_funcs.cxx | 60 ++++++++++++++++++-- utils/fgadmin/src/untarka.c | 10 ++-- utils/fgadmin/src/untarka.h | 2 +- utils/fgadmin/visualc/fgadmin/fgadmin.vcproj | 23 ++++---- 7 files changed, 88 insertions(+), 27 deletions(-) diff --git a/utils/fgadmin/src/fgadmin.cxx b/utils/fgadmin/src/fgadmin.cxx index 2578284f0..e9e55524b 100644 --- a/utils/fgadmin/src/fgadmin.cxx +++ b/utils/fgadmin/src/fgadmin.cxx @@ -47,7 +47,7 @@ FGAdminUI::FGAdminUI() { { Fl_Double_Window* o = main_window = new Fl_Double_Window(465, 435, "FlightGear Admin Wizard"); w = o; o->user_data((void*)(this)); - { Fl_Button* o = quit_b = new Fl_Button(190, 405, 85, 25, "Quit"); + { Fl_Button* o = quit_b = new Fl_Button(360, 405, 85, 25, "Quit"); o->callback((Fl_Callback*)cb_quit_b); } { Fl_Button* o = source_b = new Fl_Button(5, 5, 225, 25, "Select Scenery Source ..."); @@ -68,6 +68,10 @@ FGAdminUI::FGAdminUI() { o->labelfont(1); o->callback((Fl_Callback*)cb_remove_b); } + { Fl_Progress* o = progress = new Fl_Progress(20, 405, 195, 25); + o->color(FL_BACKGROUND_COLOR); + o->selection_color((Fl_Color)175); + } o->end(); } } diff --git a/utils/fgadmin/src/fgadmin.fl b/utils/fgadmin/src/fgadmin.fl index 536bd5200..afb2b62fc 100644 --- a/utils/fgadmin/src/fgadmin.fl +++ b/utils/fgadmin/src/fgadmin.fl @@ -11,7 +11,7 @@ decl {\#include } {public decl {using std::string;} {public } -class FGAdminUI {open selected +class FGAdminUI {open } { decl {\#include } {} decl {using std::cout;} {} @@ -20,12 +20,12 @@ class FGAdminUI {open selected } { Fl_Window main_window { label {FlightGear Admin Wizard} open - xywh {187 544 465 435} type Double visible + xywh {294 195 465 435} type Double visible } { Fl_Button quit_b { label Quit callback {quit();} - xywh {190 405 85 25} + xywh {360 405 85 25} } Fl_Button source_b { label {Select Scenery Source ...} @@ -63,6 +63,9 @@ refresh_lists();} callback {remove_selected();} xywh {250 360 195 35} labelfont 1 } + Fl_Progress progress {selected + xywh {20 405 195 25} color 49 selection_color 175 + } } } decl {~FGAdminUI();} {public @@ -71,6 +74,8 @@ refresh_lists();} } decl {void show();} {public } + decl {static void step( void * );} {public + } decl {void refresh_lists();} {} decl {void quit();} {} decl {void select_install_source();} {} diff --git a/utils/fgadmin/src/fgadmin.h b/utils/fgadmin/src/fgadmin.h index 821e2be5f..42926f263 100644 --- a/utils/fgadmin/src/fgadmin.h +++ b/utils/fgadmin/src/fgadmin.h @@ -10,6 +10,7 @@ using std::string; #include #include #include +#include class FGAdminUI { public: @@ -44,9 +45,11 @@ private: inline void cb_remove_b_i(Fl_Button*, void*); static void cb_remove_b(Fl_Button*, void*); public: + Fl_Progress *progress; ~FGAdminUI(); void init(); void show(); + static void step( void * ); private: void refresh_lists(); void quit(); diff --git a/utils/fgadmin/src/fgadmin_funcs.cxx b/utils/fgadmin/src/fgadmin_funcs.cxx index d17d7fd22..735a86f32 100644 --- a/utils/fgadmin/src/fgadmin_funcs.cxx +++ b/utils/fgadmin/src/fgadmin_funcs.cxx @@ -42,6 +42,8 @@ using std::endl; using std::vector; using std::string; +static const float min_progress = 0.0; +static const float max_progress = 5000.0; // destructor FGAdminUI::~FGAdminUI() { @@ -64,6 +66,9 @@ void FGAdminUI::init() { dest = buf; refresh_lists(); + + progress->minimum( min_progress ); + progress->maximum( max_progress ); } // show our UI @@ -180,6 +185,8 @@ void FGAdminUI::update_install_box() { } delete [] sort_list; + + install_box->redraw(); } } @@ -196,7 +203,13 @@ void FGAdminUI::update_remove_box() { ulDir *dir = ulOpenDir( dest.c_str() ) ; ulDirEnt *ent; while ( ent = ulReadDir( dir ) ) { - if ( strcmp(ent->d_name, ".") && strcmp(ent->d_name, "..") ) { + if ( strlen(ent->d_name) != 7 ) { + // simple heuristic to ingore non-scenery directories + } else if ( ent->d_name[0] != 'e' && ent->d_name[0] != 'w' ) { + // further sanity checks on name + } else if ( ent->d_name[4] != 'n' && ent->d_name[4] != 's' ) { + // further sanity checks on name + } else { dir_list.push_back( ent->d_name ); } } @@ -216,6 +229,8 @@ void FGAdminUI::update_remove_box() { } delete [] sort_list; + + remove_box->redraw(); } } @@ -224,6 +239,9 @@ void FGAdminUI::update_remove_box() { void FGAdminUI::install_selected() { char *f; + install_b->deactivate(); + remove_b->deactivate(); + // traverse install box and install each item for ( int i = 0; i <= install_box->nitems(); ++i ) { if ( install_box->checked( i ) ) { @@ -231,15 +249,21 @@ void FGAdminUI::install_selected() { SGPath file( source ); file.append( f ); cout << "installing " << file.str() << endl; - tarextract( (char *)file.c_str(), (char *)dest.c_str(), true, 0 ); + progress->value( min_progress ); + main_window->cursor( FL_CURSOR_WAIT ); + tarextract( (char *)file.c_str(), (char *)dest.c_str(), true, &FGAdminUI::step, this ); + progress->value( min_progress ); + main_window->cursor( FL_CURSOR_DEFAULT ); } } + install_b->activate(); + remove_b->activate(); refresh_lists(); } -static void remove_dir( const char *dir_name ) { +static void remove_dir( const char *dir_name, void (*step)(void*), void *data ) { ulDir *dir = ulOpenDir( dir_name ) ; ulDirEnt *ent; while ( ent = ulReadDir( dir ) ) { @@ -250,11 +274,12 @@ static void remove_dir( const char *dir_name ) { } else if ( ent->d_isdir ) { SGPath child( dir_name ); child.append( ent->d_name ); - remove_dir( child.c_str() ); + remove_dir( child.c_str(), step, data ); } else { SGPath child( dir_name ); child.append( ent->d_name ); unlink( child.c_str() ); + if (step) step( data ); } } ulCloseDir( dir ); @@ -266,17 +291,42 @@ static void remove_dir( const char *dir_name ) { void FGAdminUI::remove_selected() { char *f; + install_b->deactivate(); + remove_b->deactivate(); // traverse remove box and recursively remove each item for ( int i = 0; i <= remove_box->nitems(); ++i ) { if ( remove_box->checked( i ) ) { f = remove_box->text( i ); SGPath dir( dest ); dir.append( f ); + progress->value( min_progress ); + main_window->cursor( FL_CURSOR_WAIT ); cout << "removing " << dir.str() << endl; - remove_dir( dir.c_str() ); + remove_dir( dir.c_str(), &FGAdminUI::step, this ); + progress->value( min_progress ); + main_window->cursor( FL_CURSOR_DEFAULT ); } } + install_b->activate(); + remove_b->activate(); refresh_lists(); } + + +void FGAdminUI::step(void *data) +{ + Fl_Progress *p = ((FGAdminUI*)data)->progress; + + // we don't actually know the total work in advanced due to the + // nature of tar archives, and it would be inefficient to prescan + // the files, so just cycle the progress bar until we are done. + float tmp = p->value() + 1; + if ( tmp > max_progress ) { + tmp = 0.0; + } + p->value( tmp ); + + Fl::check(); +} diff --git a/utils/fgadmin/src/untarka.c b/utils/fgadmin/src/untarka.c index a65d1c652..f7f35bd89 100644 --- a/utils/fgadmin/src/untarka.c +++ b/utils/fgadmin/src/untarka.c @@ -1166,7 +1166,7 @@ static int matchname (int arg,int argc,char **argv,char *fname) /* Tar file list or extract */ -static int tar (Readable* rin,int action,int arg,int argc,char **argv, char const* TGZfile, int verbose, void (*step)(void)) { +static int tar (Readable* rin,int action,int arg,int argc,char **argv, char const* TGZfile, int verbose, void (*step)(void *), void *data) { union tar_buffer buffer; int is_tar_ok=0; int len; @@ -1341,7 +1341,7 @@ static int tar (Readable* rin,int action,int arg,int argc,char **argv, char cons outfile = NULL; utime(fname,&settime); #endif - if (step) step(); + if (step) step(data); } } } @@ -1440,7 +1440,7 @@ int main(int argc,char **argv) { case 3: fprintf(stderr, "%s: not a tar file: %s\n", prog, TGZfile); return 1; case 4: fprintf(stderr, "%s: cannot open tar file: %s\n", prog, TGZfile); return 1; } - return tar(&r, action, arg, argc, argv, TGZfile, 1, 0); + return tar(&r, action, arg, argc, argv, TGZfile, 1, 0, 0); default: error("Unknown option!"); } return 0; @@ -1448,7 +1448,7 @@ int main(int argc,char **argv) { #endif void -tarextract(char *TGZfile,char *dest,int verbose, void (*step)(void)) +tarextract(char *TGZfile,char *dest,int verbose, void (*step)(void *), void *data) { Readable r; if (xOpen4Read(&r,TGZfile) == 0) @@ -1459,6 +1459,6 @@ tarextract(char *TGZfile,char *dest,int verbose, void (*step)(void)) chdir( dest ); argv[0] = "fgadmin"; argv[1] = TGZfile; - tar(&r, TGZ_EXTRACT, arg, argc, argv, TGZfile, 0, step); + tar(&r, TGZ_EXTRACT, arg, argc, argv, TGZfile, 0, step, data); } } diff --git a/utils/fgadmin/src/untarka.h b/utils/fgadmin/src/untarka.h index f1ee99b1b..32fd22bfe 100644 --- a/utils/fgadmin/src/untarka.h +++ b/utils/fgadmin/src/untarka.h @@ -7,4 +7,4 @@ using std::string; // extract the specified tar file into the specified destination // directory -extern "C" void tarextract( char *tarfile, char *destdir, int verbose, void (*step)(void) ); +extern "C" void tarextract( char *tarfile, char *destdir, int verbose, void (*step)(void*), void *data ); diff --git a/utils/fgadmin/visualc/fgadmin/fgadmin.vcproj b/utils/fgadmin/visualc/fgadmin/fgadmin.vcproj index 8c6a3f3f8..a565f2c3a 100644 --- a/utils/fgadmin/visualc/fgadmin/fgadmin.vcproj +++ b/utils/fgadmin/visualc/fgadmin/fgadmin.vcproj @@ -66,9 +66,10 @@ Optimization="2" InlineFunctionExpansion="1" OmitFramePointers="TRUE" - PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" + AdditionalIncludeDirectories="..\..\..\..\fltk-1.1.4" + PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;HAVE_ZLIB" StringPooling="TRUE" - RuntimeLibrary="4" + RuntimeLibrary="2" EnableFunctionLevelLinking="TRUE" UsePrecompiledHeader="0" WarningLevel="3" @@ -78,8 +79,10 @@ Name="VCCustomBuildTool"/> + RelativePath="..\..\src\fgadmin.cxx"> + RelativePath="..\..\src\fgadmin_funcs.cxx"> + RelativePath="..\..\src\main.cxx"> + RelativePath="..\..\src\untarka.c"> + RelativePath="..\..\src\fgadmin.h"> + RelativePath="..\..\src\untarka.h"> - -