1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00
This commit is contained in:
Tux3 / Mlkj / !Lev.uXFMLA 2015-01-05 09:54:03 +01:00
parent 5b7e57751c
commit 8813d6e4ca
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
3 changed files with 23 additions and 0 deletions

View File

@ -64,6 +64,7 @@ unsigned char AutoUpdater::key[crypto_sign_PUBLICKEYBYTES];
const QString AutoUpdater::checkURI = AutoUpdater::updateServer+"/qtox/"+AutoUpdater::platform+"/version"; const QString AutoUpdater::checkURI = AutoUpdater::updateServer+"/qtox/"+AutoUpdater::platform+"/version";
const QString AutoUpdater::flistURI = AutoUpdater::updateServer+"/qtox/"+AutoUpdater::platform+"/flist"; const QString AutoUpdater::flistURI = AutoUpdater::updateServer+"/qtox/"+AutoUpdater::platform+"/flist";
const QString AutoUpdater::filesURI = AutoUpdater::updateServer+"/qtox/"+AutoUpdater::platform+"/files/"; const QString AutoUpdater::filesURI = AutoUpdater::updateServer+"/qtox/"+AutoUpdater::platform+"/files/";
bool AutoUpdater::abortFlag{false};
bool AutoUpdater::isUpdateAvailable() bool AutoUpdater::isUpdateAvailable()
{ {
@ -251,7 +252,11 @@ AutoUpdater::UpdateFile AutoUpdater::getUpdateFile(UpdateFileMeta fileMeta)
QNetworkAccessManager *manager = new QNetworkAccessManager; QNetworkAccessManager *manager = new QNetworkAccessManager;
QNetworkReply* reply = manager->get(QNetworkRequest(QUrl(filesURI+fileMeta.id))); QNetworkReply* reply = manager->get(QNetworkRequest(QUrl(filesURI+fileMeta.id)));
while (!reply->isFinished()) while (!reply->isFinished())
{
if (abortFlag)
return file;
qApp->processEvents(); qApp->processEvents();
}
if (reply->error() != QNetworkReply::NoError) if (reply->error() != QNetworkReply::NoError)
{ {
@ -280,6 +285,9 @@ bool AutoUpdater::downloadUpdate()
QList<UpdateFileMeta> newFlist = parseFlist(newFlistData); QList<UpdateFileMeta> newFlist = parseFlist(newFlistData);
QList<UpdateFileMeta> diff = genUpdateDiff(newFlist); QList<UpdateFileMeta> diff = genUpdateDiff(newFlist);
if (abortFlag)
return false;
qDebug() << "AutoUpdater: Need to update "<<diff.size()<<" files"; qDebug() << "AutoUpdater: Need to update "<<diff.size()<<" files";
// Create an empty directory to download updates into // Create an empty directory to download updates into
@ -308,6 +316,9 @@ bool AutoUpdater::downloadUpdate()
// Download and write each new file // Download and write each new file
for (UpdateFileMeta fileMeta : diff) for (UpdateFileMeta fileMeta : diff)
{ {
if (abortFlag)
return false;
qDebug() << "AutoUpdater: Downloading '"+fileMeta.installpath+"' ..."; qDebug() << "AutoUpdater: Downloading '"+fileMeta.installpath+"' ...";
// Create subdirs if necessary // Create subdirs if necessary
@ -317,6 +328,8 @@ bool AutoUpdater::downloadUpdate()
// Download // Download
UpdateFile file = getUpdateFile(fileMeta); UpdateFile file = getUpdateFile(fileMeta);
if (abortFlag)
return false;
if (file.data.isNull()) if (file.data.isNull())
{ {
qWarning() << "AutoUpdater::downloadUpdate: Error downloading a file, aborting..."; qWarning() << "AutoUpdater::downloadUpdate: Error downloading a file, aborting...";
@ -433,3 +446,8 @@ void AutoUpdater::checkUpdatesAsyncInteractiveWorker()
downloadUpdate(); downloadUpdate();
} }
} }
void AutoUpdater::abortUpdates()
{
abortFlag = true;
}

View File

@ -87,6 +87,9 @@ public:
/// The qTox updater will restart us after the update is done /// The qTox updater will restart us after the update is done
/// Note: If we fail to start the qTox updater, we will delete the update and exit /// Note: If we fail to start the qTox updater, we will delete the update and exit
[[ noreturn ]] static void installLocalUpdate(); [[ noreturn ]] static void installLocalUpdate();
/// Aborting will make some functions try to return early
/// Call before qTox exits to avoid the updater running in the background
static void abortUpdates();
protected: protected:
/// Parses and validates a flist file. Returns an empty list on error /// Parses and validates a flist file. Returns an empty list on error
@ -118,6 +121,7 @@ private:
static const QString filesURI; ///< URI of the actual files of the latest version static const QString filesURI; ///< URI of the actual files of the latest version
static const QString updaterBin; ///< Path to the qtox-updater binary static const QString updaterBin; ///< Path to the qtox-updater binary
static unsigned char key[]; static unsigned char key[];
static bool abortFlag; ///< If true, try to abort everything.
}; };
#endif // AUTOUPDATE_H #endif // AUTOUPDATE_H

View File

@ -319,6 +319,7 @@ Widget::~Widget()
coreThread->wait(500); // In case of deadlock (can happen with QtAudio/PA bugs) coreThread->wait(500); // In case of deadlock (can happen with QtAudio/PA bugs)
if (!coreThread->isFinished()) if (!coreThread->isFinished())
coreThread->terminate(); coreThread->terminate();
AutoUpdater::abortUpdates();
delete core; delete core;
delete settingsWidget; delete settingsWidget;
delete addFriendForm; delete addFriendForm;