From e9657e819d90fb243c5a3a4fe6d586218d76c96a Mon Sep 17 00:00:00 2001 From: pr4ku3p2c <925473174@qq.com> Date: Mon, 20 Jan 2025 18:06:58 +0800 Subject: [PATCH] ADD file via upload --- file_monitor.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 file_monitor.h diff --git a/file_monitor.h b/file_monitor.h new file mode 100644 index 0000000..8350d7c --- /dev/null +++ b/file_monitor.h @@ -0,0 +1,32 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include + +namespace fs = std::filesystem; + +class FileMonitor { +public: + using FileCallback = std::function; + + FileMonitor(const std::string& root_path, FileCallback callback); + ~FileMonitor(); + + void start(); + void stop(); + +private: + void monitor_thread(); + void scan_directory(const fs::path& dir); + std::string read_file_content(const fs::path& path); + + std::string root_path_; + FileCallback callback_; + std::thread monitor_thread_; + std::atomic running_{false}; + std::unordered_map file_times_; +}; \ No newline at end of file