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;
};
filemanip.h \
cli/CliParseFeedback.cc \
cli/CliGetUrlFeedback.cc \
+ cli/CliHashCheckFeedback.cc \
cli/CliFeedback.h \
LogSingleton.cc \
LogSingleton.h \
gui/GuiGetNetAuth.h \
gui/GuiGetUrlFeedback.cc \
gui/GuiFeedback.h \
+ gui/GuiHashCheckFeedback.cc \
ini.cc \
ini.h \
IniDBBuilder.h \
#include "choose_cli.h"
#include "threebar.h"
+#include "gui/GuiFeedback.h"
#include "Generic.h"
#include "ControlAdjuster.h"
#include "prereq.h"
ChooserPage::OnActivate()
{
SetBusy();
+ GuiFeedback feedback(GetHWND());
packagedb db;
- db.prep();
+ db.prep(feedback);
if (!activated)
{
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; }
--- /dev/null
+/*
+ *
+ * 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 <iostream>
+
+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";
+}
// 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)
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;
/* 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 */
// 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.
*/
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.
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
{
try
{
- if (check_for_cached (pkgsource, feedback.owner()))
+ if (check_for_cached (pkgsource, feedback))
return 0;
}
catch (Exception * e)
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
int errors = 0;
download_failures.clear ();
+ GuiFeedback feedback(owner);
Progress.SetText1 (IDS_PROGRESS_CHECKING);
Progress.SetText2 ("");
Progress.SetText3 ("");
try
{
- if (!check_for_cached (*version.source(), owner))
+ if (!check_for_cached (*version.source(), feedback))
total_download_bytes += version.source()->size;
}
catch (Exception * e)
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
#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 */
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; }
--- /dev/null
+/*
+ *
+ * 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);
+}
#include "threebar.h"
#include "Exception.h"
#include "processlist.h"
+#include "gui/GuiFeedback.h"
extern ThreeBarProgressPage Progress;
do_install_thread (HINSTANCE h, HWND owner)
{
int i;
+ GuiFeedback feedback(owner);
num_installs = 0, num_uninstalls = 0;
rebootneeded = false;
{
try
{
- (*version.source ()).check_hash ();
+ (*version.source ()).check_hash (feedback);
}
catch (Exception *e)
{
}
void
-packagedb::prep()
+packagedb::prep(Feedback &feedback)
{
/* make packagedb ready for use for chooser */
if (prepped)
/* 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 ();
class packagemeta;
class io_stream;
class PackageSpecification;
+class Feedback;
typedef enum {
PackageDB_Install,
void init();
/* 0 on success */
int flush ();
- void prep();
+ void prep(Feedback &);
/* Set the database to a "no changes requested" state. */
void noChanges ();
/* 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)
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;
}
}
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.
&& (*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
class SolvableVersion;
typedef SolvableVersion packageversion;
class packagemeta;
+class Feedback;
#include <set>
#include <vector>
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),
private:
std::string trustLabel(packageversion const &) const;
std::vector <Script> scripts_;
- static bool scan (const packageversion &pkg, bool mirror_mode);
+ static bool scan (const packageversion &pkg, bool mirror_mode, Feedback &feedback);
_actions _action;
#include "sha2.h"
#include "csu_util/MD5Sum.h"
#include "LogFile.h"
-#include "threebar.h"
#include "Exception.h"
#include "filemanip.h"
#include "io_stream.h"
-#include "resource.h"
-
-extern ThreeBarProgressPage Progress;
+#include "Feedback.h"
site::site (const std::string& newkey) : key(newkey)
{
}
void
-packagesource::check_hash ()
+packagesource::check_hash (Feedback &feedback)
{
if (validated || cached.empty ())
return;
if (sha512_isSet)
{
- check_sha512 (cached);
+ check_sha512 (cached, feedback);
validated = true;
}
else if (md5.isSet())
{
- check_md5 (cached);
+ check_md5 (cached, feedback);
validated = true;
}
else
}
void
-packagesource::check_sha512 (const std::string fullname) const
+packagesource::check_sha512 (const std::string fullname, Feedback &feedback) const
{
io_stream *thefile = io_stream::open (fullname, "rb", 0);
if (!thefile)
SHA512Init (&ctx);
Log (LOG_BABBLE) << "Checking SHA512 for " << fullname << endLog;
-
- std::wstring fmt = LoadStringW(IDS_PROGRESS_CHECKING_HASH);
- std::wstring s = format(fmt, "SHA512", shortname.c_str());
- Progress.SetText1 (s.c_str());
- Progress.SetText4 (IDS_PROGRESS_PROGRESS);
- Progress.SetBar1 (0);
+ feedback.hash_init("SHA512", shortname);
unsigned char buffer[64 * 1024];
ssize_t count;
while ((count = thefile->read (buffer, sizeof (buffer))) > 0)
{
SHA512Update (&ctx, buffer, count);
- Progress.SetBar1 (thefile->tell (), thefile->get_size ());
+ feedback.hash_progress(thefile->tell (), thefile->get_size ());
}
delete thefile;
if (count < 0)
}
void
-packagesource::check_md5 (const std::string fullname) const
+packagesource::check_md5 (const std::string fullname, Feedback &feedback) const
{
io_stream *thefile = io_stream::open (fullname, "rb", 0);
if (!thefile)
tempMD5.begin ();
Log (LOG_BABBLE) << "Checking MD5 for " << fullname << endLog;
-
- std::wstring fmt = LoadStringW(IDS_PROGRESS_CHECKING_HASH);
- std::wstring s = format(fmt, "MD5", shortname);
- Progress.SetText1 (s.c_str());
- Progress.SetText4 (IDS_PROGRESS_PROGRESS);
- Progress.SetBar1 (0);
+ feedback.hash_init("MD5", shortname);
unsigned char buffer[64 * 1024];
ssize_t count;
while ((count = thefile->read (buffer, sizeof (buffer))) > 0)
{
tempMD5.append (buffer, count);
- Progress.SetBar1 (thefile->tell (), thefile->get_size ());
+ feedback.hash_progress(thefile->tell (), thefile->get_size ());
}
delete thefile;
if (count < 0)
#include "csu_util/MD5Sum.h"
#include <vector>
+class Feedback;
+
class site
{
public:
MD5Sum md5;
/* The next two functions throw exceptions on failure. */
void check_size_and_cache (const std::string fullname);
- void check_hash ();
+ void check_hash (Feedback &feedback);
typedef std::vector <site> sitestype;
sitestype sites;
std::string shortname;
std::string cached;
bool validated;
- void check_sha512 (const std::string fullname) const;
- void check_md5 (const std::string fullname) const;
+ void check_sha512 (const std::string fullname, Feedback &feedback) const;
+ void check_md5 (const std::string fullname, Feedback &feedback) const;
};
#endif /* SETUP_PACKAGE_SOURCE_H */