From 4bd860a0d276aa154c0c976c28b6b263a6572801 Mon Sep 17 00:00:00 2001 From: Jeremy Rimpo Date: Sat, 23 Sep 2023 21:51:41 -0500 Subject: [PATCH] Remove download refresh scoped blocker - Accidentally added to this branch --- src/downloadmanager.cpp | 35 ++++++++++++++++------------------- src/downloadmanager.h | 9 --------- src/organizercore.cpp | 1 - 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 3f9a2a882..5ccbdb4da 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -153,20 +153,6 @@ DownloadManager::DownloadInfo::createFromMeta(const QString& filePath, bool show return info; } -ScopedDisableDirWatcher::ScopedDisableDirWatcher(DownloadManager* downloadManager) -{ - m_downloadManager = downloadManager; - m_downloadManager->startDisableDirWatcher(); - log::debug("Scoped Disable DirWatcher: Started"); -} - -ScopedDisableDirWatcher::~ScopedDisableDirWatcher() -{ - m_downloadManager->endDisableDirWatcher(); - m_downloadManager = nullptr; - log::debug("Scoped Disable DirWatcher: Stopped"); -} - void DownloadManager::startDisableDirWatcher() { DownloadManager::m_DirWatcherDisabler++; @@ -331,9 +317,10 @@ void DownloadManager::refreshList() { TimeThis tt("DownloadManager::refreshList()"); - // avoid triggering other refreshes - ScopedDisableDirWatcher scopedDirWatcher(this); try { + // avoid triggering other refreshes + startDisableDirWatcher(); + int downloadsBefore = m_ActiveDownloads.size(); // remove finished downloads @@ -434,6 +421,9 @@ void DownloadManager::refreshList() emit update(-1); + // let watcher trigger refreshes again + endDisableDirWatcher(); + } catch (const std::bad_alloc&) { reportError(tr("Memory allocation error (in refreshing directory).")); } @@ -768,7 +758,7 @@ void DownloadManager::addNXMDownload(const QString& url) void DownloadManager::removeFile(int index, bool deleteFile) { // Avoid triggering refreshes from DirWatcher - ScopedDisableDirWatcher scopedDirWatcher(this); + startDisableDirWatcher(); if (index >= m_ActiveDownloads.size()) { throw MyException(tr("remove: invalid download index %1").arg(index)); @@ -780,6 +770,7 @@ void DownloadManager::removeFile(int index, bool deleteFile) (download->m_State == STATE_DOWNLOADING)) { // shouldn't have been possible log::error("tried to remove active download"); + endDisableDirWatcher(); return; } @@ -790,6 +781,7 @@ void DownloadManager::removeFile(int index, bool deleteFile) if (deleteFile) { if (!shellDelete(QStringList(filePath), true)) { reportError(tr("failed to delete %1").arg(filePath)); + endDisableDirWatcher(); return; } @@ -803,6 +795,8 @@ void DownloadManager::removeFile(int index, bool deleteFile) metaSettings.setValue("removed", true); } m_DownloadRemoved(index); + + endDisableDirWatcher(); } class LessThanWrapper @@ -1440,13 +1434,15 @@ void DownloadManager::markInstalled(int index) } // Avoid triggering refreshes from DirWatcher - ScopedDisableDirWatcher scopedDirWatcher(this); + startDisableDirWatcher(); DownloadInfo* info = m_ActiveDownloads.at(index); QSettings metaFile(info->m_Output.fileName() + ".meta", QSettings::IniFormat); metaFile.setValue("installed", true); metaFile.setValue("uninstalled", false); + endDisableDirWatcher(); + setState(m_ActiveDownloads.at(index), STATE_INSTALLED); } @@ -1675,7 +1671,7 @@ void DownloadManager::downloadReadyRead() void DownloadManager::createMetaFile(DownloadInfo* info) { // Avoid triggering refreshes from DirWatcher - ScopedDisableDirWatcher scopedDirWatcher(this); + startDisableDirWatcher(); QSettings metaFile(QString("%1.meta").arg(info->m_Output.fileName()), QSettings::IniFormat); @@ -1699,6 +1695,7 @@ void DownloadManager::createMetaFile(DownloadInfo* info) (info->m_State == DownloadManager::STATE_ERROR)); metaFile.setValue("removed", info->m_Hidden); + endDisableDirWatcher(); // slightly hackish... for (int i = 0; i < m_ActiveDownloads.size(); ++i) { if (m_ActiveDownloads[i] == info) { diff --git a/src/downloadmanager.h b/src/downloadmanager.h index 76e9ab5a7..305c10e3e 100644 --- a/src/downloadmanager.h +++ b/src/downloadmanager.h @@ -626,13 +626,4 @@ private slots: QTimer m_TimeoutTimer; }; -class ScopedDisableDirWatcher -{ -public: - ScopedDisableDirWatcher(DownloadManager* downloadManager); - ~ScopedDisableDirWatcher(); - -private: - DownloadManager* m_downloadManager; -}; #endif // DOWNLOADMANAGER_H diff --git a/src/organizercore.cpp b/src/organizercore.cpp index dda731ba7..b4e758d1b 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -831,7 +831,6 @@ OrganizerCore::doInstall(const QString& archivePath, GuessedValue modNa ModInfo::Ptr OrganizerCore::installDownload(int index, int priority) { - ScopedDisableDirWatcher scopedDirwatcher(&m_DownloadManager); try { QString fileName = m_DownloadManager.getFilePath(index); QString gameName = m_DownloadManager.getGameName(index);