On Wed, 19 Mar 2003, Igor Pechtchanski wrote:

> This is a preliminary patch that runs postinstall scripts in a thread and
> updates the progress bars accordingly.  Some parts of it are pretty raw,
> and I've hacked up some stuff using existing functionality, as I didn't
> want to change some class interfaces.  It works, but is open to design
> suggestions.  I would especially like feedback from people who grok the
> PropSheet sequencing code.
>         Igor
> ==============================================================================
> ChangeLog:
> 2003-03-19  Igor Pechtchanski <[EMAIL PROTECTED]>
>
>         * threebar.h (WM_APP_START_POSTINSTALL): New message.
>         (WM_APP_POSTINSTALL_THREAD_COMPLETE): New message.
>         * threebar.cc (ThreeBarProgressPage::OnMessageApp):
>         Add handling for WM_APP_START_POSTINSTALL and
>         WM_APP_POSTINSTALL_THREAD_COMPLETE.
>         * install.cc (do_install_reflector): Add message
>         parameter.
>         (do_install_thread): Remove next_dialog.
>         * desktop.cc (DesktopSetupPage::OnFinish): Move the
>         do_postinstall call to ThreeBarProgressPage::OnMessageApp.
>         * postinstall.cc (Progress): New extern variable.
>         (numscr,s): New static variables.
>         (RunFindVisitor::visitFile): Add Progress bar and text
>         setting.
>         (CountFindVisitor): New class.
>         (do_postinstall_thread): Rename do_postinstall to.  Add
>         Progress bar and text setting.  Add package count.
>         (do_postinstall_reflector): New static function.
>         (do_postinstall): Rename to do_postinstall_thread.
>         Create a thread instead.

Same as above, but regenerated against HEAD.  ChangeLog is the same.
The only thing about this patch that really makes me uncomfortable is
having to run through iterators/FindVisitors twice.  Any suggestions for
improvement are welcome.
        Igor
-- 
                                http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_                [EMAIL PROTECTED]
ZZZzz /,`.-'`'    -.  ;-;;,_            [EMAIL PROTECTED]
     |,4-  ) )-,_. ,\ (  `'-'           Igor Pechtchanski
    '---''(_/--'  `-'\_) fL     a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

Oh, boy, virtual memory! Now I'm gonna make myself a really *big* RAMdisk!
  -- /usr/games/fortune
Index: desktop.cc
===================================================================
RCS file: /cvs/cygwin-apps/setup/desktop.cc,v
retrieving revision 2.34
diff -u -p -r2.34 desktop.cc
--- desktop.cc  25 Nov 2002 22:12:08 -0000      2.34
+++ desktop.cc  19 Mar 2003 23:05:40 -0000
@@ -397,8 +397,6 @@ DesktopSetupPage::OnFinish ()
   HWND h = GetHWND ();
   save_dialog (h);
   do_desktop_setup ();
-  NEXT (IDD_S_POSTINSTALL);
-  do_postinstall (GetInstance (), h);
 
   return true;
 }
Index: install.cc
===================================================================
RCS file: /cvs/cygwin-apps/setup/install.cc,v
retrieving revision 2.60
diff -u -p -r2.60 install.cc
--- install.cc  17 Mar 2003 22:23:33 -0000      2.60
+++ install.cc  19 Mar 2003 23:05:40 -0000
@@ -455,8 +455,6 @@ do_install_thread (HINSTANCE h, HWND own
   num_installs = 0, num_uninstalls = 0, num_replacements = 0;
   rebootneeded = false;
 
-  next_dialog = IDD_DESKTOP;
-
   io_stream::mkpath_p (PATH_TO_DIR, String ("file://") + get_root_dir ());
 
   for (i = 0; Installer::StandardDirs[i]; i++)
@@ -634,7 +632,7 @@ do_install_reflector (void *p)
   do_install_thread ((HINSTANCE) context[0], (HWND) context[1]);
 
   // Tell the progress page that we're done downloading
-  Progress.PostMessage (WM_APP_INSTALL_THREAD_COMPLETE);
+  Progress.PostMessage (WM_APP_INSTALL_THREAD_COMPLETE, 0, IDD_S_POSTINSTALL);
 
   ExitThread (0);
 }
Index: postinstall.cc
===================================================================
RCS file: /cvs/cygwin-apps/setup/postinstall.cc,v
retrieving revision 2.11
diff -u -p -r2.11 postinstall.cc
--- postinstall.cc      18 Mar 2003 22:43:15 -0000      2.11
+++ postinstall.cc      19 Mar 2003 23:05:40 -0000
@@ -29,6 +29,13 @@ static const char *cvsid =
 #include "FilterVisitor.h"
 #include "package_db.h"
 #include "package_meta.h"
+#include "resource.h"
+#include "threebar.h"
+
+extern ThreeBarProgressPage Progress;
+
+static int numscr = 0;
+static int s = 0;
 
 class RunFindVisitor : public FindVisitor
 {
@@ -36,33 +43,115 @@ public:
   RunFindVisitor (){}
   virtual void visitFile(String const &basePath, const WIN32_FIND_DATA *theFile)
     {
+      Progress.SetText3 (theFile->cFileName);
       run_script ("/etc/postinstall/", theFile->cFileName, TRUE);
+      ++s;
+      Progress.SetBar1 (s, numscr);
     }
   virtual ~ RunFindVisitor () {}
 protected:
   RunFindVisitor (RunFindVisitor const &);
   RunFindVisitor & operator= (RunFindVisitor const &);
 };
-  
-void
-do_postinstall (HINSTANCE h, HWND owner)
+
+class CountFindVisitor : public FindVisitor
 {
-  next_dialog = 0;
+public:
+  CountFindVisitor (){}
+  virtual void visitFile(String const &basePath, const WIN32_FIND_DATA *theFile)
+    {
+      ++numscr;
+    }
+  virtual ~ CountFindVisitor () {}
+protected:
+  CountFindVisitor (CountFindVisitor const &);
+  CountFindVisitor & operator= (CountFindVisitor const &);
+};
+
+static void
+do_postinstall_thread (HINSTANCE h, HWND owner)
+{
+  next_dialog = IDD_DESKTOP;
+
+  Progress.SetText1 ("Running...");
+  Progress.SetText2 ("");
+  Progress.SetText3 ("");
+  Progress.SetBar1 (0, 1);
+  Progress.SetBar2 (0, 1);
+
   init_run_script ();
   SetCurrentDirectory (get_root_dir ().cstr_oneuse());
   packagedb db;
+  // Count the packages
+  int numpkg = 1;
   PackageDBConnectedIterator i = db.connectedBegin ();
   while (i != db.connectedEnd ())
     {
+      ++numpkg;
+      ++i;
+    }
+  int k = 0;
+  i = db.connectedBegin ();
+  while (i != db.connectedEnd ())
+    {
       packagemeta & pkg = **i;
       if (pkg.installed)
-       for (std::vector<Script>::iterator script=pkg.installed.scripts().begin(); 
script != pkg.installed.scripts().end(); ++script) 
-         run_script ("/etc/postinstall/", script->baseName(), TRUE);
+       {
+         numscr = pkg.installed.scripts().size();
+         Progress.SetText2 (pkg.name.cstr_oneuse());
+         s = 0;
+         Progress.SetBar1 (s, numscr);
+         for (std::vector<Script>::iterator script=pkg.installed.scripts().begin(); 
script != pkg.installed.scripts().end(); ++script) 
+           {
+             Progress.SetText3 
((String("/etc/postinstall")+script->baseName()).cstr_oneuse());
+             run_script ("/etc/postinstall/", script->baseName(), TRUE);
+             ++s;
+             Progress.SetBar1 (s, numscr);
+           }
+         Progress.SetText3 ("");
+       }
+      ++k;
+      Progress.SetBar2 (k, numpkg);
       ++i;
     }
-  RunFindVisitor myVisitor;
+  Progress.SetText2 ("No package");
   ExcludeNameFilter notDone("*.done");
-  FilterVisitor excludeDoneVisitor(&myVisitor, &notDone);
   String postinst = cygpath ("/etc/postinstall");
+  numscr = 0;
+  CountFindVisitor countEm;
+  FilterVisitor excludeDoneCountVisitor(&countEm, &notDone);
+  Find (postinst).accept (excludeDoneCountVisitor);
+  RunFindVisitor myVisitor;
+  FilterVisitor excludeDoneVisitor(&myVisitor, &notDone);
+  s = 0;
+  Progress.SetBar1 (s, numscr);
   Find (postinst).accept (excludeDoneVisitor);
+  Progress.SetBar2 (numpkg, numpkg);
+}
+
+static DWORD WINAPI
+do_postinstall_reflector (void *p)
+{
+  HANDLE *context;
+  context = (HANDLE *) p;
+
+  do_postinstall_thread ((HINSTANCE) context[0], (HWND) context[1]);
+
+  // Tell the progress page that we're done running scripts
+  Progress.PostMessage (WM_APP_POSTINSTALL_THREAD_COMPLETE);
+
+  ExitThread(0);
 }
+
+static HANDLE context[2];
+
+void
+do_postinstall (HINSTANCE h, HWND owner)
+{
+  context[0] = h;
+  context[1] = owner;
+
+  DWORD threadID;
+  CreateThread (NULL, 0, do_postinstall_reflector, context, 0, &threadID);
+}
+
Index: threebar.cc
===================================================================
RCS file: /cvs/cygwin-apps/setup/threebar.cc,v
retrieving revision 2.4
diff -u -p -r2.4 threebar.cc
--- threebar.cc 26 Jun 2002 21:35:16 -0000      2.4
+++ threebar.cc 19 Mar 2003 23:05:40 -0000
@@ -172,6 +172,18 @@ bool
       }
     case WM_APP_INSTALL_THREAD_COMPLETE:
       {
+       // Install is complete and we want to go on to the postinstall.
+       Window::PostMessage (WM_APP_START_POSTINSTALL);
+       break;
+      }
+    case WM_APP_START_POSTINSTALL:
+      {
+       // Start the postinstall script thread.
+       do_postinstall (GetInstance (), GetHWND ());
+       break;
+      }
+    case WM_APP_POSTINSTALL_THREAD_COMPLETE:
+      {
        // Re-enable and "Push" the Next button
        GetOwner ()->SetButtons (PSWIZB_NEXT);
        GetOwner ()->PressButton (PSBTN_NEXT);
Index: threebar.h
===================================================================
RCS file: /cvs/cygwin-apps/setup/threebar.h,v
retrieving revision 2.4
diff -u -p -r2.4 threebar.h
--- threebar.h  21 Sep 2002 09:36:46 -0000      2.4
+++ threebar.h  19 Mar 2003 23:05:40 -0000
@@ -32,6 +32,8 @@
 #define WM_APP_START_SETUP_INI_DOWNLOAD    WM_APP+6
 #define WM_APP_SETUP_INI_DOWNLOAD_COMPLETE WM_APP+7
 // desktop.h: WM_APP_UNATTENDED_FINISH WM_APP+8
+#define WM_APP_START_POSTINSTALL           WM_APP+9
+#define WM_APP_POSTINSTALL_THREAD_COMPLETE WM_APP+10
 
 class ThreeBarProgressPage:public PropertyPage
 {

Reply via email to