From: Jon Turney Date: Sun, 25 Feb 2024 16:39:16 +0000 (+0000) Subject: Split out hash checking progress reporting X-Git-Tag: release_2.935^0 X-Git-Url: https://www.sourceware.org/git/?a=commitdiff_plain;h=HEAD;p=cygwin-apps%2Fsetup.git Split out hash checking progress reporting --- diff --git a/Feedback.h b/Feedback.h index 8f603a61..4db7c4a1 100644 --- a/Feedback.h +++ b/Feedback.h @@ -47,6 +47,10 @@ public: virtual void fetch_finish (int total_bytes) = 0; virtual void fetch_fatal (const char *filename, const char *err) = 0; + // hash checking + virtual void hash_init (const char *hashalg, const std::string &url) = 0; + virtual void hash_progress (int bytes, int total_bytes) = 0; + // virtual HWND owner () = 0; }; diff --git a/Makefile.am b/Makefile.am index df8ae270..4da206f2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -68,6 +68,7 @@ inilint_SOURCES = \ filemanip.h \ cli/CliParseFeedback.cc \ cli/CliGetUrlFeedback.cc \ + cli/CliHashCheckFeedback.cc \ cli/CliFeedback.h \ LogSingleton.cc \ LogSingleton.h \ @@ -189,6 +190,7 @@ endif gui/GuiGetNetAuth.h \ gui/GuiGetUrlFeedback.cc \ gui/GuiFeedback.h \ + gui/GuiHashCheckFeedback.cc \ ini.cc \ ini.h \ IniDBBuilder.h \ diff --git a/choose.cc b/choose.cc index c7831d9e..1bee0fa2 100644 --- a/choose.cc +++ b/choose.cc @@ -52,6 +52,7 @@ #include "choose_cli.h" #include "threebar.h" +#include "gui/GuiFeedback.h" #include "Generic.h" #include "ControlAdjuster.h" #include "prereq.h" @@ -349,9 +350,10 @@ void ChooserPage::OnActivate() { SetBusy(); + GuiFeedback feedback(GetHWND()); packagedb db; - db.prep(); + db.prep(feedback); if (!activated) { diff --git a/cli/CliFeedback.h b/cli/CliFeedback.h index 3bcc23c9..cb596503 100644 --- a/cli/CliFeedback.h +++ b/cli/CliFeedback.h @@ -48,6 +48,11 @@ private: unsigned int last_tics; unsigned int start_tics; + // hash checking +public: + void hash_init (const char *hashalg, const std::string &url); + void hash_progress (int bytes, int total_bytes); + // owner public: HWND owner () { return NULL; } diff --git a/cli/CliHashCheckFeedback.cc b/cli/CliHashCheckFeedback.cc new file mode 100644 index 00000000..f5df9fcd --- /dev/null +++ b/cli/CliHashCheckFeedback.cc @@ -0,0 +1,30 @@ +/* + * + * 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/ + * + */ + +#include "cli/CliFeedback.h" +#include "resource.h" +#include "String++.h" +#include + +void +CliFeedback::hash_init(const char *hashalg, const std::string &shortname) +{ + std::wstring fmt = LoadStringW(IDS_PROGRESS_CHECKING_HASH); + std::wstring s = format(fmt, hashalg, shortname.c_str()); + std::cout << wstring_to_string(s) << std::endl; +} + +void +CliFeedback::hash_progress(int bytes, int total_bytes) +{ + std::cout << bytes << "/" << total_bytes << "\r"; +} diff --git a/download.cc b/download.cc index 02fd4847..fbe36e55 100644 --- a/download.cc +++ b/download.cc @@ -52,14 +52,14 @@ extern ThreeBarProgressPage Progress; // user chooses to delete the file; otherwise throw an exception. static bool validateCachedPackage (const std::string& fullname, packagesource & pkgsource, - HWND owner, bool check_hash, bool check_size) + Feedback &feedback, bool check_hash, bool check_size) { try { if (check_size) pkgsource.check_size_and_cache (fullname); if (check_hash) - pkgsource.check_hash (); + pkgsource.check_hash (feedback); return true; } catch (Exception *e) @@ -69,7 +69,7 @@ validateCachedPackage (const std::string& fullname, packagesource & pkgsource, if (strncmp (filename, "file://", 7) == 0) filename += 7; if (e->errNo() == APPERR_CORRUPT_PACKAGE - && yesno (owner, IDS_QUERY_CORRUPT, filename) == IDYES) + && yesno (feedback.owner(), IDS_QUERY_CORRUPT, filename) == IDYES) remove (filename); else throw e; @@ -80,8 +80,8 @@ validateCachedPackage (const std::string& fullname, packagesource & pkgsource, /* 0 if not cached; may throw exception if validation fails. */ int -check_for_cached (packagesource & pkgsource, HWND owner, bool mirror_mode, - bool check_hash) +check_for_cached (packagesource & pkgsource, Feedback &feedback, + bool mirror_mode, bool check_hash) { /* If the packagesource doesn't have a filename, it can't possibly be in the cache */ @@ -105,7 +105,7 @@ check_for_cached (packagesource & pkgsource, HWND owner, bool mirror_mode, // Already found one, which we can assume to have the right size. if (pkgsource.Cached()) { - if (validateCachedPackage (pkgsource.Cached(), pkgsource, owner, + if (validateCachedPackage (pkgsource.Cached(), pkgsource, feedback, check_hash, false)) return 1; // If we get here, pkgsource.Cached() was corrupt and deleted. @@ -117,7 +117,7 @@ check_for_cached (packagesource & pkgsource, HWND owner, bool mirror_mode, */ if (io_stream::exists (fullname)) { - if (validateCachedPackage (fullname, pkgsource, owner, check_hash, true)) + if (validateCachedPackage (fullname, pkgsource, feedback, check_hash, true)) return 1; // If we get here, fullname was corrupt and deleted, but it // might have been cached. @@ -134,7 +134,7 @@ check_for_cached (packagesource & pkgsource, HWND owner, bool mirror_mode, pkgsource.Canonical (); if (io_stream::exists(fullname)) { - if (validateCachedPackage (fullname, pkgsource, owner, check_hash, + if (validateCachedPackage (fullname, pkgsource, feedback, check_hash, true)) return 1; // If we get here, fullname was corrupt and deleted, but it @@ -151,7 +151,7 @@ download_one (packagesource & pkgsource, Feedback &feedback) { try { - if (check_for_cached (pkgsource, feedback.owner())) + if (check_for_cached (pkgsource, feedback)) return 0; } catch (Exception * e) @@ -190,7 +190,7 @@ download_one (packagesource & pkgsource, Feedback &feedback) remove (local.c_str()); rename ((local + ".tmp").c_str(), local.c_str()); pkgsource.check_size_and_cache ("file://" + local); - pkgsource.check_hash (); + pkgsource.check_hash (feedback); Log (LOG_PLAIN) << "Downloaded " << local << endLog; success = 1; // FIXME: move the downloaded file to the @@ -277,6 +277,7 @@ do_download_thread (HINSTANCE h, HWND owner) int errors = 0; download_failures.clear (); + GuiFeedback feedback(owner); Progress.SetText1 (IDS_PROGRESS_CHECKING); Progress.SetText2 (""); Progress.SetText3 (""); @@ -294,7 +295,7 @@ do_download_thread (HINSTANCE h, HWND owner) try { - if (!check_for_cached (*version.source(), owner)) + if (!check_for_cached (*version.source(), feedback)) total_download_bytes += version.source()->size; } catch (Exception * e) @@ -308,7 +309,6 @@ do_download_thread (HINSTANCE h, HWND owner) Progress.SetBar2(std::distance(t.begin(), i) + 1, t.size()); } - GuiFeedback feedback(owner); feedback.fetch_set_total_length(total_download_bytes); /* and do the download. FIXME: This here we assign a new name for the cached version diff --git a/download.h b/download.h index 9f4cb8ee..3f65153e 100644 --- a/download.h +++ b/download.h @@ -16,10 +16,10 @@ #ifndef SETUP_DOWNLOAD_H #define SETUP_DOWNLOAD_H -#include "win32.h" +#include "Feedback.h" class packagesource; -int check_for_cached (packagesource & pkgsource, HWND owner, - bool mirror_mode = false, bool check_hash = true); +int check_for_cached (packagesource & pkgsource, Feedback &feedback, + bool mirror_mode = false, bool check_hash = true); #endif /* SETUP_DOWNLOAD_H */ diff --git a/gui/GuiFeedback.h b/gui/GuiFeedback.h index 1dcd42f4..7ac0c806 100644 --- a/gui/GuiFeedback.h +++ b/gui/GuiFeedback.h @@ -55,6 +55,11 @@ private: long long int total_download_bytes_sofar = 0; DWORD start_tics; + // hash checking +public: + void hash_init (const char *hashalg, const std::string &url); + void hash_progress (int bytes, int total_bytes); + public: // owner HWND owner () { return owner_window; } diff --git a/gui/GuiHashCheckFeedback.cc b/gui/GuiHashCheckFeedback.cc new file mode 100644 index 00000000..a0b4c57a --- /dev/null +++ b/gui/GuiHashCheckFeedback.cc @@ -0,0 +1,34 @@ +/* + * + * 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/ + * + */ + +#include "gui/GuiFeedback.h" +#include "resource.h" +#include "threebar.h" +#include "String++.h" + +extern ThreeBarProgressPage Progress; + +void +GuiFeedback::hash_init(const char *hashalg, const std::string &shortname) +{ + std::wstring fmt = LoadStringW(IDS_PROGRESS_CHECKING_HASH); + std::wstring s = format(fmt, hashalg, shortname.c_str()); + Progress.SetText1(s.c_str()); + Progress.SetText4(IDS_PROGRESS_PROGRESS); + Progress.SetBar1(0); +} + +void +GuiFeedback::hash_progress(int bytes, int total_bytes) +{ + Progress.SetBar1(bytes, total_bytes); +} diff --git a/install.cc b/install.cc index 001529b9..578ff7ff 100644 --- a/install.cc +++ b/install.cc @@ -62,6 +62,7 @@ #include "threebar.h" #include "Exception.h" #include "processlist.h" +#include "gui/GuiFeedback.h" extern ThreeBarProgressPage Progress; @@ -805,6 +806,7 @@ static void do_install_thread (HINSTANCE h, HWND owner) { int i; + GuiFeedback feedback(owner); num_installs = 0, num_uninstalls = 0; rebootneeded = false; @@ -870,7 +872,7 @@ do_install_thread (HINSTANCE h, HWND owner) { try { - (*version.source ()).check_hash (); + (*version.source ()).check_hash (feedback); } catch (Exception *e) { diff --git a/package_db.cc b/package_db.cc index aac018f1..9b74fc99 100644 --- a/package_db.cc +++ b/package_db.cc @@ -755,7 +755,7 @@ packagedb::fixup_source_package_ids() } void -packagedb::prep() +packagedb::prep(Feedback &feedback) { /* make packagedb ready for use for chooser */ if (prepped) @@ -770,8 +770,8 @@ packagedb::prep() /* XXX: this needs to be broken out somewhere where it can do progress reporting, as it can take a long time... */ - if (source == IDC_SOURCE_DOWNLOAD || source ==IDC_SOURCE_LOCALDIR) - packagemeta::ScanDownloadedFiles (MirrorOption); + if (source == IDC_SOURCE_DOWNLOAD || source == IDC_SOURCE_LOCALDIR) + packagemeta::ScanDownloadedFiles (MirrorOption, feedback); setExistence (); fillMissingCategory (); diff --git a/package_db.h b/package_db.h index 3886bf22..c3c2b051 100644 --- a/package_db.h +++ b/package_db.h @@ -23,6 +23,7 @@ class packagemeta; class io_stream; class PackageSpecification; +class Feedback; typedef enum { PackageDB_Install, @@ -67,7 +68,7 @@ public: void init(); /* 0 on success */ int flush (); - void prep(); + void prep(Feedback &); /* Set the database to a "no changes requested" state. */ void noChanges (); diff --git a/package_meta.cc b/package_meta.cc index 322c28f9..85e0a7f2 100644 --- a/package_meta.cc +++ b/package_meta.cc @@ -642,7 +642,7 @@ packagemeta::logSelectionStatus() const /* scan for local copies of package */ bool -packagemeta::scan (const packageversion &pkg, bool mirror_mode) +packagemeta::scan (const packageversion &pkg, bool mirror_mode, Feedback &feedback) { /* empty version */ if (!pkg) @@ -650,7 +650,7 @@ packagemeta::scan (const packageversion &pkg, bool mirror_mode) try { - if (!check_for_cached (*(pkg.source ()), NULL, mirror_mode, false) + if (!check_for_cached (*(pkg.source ()), feedback, mirror_mode, false) && ::source == IDC_SOURCE_LOCALDIR) return false; } @@ -668,7 +668,7 @@ packagemeta::scan (const packageversion &pkg, bool mirror_mode) } void -packagemeta::ScanDownloadedFiles (bool mirror_mode) +packagemeta::ScanDownloadedFiles (bool mirror_mode, Feedback &feedback) { /* Look at every known package, in all the known mirror dirs, * and fill in the Cached attribute if it exists. @@ -686,10 +686,10 @@ packagemeta::ScanDownloadedFiles (bool mirror_mode) && (*i != pkg.installed || pkg.installed == pkg.curr || pkg.installed == pkg.exp); - bool accessible = scan (*i, lazy_scan); + bool accessible = scan (*i, lazy_scan, feedback); packageversion foo = *i; packageversion pkgsrcver = foo.sourcePackage (); - bool src_accessible = scan (pkgsrcver, lazy_scan); + bool src_accessible = scan (pkgsrcver, lazy_scan, feedback); /* For local installs, if there is no src and no bin, the version * is unavailable diff --git a/package_meta.h b/package_meta.h index 11448475..a76342bf 100644 --- a/package_meta.h +++ b/package_meta.h @@ -19,6 +19,7 @@ class SolvableVersion; typedef SolvableVersion packageversion; class packagemeta; +class Feedback; #include #include @@ -34,7 +35,7 @@ typedef std::pair > Category; class packagemeta { public: - static void ScanDownloadedFiles (bool); + static void ScanDownloadedFiles (bool, Feedback&); packagemeta (packagemeta const &); packagemeta (const std::string& pkgname) : name (pkgname), user_picked (false), @@ -160,7 +161,7 @@ protected: private: std::string trustLabel(packageversion const &) const; std::vector