From e77054b80568f65aaf8a6201cf8432d000288209 Mon Sep 17 00:00:00 2001 From: ladevieq Date: Wed, 20 Jul 2022 00:09:03 +0200 Subject: Add file watching api --- include/utils.hpp | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'include/utils.hpp') diff --git a/include/utils.hpp b/include/utils.hpp index 52f3297..cbc92b3 100644 --- a/include/utils.hpp +++ b/include/utils.hpp @@ -1,11 +1,11 @@ -#ifndef __UTILS_HPP_ -#define __UTILS_HPP_ +#pragma once #include #include +#include +#include std::vector read_file(const char* path); -std::vector read_file(std::string& path); #define PI 3.14159265359 #define EPSILON 0.000001 @@ -36,6 +36,28 @@ inline float clamp(float x, float min, float max) { return x; } -void watch_file(std::filesystem::path&& filepath, std::function&& callback); +#include -#endif // !__UTILS_HPP_ +#if defined(WINDOWS) +void log_last_error(); +#endif + +class watcher { +public: + static bool watch_file(std::filesystem::path&& filepath, std::function callback); + + static bool watch_dir(std::filesystem::path&& dir_path); + + static void pull_changes(); + +private: + + struct watch_data { + HANDLE dir_handle; + OVERLAPPED overlapped; + DWORD buffer[512]; + }; + + inline static std::unordered_map> callbacks; + inline static std::unordered_map watched_dirs; +}; -- cgit v1.3