Reworked the file watcher

main
anulax1225 ago%!(EXTRA string=1 year)
parent 9608bb05c8
commit 1e0cea02a5
  1. 8
      src/bakatools/file_system/file_watcher.cpp
  2. 9
      src/bakatools/file_system/file_watcher.h

@ -10,7 +10,7 @@ namespace Bk::Tools {
FileWatcher::~FileWatcher() { stop(); } FileWatcher::~FileWatcher() { stop(); }
void FileWatcher::start(const std::function<void (std::string, FileStatus)>& action) void FileWatcher::start(const std::function<void (std::string, FileStat)>& action)
{ {
std::function<void()> task([&]() std::function<void()> task([&]()
{ {
@ -19,7 +19,7 @@ namespace Bk::Tools {
{ {
if (!std::filesystem::exists(it->first)) if (!std::filesystem::exists(it->first))
{ {
action(it->first, FileStatus::Deleted); action(it->first, FileStat::Deleted);
it = paths.erase(it); it = paths.erase(it);
} }
else it++; else it++;
@ -31,12 +31,12 @@ namespace Bk::Tools {
{ {
if(paths[file.path().string()] != current_file_last_write_time) { if(paths[file.path().string()] != current_file_last_write_time) {
paths[file.path().string()] = current_file_last_write_time; paths[file.path().string()] = current_file_last_write_time;
action(file.path().string(), FileStatus::Modified); action(file.path().string(), FileStat::Modified);
} }
} else } else
{ {
paths[file.path().string()] = current_file_last_write_time; paths[file.path().string()] = current_file_last_write_time;
action(file.path().string(), FileStatus::Created); action(file.path().string(), FileStat::Created);
} }
} }
}); });

@ -1,9 +1,10 @@
#pragma once #pragma once
#include <bakatools.h> #include <bakatoolspch.h>
#include <bakatools/thread/task_timer.h> #include <thread/task_timer.h>
namespace Bk::Tools { namespace Bk::Tools {
enum class FileStatus enum class FileStat
{ {
Created = 0, Created = 0,
Modified = 1, Modified = 1,
@ -16,7 +17,7 @@ namespace Bk::Tools {
FileWatcher(std::string path, TimeSpan<Millisecond> ts); FileWatcher(std::string path, TimeSpan<Millisecond> ts);
~FileWatcher(); ~FileWatcher();
void start(const std::function<void (std::string, FileStatus)>& action); void start(const std::function<void (std::string, FileStat)>& action);
void stop(); void stop();
bool contains(std::string path); bool contains(std::string path);

Loading…
Cancel
Save