From c48b7d8803c61077a7886c5db0844edef259cab5 Mon Sep 17 00:00:00 2001 From: Jeremy Rimpo Date: Sun, 5 Nov 2023 12:37:16 -0600 Subject: Download issue fixes - Add scoped watcher disabler - Disable during mod install - Update interprocess message handler to fix 'unable to communicate' issues --- src/downloadmanager.cpp | 48 ++++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 26 deletions(-) (limited to 'src/downloadmanager.cpp') diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 5ccbdb4d..730803f6 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -153,6 +153,20 @@ 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++; @@ -319,7 +333,7 @@ void DownloadManager::refreshList() try { // avoid triggering other refreshes - startDisableDirWatcher(); + ScopedDisableDirWatcher scopedDirWatcher(this); int downloadsBefore = m_ActiveDownloads.size(); @@ -421,9 +435,6 @@ 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).")); } @@ -758,7 +769,7 @@ void DownloadManager::addNXMDownload(const QString& url) void DownloadManager::removeFile(int index, bool deleteFile) { // Avoid triggering refreshes from DirWatcher - startDisableDirWatcher(); + ScopedDisableDirWatcher scopedDirWatcher(this); if (index >= m_ActiveDownloads.size()) { throw MyException(tr("remove: invalid download index %1").arg(index)); @@ -770,7 +781,6 @@ 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; } @@ -781,7 +791,6 @@ void DownloadManager::removeFile(int index, bool deleteFile) if (deleteFile) { if (!shellDelete(QStringList(filePath), true)) { reportError(tr("failed to delete %1").arg(filePath)); - endDisableDirWatcher(); return; } @@ -795,8 +804,6 @@ void DownloadManager::removeFile(int index, bool deleteFile) metaSettings.setValue("removed", true); } m_DownloadRemoved(index); - - endDisableDirWatcher(); } class LessThanWrapper @@ -871,7 +878,7 @@ void DownloadManager::removeDownload(int index, bool deleteFile) { try { // avoid dirWatcher triggering refreshes - startDisableDirWatcher(); + ScopedDisableDirWatcher scopedDirWatcher(this); emit aboutToUpdate(); @@ -897,7 +904,6 @@ void DownloadManager::removeDownload(int index, bool deleteFile) if (index >= m_ActiveDownloads.size()) { reportError(tr("remove: invalid download index %1").arg(index)); // emit update(-1); - endDisableDirWatcher(); return; } @@ -906,7 +912,6 @@ void DownloadManager::removeDownload(int index, bool deleteFile) m_ActiveDownloads.erase(m_ActiveDownloads.begin() + index); } emit update(-1); - endDisableDirWatcher(); } catch (const std::exception& e) { log::error("failed to remove download: {}", e.what()); } @@ -1434,15 +1439,13 @@ void DownloadManager::markInstalled(int index) } // Avoid triggering refreshes from DirWatcher - startDisableDirWatcher(); + ScopedDisableDirWatcher scopedDirWatcher(this); 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); } @@ -1455,14 +1458,12 @@ void DownloadManager::markInstalled(QString fileName) DownloadInfo* info = getDownloadInfo(fileName); if (info != nullptr) { // Avoid triggering refreshes from DirWatcher - startDisableDirWatcher(); + ScopedDisableDirWatcher scopedDirWatcher(this); QSettings metaFile(info->m_Output.fileName() + ".meta", QSettings::IniFormat); metaFile.setValue("installed", true); metaFile.setValue("uninstalled", false); delete info; - - endDisableDirWatcher(); } } } @@ -1479,14 +1480,12 @@ void DownloadManager::markUninstalled(int index) } // Avoid triggering refreshes from DirWatcher - startDisableDirWatcher(); + ScopedDisableDirWatcher scopedDirWatcher(this); DownloadInfo* info = m_ActiveDownloads.at(index); QSettings metaFile(info->m_Output.fileName() + ".meta", QSettings::IniFormat); metaFile.setValue("uninstalled", true); - endDisableDirWatcher(); - setState(m_ActiveDownloads.at(index), STATE_UNINSTALLED); } @@ -1501,13 +1500,11 @@ void DownloadManager::markUninstalled(QString fileName) if (info != nullptr) { // Avoid triggering refreshes from DirWatcher - startDisableDirWatcher(); + ScopedDisableDirWatcher scopedDirWatcher(this); QSettings metaFile(info->m_Output.fileName() + ".meta", QSettings::IniFormat); metaFile.setValue("uninstalled", true); delete info; - - endDisableDirWatcher(); } } } @@ -1671,7 +1668,7 @@ void DownloadManager::downloadReadyRead() void DownloadManager::createMetaFile(DownloadInfo* info) { // Avoid triggering refreshes from DirWatcher - startDisableDirWatcher(); + ScopedDisableDirWatcher scopedDirWatcher(this); QSettings metaFile(QString("%1.meta").arg(info->m_Output.fileName()), QSettings::IniFormat); @@ -1695,7 +1692,6 @@ 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) { -- cgit v1.3.1