From 30c177cb371e92fe5e4cfc600cf27586402cf0a8 Mon Sep 17 00:00:00 2001 From: Silarn Date: Mon, 16 Apr 2018 12:47:17 -0500 Subject: Support for multi-game downloads --- src/installationmanager.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/installationmanager.cpp') diff --git a/src/installationmanager.cpp b/src/installationmanager.cpp index 9a70f8bd..6785bf67 100644 --- a/src/installationmanager.cpp +++ b/src/installationmanager.cpp @@ -537,7 +537,7 @@ bool InstallationManager::ensureValidModName(GuessedValue &name) const return true; } -bool InstallationManager::doInstall(GuessedValue &modName, int modID, +bool InstallationManager::doInstall(GuessedValue &modName, QString gameName, int modID, const QString &version, const QString &newestVersion, int categoryID, const QString &repository) { @@ -582,6 +582,9 @@ bool InstallationManager::doInstall(GuessedValue &modName, int modID, QSettings settingsFile(targetDirectory + "/meta.ini", QSettings::IniFormat); // overwrite settings only if they are actually are available or haven't been set before + if ((gameName != "") || !settingsFile.contains("gameName")) { + settingsFile.setValue("gameName", gameName); + } if ((modID != 0) || !settingsFile.contains("modid")) { settingsFile.setValue("modid", modID); } @@ -662,6 +665,7 @@ bool InstallationManager::install(const QString &fileName, modName.update(QFileInfo(fileName).completeBaseName(), GUESS_FALLBACK); // read out meta information from the download if available + QString gameName = ""; int modID = 0; QString version = ""; QString newestVersion = ""; @@ -671,6 +675,7 @@ bool InstallationManager::install(const QString &fileName, QString metaName = fileName + ".meta"; if (QFile(metaName).exists()) { QSettings metaFile(metaName, QSettings::IniFormat); + gameName = metaFile.value("gameName", "").toString(); modID = metaFile.value("modID", 0).toInt(); QTextDocument doc; doc.setHtml(metaFile.value("name", "").toString()); @@ -759,7 +764,7 @@ bool InstallationManager::install(const QString &fileName, mapToArchive(filesTree.data()); // the simple installer only prepares the installation, the rest // works the same for all installers - if (!doInstall(modName, modID, version, newestVersion, categoryID, + if (!doInstall(modName, gameName, modID, version, newestVersion, categoryID, repository)) { installResult = IPluginInstaller::RESULT_FAILED; } @@ -780,6 +785,15 @@ bool InstallationManager::install(const QString &fileName, if (installerExt.find(fileInfo.suffix()) != installerExt.end()) { installResult = installerCustom->install(modName, fileName, version, modID); + if (installResult == IPluginInstaller::RESULT_SUCCESS) { + mapToArchive(filesTree.data()); + // the simple installer only prepares the installation, the rest + // works the same for all installers + if (!doInstall(modName, gameName, modID, version, newestVersion, categoryID, + repository)) { + installResult = IPluginInstaller::RESULT_FAILED; + } + } unsigned int idx = ModInfo::getIndex(modName); if (idx != UINT_MAX) { ModInfo::Ptr info = ModInfo::getByIndex(idx); -- cgit v1.3.1 From 584c6049f981e601f6c88c00823ee322c9002bbe Mon Sep 17 00:00:00 2001 From: Silarn Date: Tue, 1 May 2018 12:37:07 -0500 Subject: Remove redundant code causing multiple installs --- src/installationmanager.cpp | 9 --------- 1 file changed, 9 deletions(-) (limited to 'src/installationmanager.cpp') diff --git a/src/installationmanager.cpp b/src/installationmanager.cpp index 6785bf67..668be84e 100644 --- a/src/installationmanager.cpp +++ b/src/installationmanager.cpp @@ -785,15 +785,6 @@ bool InstallationManager::install(const QString &fileName, if (installerExt.find(fileInfo.suffix()) != installerExt.end()) { installResult = installerCustom->install(modName, fileName, version, modID); - if (installResult == IPluginInstaller::RESULT_SUCCESS) { - mapToArchive(filesTree.data()); - // the simple installer only prepares the installation, the rest - // works the same for all installers - if (!doInstall(modName, gameName, modID, version, newestVersion, categoryID, - repository)) { - installResult = IPluginInstaller::RESULT_FAILED; - } - } unsigned int idx = ModInfo::getIndex(modName); if (idx != UINT_MAX) { ModInfo::Ptr info = ModInfo::getByIndex(idx); -- cgit v1.3.1 From f7c9b8c3336da02d3360b810247c00494df114fd Mon Sep 17 00:00:00 2001 From: Silarn Date: Wed, 2 May 2018 17:04:28 -0500 Subject: Thread extraction process and properly offload function calls from threads --- src/installationmanager.cpp | 80 +++++++++++++++++++++++++++++++++++---------- src/installationmanager.h | 10 ++++++ 2 files changed, 72 insertions(+), 18 deletions(-) (limited to 'src/installationmanager.cpp') diff --git a/src/installationmanager.cpp b/src/installationmanager.cpp index 668be84e..8ee2220e 100644 --- a/src/installationmanager.cpp +++ b/src/installationmanager.cpp @@ -49,6 +49,7 @@ along with Mod Organizer. If not, see . #include #include #include +#include #include @@ -94,6 +95,9 @@ InstallationManager::InstallationManager() if (!m_ArchiveHandler->isValid()) { throw MyException(getErrorString(m_ArchiveHandler->getLastError())); } + + connect(this, SIGNAL(progressUpdate(float)), this, (SLOT(doProgressUpdate(float)))); + connect(this, SIGNAL(progressUpdate(const QString)), this, (SLOT(doProgressFileUpdate(const QString)))); } InstallationManager::~InstallationManager() @@ -190,10 +194,19 @@ bool InstallationManager::unpackSingleFile(const QString &fileName) m_InstallationProgress->setFixedSize(600, 100); m_InstallationProgress->show(); - bool res = m_ArchiveHandler->extract(QDir::tempPath(), - new MethodCallback(this, &InstallationManager::updateProgress), - nullptr, - new MethodCallback(this, &InstallationManager::report7ZipError)); + QFuture future = QtConcurrent::run([&]() -> bool { + return m_ArchiveHandler->extract( + QDir::tempPath(), + new MethodCallback(this, &InstallationManager::updateProgress), + nullptr, + new MethodCallback(this, &InstallationManager::report7ZipError) + ); + }); + while (!future.isFinished()) { + QCoreApplication::processEvents(); + ::Sleep(50); + } + bool res = future.result(); return res; } @@ -279,10 +292,19 @@ QStringList InstallationManager::extractFiles(const QStringList &filesOrig, bool m_InstallationProgress->show(); // unpack only the files we need for the installer - if (!m_ArchiveHandler->extract(QDir::tempPath(), - new MethodCallback(this, &InstallationManager::updateProgress), - nullptr, - new MethodCallback(this, &InstallationManager::report7ZipError))) { + QFuture future = QtConcurrent::run([&]() -> bool { + return m_ArchiveHandler->extract( + QDir::tempPath(), + new MethodCallback(this, &InstallationManager::updateProgress), + nullptr, + new MethodCallback(this, &InstallationManager::report7ZipError) + ); + }); + while (!future.isFinished()) { + QCoreApplication::processEvents(); + ::Sleep(50); + } + if (!future.result()) { throw MyException(QString("extracting failed (%1)").arg(m_ArchiveHandler->getLastError())); } @@ -408,9 +430,23 @@ DirectoryTree::Node *InstallationManager::getSimpleArchiveBase(DirectoryTree *da void InstallationManager::updateProgress(float percentage) +{ + emit progressUpdate(percentage); +} + + +void InstallationManager::updateProgressFile(QString const &fileName) +{ + emit progressUpdate(fileName); +} + + +void InstallationManager::doProgressUpdate(float percentage) { if (m_InstallationProgress != nullptr) { - m_InstallationProgress->setValue(static_cast(percentage * 100.0)); + QMetaObject::invokeMethod(m_InstallationProgress, "setValue", Qt::QueuedConnection, Q_ARG(int, static_cast(percentage * 100.0))); + //m_InstallationProgress->setValue(percent); + if (m_InstallationProgress->wasCanceled()) { m_ArchiveHandler->cancel(); m_InstallationProgress->reset(); @@ -419,12 +455,11 @@ void InstallationManager::updateProgress(float percentage) } -void InstallationManager::updateProgressFile(QString const &fileName) +void InstallationManager::doProgressFileUpdate(QString const fileName) { - if (m_InstallationProgress != nullptr) { - m_InstallationProgress->setLabelText(fileName); - QCoreApplication::processEvents(); - } + if (m_InstallationProgress != nullptr) { + m_InstallationProgress->setLabelText(fileName); + } } @@ -568,10 +603,19 @@ bool InstallationManager::doInstall(GuessedValue &modName, QString game m_InstallationProgress->setWindowModality(Qt::WindowModal); m_InstallationProgress->setFixedSize(600, 100); m_InstallationProgress->show(); - if (!m_ArchiveHandler->extract(targetDirectory, - new MethodCallback(this, &InstallationManager::updateProgress), - new MethodCallback(this, &InstallationManager::updateProgressFile), - new MethodCallback(this, &InstallationManager::report7ZipError))) { + QFuture future = QtConcurrent::run([&]() -> bool { + return m_ArchiveHandler->extract( + targetDirectory, + new MethodCallback(this, &InstallationManager::updateProgress), + new MethodCallback(this, &InstallationManager::updateProgressFile), + new MethodCallback(this, &InstallationManager::report7ZipError) + ); + }); + while (!future.isFinished()) { + QCoreApplication::processEvents(); + ::Sleep(50); + } + if (!future.result()) { if (m_ArchiveHandler->getLastError() == Archive::ERROR_EXTRACT_CANCELLED) { return false; } else { diff --git a/src/installationmanager.h b/src/installationmanager.h index bdf71a8d..84ccd1a4 100644 --- a/src/installationmanager.h +++ b/src/installationmanager.h @@ -177,6 +177,16 @@ private: void postInstallCleanup(); +signals: + + void progressUpdate(float percentage); + void progressUpdate(QString const fileName); + +private slots: + + void doProgressUpdate(float percentage); + void doProgressFileUpdate(const QString fileName); + private: struct ByPriority { -- cgit v1.3.1 From d9b1cfdb4b287fe43742269aaec26907ddcb6445 Mon Sep 17 00:00:00 2001 From: Silarn Date: Fri, 4 May 2018 02:30:10 -0500 Subject: invokeMethod was getting called too late and is unneeded now --- src/installationmanager.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/installationmanager.cpp') diff --git a/src/installationmanager.cpp b/src/installationmanager.cpp index 8ee2220e..4b433899 100644 --- a/src/installationmanager.cpp +++ b/src/installationmanager.cpp @@ -444,8 +444,7 @@ void InstallationManager::updateProgressFile(QString const &fileName) void InstallationManager::doProgressUpdate(float percentage) { if (m_InstallationProgress != nullptr) { - QMetaObject::invokeMethod(m_InstallationProgress, "setValue", Qt::QueuedConnection, Q_ARG(int, static_cast(percentage * 100.0))); - //m_InstallationProgress->setValue(percent); + m_InstallationProgress->setValue(static_cast(percentage * 100.0)); if (m_InstallationProgress->wasCanceled()) { m_ArchiveHandler->cancel(); @@ -454,7 +453,6 @@ void InstallationManager::doProgressUpdate(float percentage) } } - void InstallationManager::doProgressFileUpdate(QString const fileName) { if (m_InstallationProgress != nullptr) { -- cgit v1.3.1 From 0d7460996ae92c59f78cd2b5ccac43a1bf8869b2 Mon Sep 17 00:00:00 2001 From: Silarn Date: Fri, 4 May 2018 11:34:49 -0500 Subject: Further offload setValue to avoid threading issues --- src/installationmanager.cpp | 9 ++++++++- src/installationmanager.h | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'src/installationmanager.cpp') diff --git a/src/installationmanager.cpp b/src/installationmanager.cpp index 4b433899..a99a07e1 100644 --- a/src/installationmanager.cpp +++ b/src/installationmanager.cpp @@ -444,7 +444,7 @@ void InstallationManager::updateProgressFile(QString const &fileName) void InstallationManager::doProgressUpdate(float percentage) { if (m_InstallationProgress != nullptr) { - m_InstallationProgress->setValue(static_cast(percentage * 100.0)); + QMetaObject::invokeMethod(this, "setProgressValue", Qt::QueuedConnection, Q_ARG(int, static_cast(percentage * 100.0))); if (m_InstallationProgress->wasCanceled()) { m_ArchiveHandler->cancel(); @@ -453,6 +453,13 @@ void InstallationManager::doProgressUpdate(float percentage) } } +void InstallationManager::setProgressValue(int percentage) +{ + if (m_InstallationProgress != nullptr) { + m_InstallationProgress->setValue(percentage); + } +} + void InstallationManager::doProgressFileUpdate(QString const fileName) { if (m_InstallationProgress != nullptr) { diff --git a/src/installationmanager.h b/src/installationmanager.h index 84ccd1a4..851390a7 100644 --- a/src/installationmanager.h +++ b/src/installationmanager.h @@ -186,6 +186,7 @@ private slots: void doProgressUpdate(float percentage); void doProgressFileUpdate(const QString fileName); + void setProgressValue(int percentage); private: -- cgit v1.3.1 From a77433f8810c100e6934c64afe9d69c6c0cff2f4 Mon Sep 17 00:00:00 2001 From: Silarn Date: Fri, 4 May 2018 14:28:19 -0500 Subject: Use queued connections and do while loops to finish event processing --- src/installationmanager.cpp | 31 ++++++++++++------------------- src/installationmanager.h | 1 - 2 files changed, 12 insertions(+), 20 deletions(-) (limited to 'src/installationmanager.cpp') diff --git a/src/installationmanager.cpp b/src/installationmanager.cpp index a99a07e1..27c83787 100644 --- a/src/installationmanager.cpp +++ b/src/installationmanager.cpp @@ -96,8 +96,8 @@ InstallationManager::InstallationManager() throw MyException(getErrorString(m_ArchiveHandler->getLastError())); } - connect(this, SIGNAL(progressUpdate(float)), this, (SLOT(doProgressUpdate(float)))); - connect(this, SIGNAL(progressUpdate(const QString)), this, (SLOT(doProgressFileUpdate(const QString)))); + connect(this, SIGNAL(progressUpdate(float)), this, (SLOT(doProgressUpdate(float))), Qt::QueuedConnection); + connect(this, SIGNAL(progressUpdate(const QString)), this, (SLOT(doProgressFileUpdate(const QString))), Qt::QueuedConnection); } InstallationManager::~InstallationManager() @@ -202,10 +202,10 @@ bool InstallationManager::unpackSingleFile(const QString &fileName) new MethodCallback(this, &InstallationManager::report7ZipError) ); }); - while (!future.isFinished()) { - QCoreApplication::processEvents(); + do { ::Sleep(50); - } + QCoreApplication::processEvents(); + } while (!future.isFinished()); bool res = future.result(); return res; @@ -300,10 +300,10 @@ QStringList InstallationManager::extractFiles(const QStringList &filesOrig, bool new MethodCallback(this, &InstallationManager::report7ZipError) ); }); - while (!future.isFinished()) { - QCoreApplication::processEvents(); + do { ::Sleep(50); - } + QCoreApplication::processEvents(); + } while (!future.isFinished()); if (!future.result()) { throw MyException(QString("extracting failed (%1)").arg(m_ArchiveHandler->getLastError())); } @@ -444,7 +444,7 @@ void InstallationManager::updateProgressFile(QString const &fileName) void InstallationManager::doProgressUpdate(float percentage) { if (m_InstallationProgress != nullptr) { - QMetaObject::invokeMethod(this, "setProgressValue", Qt::QueuedConnection, Q_ARG(int, static_cast(percentage * 100.0))); + m_InstallationProgress->setValue(static_cast(percentage * 100.0)); if (m_InstallationProgress->wasCanceled()) { m_ArchiveHandler->cancel(); @@ -453,13 +453,6 @@ void InstallationManager::doProgressUpdate(float percentage) } } -void InstallationManager::setProgressValue(int percentage) -{ - if (m_InstallationProgress != nullptr) { - m_InstallationProgress->setValue(percentage); - } -} - void InstallationManager::doProgressFileUpdate(QString const fileName) { if (m_InstallationProgress != nullptr) { @@ -616,10 +609,10 @@ bool InstallationManager::doInstall(GuessedValue &modName, QString game new MethodCallback(this, &InstallationManager::report7ZipError) ); }); - while (!future.isFinished()) { - QCoreApplication::processEvents(); + do { ::Sleep(50); - } + QCoreApplication::processEvents(); + } while (!future.isFinished()); if (!future.result()) { if (m_ArchiveHandler->getLastError() == Archive::ERROR_EXTRACT_CANCELLED) { return false; diff --git a/src/installationmanager.h b/src/installationmanager.h index 851390a7..84ccd1a4 100644 --- a/src/installationmanager.h +++ b/src/installationmanager.h @@ -186,7 +186,6 @@ private slots: void doProgressUpdate(float percentage); void doProgressFileUpdate(const QString fileName); - void setProgressValue(int percentage); private: -- cgit v1.3.1 From 6359d7d23f4137a35dfd241a0daa22c6a885e426 Mon Sep 17 00:00:00 2001 From: Silarn Date: Sun, 6 May 2018 17:21:35 -0500 Subject: Fixes for downloads and installs --- src/downloadmanager.cpp | 49 +++++++++++++++++++++++++-------------------- src/downloadmanager.h | 4 ++-- src/installationmanager.cpp | 43 +++++++++++++++++---------------------- src/installationmanager.h | 7 ++----- 4 files changed, 49 insertions(+), 54 deletions(-) (limited to 'src/installationmanager.cpp') diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 0da5ced3..2ab56fab 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -145,8 +145,10 @@ void DownloadManager::DownloadInfo::setName(QString newName, bool renameFile) QString oldMetaFileName = QString("%1.meta").arg(m_FileName); m_FileName = QFileInfo(newName).fileName(); if ((m_State == DownloadManager::STATE_STARTED) || - (m_State == DownloadManager::STATE_DOWNLOADING)) { + (m_State == DownloadManager::STATE_DOWNLOADING) || + (m_State == DownloadManager::STATE_PAUSED)) { newName.append(UNFINISHED); + oldMetaFileName = QString("%1%2.meta").arg(m_FileName).arg(UNFINISHED); } if (renameFile) { if ((newName != m_Output.fileName()) && !m_Output.rename(newName)) { @@ -154,10 +156,9 @@ void DownloadManager::DownloadInfo::setName(QString newName, bool renameFile) return; } - QFile metaFile(oldMetaFileName); - if (metaFile.exists()) { + QFile metaFile(QFileInfo(newName).path() + "/" + oldMetaFileName); + if (metaFile.exists()) metaFile.rename(newName.mid(0).append(".meta")); - } } if (!m_Output.isOpen()) { // can't set file name if it's open @@ -457,7 +458,9 @@ void DownloadManager::startDownload(QNetworkReply *reply, DownloadInfo *newDownl else setState(newDownload, STATE_DOWNLOADING); } - } + } else + connect(newDownload->m_Reply, SIGNAL(finished()), this, SLOT(downloadFinished())); + QCoreApplication::processEvents(); @@ -465,8 +468,8 @@ void DownloadManager::startDownload(QNetworkReply *reply, DownloadInfo *newDownl downloadFinished(indexByName(newDownload->m_FileName)); return; } - } - connect(newDownload->m_Reply, SIGNAL(finished()), this, SLOT(downloadFinished())); + } else + connect(newDownload->m_Reply, SIGNAL(finished()), this, SLOT(downloadFinished())); } @@ -496,11 +499,11 @@ void DownloadManager::addNXMDownload(const QString &url) for (DownloadInfo *download : m_ActiveDownloads) { if (download->m_FileInfo->modID == nxmInfo.modId() && download->m_FileInfo->fileID == nxmInfo.fileId()) { if (download->m_State == STATE_DOWNLOADING || download->m_State == STATE_PAUSED || download->m_State == STATE_STARTED) { - qDebug("download requested is already started (mod: %s, file: %s)", qPrintable(download->m_FileInfo->modName), + qDebug("download requested is already started (mod: %s, file: %s)", qPrintable(download->m_FileInfo->modID), qPrintable(download->m_FileInfo->fileName)); - QMessageBox::information(nullptr, tr("Already Started"), tr("There is already a download started for this file (%2).") - .arg(download->m_FileInfo->modName).arg(download->m_FileInfo->name), QMessageBox::Ok); + QMessageBox::information(nullptr, tr("Already Started"), tr("There is already a download started for this file (mod: %1, file: %2).") + .arg(download->m_FileInfo->modName).arg(download->m_FileInfo->fileName), QMessageBox::Ok); return; } } @@ -702,6 +705,8 @@ void DownloadManager::resumeDownloadInt(int index) std::get<0>(info->m_SpeedDiff) = 0; std::get<1>(info->m_SpeedDiff) = 0; std::get<2>(info->m_SpeedDiff) = 0; + std::get<3>(info->m_SpeedDiff) = 0; + std::get<4>(info->m_SpeedDiff) = 0; qDebug("resume at %lld bytes", info->m_ResumePos); QByteArray rangeHeader = "bytes=" + QByteArray::number(info->m_ResumePos) + "-"; request.setRawHeader("Range", rangeHeader); @@ -1105,11 +1110,17 @@ void DownloadManager::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) int oldProgress = info->m_Progress.first; info->m_Progress.first = ((info->m_ResumePos + bytesReceived) * 100) / (info->m_ResumePos + bytesTotal); + int elapsed = info->m_StartTime.elapsed(); + std::get<0>(info->m_SpeedDiff) = bytesReceived - std::get<2>(info->m_SpeedDiff); + std::get<1>(info->m_SpeedDiff) = elapsed - std::get<3>(info->m_SpeedDiff); + std::get<2>(info->m_SpeedDiff) = bytesReceived; + std::get<3>(info->m_SpeedDiff) = elapsed; + + double calc = ((double)std::get<0>(info->m_SpeedDiff)) / (((double)(std::get<1>(info->m_SpeedDiff)) / 5000.0)); + std::get<4>(info->m_SpeedDiff) = ((calc*0.5) + (std::get<4>(info->m_SpeedDiff)*1.5)) / 2; + // calculate the download speed - double speed = (bytesReceived - std::get<1>(info->m_SpeedDiff)) * 1000.0 / // Calculate with the data transferred in the last 5 seconds... - (std::get<1>(info->m_SpeedDiff) ? // If we are past 5 seconds - (5 * 1000) + (info->m_StartTime.elapsed() - std::get<2>(info->m_SpeedDiff)) : // Divide by 5 seconds + the diff between chunks - info->m_StartTime.elapsed()); // Else just use the current elapsed time + double speed = (std::get<4>(info->m_SpeedDiff) * 1000.0) / (5 * 1000); QString unit; if (speed < 1024) { @@ -1126,12 +1137,6 @@ void DownloadManager::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) info->m_Progress.second = QString::fromLatin1("%1% - %2 %3").arg(info->m_Progress.first).arg(speed, 3, 'f', 1).arg(unit); - if (info->m_StartTime.elapsed() >= 5 * 1000) { - std::get<1>(info->m_SpeedDiff) = std::get<1>(info->m_SpeedDiff) + bytesReceived - std::get<0>(info->m_SpeedDiff); - std::get<2>(info->m_SpeedDiff) = info->m_StartTime.elapsed(); - } - std::get<0>(info->m_SpeedDiff) = bytesReceived; - TaskProgressManager::instance().updateProgress(info->m_TaskProgressId, bytesReceived, bytesTotal); emit update(index); } @@ -1551,7 +1556,7 @@ void DownloadManager::downloadFinished(int index) QString newName = getFileNameFromNetworkReply(reply); QString oldName = QFileInfo(info->m_Output).fileName(); - if (!newName.isEmpty() && (newName != oldName)) { + if (!newName.isEmpty() && (oldName.isEmpty())) { info->setName(getDownloadFileName(newName), true); } else { info->setName(m_OutputDirectory + "/" + info->m_FileName, true); // don't rename but remove the ".unfinished" extension @@ -1594,7 +1599,7 @@ void DownloadManager::metaDataChanged() DownloadInfo *info = findDownload(this->sender(), &index); if (info != nullptr) { QString newName = getFileNameFromNetworkReply(info->m_Reply); - if (!newName.isEmpty() && (newName != info->m_FileName)) { + if (!newName.isEmpty() && (info->m_FileName.isEmpty())) { info->setName(getDownloadFileName(newName), true); refreshAlphabeticalTranslation(); if (!info->m_Output.isOpen() && !info->m_Output.open(QIODevice::WriteOnly | QIODevice::Append)) { diff --git a/src/downloadmanager.h b/src/downloadmanager.h index 6e3f9c2c..98f5e468 100644 --- a/src/downloadmanager.h +++ b/src/downloadmanager.h @@ -76,7 +76,7 @@ private: QTime m_StartTime; qint64 m_PreResumeSize; std::pair m_Progress; - std::tuple m_SpeedDiff; + std::tuple m_SpeedDiff; DownloadState m_State; int m_CurrentUrl; QStringList m_Urls; @@ -114,7 +114,7 @@ private: private: static unsigned int s_NextDownloadID; private: - DownloadInfo() : m_TotalSize(0), m_ReQueried(false), m_Hidden(false), m_SpeedDiff(std::tuple(0,0,0)) {} + DownloadInfo() : m_TotalSize(0), m_ReQueried(false), m_Hidden(false), m_SpeedDiff(std::tuple(0,0,0,0,0)) {} }; public: diff --git a/src/installationmanager.cpp b/src/installationmanager.cpp index 27c83787..b7ec3d68 100644 --- a/src/installationmanager.cpp +++ b/src/installationmanager.cpp @@ -95,9 +95,6 @@ InstallationManager::InstallationManager() if (!m_ArchiveHandler->isValid()) { throw MyException(getErrorString(m_ArchiveHandler->getLastError())); } - - connect(this, SIGNAL(progressUpdate(float)), this, (SLOT(doProgressUpdate(float))), Qt::QueuedConnection); - connect(this, SIGNAL(progressUpdate(const QString)), this, (SLOT(doProgressFileUpdate(const QString))), Qt::QueuedConnection); } InstallationManager::~InstallationManager() @@ -203,9 +200,12 @@ bool InstallationManager::unpackSingleFile(const QString &fileName) ); }); do { - ::Sleep(50); + if (m_Progress != m_InstallationProgress->value()) + m_InstallationProgress->setValue(m_Progress); + if (m_ProgressFile != m_InstallationProgress->labelText()) + m_InstallationProgress->setLabelText(m_ProgressFile); QCoreApplication::processEvents(); - } while (!future.isFinished()); + } while (!future.isFinished() || m_InstallationProgress->isVisible()); bool res = future.result(); return res; @@ -301,9 +301,12 @@ QStringList InstallationManager::extractFiles(const QStringList &filesOrig, bool ); }); do { - ::Sleep(50); + if (m_Progress != m_InstallationProgress->value()) + m_InstallationProgress->setValue(m_Progress); + if (m_ProgressFile != m_InstallationProgress->labelText()) + m_InstallationProgress->setLabelText(m_ProgressFile); QCoreApplication::processEvents(); - } while (!future.isFinished()); + } while (!future.isFinished() || m_InstallationProgress->isVisible()); if (!future.result()) { throw MyException(QString("extracting failed (%1)").arg(m_ArchiveHandler->getLastError())); } @@ -430,21 +433,9 @@ DirectoryTree::Node *InstallationManager::getSimpleArchiveBase(DirectoryTree *da void InstallationManager::updateProgress(float percentage) -{ - emit progressUpdate(percentage); -} - - -void InstallationManager::updateProgressFile(QString const &fileName) -{ - emit progressUpdate(fileName); -} - - -void InstallationManager::doProgressUpdate(float percentage) { if (m_InstallationProgress != nullptr) { - m_InstallationProgress->setValue(static_cast(percentage * 100.0)); + m_Progress = static_cast(percentage * 100.0); if (m_InstallationProgress->wasCanceled()) { m_ArchiveHandler->cancel(); @@ -453,11 +444,10 @@ void InstallationManager::doProgressUpdate(float percentage) } } -void InstallationManager::doProgressFileUpdate(QString const fileName) + +void InstallationManager::updateProgressFile(QString const &fileName) { - if (m_InstallationProgress != nullptr) { - m_InstallationProgress->setLabelText(fileName); - } + m_ProgressFile = fileName; } @@ -610,7 +600,10 @@ bool InstallationManager::doInstall(GuessedValue &modName, QString game ); }); do { - ::Sleep(50); + if (m_Progress != m_InstallationProgress->value()) + m_InstallationProgress->setValue(m_Progress); + if (m_ProgressFile != m_InstallationProgress->labelText()) + m_InstallationProgress->setLabelText(m_ProgressFile); QCoreApplication::processEvents(); } while (!future.isFinished()); if (!future.result()) { diff --git a/src/installationmanager.h b/src/installationmanager.h index 84ccd1a4..e17aee17 100644 --- a/src/installationmanager.h +++ b/src/installationmanager.h @@ -182,11 +182,6 @@ signals: void progressUpdate(float percentage); void progressUpdate(QString const fileName); -private slots: - - void doProgressUpdate(float percentage); - void doProgressFileUpdate(const QString fileName); - private: struct ByPriority { @@ -217,6 +212,8 @@ private: QString m_CurrentFile; QProgressDialog *m_InstallationProgress { nullptr }; + int m_Progress; + QString m_ProgressFile; std::set m_TempFilesToDelete; -- cgit v1.3.1 From 02d3f8182984c86b6a1e778e9f32a118f6fe02fe Mon Sep 17 00:00:00 2001 From: Silarn Date: Mon, 7 May 2018 01:29:00 -0500 Subject: Changes to allow installer_NCC to use the game source set in the DL meta --- src/installationmanager.cpp | 2 +- src/organizercore.cpp | 9 +++++++++ src/organizercore.h | 1 + src/organizerproxy.cpp | 5 +++++ src/organizerproxy.h | 1 + 5 files changed, 17 insertions(+), 1 deletion(-) (limited to 'src/installationmanager.cpp') diff --git a/src/installationmanager.cpp b/src/installationmanager.cpp index b7ec3d68..d1922cf9 100644 --- a/src/installationmanager.cpp +++ b/src/installationmanager.cpp @@ -819,7 +819,7 @@ bool InstallationManager::install(const QString &fileName, = installerCustom->supportedExtensions(); if (installerExt.find(fileInfo.suffix()) != installerExt.end()) { installResult - = installerCustom->install(modName, fileName, version, modID); + = installerCustom->install(modName, gameName, fileName, version, modID); unsigned int idx = ModInfo::getIndex(modName); if (idx != UINT_MAX) { ModInfo::Ptr info = ModInfo::getByIndex(idx); diff --git a/src/organizercore.cpp b/src/organizercore.cpp index d1b1fcd7..35486f98 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -789,6 +789,15 @@ MOBase::IModInterface *OrganizerCore::getMod(const QString &name) const return index == UINT_MAX ? nullptr : ModInfo::getByIndex(index).data(); } +MOBase::IPluginGame *OrganizerCore::getGame(const QString &name) const +{ + for (IPluginGame *game : m_PluginContainer->plugins()) { + if (game->gameShortName().compare(name, Qt::CaseInsensitive) == 0) + return game; + } + return nullptr; +} + MOBase::IModInterface *OrganizerCore::createMod(GuessedValue &name) { bool merge = false; diff --git a/src/organizercore.h b/src/organizercore.h index 76c286be..28ecef48 100644 --- a/src/organizercore.h +++ b/src/organizercore.h @@ -184,6 +184,7 @@ public: QString basePath() const; MOBase::VersionInfo appVersion() const; MOBase::IModInterface *getMod(const QString &name) const; + MOBase::IPluginGame *getGame(const QString &gameName) const; MOBase::IModInterface *createMod(MOBase::GuessedValue &name); bool removeMod(MOBase::IModInterface *mod); void modDataChanged(MOBase::IModInterface *mod); diff --git a/src/organizerproxy.cpp b/src/organizerproxy.cpp index 77d61a52..8e0bc95b 100644 --- a/src/organizerproxy.cpp +++ b/src/organizerproxy.cpp @@ -60,6 +60,11 @@ IModInterface *OrganizerProxy::getMod(const QString &name) const return m_Proxied->getMod(name); } +IPluginGame *OrganizerProxy::getGame(const QString &gameName) const +{ + return m_Proxied->getGame(gameName); +} + IModInterface *OrganizerProxy::createMod(MOBase::GuessedValue &name) { return m_Proxied->createMod(name); diff --git a/src/organizerproxy.h b/src/organizerproxy.h index cebb98ac..b8eb9b82 100644 --- a/src/organizerproxy.h +++ b/src/organizerproxy.h @@ -22,6 +22,7 @@ public: virtual QString basePath() const; virtual MOBase::VersionInfo appVersion() const; virtual MOBase::IModInterface *getMod(const QString &name) const; + virtual MOBase::IPluginGame *getGame(const QString &gameName) const; virtual MOBase::IModInterface *createMod(MOBase::GuessedValue &name); virtual bool removeMod(MOBase::IModInterface *mod); virtual void modDataChanged(MOBase::IModInterface *mod); -- cgit v1.3.1