Skip to content

Commit

Permalink
Remove download refresh scoped blocker
Browse files Browse the repository at this point in the history
- Accidentally added to this branch
  • Loading branch information
Silarn committed Sep 24, 2023
1 parent 5f14c57 commit 4bd860a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 29 deletions.
35 changes: 16 additions & 19 deletions src/downloadmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)."));
}
Expand Down Expand Up @@ -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));
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -803,6 +795,8 @@ void DownloadManager::removeFile(int index, bool deleteFile)
metaSettings.setValue("removed", true);
}
m_DownloadRemoved(index);

endDisableDirWatcher();
}

class LessThanWrapper
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
9 changes: 0 additions & 9 deletions src/downloadmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -626,13 +626,4 @@ private slots:
QTimer m_TimeoutTimer;
};

class ScopedDisableDirWatcher
{
public:
ScopedDisableDirWatcher(DownloadManager* downloadManager);
~ScopedDisableDirWatcher();

private:
DownloadManager* m_downloadManager;
};
#endif // DOWNLOADMANAGER_H
1 change: 0 additions & 1 deletion src/organizercore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,6 @@ 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);
Expand Down

0 comments on commit 4bd860a

Please sign in to comment.