From 6bfdbc74c2ad81b88dfa7736a31712464a6ccb34 Mon Sep 17 00:00:00 2001 From: Mark Watkins Date: Sat, 17 Dec 2011 19:56:21 +1000 Subject: [PATCH] Update test for windows.. Please Don't touch. --- UpdaterWindow.cpp | 19 +++++++++++++++++-- UpdaterWindow.h | 2 ++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/UpdaterWindow.cpp b/UpdaterWindow.cpp index 95268fc9..c775bf7d 100644 --- a/UpdaterWindow.cpp +++ b/UpdaterWindow.cpp @@ -81,10 +81,16 @@ void UpdaterWindow::checkForUpdates() } mainwin->Notify("Checking for SleepyHead Updates"); + update_url=QUrl("http://192.168.1.8/update.xml"); + downloadUpdateXML(); +} + +void UpdaterWindow::downloadUpdateXML() +{ requestmode=RM_CheckUpdates; - reply=netmanager->get(QNetworkRequest(QUrl("http://192.168.1.8/update.xml"))); - ui->plainTextEdit->appendPlainText("Requesting "+reply->url().toString()); + reply=netmanager->get(QNetworkRequest(update_url)); + ui->plainTextEdit->appendPlainText("Requesting "+update_url.toString()); netmanager->connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this, SLOT(downloadProgress(qint64,qint64))); dltime.start(); } @@ -259,7 +265,16 @@ void UpdaterWindow::replyFinished(QNetworkReply * reply) { netmanager->disconnect(reply,SIGNAL(downloadProgress(qint64,qint64)),this, SLOT(downloadProgress(qint64,qint64))); if (reply->error()==QNetworkReply::NoError) { + if (requestmode==RM_CheckUpdates) { + QUrl redirectUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl(); + if (!redirectUrl.isEmpty() && (redirectUrl!=reply->url())) { + update_url = redirectUrl; + reply->deleteLater(); + QTimer::singleShot(100,this,SLOT(downloadUpdateXML())); + return; + } + ui->plainTextEdit->appendPlainText(QString::number(reply->size())+" bytes received."); QString filename=QApplication::applicationDirPath()+QDir::separator()+reply->url().toString().section("/",-1); qDebug() << filename; diff --git a/UpdaterWindow.h b/UpdaterWindow.h index 83550027..5dfb8b7f 100644 --- a/UpdaterWindow.h +++ b/UpdaterWindow.h @@ -31,6 +31,7 @@ protected slots: void downloadProgress(qint64 bytesReceived, qint64 bytesTotal); void dataReceived(); void requestFile(); + void downloadUpdateXML(); private slots: void on_CloseButton_clicked(); @@ -58,6 +59,7 @@ private: QList updates; int current_row; bool success; + QUrl update_url; // for update.xml redirects.. }; #endif // UPDATEWINDOW_H