]> cygwin.com Git - cygwin-apps/setup.git/commitdiff
2003-03-25 Igor Pechtchanski <pechtcha@cs.nyu.edu>
authorMax Bowsher <maxb1@ukf.net>
Tue, 25 Mar 2003 20:57:13 +0000 (20:57 +0000)
committerMax Bowsher <maxb1@ukf.net>
Tue, 25 Mar 2003 20:57:13 +0000 (20:57 +0000)
* 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_thread): Set next_dialog to
IDD_S_POSTINSTALL.
* desktop.cc (DesktopSetupPage::OnFinish): Move the
do_postinstall call to ThreeBarProgressPage::OnMessageApp.
* script.h (Script::fullName): New member function.
(Script::run): New member function.
(Script::ETCPostinstall): New static member constant.
* script.cc (Script::fullName): Implement.
(Script::run): Implement.
(Script::ETCPostinstall): Define.
(Script::isAScript): Use ETCPostinstall instead of a
hardcoded string constant.
(run): Enable "#if 0"'d code.
* postinstall.cc (Progress): New extern variable.
(RunFindVisitor::visitFile): Add script to vector
instead of running.
(RunFindVisitor::_scripts): New member variable.
(RunScript): New helper class for use in for_each.
(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.

ChangeLog
desktop.cc
install.cc
postinstall.cc
script.cc
script.h
threebar.cc
threebar.h

index 797c61ff0cb337474ec7f73cb8e4b29ba8d387b3..0670f0f58310553567b9c6fd38db66c4e1a98428 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,34 @@
+2003-03-25  Igor Pechtchanski  <pechtcha@cs.nyu.edu>
+
+       * 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_thread): Set next_dialog to
+       IDD_S_POSTINSTALL.
+       * desktop.cc (DesktopSetupPage::OnFinish): Move the
+       do_postinstall call to ThreeBarProgressPage::OnMessageApp.
+       * script.h (Script::fullName): New member function.
+       (Script::run): New member function.
+       (Script::ETCPostinstall): New static member constant.
+       * script.cc (Script::fullName): Implement.
+       (Script::run): Implement.
+       (Script::ETCPostinstall): Define.
+       (Script::isAScript): Use ETCPostinstall instead of a
+       hardcoded string constant.
+       (run): Enable "#if 0"'d code.
+       * postinstall.cc (Progress): New extern variable.
+       (RunFindVisitor::visitFile): Add script to vector
+       instead of running.
+       (RunFindVisitor::_scripts): New member variable.
+       (RunScript): New helper class for use in for_each.
+       (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.
+
 2003-03-18  Igor Pechtchanski  <pechtcha@cs.nyu.edu>
 
        * script.cc (run): Add file_out parameter.
index 35276624fed3bb6da0fe0a483c9db79651521bfd..d6bc692b360c1cb8dc84fb89fb54bc95354246d5 100644 (file)
@@ -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 def8b207e519634917583ee752cbd4f0cee27983..a33974060ee82d64475a7d83cdedf1705ec36637 100644 (file)
@@ -455,7 +455,7 @@ do_install_thread (HINSTANCE h, HWND owner)
   num_installs = 0, num_uninstalls = 0, num_replacements = 0;
   rebootneeded = false;
 
-  next_dialog = IDD_DESKTOP;
+  next_dialog = IDD_S_POSTINSTALL;
 
   io_stream::mkpath_p (PATH_TO_DIR, String ("file://") + get_root_dir ());
 
index 77636ce900539df7770793be790c453cf7f264ab..ec9b0036ffb1db4a5f3a9603d9b2ba212fcc6dee 100644 (file)
@@ -29,40 +29,124 @@ static const char *cvsid =
 #include "FilterVisitor.h"
 #include "package_db.h"
 #include "package_meta.h"
+#include "resource.h"
+#include "threebar.h"
+
+#include <algorithm>
+
+using namespace std;
+
+extern ThreeBarProgressPage Progress;
 
 class RunFindVisitor : public FindVisitor
 {
 public:
-  RunFindVisitor (){}
+  RunFindVisitor (vector<Script> *scripts) : _scripts(scripts) {}
   virtual void visitFile(String const &basePath, const WIN32_FIND_DATA *theFile)
     {
-      run_script ("/etc/postinstall/", theFile->cFileName, TRUE);
+      String fn = String("/etc/postinstall/")+theFile->cFileName;
+      _scripts->push_back(Script (fn));
     }
   virtual ~ RunFindVisitor () {}
 protected:
   RunFindVisitor (RunFindVisitor const &);
   RunFindVisitor & operator= (RunFindVisitor const &);
+private:
+  vector<Script> *_scripts;
 };
-  
-void
-do_postinstall (HINSTANCE h, HWND owner)
+
+class RunScript : public unary_function<Script const &, void>
 {
-  next_dialog = 0;
+public:
+  RunScript(String const &name, int num) : _num(num), _cnt(0)
+    {
+      Progress.SetText2 (name.cstr_oneuse());
+      Progress.SetBar1 (_cnt, _num);
+    }
+  virtual ~RunScript()
+    {
+      Progress.SetText3 ("");
+    }
+  void operator() (Script const &aScript) 
+    {
+      Progress.SetText3 (aScript.fullName().cstr_oneuse());
+      aScript.run(TRUE);
+      ++_cnt;
+      Progress.SetBar1 (_cnt, _num);
+    }
+private:
+  int _num;
+  int _cnt;
+};
+
+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;
+  vector<packagemeta*> packages;
   PackageDBConnectedIterator 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);
+       packages.push_back(&pkg);
       ++i;
     }
-  RunFindVisitor myVisitor;
+  int numpkg = packages.size() + 1;
+  int k = 0;
+  for (i = packages.begin (); i != packages.end (); ++i)
+    {
+      packagemeta & pkg = **i;
+      for_each (pkg.installed.scripts().begin(), pkg.installed.scripts().end(),
+               RunScript(pkg.name, pkg.installed.scripts().size()));
+      ++k;
+      Progress.SetBar2 (k, numpkg);
+    }
   ExcludeNameFilter notDone("*.done");
-  FilterVisitor excludeDoneVisitor(&myVisitor, &notDone);
   String postinst = cygpath ("/etc/postinstall");
+  vector<Script> scripts;
+  RunFindVisitor myVisitor (&scripts);
+  FilterVisitor excludeDoneVisitor(&myVisitor, &notDone);
+  Progress.SetBar1 (0, 1);
   Find (postinst).accept (excludeDoneVisitor);
+  for_each (scripts.begin(), scripts.end(),
+           RunScript("No package", scripts.size()));
+  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 1652b8fc0b7745135d0866bfb4284970e9515cdc..9e969258832e8c3407bb5b960b0b8b509284e663 100644 (file)
--- a/script.cc
+++ b/script.cc
@@ -182,13 +182,8 @@ run (const char *sh, const char *args, const char *file, OutputLog &file_out)
       si.hStdOutput = file_out.handle ();
       si.hStdError = file_out.handle ();
       si.dwFlags |= STARTF_USESHOWWINDOW;
-#if 0
       si.wShowWindow = SW_HIDE;
-      flags = CREATE_NO_WINDOW;  // Note: might not work on Win9x
-#else
-      // TODO: introduce a script progress tracker and use the above
-      si.wShowWindow = SW_MINIMIZE;
-#endif
+      flags = CREATE_NO_WINDOW;  // Note: this is ignored on Win9x
     }
 
   BOOL createSucceeded = CreateProcess (0, cmdline, 0, 0, inheritHandles,
@@ -250,11 +245,14 @@ try_run_script (String const &dir, String const &fname)
     run_script (dir.cstr_oneuse(), (fname + ".bat").cstr_oneuse());
 }
 
+char const Script::ETCPostinstall[] = "/etc/postinstall/";
+
 bool
 Script::isAScript (String const &file)
 {
     /* file may be /etc/postinstall or etc/postinstall */
-    if (file.casecompare ("/etc/postinstall/", 17) && file.casecompare ("etc/postinstall/", 16))
+    if (file.casecompare (ETCPostinstall, sizeof(ETCPostinstall)) &&
+       file.casecompare (ETCPostinstall+1, sizeof(ETCPostinstall)-1))
       return false;
     if (file.cstr_oneuse()[file.size() - 1] == '/')
       return false;
@@ -267,10 +265,23 @@ Script::Script (String const &fileName) : scriptName (fileName)
 }
 
 String
-Script::baseName()const
+Script::baseName() const
 {
   String result = scriptName;
   while (result.find ('/'))
     result = result.substr(result.find ('/'));
   return result;
 }
+
+String
+Script::fullName() const
+{
+  return scriptName;
+}
+
+void
+Script::run(BOOL to_log) const
+{
+  run_script("", scriptName, to_log);
+}
+
index 717b12512059403a66b3e6994d1fba107cc58feb..de63c2493c1ab9064c1a8d0e1fef0952a30c7af3 100644 (file)
--- a/script.h
+++ b/script.h
@@ -30,12 +30,15 @@ void init_run_script ();
 void try_run_script (String const &dir, String const &fname);
 
 class Script {
-  public:
-    static bool isAScript (String const &file);
-    Script (String const &fileName);
-    String baseName()const;
-  private:
-    String scriptName;
+public:
+  static bool isAScript (String const &file);
+  Script (String const &fileName);
+  String baseName() const;
+  String fullName() const;
+  void run(BOOL to_log = FALSE) const;
+private:
+  String scriptName;
+  static char const ETCPostinstall[];
 };
 
 #endif /* SCRIPT_H */
index 100056c47e400e02b60e73e69a6e7bdf3e22ee9e..183e6a94d4260e4ab3e4d403b389e11c854c8813 100644 (file)
@@ -171,6 +171,18 @@ bool
        break;
       }
     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);
index 0fb104cbcc8cb4b53339a30c454b8191de51e3ca..1b2d1c6a6bf0765b1dc10a89eb29a40e5eb64eaf 100644 (file)
@@ -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
 {
This page took 0.049637 seconds and 5 git commands to generate.