You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
813 B

#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_;
};