Mercurial > minori
diff include/core/filesystem.h @ 382:0265e125f680
filesystem: implement filesystem watcher
I also ported the library code to use it as well. Once we implement
proper directory watching on Windows (and maybe others) this will
be fairly useful :)
| author | Paper <paper@tflc.us> |
|---|---|
| date | Thu, 06 Nov 2025 03:16:55 -0500 |
| parents | 5eaafed6c10b |
| children |
line wrap: on
line diff
--- a/include/core/filesystem.h Thu Nov 06 01:17:24 2025 -0500 +++ b/include/core/filesystem.h Thu Nov 06 03:16:55 2025 -0500 @@ -2,6 +2,7 @@ #define MINORI_CORE_FILESYSTEM_H_ #include <filesystem> #include <string> +#include <functional> namespace Filesystem { @@ -12,6 +13,29 @@ std::filesystem::path GetTorrentsPath(); // (dotpath)/torrents/... std::filesystem::path GetAnimePostersPath(); // (dotpath)/anime/posters/ +/* ------------------------------------------------------------------------ */ +/* Filesystem watcher interface. This is implemented differently on + * different platforms :) */ + +struct IWatcher { + enum Event { + /* File/directory 'path' was created */ + Created, + /* File/directory 'path' was deleted */ + Deleted, + }; + + using EventHandler = std::function<void(void *opaque, const std::filesystem::path &path, Event event)>; + + virtual ~IWatcher() = default; + virtual void Process() = 0; +}; + +/* Constructor functions. Yes, I'm doing this the C way :) */ +IWatcher *GetRecursiveFilesystemWatcher(void *opaque, + const std::filesystem::path &path, IWatcher::EventHandler handler); +IWatcher *GetFilesystemWatcher(void *opaque, const std::filesystem::path &path, IWatcher::EventHandler handler); + } // namespace Filesystem #endif // MINORI_CORE_FILESYSTEM_H_
