diff 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
line wrap: on
line diff
--- a/include/library/library.h	Thu Nov 06 01:17:24 2025 -0500
+++ b/include/library/library.h	Thu Nov 06 03:16:55 2025 -0500
@@ -2,6 +2,7 @@
 #define MINORI_LIBRARY_LIBRARY_H_
 
 #include "library/library.h"
+#include "core/filesystem.h"
 
 #include <filesystem>
 #include <optional>
@@ -11,6 +12,16 @@
 
 class Database final {
 public:
+	Database();
+
+	/* Update watchers from current library paths */
+	void UpdateWatchers();
+
+	bool GetPathAnimeAndEpisode(const std::string &basename, int *aid, int *ep);
+
+	void EventHandler(const std::filesystem::path &path, Filesystem::IWatcher::Event event);
+	static void StaticEventHandler(void *opaque, const std::filesystem::path &path, Filesystem::IWatcher::Event event);
+
 	std::optional<std::filesystem::path> GetAnimeFolder(int id);
 	void Refresh();
 	void Refresh(int id);
@@ -20,6 +31,11 @@
 
 private:
 	void Refresh(std::optional<int> find_id);
+
+	std::unordered_map<std::filesystem::path, std::unique_ptr<Filesystem::IWatcher>> watchers_;
+
+	/* ID we're looking for */
+	std::optional<int> find_id_;
 };
 
 extern Database db;