From 90d87a0cf75be44da34c3c3282f82e5b3a399168 Mon Sep 17 00:00:00 2001 From: Tannin Date: Sat, 10 Oct 2015 19:35:18 +0200 Subject: fixed progress dialogs appearing on startup Appears to be a new bug in qt or maybe incompatibility with Windows 10: All Progress dialogs were made visibly automatically a few seconds after application startup. This was "fixed" by creating the dialog dynamically on demand --- src/installationmanager.cpp | 83 +++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 37 deletions(-) (limited to 'src/installationmanager.cpp') 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 . #include #include #include +#include #include #include #include @@ -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(this, &InstallationManager::updateProgress), new MethodCallback(this, &InstallationManager::dummyProgressFile), new MethodCallback(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(this, &InstallationManager::updateProgress), new MethodCallback(this, &InstallationManager::dummyProgressFile), new MethodCallback(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(percentage * 100.0)); - if (m_InstallationProgress.wasCanceled()) { - m_CurrentArchive->cancel(); - m_InstallationProgress.reset(); + if (m_InstallationProgress != nullptr) { + m_InstallationProgress->setValue(static_cast(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 &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(this, &InstallationManager::updateProgress), new MethodCallback(this, &InstallationManager::updateProgressFile), new MethodCallback(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 &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 -- cgit v1.3.1