summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Tanner <trtanner@btinternet.com>2015-10-11 21:26:21 +0100
committerThomas Tanner <trtanner@btinternet.com>2015-10-11 21:26:21 +0100
commitaf9a128b4f3393d4e7e8a0c4fda48148b80a0e4c (patch)
tree9f17c99511231bdd2d431eed04bd38a7322f6bb6 /src
parentc5876cb6a142dc228ff3e3c3a936699f58d6b2a0 (diff)
parent7d93a9a2003f31188e4da8cbcd7e5df0352bb900 (diff)
Merge branch 'TanninOne/master'
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/aboutdialog.cpp2
-rw-r--r--src/aboutdialog.ui2
-rw-r--r--src/app_icon.rc4
-rw-r--r--src/installationmanager.cpp83
-rw-r--r--src/installationmanager.h2
-rw-r--r--src/nxmaccessmanager.cpp18
-rw-r--r--src/nxmaccessmanager.h2
-rw-r--r--src/selfupdater.cpp40
-rw-r--r--src/selfupdater.h8
10 files changed, 94 insertions, 69 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index c2d0b42a..22b725de 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -228,7 +228,7 @@ SET(organizer_QRCS
SET(organizer_RCS
app_icon.rc
- #version.rc
+ version.rc
)
diff --git a/src/aboutdialog.cpp b/src/aboutdialog.cpp
index 7b311263..6fce2acb 100644
--- a/src/aboutdialog.cpp
+++ b/src/aboutdialog.cpp
@@ -37,7 +37,7 @@ AboutDialog::AboutDialog(const QString &version, QWidget *parent)
m_LicenseFiles[LICENSE_ZLIB] = "zlib.txt";
m_LicenseFiles[LICENSE_APACHE2] = "apache-license-2.0.txt";
- addLicense("Qt 5.4", LICENSE_LGPL3);
+ addLicense("Qt", LICENSE_LGPL3);
addLicense("Qt Json", LICENSE_GPL3);
addLicense("Boost Library", LICENSE_BOOST);
addLicense("7-zip", LICENSE_LGPL3);
diff --git a/src/aboutdialog.ui b/src/aboutdialog.ui
index 2806921f..ea5d2141 100644
--- a/src/aboutdialog.ui
+++ b/src/aboutdialog.ui
@@ -90,7 +90,7 @@
<item>
<widget class="QLabel" name="label_2">
<property name="text">
- <string notr="true">&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.&lt;/p&gt;&lt;p&gt;See the GNU General Public License for more details.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+ <string notr="true">&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.&lt;/p&gt;&lt;p&gt;See the GNU General Public License for more details.&lt;/p&gt;&lt;p&gt;Source code can be found at &lt;a href=&quot;https://github.com/TanninOne/modorganizer&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#007af4;&quot;&gt;GitHub&lt;/span&gt;&lt;/a&gt;.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
diff --git a/src/app_icon.rc b/src/app_icon.rc
index 2550f49d..6e79ef7d 100644
--- a/src/app_icon.rc
+++ b/src/app_icon.rc
@@ -1,3 +1 @@
-#include "version.rc"
-
- IDI_ICON1 ICON DISCARDABLE "mo_icon.ico"
+IDI_ICON1 ICON DISCARDABLE "mo_icon.ico"
diff --git a/src/installationmanager.cpp b/src/installationmanager.cpp
index 75abd750..a6af1a7f 100644
--- a/src/installationmanager.cpp
+++ b/src/installationmanager.cpp
@@ -34,6 +34,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include <installationtester.h>
#include <gameinfo.h>
#include <utility.h>
+#include <scopeguard.h>
#include <QFileInfo>
#include <QLibrary>
#include <QInputDialog>
@@ -71,7 +72,6 @@ static T resolveFunction(QLibrary &lib, const char *name)
InstallationManager::InstallationManager()
: m_ParentWidget(nullptr)
- , m_InstallationProgress(nullptr)
, m_SupportedExtensions({ "zip", "rar", "7z", "fomod", "001" })
{
QLibrary archiveLib("dlls\\archive.dll");
@@ -85,8 +85,6 @@ InstallationManager::InstallationManager()
if (!m_CurrentArchive->isValid()) {
throw MyException(getErrorString(m_CurrentArchive->getLastError()));
}
-
- m_InstallationProgress.setWindowFlags(m_InstallationProgress.windowFlags() & (~Qt::WindowContextHelpButtonHint));
}
@@ -97,7 +95,6 @@ InstallationManager::~InstallationManager()
void InstallationManager::setParentWidget(QWidget *widget)
{
- m_InstallationProgress.setParent(widget, Qt::Dialog);
for (IPluginInstaller *installer : m_Installers) {
installer->setParentWidget(widget);
}
@@ -171,19 +168,24 @@ bool InstallationManager::unpackSingleFile(const QString &fileName)
return false;
}
- m_InstallationProgress.setWindowTitle(tr("Extracting files"));
- m_InstallationProgress.setLabelText(QString());
- m_InstallationProgress.setValue(0);
- m_InstallationProgress.setWindowModality(Qt::WindowModal);
- m_InstallationProgress.show();
+ m_InstallationProgress = new QProgressDialog(m_ParentWidget);
+ ON_BLOCK_EXIT([this] () {
+ m_InstallationProgress->hide();
+ m_InstallationProgress->deleteLater();
+ m_InstallationProgress = nullptr;
+ });
+ m_InstallationProgress->setWindowFlags(
+ m_InstallationProgress->windowFlags() & ~Qt::WindowContextHelpButtonHint);
+
+ m_InstallationProgress->setWindowTitle(tr("Extracting files"));
+ m_InstallationProgress->setWindowModality(Qt::WindowModal);
+ m_InstallationProgress->show();
bool res = m_CurrentArchive->extract(ToWString(QDir::toNativeSeparators(QDir::tempPath())).c_str(),
new MethodCallback<InstallationManager, void, float>(this, &InstallationManager::updateProgress),
new MethodCallback<InstallationManager, void, LPCWSTR>(this, &InstallationManager::dummyProgressFile),
new MethodCallback<InstallationManager, void, LPCWSTR>(this, &InstallationManager::report7ZipError));
- m_InstallationProgress.hide();
-
return res;
}
@@ -191,7 +193,7 @@ bool InstallationManager::unpackSingleFile(const QString &fileName)
QString InstallationManager::extractFile(const QString &fileName)
{
if (unpackSingleFile(fileName)) {
- return QDir::tempPath().append("/").append(QFileInfo(fileName).fileName());
+ return QDir::tempPath() + "/" + QFileInfo(fileName).fileName();
} else {
return QString();
}
@@ -215,7 +217,7 @@ QStringList InstallationManager::extractFiles(const QStringList &filesOrig, bool
{
QStringList files;
- foreach (const QString &file, filesOrig) {
+ for (const QString &file : filesOrig) {
files.append(canonicalize(file));
}
@@ -249,22 +251,26 @@ QStringList InstallationManager::extractFiles(const QStringList &filesOrig, bool
}
}
- m_InstallationProgress.setWindowTitle(tr("Extracting files"));
- m_InstallationProgress.setLabelText(QString());
- m_InstallationProgress.setValue(0);
- m_InstallationProgress.setWindowModality(Qt::WindowModal);
- m_InstallationProgress.show();
+ m_InstallationProgress = new QProgressDialog(m_ParentWidget);
+ ON_BLOCK_EXIT([this] () {
+ m_InstallationProgress->hide();
+ m_InstallationProgress->deleteLater();
+ m_InstallationProgress = nullptr;
+ });
+ m_InstallationProgress->setWindowFlags(
+ m_InstallationProgress->windowFlags() & (~Qt::WindowContextHelpButtonHint));
+ m_InstallationProgress->setWindowTitle(tr("Extracting files"));
+ m_InstallationProgress->setWindowModality(Qt::WindowModal);
+ m_InstallationProgress->show();
// unpack only the files we need for the installer
if (!m_CurrentArchive->extract(ToWString(QDir::toNativeSeparators(QDir::tempPath())).c_str(),
new MethodCallback<InstallationManager, void, float>(this, &InstallationManager::updateProgress),
new MethodCallback<InstallationManager, void, LPCWSTR>(this, &InstallationManager::dummyProgressFile),
new MethodCallback<InstallationManager, void, LPCWSTR>(this, &InstallationManager::report7ZipError))) {
- m_InstallationProgress.hide();
throw MyException(QString("extracting failed (%1)").arg(m_CurrentArchive->getLastError()));
}
- m_InstallationProgress.hide();
return result;
}
@@ -387,21 +393,21 @@ DirectoryTree::Node *InstallationManager::getSimpleArchiveBase(DirectoryTree *da
void InstallationManager::updateProgress(float percentage)
{
- m_InstallationProgress.setValue(static_cast<int>(percentage * 100.0));
- if (m_InstallationProgress.wasCanceled()) {
- m_CurrentArchive->cancel();
- m_InstallationProgress.reset();
+ if (m_InstallationProgress != nullptr) {
+ m_InstallationProgress->setValue(static_cast<int>(percentage * 100.0));
+ if (m_InstallationProgress->wasCanceled()) {
+ m_CurrentArchive->cancel();
+ m_InstallationProgress->reset();
+ }
}
}
void InstallationManager::updateProgressFile(LPCWSTR fileName)
{
-#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
- m_InstallationProgress.setLabelText(QString::fromWCharArray(fileName));
-#else
- m_InstallationProgress.setLabelText(QString::fromUtf16(fileName));
-#endif
+ if (m_InstallationProgress != nullptr) {
+ m_InstallationProgress->setLabelText(QString::fromWCharArray(fileName));
+ }
}
@@ -533,16 +539,21 @@ bool InstallationManager::doInstall(GuessedValue<QString> &modName, int modID,
qDebug("installing to \"%s\"", targetDirectoryNative.toUtf8().constData());
- m_InstallationProgress.setWindowTitle(tr("Extracting files"));
- m_InstallationProgress.setLabelText(QString());
- m_InstallationProgress.setValue(0);
- m_InstallationProgress.setWindowModality(Qt::WindowModal);
- m_InstallationProgress.show();
+ m_InstallationProgress = new QProgressDialog(m_ParentWidget);
+ ON_BLOCK_EXIT([this] () {
+ m_InstallationProgress->hide();
+ m_InstallationProgress->deleteLater();
+ m_InstallationProgress = nullptr;
+ });
+
+ m_InstallationProgress->setWindowFlags(
+ m_InstallationProgress->windowFlags() & (~Qt::WindowContextHelpButtonHint));
+ m_InstallationProgress->setWindowModality(Qt::WindowModal);
+ m_InstallationProgress->show();
if (!m_CurrentArchive->extract(ToWString("\\\\?\\" + targetDirectoryNative).c_str(),
new MethodCallback<InstallationManager, void, float>(this, &InstallationManager::updateProgress),
new MethodCallback<InstallationManager, void, LPCWSTR>(this, &InstallationManager::updateProgressFile),
new MethodCallback<InstallationManager, void, LPCWSTR>(this, &InstallationManager::report7ZipError))) {
- m_InstallationProgress.hide();
if (m_CurrentArchive->getLastError() == Archive::ERROR_EXTRACT_CANCELLED) {
return false;
} else {
@@ -550,8 +561,6 @@ bool InstallationManager::doInstall(GuessedValue<QString> &modName, int modID,
}
}
- m_InstallationProgress.hide();
-
QSettings settingsFile(targetDirectory + "/meta.ini", QSettings::IniFormat);
// overwrite settings only if they are actually are available or haven't been set before
diff --git a/src/installationmanager.h b/src/installationmanager.h
index d4b4f7dc..111b41f5 100644
--- a/src/installationmanager.h
+++ b/src/installationmanager.h
@@ -208,7 +208,7 @@ private:
Archive *m_CurrentArchive;
QString m_CurrentFile;
- QProgressDialog m_InstallationProgress;
+ QProgressDialog *m_InstallationProgress { nullptr };
std::set<QString> m_TempFilesToDelete;
diff --git a/src/nxmaccessmanager.cpp b/src/nxmaccessmanager.cpp
index 07a75910..0763bb71 100644
--- a/src/nxmaccessmanager.cpp
+++ b/src/nxmaccessmanager.cpp
@@ -52,7 +52,6 @@ const std::set<int> NXMAccessManager::s_PremiumAccountStates { 4, 6, 13, 27, 31,
NXMAccessManager::NXMAccessManager(QObject *parent, const QString &moVersion)
: QNetworkAccessManager(parent)
, m_LoginReply(nullptr)
- , m_ProgressDialog()
, m_MOVersion(moVersion)
{
m_LoginTimeout.setSingleShot(true);
@@ -239,10 +238,11 @@ void NXMAccessManager::pageLogin()
request.setRawHeader("User-Agent", userAgent().toUtf8());
- m_ProgressDialog.setLabelText(tr("Logging into Nexus"));
- QList<QPushButton*> buttons = m_ProgressDialog.findChildren<QPushButton*>();
+ m_ProgressDialog = new QProgressDialog(nullptr);
+ m_ProgressDialog->setLabelText(tr("Logging into Nexus"));
+ QList<QPushButton*> buttons = m_ProgressDialog->findChildren<QPushButton*>();
buttons.at(0)->setEnabled(false);
- m_ProgressDialog.show();
+ m_ProgressDialog->show();
QCoreApplication::processEvents(); // for some reason the whole app hangs during the login. This way the user has at least a little feedback
m_LoginReply = post(request, postDataQuery);
@@ -269,7 +269,10 @@ void NXMAccessManager::loginTimeout()
void NXMAccessManager::loginError(QNetworkReply::NetworkError)
{
qDebug("login error");
- m_ProgressDialog.hide();
+ if (m_ProgressDialog != nullptr) {
+ m_ProgressDialog->deleteLater();
+ m_ProgressDialog = nullptr;
+ }
m_Username.clear();
m_Password.clear();
m_LoginState = LOGIN_NOT_VALID;
@@ -300,7 +303,10 @@ bool NXMAccessManager::hasLoginCookies() const
void NXMAccessManager::loginFinished()
{
- m_ProgressDialog.hide();
+ if (m_ProgressDialog != nullptr) {
+ m_ProgressDialog->deleteLater();
+ m_ProgressDialog = nullptr;
+ }
m_LoginReply->deleteLater();
m_LoginReply = nullptr;
diff --git a/src/nxmaccessmanager.h b/src/nxmaccessmanager.h
index 2b615cdc..a03dbe36 100644
--- a/src/nxmaccessmanager.h
+++ b/src/nxmaccessmanager.h
@@ -109,7 +109,7 @@ private:
QTimer m_LoginTimeout;
QNetworkReply *m_LoginReply;
- QProgressDialog m_ProgressDialog;
+ QProgressDialog *m_ProgressDialog { nullptr };
QString m_MOVersion;
QString m_NMMVersion;
diff --git a/src/selfupdater.cpp b/src/selfupdater.cpp
index ed34bfc2..bcf81cfd 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_CurrentArchive->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;
@@ -439,7 +450,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();
}
}
@@ -474,8 +485,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();
}
}
}
-
diff --git a/src/selfupdater.h b/src/selfupdater.h
index b5bbc406..143b05cb 100644
--- a/src/selfupdater.h
+++ b/src/selfupdater.h
@@ -32,6 +32,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
class NexusInterface;
+
/**
* @brief manages updates for Mod Organizer itself
* This class is used to update the Mod Organizer
@@ -39,7 +40,7 @@ class NexusInterface;
* 1. call testForUpdate() to determine is available
* 2. if the updateAvailable() signal is received, allow the user to start the update
* 3. if the user start the update, call startUpdate()
- * 4. startUpdate() will first query a list of files, try to determine if there is an
+ * 4. startUpdate() will first query a list of files, try to determine if there is an
* incremental update. If not, the user will have to confirm the download of a full download.
* Once the correct file is selected, it is downloaded.
* 5. before the downloaded file is extracted, existing files that are going to be replaced are
@@ -48,7 +49,7 @@ class NexusInterface;
* 7. finally, a restart is requested via signal.
* 8. at restart, Mod Organizer will remove the update_backup directory since none of the files
* should now be open
- *
+ *
* @todo use NexusBridge
**/
class SelfUpdater : public QObject
@@ -121,6 +122,7 @@ private:
void report7ZipError(LPCWSTR errorMessage);
QString retrieveNews(const QString &description);
void showProgress();
+ void closeProgress();
private slots:
@@ -138,7 +140,7 @@ private:
QString m_NewestVersion;
QFile m_UpdateFile;
QNetworkReply *m_Reply;
- QProgressDialog m_Progress;
+ QProgressDialog *m_Progress { nullptr };
bool m_Canceled;
int m_Attempts;