parent
c8a7a39f55
commit
e9657e819d
@ -0,0 +1,32 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
#include <functional>
|
||||||
|
#include <thread>
|
||||||
|
#include <atomic>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
|
class FileMonitor {
|
||||||
|
public:
|
||||||
|
using FileCallback = std::function<void(const std::string&, const std::string&)>;
|
||||||
|
|
||||||
|
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<bool> running_{false};
|
||||||
|
std::unordered_map<std::string, fs::file_time_type> file_times_;
|
||||||
|
};
|
Loading…
Reference in new issue