Mountain  1.0.0
Simple C++ 2D Game Framework
file_system_watcher.hpp
1 #pragma once
2 
3 #include <chrono>
4 #include <condition_variable>
5 
6 #include <magic_enum/magic_enum.hpp>
7 
8 #include "Mountain/core.hpp"
10 
11 // ReSharper disable once CppInconsistentNaming
12 // ReSharper disable once CppEnforceTypeAliasCodeStyle
13 typedef unsigned long DWORD; // Windows type forward declaration // NOLINT(modernize-use-using)
14 
15 namespace Mountain
16 {
18  enum class FswNotifyFilters : uint8_t
19  {
20  FileName = 1 << 0,
21  DirectoryName = 1 << 1,
22  Attributes = 1 << 2,
23  Size = 1 << 3,
24  LastWrite = 1 << 4,
25  LastAccess = 1 << 5,
26  Creation = 1 << 6,
27  Security = 1 << 7,
28 
29  Default = Creation | FileName | DirectoryName | LastWrite,
30 
31  All = FileName | DirectoryName | Attributes | Size | LastWrite | LastAccess | Creation | Security
32  };
33 
35  {
36  public:
41 
43  std::chrono::milliseconds updateRate{750};
44 
46  bool_t checkContents = true;
47 
49  bool_t recursive = false;
50 
53 
54  FswNotifyFilters notifyFilters = FswNotifyFilters::Default;
55 
56  MOUNTAIN_API FileSystemWatcher() = default;
57 
58  MOUNTAIN_API explicit FileSystemWatcher(const std::string& path);
59 
60  MOUNTAIN_API ~FileSystemWatcher();
61 
62  DELETE_COPY_MOVE_OPERATIONS(FileSystemWatcher)
63 
64  MOUNTAIN_API void Start();
65 
66  MOUNTAIN_API void Stop();
67 
69  MOUNTAIN_API void Update();
70 
71  MOUNTAIN_API std::filesystem::path GetPath() const;
72 
73  MOUNTAIN_API void SetPath(const std::filesystem::path& newPath);
74 
75  MOUNTAIN_API bool_t GetRunning() const;
76 
77  private:
78  std::thread m_Thread;
79  std::condition_variable m_CondVar;
80  std::mutex m_Mutex;
81 
82  std::filesystem::path m_Path;
83  bool_t m_IsDirectory = false;
84 
85  bool_t m_Running = false;
86 
87  bool_t m_PathChanged = false;
88 
89  void Run();
90 
91  static DWORD NotifyFiltersToWindows(FswNotifyFilters filters);
92  };
93 }
94 
95 ENUM_FLAGS(Mountain::FswNotifyFilters)
Encapsulates a delegate system similar to its C# implementation.
Definition: event.hpp:25
Defines the Event class.
List< std::string > fileExtensions
File extensions including the dot &#39;.&#39;.
Contains all declarations of the Mountain Framework.
Definition: audio.hpp:22