Navigation Menu

Skip to content

Commit

Permalink
Updater: Adding a fallback URI where to download the package
Browse files Browse the repository at this point in the history
In case the primary location is not working, we can attempt to download
from a secondary location.
  • Loading branch information
skyjake committed Jun 19, 2012
1 parent 55eb17e commit 0dfc2ab
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
15 changes: 14 additions & 1 deletion doomsday/engine/portable/src/updater.cpp
Expand Up @@ -132,6 +132,7 @@ struct Updater::Instance

VersionInfo latestVersion;
QString latestPackageUri;
QString latestPackageUri2; // fallback location
QString latestLogUri;

Instance(Updater* up) : self(up), network(0), download(0), availableDlg(0), settingsDlg(0), backToFullscreen(false)
Expand Down Expand Up @@ -262,6 +263,18 @@ struct Updater::Instance
latestPackageUri = map["direct_download_uri"].toString();
latestLogUri = map["release_changeloguri"].toString();

latestPackageUri = "http://sourceforge.net/projects/deng/files/Doomsday%20Engine/Builds/doomsday_1.9.9_build999_64bit.dmg/download";

// Check if a fallback location is specified for the download.
if(map.contains("direct_download_fallback_uri"))
{
latestPackageUri2 = map["direct_download_fallback_uri"].toString();
}
else
{
latestPackageUri2 = "";
}

latestVersion = VersionInfo(map["version"].toString(), map["build_uniqueid"].toInt());

VersionInfo currentVersion;
Expand Down Expand Up @@ -296,7 +309,7 @@ struct Updater::Instance
{
availableDlg = 0;
LOG_MSG("Download and install.");
download = new DownloadDialog(latestPackageUri);
download = new DownloadDialog(latestPackageUri, latestPackageUri2);
QObject::connect(download, SIGNAL(finished(int)), self, SLOT(downloadCompleted(int)));
download->show();
}
Expand Down
19 changes: 14 additions & 5 deletions doomsday/engine/portable/src/updater/downloaddialog.cpp
Expand Up @@ -22,15 +22,17 @@ struct DownloadDialog::Instance
bool downloading;
QPushButton* install;
QProgressBar* bar;
QLabel* hostText;
QLabel* progText;
QUrl uri;
QUrl uri2;
de::String savedFilePath;
bool fileReady;
QNetworkReply* reply;
de::String redirected;

Instance(DownloadDialog* d, de::String downloadUri)
: self(d), downloading(false), uri(downloadUri), fileReady(false), reply(0)
Instance(DownloadDialog* d, de::String downloadUri, de::String fallbackUri)
: self(d), downloading(false), uri(downloadUri), uri2(fallbackUri), fileReady(false), reply(0)
{
QVBoxLayout* mainLayout = new QVBoxLayout;
self->setLayout(mainLayout);
Expand All @@ -47,7 +49,9 @@ struct DownloadDialog::Instance
QObject::connect(install, SIGNAL(clicked()), self, SLOT(accept()));
QObject::connect(cancel, SIGNAL(clicked()), self, SLOT(reject()));

mainLayout->addWidget(new QLabel(tr("Downloading update from <b>%1</b>...").arg(uri.host())));
hostText = new QLabel;
updateLocation(uri);
mainLayout->addWidget(hostText);
mainLayout->addWidget(bar);

progText = new QLabel;
Expand All @@ -62,6 +66,11 @@ struct DownloadDialog::Instance
startDownload();
}

void updateLocation(const QUrl& url)
{
hostText->setText(tr("Downloading update from <b>%1</b>...").arg(url.host()));
}

void startDownload()
{
downloading = true;
Expand All @@ -86,10 +95,10 @@ struct DownloadDialog::Instance
}
};

DownloadDialog::DownloadDialog(de::String downloadUri, QWidget *parent)
DownloadDialog::DownloadDialog(de::String downloadUri, de::String fallbackUri, QWidget *parent)
: QDialog(parent)
{
d = new Instance(this, downloadUri);
d = new Instance(this, downloadUri, fallbackUri);
}

DownloadDialog::~DownloadDialog()
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/updater/downloaddialog.h
Expand Up @@ -17,7 +17,7 @@ class DownloadDialog : public QDialog
Q_OBJECT

public:
explicit DownloadDialog(de::String downloadUri, QWidget *parent = 0);
explicit DownloadDialog(de::String downloadUri, de::String fallbackUri, QWidget *parent = 0);
~DownloadDialog();

/**
Expand Down

0 comments on commit 0dfc2ab

Please sign in to comment.