summaryrefslogtreecommitdiff
path: root/src/selfupdater.cpp
diff options
context:
space:
mode:
authorThomas Tanner <trtanner@btinternet.com>2015-10-12 12:54:19 +0100
committerThomas Tanner <trtanner@btinternet.com>2015-10-12 12:54:19 +0100
commit077a58f410b4d4ef32f7a9ebc0821f08c3cec6eb (patch)
treeba17c41455a06a74224a096544efd3c3355b3e21 /src/selfupdater.cpp
parentf5c86bc22c23374540d07ef63320b810c39e1df4 (diff)
parent7d93a9a2003f31188e4da8cbcd7e5df0352bb900 (diff)
Merge branch 'master' of https://github.com/TanninOne/modorganizer into archive_cleanup
# Conflicts: # src/installationmanager.cpp
Diffstat (limited to 'src/selfupdater.cpp')
-rw-r--r--src/selfupdater.cpp40
1 files changed, 25 insertions, 15 deletions
diff --git a/src/selfupdater.cpp b/src/selfupdater.cpp
index 724b89db..5cd6cf36 100644
--- a/src/selfupdater.cpp
+++ b/src/selfupdater.cpp
@@ -61,11 +61,8 @@ SelfUpdater::SelfUpdater(NexusInterface *nexusInterface)
, m_Interface(nexusInterface)
, m_UpdateRequestID(-1)
, m_Reply(nullptr)
- , m_Progress(nullptr)
, m_Attempts(3)
{
- m_Progress.setMaximum(100);
-
QLibrary archiveLib("dlls\\archive.dll");
if (!archiveLib.load()) {
throw MyException(tr("archive.dll not loaded: \"%1\"").arg(archiveLib.errorString()));
@@ -78,7 +75,7 @@ SelfUpdater::SelfUpdater(NexusInterface *nexusInterface)
throw MyException(InstallationManager::getErrorString(m_ArchiveHandler->getLastError()));
}
- connect(&m_Progress, SIGNAL(canceled()), this, SLOT(downloadCancel()));
+ connect(m_Progress, SIGNAL(canceled()), this, SLOT(downloadCancel()));
VS_FIXEDFILEINFO version = GetFileVersion(ToWString(QApplication::applicationFilePath()));
@@ -136,12 +133,23 @@ void SelfUpdater::startUpdate()
void SelfUpdater::showProgress()
{
- m_Progress.setModal(true);
- m_Progress.setParent(m_Parent, Qt::Dialog);
- m_Progress.show();
- m_Progress.setValue(0);
- m_Progress.setWindowTitle(tr("Update"));
- m_Progress.setLabelText(tr("Download in progress"));
+ if (m_Progress == nullptr) {
+ m_Progress = new QProgressDialog(m_Parent, Qt::Dialog);
+ }
+ m_Progress->setModal(true);
+ m_Progress->show();
+ m_Progress->setValue(0);
+ m_Progress->setWindowTitle(tr("Update"));
+ m_Progress->setLabelText(tr("Download in progress"));
+}
+
+void SelfUpdater::closeProgress()
+{
+ if (m_Progress != nullptr) {
+ m_Progress->hide();
+ m_Progress->deleteLater();
+ m_Progress = nullptr;
+ }
}
void SelfUpdater::download(const QString &downloadLink, const QString &fileName)
@@ -168,7 +176,9 @@ void SelfUpdater::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
m_Reply->abort();
} else {
if (bytesTotal != 0) {
- m_Progress.setValue((bytesReceived * 100) / bytesTotal);
+ if (m_Progress != nullptr) {
+ m_Progress->setValue((bytesReceived * 100) / bytesTotal);
+ }
}
}
}
@@ -196,7 +206,8 @@ void SelfUpdater::downloadFinished()
m_Canceled = true;
}
- m_Progress.hide();
+ closeProgress();
+
m_Reply->close();
m_Reply->deleteLater();
m_Reply = nullptr;
@@ -423,7 +434,7 @@ void SelfUpdater::nxmFilesAvailable(int, QVariant userData, QVariant resultData,
} else {
qCritical("no file for update found");
MessageDialog::showMessage(tr("no file for update found. Please update manually."), m_Parent);
- m_Progress.hide();
+ closeProgress();
}
}
@@ -458,8 +469,7 @@ void SelfUpdater::nxmDownloadURLsAvailable(int, int, QVariant userData, QVariant
download(dlServer["URI"].toString(), userData.toString());
} else {
MessageDialog::showMessage(tr("No download server available. Please try again later."), m_Parent);
- m_Progress.hide();
+ closeProgress();
}
}
}
-