aboutsummaryrefslogtreecommitdiffstats
path: root/include/utils.hpp
diff options
context:
space:
mode:
authorladevieq <ladevie.quentin@gmail.com>2022-07-20 00:09:03 +0200
committerladevieq <ladevie.quentin@gmail.com>2022-07-20 00:09:03 +0200
commite77054b80568f65aaf8a6201cf8432d000288209 (patch)
tree845f38235652b11ef8c435f48b95005616b33fea /include/utils.hpp
parent9cf2e341adfdb389c0dd8eb9a621d83ccba78826 (diff)
Add file watching api
Diffstat (limited to 'include/utils.hpp')
-rw-r--r--include/utils.hpp32
1 files changed, 27 insertions, 5 deletions
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 <vector>
#include <functional>
+#include <unordered_map>
+#include <string>
std::vector<uint8_t> read_file(const char* path);
-std::vector<uint8_t> 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<void()>&& callback);
+#include <windows.h>
-#endif // !__UTILS_HPP_
+#if defined(WINDOWS)
+void log_last_error();
+#endif
+
+class watcher {
+public:
+ static bool watch_file(std::filesystem::path&& filepath, std::function<void()> 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<std::string, std::function<void()>> callbacks;
+ inline static std::unordered_map<std::string, watch_data> watched_dirs;
+};