diff options
Diffstat (limited to 'src/selfupdater.cpp')
| -rw-r--r-- | src/selfupdater.cpp | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/src/selfupdater.cpp b/src/selfupdater.cpp index 803b2cfa..0c222ebb 100644 --- a/src/selfupdater.cpp +++ b/src/selfupdater.cpp @@ -48,7 +48,7 @@ typedef Archive* (*CreateArchiveType)(); template <typename T> T resolveFunction(QLibrary &lib, const char *name)
{
T temp = reinterpret_cast<T>(lib.resolve(name));
- if (temp == NULL) {
+ if (temp == nullptr) {
throw std::runtime_error(QObject::tr("invalid 7-zip32.dll: %1").arg(lib.errorString()).toLatin1().constData());
}
return temp;
@@ -56,8 +56,12 @@ template <typename T> T resolveFunction(QLibrary &lib, const char *name) SelfUpdater::SelfUpdater(NexusInterface *nexusInterface)
- : m_Parent(nullptr), m_Interface(nexusInterface), m_UpdateRequestID(-1),
- m_Reply(NULL), m_Progress(nullptr), m_Attempts(3)
+ : m_Parent(nullptr)
+ , m_Interface(nexusInterface)
+ , m_UpdateRequestID(-1)
+ , m_Reply(nullptr)
+ , m_Progress(nullptr)
+ , m_Attempts(3)
{
m_Progress.setMaximum(100);
@@ -90,7 +94,6 @@ SelfUpdater::~SelfUpdater() void SelfUpdater::setUserInterface(QWidget *widget)
{
- m_Progress.setParent(widget);
m_Parent = widget;
}
@@ -130,6 +133,16 @@ 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"));
+}
+
void SelfUpdater::download(const QString &downloadLink, const QString &fileName)
{
QNetworkAccessManager *accessManager = m_Interface->getAccessManager();
@@ -139,11 +152,7 @@ void SelfUpdater::download(const QString &downloadLink, const QString &fileName) m_Reply = accessManager->get(request);
m_UpdateFile.setFileName(QDir::fromNativeSeparators(ToQString(GameInfo::instance().getOrganizerDirectory()).append("\\").append(fileName)));
m_UpdateFile.open(QIODevice::WriteOnly);
- m_Progress.setModal(true);
- m_Progress.show();
- m_Progress.setValue(0);
- m_Progress.setWindowTitle(tr("Update"));
- m_Progress.setLabelText(tr("Download in progress"));
+ showProgress();
connect(m_Reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(downloadProgress(qint64, qint64)));
connect(m_Reply, SIGNAL(finished()), this, SLOT(downloadFinished()));
@@ -153,7 +162,7 @@ void SelfUpdater::download(const QString &downloadLink, const QString &fileName) void SelfUpdater::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
{
- if (m_Reply != NULL) {
+ if (m_Reply != nullptr) {
if (m_Canceled) {
m_Reply->abort();
} else {
@@ -167,7 +176,7 @@ void SelfUpdater::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) void SelfUpdater::downloadReadyRead()
{
- if (m_Reply != NULL) {
+ if (m_Reply != nullptr) {
m_UpdateFile.write(m_Reply->readAll());
}
}
@@ -177,7 +186,7 @@ void SelfUpdater::downloadFinished() {
int error = QNetworkReply::NoError;
- if (m_Reply != NULL) {
+ if (m_Reply != nullptr) {
m_UpdateFile.write(m_Reply->readAll());
error = m_Reply->error();
@@ -189,7 +198,7 @@ void SelfUpdater::downloadFinished() m_Progress.hide();
m_Reply->close();
m_Reply->deleteLater();
- m_Reply = NULL;
+ m_Reply = nullptr;
}
m_UpdateFile.close();
|
