3
3
#include " Core/Directory.hpp"
4
4
#include " Core/DirectoryWatcher.hpp"
5
5
6
+ #include " Core/Log.hpp"
7
+
6
8
#include < QDateTime>
7
9
#include < QDir>
8
10
#include < QFileInfo>
@@ -86,19 +88,19 @@ void DirectoryWatcher::OnDirectoryChanged(const QString& path)
86
88
emit DirectoryChanged (path.toStdString ());
87
89
88
90
const QDir dir (path);
89
- const QFileInfoList watchedList = dir.entryInfoList (QDir::NoDotAndDotDot | QDir::Files);
91
+ const QFileInfoList files = dir.entryInfoList (QDir::NoDotAndDotDot | QDir::Files);
90
92
91
- std::unordered_set<QString> missing (m_lastModified.size ());
92
- for (const auto & file : m_lastModified | std::views::keys)
93
- missing.insert (file);
93
+ auto beforeFiles = m_lastModified | std::views::keys | std::views::filter ([&path](const QString& m) -> bool
94
+ {
95
+ return m.startsWith (path);
96
+ }) | std::ranges::to<std::unordered_set<QString>>();
94
97
95
- for (const QFileInfo& fileInfo : watchedList )
98
+ for (const QFileInfo& fileInfo : files )
96
99
{
97
- QString filePath = fileInfo.absoluteFilePath ();
98
- QDateTime lastModified = fileInfo.lastModified ();
100
+ const QString filePath = fileInfo.absoluteFilePath ();
101
+ const QDateTime lastModified = fileInfo.lastModified ();
99
102
100
- const bool contains = m_lastModified.contains (filePath);
101
- if (!contains || m_lastModified[filePath] < lastModified)
103
+ if (!m_lastModified.contains (filePath) || m_lastModified[filePath] < lastModified)
102
104
{
103
105
m_lastModified[filePath] = lastModified;
104
106
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
@@ -108,13 +110,15 @@ void DirectoryWatcher::OnDirectoryChanged(const QString& path)
108
110
#endif
109
111
}
110
112
111
- if (missing.contains (filePath))
113
+ // remove it from the list if it still exists
114
+ if (beforeFiles.contains (filePath))
112
115
{
113
- missing .erase (filePath);
116
+ beforeFiles .erase (filePath);
114
117
}
115
118
}
116
119
117
- for (const QString& file : missing)
120
+ // these files were removed
121
+ for (const QString& file : beforeFiles)
118
122
{
119
123
m_lastModified.erase (file);
120
124
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
0 commit comments