summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Rimpo <jeremy.rimpo@servermonkey.com>2023-11-05 12:55:19 -0600
committerGitHub <noreply@github.com>2023-11-05 12:55:19 -0600
commit8c562fe8a957e6820a2bf6e4f6d1678698d2e913 (patch)
tree90bf9230d56cf9a64f465f024af9d9ed3c6050b0
parent8f77fff215c9cb035738ecf8485427679ea08a2c (diff)
parentc48b7d8803c61077a7886c5db0844edef259cab5 (diff)
Merge pull request #1915 from ModOrganizer2/download_issues
Download issue fixes
-rw-r--r--src/downloadmanager.cpp48
-rw-r--r--src/downloadmanager.h10
-rw-r--r--src/multiprocess.cpp9
-rw-r--r--src/organizercore.cpp2
4 files changed, 39 insertions, 30 deletions
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) {
diff --git a/src/downloadmanager.h b/src/downloadmanager.h
index 305c10e3..1e7a626e 100644
--- a/src/downloadmanager.h
+++ b/src/downloadmanager.h
@@ -626,4 +626,14 @@ private:
QTimer m_TimeoutTimer;
};
+class ScopedDisableDirWatcher
+{
+public:
+ ScopedDisableDirWatcher(DownloadManager* downloadManager);
+ ~ScopedDisableDirWatcher();
+
+private:
+ DownloadManager* m_downloadManager;
+};
+
#endif // DOWNLOADMANAGER_H
diff --git a/src/multiprocess.cpp b/src/multiprocess.cpp
index 9637a637..2851b9e7 100644
--- a/src/multiprocess.cpp
+++ b/src/multiprocess.cpp
@@ -65,10 +65,11 @@ void MOMultiProcess::sendMessage(const QString& message)
}
socket.write(message.toUtf8());
- if (socket.bytesToWrite() && !socket.waitForBytesWritten(s_Timeout)) {
- reportError(
- tr("failed to communicate with running process: %1").arg(socket.errorString()));
- return;
+ if (!socket.waitForBytesWritten(s_Timeout)) {
+ if (socket.bytesToWrite()) {
+ reportError(tr("failed to communicate with running process: %1")
+ .arg(socket.errorString()));
+ }
}
socket.disconnectFromServer();
diff --git a/src/organizercore.cpp b/src/organizercore.cpp
index c06bbae2..5bc3851c 100644
--- a/src/organizercore.cpp
+++ b/src/organizercore.cpp
@@ -831,6 +831,8 @@ OrganizerCore::doInstall(const QString& archivePath, GuessedValue<QString> 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);