From 31718fef1b386e7e360a08ebbc5a79f410f1920a Mon Sep 17 00:00:00 2001 From: GriffinR Date: Tue, 7 Oct 2025 07:52:24 -0400 Subject: [PATCH] Reduce logging for failed file watcher --- CHANGELOG.md | 1 + include/core/map.h | 4 ++++ src/core/map.cpp | 3 ++- src/project.cpp | 4 ++++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82fc8fbe..12b3417c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project somewhat adheres to [Semantic Versioning](https://semver.org/sp - Fix rare crash while quitting Porymap. - Fix exported images on macOS using a different color space than in Porymap. - Fix some `INCBIN` statements not being parsed correctly. +- Fix excessive logging if Porymap fails to monitor all map files. ## [6.2.0] - 2025-08-08 ### Added diff --git a/include/core/map.h b/include/core/map.h index f3a377c1..47d52b08 100644 --- a/include/core/map.h +++ b/include/core/map.h @@ -116,6 +116,9 @@ public: void setCustomAttributes(const QJsonObject &attributes) { m_customAttributes = attributes; } QJsonObject customAttributes() const { return m_customAttributes; } + static void setFileWatchingEnabled(bool enabled) { m_fileWatchingEnabled = enabled; } + static bool isFileWatchingEnabled() { return m_fileWatchingEnabled; } + private: QString m_name; QString m_constantName; @@ -134,6 +137,7 @@ private: bool m_needsHealLocation = false; bool m_scriptsLoaded = false; bool m_loggedScriptsFileError = false; + static bool m_fileWatchingEnabled; QMap> m_events; QSet m_ownedEvents; // for memory management diff --git a/src/core/map.cpp b/src/core/map.cpp index 1f3b5916..47b27991 100644 --- a/src/core/map.cpp +++ b/src/core/map.cpp @@ -11,6 +11,7 @@ #include #include +bool Map::m_fileWatchingEnabled = true; Map::Map(QObject *parent) : QObject(parent) { @@ -149,7 +150,7 @@ QStringList Map::getScriptLabels(Event::Group group) { m_loggedScriptsFileError = true; } - if (porymapConfig.monitorFiles && !m_loggedScriptsFileError) { + if (m_fileWatchingEnabled && !m_loggedScriptsFileError) { if (!m_scriptFileWatcher) { // Only create the file watcher when it's first needed (even an empty QFileSystemWatcher will consume system resources). // The other option would be for Porymap to have a single global QFileSystemWatcher, but that has complications of its own. diff --git a/src/project.cpp b/src/project.cpp index d9082d3a..85a6b420 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -838,6 +838,7 @@ void Project::recordFileChange(const QString &filepath) { // When calling 'watchFile' we record failures rather than log them immediately. // We do this primarily to condense the warning if we fail to monitor any files. void Project::logFileWatchStatus() { + Map::setFileWatchingEnabled(porymapConfig.monitorFiles); if (!this->fileWatcher) return; @@ -851,6 +852,9 @@ void Project::logFileWatchStatus() { // on Windows and the project files are in WSL2. Rather than filling the log by // outputting a warning for every file, just log that we failed to monitor any of them. logWarn(QString("Failed to monitor project files")); + + // Similarly, avoid logging a warning every time we open a map. We can assume that will also fail. + Map::setFileWatchingEnabled(false); return; } else { logInfo(QString("Successfully monitoring %1/%2 project files").arg(numSuccessful).arg(numAttempted));