public inbox for cygwin-apps@cygwin.com
 help / color / mirror / Atom feed
From: Jon Turney <jon.turney@dronecode.org.uk>
To: cygwin-apps@cygwin.com
Cc: Jon Turney <jon.turney@dronecode.org.uk>
Subject: [PATCH setup 03/16] Split GuiParseFeedback out from ini fetcher
Date: Fri,  8 Mar 2024 18:34:22 +0000	[thread overview]
Message-ID: <20240308183440.4263-4-jon.turney@dronecode.org.uk> (raw)
In-Reply-To: <20240308183440.4263-1-jon.turney@dronecode.org.uk>

This will ultimately make it possible to fetch and parse an ini file
without having a GUI.
---
 Makefile.am             |   1 +
 gui/GuiParseFeedback.cc | 139 ++++++++++++++++++++++++++++++++++++++++
 ini.cc                  | 134 ++------------------------------------
 ini.h                   |   2 +
 4 files changed, 149 insertions(+), 127 deletions(-)
 create mode 100644 gui/GuiParseFeedback.cc

diff --git a/Makefile.am b/Makefile.am
index 8a50cb0..82efbd8 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -180,6 +180,7 @@ endif
 	geturl.h \
 	gpg-packet.cc \
 	gpg-packet.h \
+	gui/GuiParseFeedback.cc \
 	ini.cc \
 	ini.h \
 	IniDBBuilder.h \
diff --git a/gui/GuiParseFeedback.cc b/gui/GuiParseFeedback.cc
new file mode 100644
index 0000000..263fae1
--- /dev/null
+++ b/gui/GuiParseFeedback.cc
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2000,2007 Red Hat, Inc.
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+#include "Exception.h"
+#include "IniParseFeedback.h"
+#include "ini.h"
+#include "msg.h"
+#include "resource.h"
+#include "state.h"
+#include "threebar.h"
+
+extern ThreeBarProgressPage Progress;
+
+class GuiParseFeedback : public IniParseFeedback
+{
+public:
+  GuiParseFeedback () : lastpct (0)
+    {
+      Progress.SetText1 (IDS_PROGRESS_PARSING);
+      Progress.SetText2 ("");
+      Progress.SetText3 ("");
+      Progress.SetText4 (IDS_PROGRESS_PROGRESS);
+
+      yyerror_count = 0;
+      yyerror_messages.clear ();
+    }
+  virtual void progress (unsigned long const pos, unsigned long const max)
+    {
+      if (!max)
+        /* length not known or eof */
+        return;
+      if (lastpct == 100)
+        /* rounding down should mean this only ever fires once */
+        lastpct = 0;
+      if (pos * 100 / max > lastpct)
+        {
+          lastpct = pos * 100 / max;
+          /* Log (LOG_BABBLE) << lastpct << "% (" << pos << " of " << max
+            << " bytes of ini file read)" << endLog; */
+        }
+      Progress.SetBar1 (pos, max);
+
+      static char buf[100];
+      sprintf (buf, "%d %%  (%ldk/%ldk)", lastpct, pos/1000, max/1000);
+      Progress.SetText3 (buf);
+    }
+  virtual void iniName (const std::string& name)
+    {
+      Progress.SetText2 (name.c_str ());
+      Progress.SetText3 ("");
+      filename = name;
+    }
+  virtual void babble (const std::string& message)const
+    {
+      Log (LOG_BABBLE) << message << endLog;
+    }
+  virtual void warning (const std::string& message)const
+    {
+      mbox (Progress.GetHWND(), message.c_str (), "Warning", 0);
+    }
+  virtual void note_error(int lineno, const std::string &error)
+    {
+      char tmp[16];
+      sprintf (tmp, "%d", lineno);
+
+      std::string e = filename + " line " + tmp + ": " + error;
+
+      if (!yyerror_messages.empty ())
+        yyerror_messages += "\n";
+
+      yyerror_messages += e;
+      yyerror_count++;
+    }
+  virtual bool has_errors () const
+    {
+      return (yyerror_count > 0);
+    }
+  virtual void show_errors () const
+    {
+      mbox (Progress.GetHWND(), yyerror_messages.c_str (), "Parse Errors", 0);
+    }
+  virtual ~ GuiParseFeedback ()
+    {
+      Progress.SetText2 ("");
+      Progress.SetText3 ("");
+      Progress.SetText4 (IDS_PROGRESS_PACKAGE);
+      Progress.SetBar1 (0);
+    }
+private:
+  unsigned int lastpct;
+  std::string filename;
+  std::string yyerror_messages;
+  int yyerror_count;
+};
+
+static DWORD WINAPI
+do_ini_thread_reflector (void* p)
+{
+  HANDLE *context;
+  context = (HANDLE*)p;
+
+  SetThreadUILanguage(langid);
+
+  try
+  {
+    GuiParseFeedback feedback;
+    bool succeeded = do_ini_thread ((HINSTANCE)context[0], (HWND)context[1], feedback);
+
+    // Tell the progress page that we're done downloading
+    Progress.PostMessageNow (WM_APP_SETUP_INI_DOWNLOAD_COMPLETE, 0, succeeded);
+  }
+  TOPLEVEL_CATCH ((HWND) context[1], "ini");
+
+  ExitThread (0);
+}
+
+static HANDLE context[2];
+
+void
+do_ini (HINSTANCE h, HWND owner)
+{
+  context[0] = h;
+  context[1] = owner;
+
+  DWORD threadID;
+  CreateThread (NULL, 0, do_ini_thread_reflector, context, 0, &threadID);
+}
diff --git a/ini.cc b/ini.cc
index 112a0ad..95c9964 100644
--- a/ini.cc
+++ b/ini.cc
@@ -33,7 +33,6 @@
 #include <process.h>
 
 #include "resource.h"
-#include "state.h"
 #include "geturl.h"
 #include "dialog.h"
 #include "mount.h"
@@ -44,17 +43,13 @@
 #include "io_stream.h"
 #include "io_stream_memory.h"
 
-#include "threebar.h"
-
 #include "getopt++/BoolOption.h"
 #include "IniDBBuilderPackage.h"
 #include "compress.h"
-#include "Exception.h"
+#include "msg.h"
 #include "crypto.h"
 #include "package_db.h"
 
-extern ThreeBarProgressPage Progress;
-
 unsigned int setup_timestamp = 0;
 std::string ini_setup_version;
 // TODO: use C++11x initializer lists instead and drop the literal array
@@ -65,87 +60,6 @@ IniList setup_ext_list (setup_exts,
 static BoolOption NoVerifyOption (false, 'X', "no-verify", IDS_HELPTEXT_NO_VERIFY);
 static BoolOption NoVersionCheckOption (false, '\0', "no-version-check", IDS_HELPTEXT_NO_VERSION_CHECK);
 
-class GuiParseFeedback : public IniParseFeedback
-{
-public:
-  GuiParseFeedback () : lastpct (0)
-    {
-      Progress.SetText1 (IDS_PROGRESS_PARSING);
-      Progress.SetText2 ("");
-      Progress.SetText3 ("");
-      Progress.SetText4 (IDS_PROGRESS_PROGRESS);
-
-      yyerror_count = 0;
-      yyerror_messages.clear ();
-    }
-  virtual void progress (unsigned long const pos, unsigned long const max)
-    {
-      if (!max)
-	/* length not known or eof */
-	return;
-      if (lastpct == 100)
-	/* rounding down should mean this only ever fires once */
-	lastpct = 0;
-      if (pos * 100 / max > lastpct)
-	{
-	  lastpct = pos * 100 / max;
-	  /* Log (LOG_BABBLE) << lastpct << "% (" << pos << " of " << max
-	    << " bytes of ini file read)" << endLog; */
-	}
-      Progress.SetBar1 (pos, max);
-
-      static char buf[100];
-      sprintf (buf, "%d %%  (%ldk/%ldk)", lastpct, pos/1000, max/1000);
-      Progress.SetText3 (buf);
-    }
-  virtual void iniName (const std::string& name)
-    {
-      Progress.SetText2 (name.c_str ());
-      Progress.SetText3 ("");
-      filename = name;
-    }
-  virtual void babble (const std::string& message)const
-    {
-      Log (LOG_BABBLE) << message << endLog;
-    }
-  virtual void warning (const std::string& message)const
-    {
-      mbox (Progress.GetHWND(), message.c_str (), "Warning", 0);
-    }
-  virtual void note_error(int lineno, const std::string &error)
-    {
-      char tmp[16];
-      sprintf (tmp, "%d", lineno);
-
-      std::string e = filename + " line " + tmp + ": " + error;
-
-      if (!yyerror_messages.empty ())
-        yyerror_messages += "\n";
-
-      yyerror_messages += e;
-      yyerror_count++;
-    }
-  virtual bool has_errors () const
-    {
-      return (yyerror_count > 0);
-    }
-  virtual void show_errors () const
-    {
-      mbox (Progress.GetHWND(), yyerror_messages.c_str (), "Parse Errors", 0);
-    }
-  virtual ~ GuiParseFeedback ()
-    {
-      Progress.SetText2 ("");
-      Progress.SetText3 ("");
-      Progress.SetText4 (IDS_PROGRESS_PACKAGE);
-      Progress.SetBar1 (0);
-    }
-private:
-  unsigned int lastpct;
-  std::string filename;
-  std::string yyerror_messages;
-  int yyerror_count;
-};
 
 static io_stream*
 decompress_ini (io_stream *ini_file, std::string &current_ini_name)
@@ -231,7 +145,7 @@ check_ini_sig (io_stream* ini_file, io_stream* ini_sig_file,
 }
 
 static bool
-do_local_ini (HWND owner)
+do_local_ini (HWND owner, IniParseFeedback &myFeedback)
 {
   bool ini_error = false;
   io_stream *ini_file, *ini_sig_file;
@@ -239,7 +153,6 @@ do_local_ini (HWND owner)
   for (IniList::const_iterator n = found_ini_list.begin ();
        n != found_ini_list.end (); ++n)
     {
-      GuiParseFeedback myFeedback;
       IniDBBuilderPackage aBuilder (myFeedback);
       bool sig_fail = false;
       std::string current_ini_ext, current_ini_name, current_ini_sig_name;
@@ -290,7 +203,7 @@ do_local_ini (HWND owner)
 }
 
 static bool
-do_remote_ini (HWND owner)
+do_remote_ini (HWND owner, IniParseFeedback &myFeedback)
 {
   bool ini_error = false;
   io_stream *ini_file = NULL, *ini_sig_file;
@@ -302,7 +215,6 @@ do_remote_ini (HWND owner)
   for (SiteList::const_iterator n = site_list.begin ();
        n != site_list.end (); ++n)
     {
-      GuiParseFeedback myFeedback;
       IniDBBuilderPackage aBuilder (myFeedback);
       bool sig_fail = false;
       std::string current_ini_ext, current_ini_name, current_ini_sig_name;
@@ -369,8 +281,8 @@ do_remote_ini (HWND owner)
   return ini_error;
 }
 
-static bool
-do_ini_thread (HINSTANCE h, HWND owner)
+bool
+do_ini_thread (HINSTANCE h, HWND owner, IniParseFeedback &feedback)
 {
   packagedb db;
   db.init();
@@ -378,9 +290,9 @@ do_ini_thread (HINSTANCE h, HWND owner)
   bool ini_error = true;
 
   if (source == IDC_SOURCE_LOCALDIR)
-    ini_error = do_local_ini (owner);
+    ini_error = do_local_ini (owner, feedback);
   else
-    ini_error = do_remote_ini (owner);
+    ini_error = do_remote_ini (owner, feedback);
 
   if (ini_error)
     return false;
@@ -434,35 +346,3 @@ do_ini_thread (HINSTANCE h, HWND owner)
 
   return true;
 }
-
-static DWORD WINAPI
-do_ini_thread_reflector (void* p)
-{
-  HANDLE *context;
-  context = (HANDLE*)p;
-
-  SetThreadUILanguage(langid);
-
-  try
-  {
-    bool succeeded = do_ini_thread ((HINSTANCE)context[0], (HWND)context[1]);
-
-    // Tell the progress page that we're done downloading
-    Progress.PostMessageNow (WM_APP_SETUP_INI_DOWNLOAD_COMPLETE, 0, succeeded);
-  }
-  TOPLEVEL_CATCH ((HWND) context[1], "ini");
-
-  ExitThread (0);
-}
-
-static HANDLE context[2];
-
-void
-do_ini (HINSTANCE h, HWND owner)
-{
-  context[0] = h;
-  context[1] = owner;
-
-  DWORD threadID;
-  CreateThread (NULL, 0, do_ini_thread_reflector, context, 0, &threadID);
-}
diff --git a/ini.h b/ini.h
index 4088968..6b24211 100644
--- a/ini.h
+++ b/ini.h
@@ -16,6 +16,7 @@
 #ifndef SETUP_INI_H
 #define SETUP_INI_H
 
+#include "win32.h"
 #include <string>
 #include <vector>
 
@@ -32,6 +33,7 @@ class io_stream;
 class IniDBBuilder;
 class IniParseFeedback;
 void ini_init (io_stream *, IniDBBuilder *, IniParseFeedback &);
+bool do_ini_thread (HINSTANCE h, HWND owner, IniParseFeedback &feedback);
 
 #define YYSTYPE char *
 
-- 
2.43.0


  parent reply	other threads:[~2024-03-08 18:35 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-08 18:34 [PATCH setup 00/16] Groundwork for a GUI-less installation tool Jon Turney
2024-03-08 18:34 ` [PATCH setup 01/16] Drop forward declaration of non-existent class IniState Jon Turney
2024-03-08 18:34 ` [PATCH setup 02/16] Move setup_exts[] to the only place it's used Jon Turney
2024-03-08 18:34 ` Jon Turney [this message]
2024-03-08 18:34 ` [PATCH setup 04/16] Split out site into SiteSettings and SitePage Jon Turney
2024-03-08 18:34 ` [PATCH setup 05/16] Don't call Antivirus::AtExit() directly from Logger::exit() Jon Turney
2024-03-08 18:34 ` [PATCH setup 06/16] Simplify invocation of UserSettings::open_settings() Jon Turney
2024-03-08 18:34 ` [PATCH setup 07/16] Split out URL fetching progress reporting Jon Turney
2024-03-08 18:34 ` [PATCH setup 08/16] Instantiate found_ini_list in ini.cc Jon Turney
2024-03-08 18:34 ` [PATCH setup 09/16] Move is_64bit to state Jon Turney
2024-03-08 18:34 ` [PATCH setup 10/16] Move setup.ini pathame components to ini.cc Jon Turney
2024-03-08 18:34 ` [PATCH setup 11/16] Drop hinstance global Jon Turney
2024-03-08 18:34 ` [PATCH setup 12/16] Spit out GetNetAuth from NetIO Jon Turney
2024-03-08 18:34 ` [PATCH setup 13/16] Split out hash checking progress reporting Jon Turney
2024-03-08 18:34 ` [PATCH setup 14/16] Push check_for_cached into package_source Jon Turney
2024-03-08 18:34 ` [PATCH setup 15/16] Put various shared subcomponents into a convenience library Jon Turney
2024-03-08 18:34 ` [PATCH setup 16/16] Add beginnings of a command line installation tool Jon Turney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240308183440.4263-4-jon.turney@dronecode.org.uk \
    --to=jon.turney@dronecode.org.uk \
    --cc=cygwin-apps@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).