1
0
Fork 0

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.
This commit is contained in:
curt 2004-02-16 14:08:20 +00:00
parent 2985caa09b
commit 2513d06633
7 changed files with 88 additions and 27 deletions

View file

@ -47,7 +47,7 @@ FGAdminUI::FGAdminUI() {
{ Fl_Double_Window* o = main_window = new Fl_Double_Window(465, 435, "FlightGear Admin Wizard"); { Fl_Double_Window* o = main_window = new Fl_Double_Window(465, 435, "FlightGear Admin Wizard");
w = o; w = o;
o->user_data((void*)(this)); 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); o->callback((Fl_Callback*)cb_quit_b);
} }
{ Fl_Button* o = source_b = new Fl_Button(5, 5, 225, 25, "Select Scenery Source ..."); { 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->labelfont(1);
o->callback((Fl_Callback*)cb_remove_b); 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(); o->end();
} }
} }

View file

@ -11,7 +11,7 @@ decl {\#include <FL/Fl_Preferences.H>} {public
decl {using std::string;} {public decl {using std::string;} {public
} }
class FGAdminUI {open selected class FGAdminUI {open
} { } {
decl {\#include <iostream>} {} decl {\#include <iostream>} {}
decl {using std::cout;} {} decl {using std::cout;} {}
@ -20,12 +20,12 @@ class FGAdminUI {open selected
} { } {
Fl_Window main_window { Fl_Window main_window {
label {FlightGear Admin Wizard} open 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 { Fl_Button quit_b {
label Quit label Quit
callback {quit();} callback {quit();}
xywh {190 405 85 25} xywh {360 405 85 25}
} }
Fl_Button source_b { Fl_Button source_b {
label {Select Scenery Source ...} label {Select Scenery Source ...}
@ -63,6 +63,9 @@ refresh_lists();}
callback {remove_selected();} callback {remove_selected();}
xywh {250 360 195 35} labelfont 1 xywh {250 360 195 35} labelfont 1
} }
Fl_Progress progress {selected
xywh {20 405 195 25} color 49 selection_color 175
}
} }
} }
decl {~FGAdminUI();} {public decl {~FGAdminUI();} {public
@ -71,6 +74,8 @@ refresh_lists();}
} }
decl {void show();} {public decl {void show();} {public
} }
decl {static void step( void * );} {public
}
decl {void refresh_lists();} {} decl {void refresh_lists();} {}
decl {void quit();} {} decl {void quit();} {}
decl {void select_install_source();} {} decl {void select_install_source();} {}

View file

@ -10,6 +10,7 @@ using std::string;
#include <FL/Fl_Button.H> #include <FL/Fl_Button.H>
#include <FL/Fl_Input.H> #include <FL/Fl_Input.H>
#include <FL/Fl_Check_Browser.H> #include <FL/Fl_Check_Browser.H>
#include <FL/Fl_Progress.H>
class FGAdminUI { class FGAdminUI {
public: public:
@ -44,9 +45,11 @@ private:
inline void cb_remove_b_i(Fl_Button*, void*); inline void cb_remove_b_i(Fl_Button*, void*);
static void cb_remove_b(Fl_Button*, void*); static void cb_remove_b(Fl_Button*, void*);
public: public:
Fl_Progress *progress;
~FGAdminUI(); ~FGAdminUI();
void init(); void init();
void show(); void show();
static void step( void * );
private: private:
void refresh_lists(); void refresh_lists();
void quit(); void quit();

View file

@ -42,6 +42,8 @@ using std::endl;
using std::vector; using std::vector;
using std::string; using std::string;
static const float min_progress = 0.0;
static const float max_progress = 5000.0;
// destructor // destructor
FGAdminUI::~FGAdminUI() { FGAdminUI::~FGAdminUI() {
@ -64,6 +66,9 @@ void FGAdminUI::init() {
dest = buf; dest = buf;
refresh_lists(); refresh_lists();
progress->minimum( min_progress );
progress->maximum( max_progress );
} }
// show our UI // show our UI
@ -180,6 +185,8 @@ void FGAdminUI::update_install_box() {
} }
delete [] sort_list; delete [] sort_list;
install_box->redraw();
} }
} }
@ -196,7 +203,13 @@ void FGAdminUI::update_remove_box() {
ulDir *dir = ulOpenDir( dest.c_str() ) ; ulDir *dir = ulOpenDir( dest.c_str() ) ;
ulDirEnt *ent; ulDirEnt *ent;
while ( ent = ulReadDir( dir ) ) { 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 ); dir_list.push_back( ent->d_name );
} }
} }
@ -216,6 +229,8 @@ void FGAdminUI::update_remove_box() {
} }
delete [] sort_list; delete [] sort_list;
remove_box->redraw();
} }
} }
@ -224,6 +239,9 @@ void FGAdminUI::update_remove_box() {
void FGAdminUI::install_selected() { void FGAdminUI::install_selected() {
char *f; char *f;
install_b->deactivate();
remove_b->deactivate();
// traverse install box and install each item // traverse install box and install each item
for ( int i = 0; i <= install_box->nitems(); ++i ) { for ( int i = 0; i <= install_box->nitems(); ++i ) {
if ( install_box->checked( i ) ) { if ( install_box->checked( i ) ) {
@ -231,15 +249,21 @@ void FGAdminUI::install_selected() {
SGPath file( source ); SGPath file( source );
file.append( f ); file.append( f );
cout << "installing " << file.str() << endl; 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(); 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 ) ; ulDir *dir = ulOpenDir( dir_name ) ;
ulDirEnt *ent; ulDirEnt *ent;
while ( ent = ulReadDir( dir ) ) { while ( ent = ulReadDir( dir ) ) {
@ -250,11 +274,12 @@ static void remove_dir( const char *dir_name ) {
} else if ( ent->d_isdir ) { } else if ( ent->d_isdir ) {
SGPath child( dir_name ); SGPath child( dir_name );
child.append( ent->d_name ); child.append( ent->d_name );
remove_dir( child.c_str() ); remove_dir( child.c_str(), step, data );
} else { } else {
SGPath child( dir_name ); SGPath child( dir_name );
child.append( ent->d_name ); child.append( ent->d_name );
unlink( child.c_str() ); unlink( child.c_str() );
if (step) step( data );
} }
} }
ulCloseDir( dir ); ulCloseDir( dir );
@ -266,17 +291,42 @@ static void remove_dir( const char *dir_name ) {
void FGAdminUI::remove_selected() { void FGAdminUI::remove_selected() {
char *f; char *f;
install_b->deactivate();
remove_b->deactivate();
// traverse remove box and recursively remove each item // traverse remove box and recursively remove each item
for ( int i = 0; i <= remove_box->nitems(); ++i ) { for ( int i = 0; i <= remove_box->nitems(); ++i ) {
if ( remove_box->checked( i ) ) { if ( remove_box->checked( i ) ) {
f = remove_box->text( i ); f = remove_box->text( i );
SGPath dir( dest ); SGPath dir( dest );
dir.append( f ); dir.append( f );
progress->value( min_progress );
main_window->cursor( FL_CURSOR_WAIT );
cout << "removing " << dir.str() << endl; 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(); 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();
}

View file

@ -1166,7 +1166,7 @@ static int matchname (int arg,int argc,char **argv,char *fname)
/* Tar file list or extract */ /* 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; union tar_buffer buffer;
int is_tar_ok=0; int is_tar_ok=0;
int len; int len;
@ -1341,7 +1341,7 @@ static int tar (Readable* rin,int action,int arg,int argc,char **argv, char cons
outfile = NULL; outfile = NULL;
utime(fname,&settime); utime(fname,&settime);
#endif #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 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; 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!"); default: error("Unknown option!");
} }
return 0; return 0;
@ -1448,7 +1448,7 @@ int main(int argc,char **argv) {
#endif #endif
void 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; Readable r;
if (xOpen4Read(&r,TGZfile) == 0) if (xOpen4Read(&r,TGZfile) == 0)
@ -1459,6 +1459,6 @@ tarextract(char *TGZfile,char *dest,int verbose, void (*step)(void))
chdir( dest ); chdir( dest );
argv[0] = "fgadmin"; argv[0] = "fgadmin";
argv[1] = TGZfile; argv[1] = TGZfile;
tar(&r, TGZ_EXTRACT, arg, argc, argv, TGZfile, 0, step); tar(&r, TGZ_EXTRACT, arg, argc, argv, TGZfile, 0, step, data);
} }
} }

View file

@ -7,4 +7,4 @@ using std::string;
// extract the specified tar file into the specified destination // extract the specified tar file into the specified destination
// directory // 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 );

View file

@ -66,9 +66,10 @@
Optimization="2" Optimization="2"
InlineFunctionExpansion="1" InlineFunctionExpansion="1"
OmitFramePointers="TRUE" OmitFramePointers="TRUE"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" AdditionalIncludeDirectories="..\..\..\..\fltk-1.1.4"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;HAVE_ZLIB"
StringPooling="TRUE" StringPooling="TRUE"
RuntimeLibrary="4" RuntimeLibrary="2"
EnableFunctionLevelLinking="TRUE" EnableFunctionLevelLinking="TRUE"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
WarningLevel="3" WarningLevel="3"
@ -78,8 +79,10 @@
Name="VCCustomBuildTool"/> Name="VCCustomBuildTool"/>
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="fltk.lib Simgear.lib ul.lib comctl32.lib wsock32.lib zlib.lib"
OutputFile="$(OutDir)/fgadmin.exe" OutputFile="$(OutDir)/fgadmin.exe"
LinkIncremental="1" LinkIncremental="1"
AdditionalLibraryDirectories="&quot;..\..\..\..\fltk-1.1.4\lib&quot;"
GenerateDebugInformation="TRUE" GenerateDebugInformation="TRUE"
SubSystem="1" SubSystem="1"
OptimizeReferences="2" OptimizeReferences="2"
@ -106,32 +109,28 @@
Name="Source Files" Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm"> Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
<File <File
RelativePath="..\..\..\src\fgadmin.cxx"> RelativePath="..\..\src\fgadmin.cxx">
</File> </File>
<File <File
RelativePath="..\..\..\src\fgadmin_funcs.cxx"> RelativePath="..\..\src\fgadmin_funcs.cxx">
</File> </File>
<File <File
RelativePath="..\..\..\src\main.cxx"> RelativePath="..\..\src\main.cxx">
</File> </File>
<File <File
RelativePath="..\..\..\src\untarka.c"> RelativePath="..\..\src\untarka.c">
</File> </File>
</Filter> </Filter>
<Filter <Filter
Name="Header Files" Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc"> Filter="h;hpp;hxx;hm;inl;inc">
<File <File
RelativePath="..\..\..\src\fgadmin.h"> RelativePath="..\..\src\fgadmin.h">
</File> </File>
<File <File
RelativePath="..\..\..\src\tar_utils.hxx"> RelativePath="..\..\src\untarka.h">
</File> </File>
</Filter> </Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
</Filter>
</Files> </Files>
<Globals> <Globals>
</Globals> </Globals>