From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from re-prd-fep-045.btinternet.com (mailomta21-re.btinternet.com [213.120.69.114]) by sourceware.org (Postfix) with ESMTPS id 36EDB385E009 for ; Fri, 8 Mar 2024 18:35:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 36EDB385E009 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=dronecode.org.uk Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=dronecode.org.uk ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 36EDB385E009 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=213.120.69.114 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709922923; cv=none; b=XZeT9bKeIcU5nJjZ9eIPfaXHWQ846t3oQ3wB0ANLDf+bT28NltipQKMqheBQmMvGkm6XY37SKMrjQfk5UY6esaCsfHfOuBAaA3dslflGI8nPg/cwNESsY1gqmooa755PnyMw7q7SGCZKOdIUyLoLdZB+9FNFbTbv/pRsVFam+z4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709922923; c=relaxed/simple; bh=Ip7xOhoTqbQFo6ieYdvOhMCCXDMvItMJkpOKXvmOifY=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=EmLjEBKAUat/t1I3q/lQBsjRWiCP4Die0y9hBCPNByVx0cFt4+2OOUdC1P2GnyfFfcIcJlwzHs1r56bB5yCsib91Q2+KChLFiq2Gvk1yDehovG+7CXsDk5U4Ha2L+/gY4Sub2oWHb69zwxkA87S9Khqe+hHMwt8r6ssZsLJCqTI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from re-prd-rgout-004.btmx-prd.synchronoss.net ([10.2.54.7]) by re-prd-fep-045.btinternet.com with ESMTP id <20240308183519.TNWG21611.re-prd-fep-045.btinternet.com@re-prd-rgout-004.btmx-prd.synchronoss.net>; Fri, 8 Mar 2024 18:35:19 +0000 Authentication-Results: btinternet.com; none X-SNCR-Rigid: 6577B87C0AB0648C X-Originating-IP: [81.153.98.185] X-OWM-Source-IP: 81.153.98.185 X-OWM-Env-Sender: jon.turney@dronecode.org.uk X-VadeSecure-score: verdict=clean score=0/300, class=clean X-RazorGate-Vade: gggruggvucftvghtrhhoucdtuddrgedvledrieehgdduudegucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuueftkffvkffujffvgffngfevqffopdfqfgfvnecuuegrihhlohhuthemuceftddunecunecujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomheplfhonhcuvfhurhhnvgihuceojhhonhdrthhurhhnvgihsegurhhonhgvtghouggvrdhorhhgrdhukheqnecuggftrfgrthhtvghrnhepudevleegtdduudeltedugeeuhefgteegkeeuhfeukeetkeduteekvdfgiefguddvnecuffhomhgrihhnpehgnhhurdhorhhgnecukfhppeekuddrudehfedrleekrddukeehnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehhvghloheplhhotggrlhhhohhsthdrlhhotggrlhguohhmrghinhdpihhnvghtpeekuddrudehfedrleekrddukeehpdhmrghilhhfrhhomhepjhhonhdrthhurhhnvgihsegurhhonhgvtghouggvrdhorhhgrdhukhdpnhgspghrtghpthhtohepvddprhgtphhtthhopegthihgfihinhdqrghpphhssegthihgfihinhdrtghomhdprhgtphhtthhopehjohhnrdhtuhhrnhgvhiesughrohhnvggtohguvgdrohhrghdruhhkpdhrvghvkffrpehhohhsthekuddqudehfedqleekqddukeehrdhrrghnghgvkeduqdduheefrdgsthgtvghnthhrrghlphhluhhsrdgtohhmpdgruhhthhgpuhhsvghrpehjohhnthhurhhnvgihsegsthhi nhhtvghrnhgvthdrtghomhdpghgvohfkrfepifeupdfovfetjfhoshhtpehrvgdqphhrugdqrhhgohhuthdqtddtge X-RazorGate-Vade-Verdict: clean 0 X-RazorGate-Vade-Classification: clean Received: from localhost.localdomain (81.153.98.185) by re-prd-rgout-004.btmx-prd.synchronoss.net (authenticated as jonturney@btinternet.com) id 6577B87C0AB0648C; Fri, 8 Mar 2024 18:35:19 +0000 From: Jon Turney To: cygwin-apps@cygwin.com Cc: Jon Turney Subject: [PATCH setup 03/16] Split GuiParseFeedback out from ini fetcher Date: Fri, 8 Mar 2024 18:34:22 +0000 Message-ID: <20240308183440.4263-4-jon.turney@dronecode.org.uk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240308183440.4263-1-jon.turney@dronecode.org.uk> References: <20240308183440.4263-1-jon.turney@dronecode.org.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 + * + */ + +#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 #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 ¤t_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 #include @@ -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