Mercurial > minori
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 381:5beae59cf042 | 382:0265e125f680 |
|---|---|
| 1 #ifndef MINORI_CORE_FILESYSTEM_H_ | 1 #ifndef MINORI_CORE_FILESYSTEM_H_ |
| 2 #define MINORI_CORE_FILESYSTEM_H_ | 2 #define MINORI_CORE_FILESYSTEM_H_ |
| 3 #include <filesystem> | 3 #include <filesystem> |
| 4 #include <string> | 4 #include <string> |
| 5 #include <functional> | |
| 5 | 6 |
| 6 namespace Filesystem { | 7 namespace Filesystem { |
| 7 | 8 |
| 8 void CreateDirectories(const std::filesystem::path &path); | 9 void CreateDirectories(const std::filesystem::path &path); |
| 9 std::filesystem::path GetDotPath(); // %APPDATA%/minori/, ~/Library/Application Support/minori/, ~/.config/minori/... | 10 std::filesystem::path GetDotPath(); // %APPDATA%/minori/, ~/Library/Application Support/minori/, ~/.config/minori/... |
| 10 std::filesystem::path GetConfigPath(); // (dotpath)/config.json | 11 std::filesystem::path GetConfigPath(); // (dotpath)/config.json |
| 11 std::filesystem::path GetAnimeDBPath(); // (dotpath)/anime/db.json | 12 std::filesystem::path GetAnimeDBPath(); // (dotpath)/anime/db.json |
| 12 std::filesystem::path GetTorrentsPath(); // (dotpath)/torrents/... | 13 std::filesystem::path GetTorrentsPath(); // (dotpath)/torrents/... |
| 13 std::filesystem::path GetAnimePostersPath(); // (dotpath)/anime/posters/ | 14 std::filesystem::path GetAnimePostersPath(); // (dotpath)/anime/posters/ |
| 14 | 15 |
| 16 /* ------------------------------------------------------------------------ */ | |
| 17 /* Filesystem watcher interface. This is implemented differently on | |
| 18 * different platforms :) */ | |
| 19 | |
| 20 struct IWatcher { | |
| 21 enum Event { | |
| 22 /* File/directory 'path' was created */ | |
| 23 Created, | |
| 24 /* File/directory 'path' was deleted */ | |
| 25 Deleted, | |
| 26 }; | |
| 27 | |
| 28 using EventHandler = std::function<void(void *opaque, const std::filesystem::path &path, Event event)>; | |
| 29 | |
| 30 virtual ~IWatcher() = default; | |
| 31 virtual void Process() = 0; | |
| 32 }; | |
| 33 | |
| 34 /* Constructor functions. Yes, I'm doing this the C way :) */ | |
| 35 IWatcher *GetRecursiveFilesystemWatcher(void *opaque, | |
| 36 const std::filesystem::path &path, IWatcher::EventHandler handler); | |
| 37 IWatcher *GetFilesystemWatcher(void *opaque, const std::filesystem::path &path, IWatcher::EventHandler handler); | |
| 38 | |
| 15 } // namespace Filesystem | 39 } // namespace Filesystem |
| 16 | 40 |
| 17 #endif // MINORI_CORE_FILESYSTEM_H_ | 41 #endif // MINORI_CORE_FILESYSTEM_H_ |
