[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[vidalia-svn] r3389: Add a couple fugnasty kludges to glean some update download (vidalia/branches/auto-updates/src/vidalia)
Author: edmanm
Date: 2008-12-13 01:11:43 -0500 (Sat, 13 Dec 2008)
New Revision: 3389
Modified:
vidalia/branches/auto-updates/src/vidalia/updateprocess.cpp
vidalia/branches/auto-updates/src/vidalia/updateprocess.h
Log:
Add a couple fugnasty kludges to glean some update download progress information
from thandy, as well as get the thandy failure message from the python traceback
it dumps an update fails to install. Also add a couple helper methods to
UpdateProcess to see if we're in the middle of an update, and kill it if the
user so desires.
Modified: vidalia/branches/auto-updates/src/vidalia/updateprocess.cpp
===================================================================
--- vidalia/branches/auto-updates/src/vidalia/updateprocess.cpp 2008-12-13 06:01:37 UTC (rev 3388)
+++ vidalia/branches/auto-updates/src/vidalia/updateprocess.cpp 2008-12-13 06:11:43 UTC (rev 3389)
@@ -66,7 +66,23 @@
start(updateExecutable(), args);
}
+bool
+UpdateProcess::isRunning() const
+{
+ return (state() != QProcess::NotRunning);
+}
+
void
+UpdateProcess::cancel()
+{
+#if defined(Q_OS_WIN32)
+ kill();
+#else
+ terminate();
+#endif
+}
+
+void
UpdateProcess::readStandardError()
{
int idx;
@@ -88,15 +104,48 @@
args = string_parse_keyvals(line, &ok);
if (! ok)
continue;
+ else if (line.startsWith("thandy.InstallFailed: ", Qt::CaseInsensitive)) {
+ /** XXX: This is a fucking kludge. If installation fails, Thandy just
+ * dumps a Python traceback that (for obvious reasons) doesn't
+ * follow the expected format. There isn't a defined control
+ * message type for this yet we'd really like the error, so treat
+ * this one specially.
+ */
+ emit installUpdatesFailed(line);
+ continue;
+ }
- if (_currentCommand == CheckForUpdates
- && ! type.compare("CAN_INSTALL", Qt::CaseInsensitive)) {
+ if (! type.compare("CAN_INSTALL", Qt::CaseInsensitive)) {
QString package = args.value("PKG");
if (! package.isEmpty()) {
PackageInfo pkgInfo = packageInfo(package);
if (pkgInfo.isValid())
_packageList << pkgInfo;
}
+ } else if (_currentCommand == CheckForUpdates
+ && ! type.compare("DEBUG")
+ && args.value("msg").startsWith("Got ")) {
+ /* XXX: This is an even worse fucking kludge. Thandy only reports
+ * download progress in a not-so-parser-friendly log message,
+ * though, so we must kludge again.
+ *
+ * Here's an example of what we're parsing:
+ * "Got 1666048/1666560 bytes from http://updates.torproject.org/thandy/data/win32/tor-0.2.1.9-alpha.msi"
+ *
+ * (Note that the kludge above would even match on "Got milk?".)
+ */
+ QStringList parts = args.value("msg").split(" ");
+ if (parts.size() == 5) {
+ QStringList progress = parts.at(1).split("/");
+ if (progress.size() == 2) {
+ int bytesReceived = progress.at(0).toUInt();
+ int bytesTotal = progress.at(1).toUInt();
+ vInfo("updater: Downloaded %1 of %2 bytes of file %3").arg(bytesReceived)
+ .arg(bytesTotal)
+ .arg(parts.at(4));
+ emit downloadProgress(parts.at(4), bytesReceived, bytesTotal);
+ }
+ }
}
}
}
@@ -116,7 +165,8 @@
void
UpdateProcess::onFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
- Q_UNUSED(exitCode);
+ vInfo("updater: update process finished with exit code %1").arg(exitCode);
+
if (_currentCommand == CheckForUpdates) {
if (exitStatus == QProcess::NormalExit) {
emit updatesAvailable(_currentBundle, _packageList);
@@ -125,8 +175,11 @@
"software updates because Tor's handy pocket "
"creature died. Sorry."));
}
- _packageList.clear();
+ } else if (_currentCommand == InstallUpdates) {
+ if (exitStatus == QProcess::NormalExit && exitCode == 0)
+ emit updatesInstalled(_packageList.size());
}
+ _packageList.clear();
}
void
Modified: vidalia/branches/auto-updates/src/vidalia/updateprocess.h
===================================================================
--- vidalia/branches/auto-updates/src/vidalia/updateprocess.h 2008-12-13 06:01:37 UTC (rev 3388)
+++ vidalia/branches/auto-updates/src/vidalia/updateprocess.h 2008-12-13 06:11:43 UTC (rev 3389)
@@ -14,6 +14,7 @@
#include <QProcess>
#include <QDateTime>
#include <QStringList>
+#include <QUrl>
#include "packageinfo.h"
@@ -41,6 +42,11 @@
*/
void installUpdates(BundleInfo bi);
+ /** Returns true if the update process is currently in the middle of an
+ * operation, such as checking for or installing updates.
+ */
+ bool isRunning() const;
+
/** Return the time at which we should next check for available updates,
* given the last we checked was at <b>lastCheckedAt</b>.
*/
@@ -73,12 +79,33 @@
*/
void checkForUpdatesFailed(QString errmsg);
+ /** Emitted while an updated package download is in progress. <b>url</b> is
+ * location of the update, <b>bytesReceived</b> is how many bytes have been
+ * downloaded so far and <b>bytesTotal</b> is the total size of the package
+ * being downloaded. */
+ void downloadProgress(QString url, int bytesReceived, int bytesTotal);
+
/** Emitted when updated software packages in bundle <b>bi</b> are
* are available. <b>packages</b> contains a collection of PackageInfo objects
* describing the updates available for installation.
*/
void updatesAvailable(UpdateProcess::BundleInfo bi, PackageList packages);
+ /** Emitted after all available updated packages have been successfully
+ * installed.
+ */
+ void updatesInstalled(int nPackagesInstalled);
+
+ /** Emitted when there is an error installing one or more updated software
+ * packages. <b>errmsg</b> might even contain a useful description of the
+ * error encountered (but don't bet the farm on it).
+ */
+ void installUpdatesFailed(QString errmsg);
+
+public slots:
+ /** Cancels the currently running software update operation immediately. */
+ void cancel();
+
protected slots:
/** Called when there is data to be read from the update process's stdout.
* Reads and parses all available data.