comparison include/library/library.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 47c9f8502269
children
comparison
equal deleted inserted replaced
381:5beae59cf042 382:0265e125f680
1 #ifndef MINORI_LIBRARY_LIBRARY_H_ 1 #ifndef MINORI_LIBRARY_LIBRARY_H_
2 #define MINORI_LIBRARY_LIBRARY_H_ 2 #define MINORI_LIBRARY_LIBRARY_H_
3 3
4 #include "library/library.h" 4 #include "library/library.h"
5 #include "core/filesystem.h"
5 6
6 #include <filesystem> 7 #include <filesystem>
7 #include <optional> 8 #include <optional>
8 #include <unordered_map> 9 #include <unordered_map>
9 10
10 namespace Library { 11 namespace Library {
11 12
12 class Database final { 13 class Database final {
13 public: 14 public:
15 Database();
16
17 /* Update watchers from current library paths */
18 void UpdateWatchers();
19
20 bool GetPathAnimeAndEpisode(const std::string &basename, int *aid, int *ep);
21
22 void EventHandler(const std::filesystem::path &path, Filesystem::IWatcher::Event event);
23 static void StaticEventHandler(void *opaque, const std::filesystem::path &path, Filesystem::IWatcher::Event event);
24
14 std::optional<std::filesystem::path> GetAnimeFolder(int id); 25 std::optional<std::filesystem::path> GetAnimeFolder(int id);
15 void Refresh(); 26 void Refresh();
16 void Refresh(int id); 27 void Refresh(int id);
17 28
18 // Anime episodes. Indexed as `folders[id][episode]' 29 // Anime episodes. Indexed as `folders[id][episode]'
19 std::unordered_map<int, std::unordered_map<int, std::filesystem::path>> items; 30 std::unordered_map<int, std::unordered_map<int, std::filesystem::path>> items;
20 31
21 private: 32 private:
22 void Refresh(std::optional<int> find_id); 33 void Refresh(std::optional<int> find_id);
34
35 std::unordered_map<std::filesystem::path, std::unique_ptr<Filesystem::IWatcher>> watchers_;
36
37 /* ID we're looking for */
38 std::optional<int> find_id_;
23 }; 39 };
24 40
25 extern Database db; 41 extern Database db;
26 42
27 } // namespace Library 43 } // namespace Library