ezEngine  Milestone 9
DirectoryWatcher.h
1 #pragma once
2 
3 #include <Foundation/Basics.h>
4 #include <Foundation/Strings/String.h>
6 #include <Foundation/Types/Delegate.h>
7 
9 
11 enum class ezDirectoryWatcherAction
12 {
13  None,
14  Added,
15  Removed,
16  Modified,
17  RenamedOldName,
18  RenamedNewName,
19 };
20 
23 class EZ_FOUNDATION_DLL ezDirectoryWatcher
24 {
25 public:
27  struct Watch
28  {
29  typedef ezUInt8 StorageType;
30 
32  enum Enum
33  {
34  Reads = EZ_BIT(0),
35  Writes = EZ_BIT(1),
36  Creates = EZ_BIT(2),
37  Renames = EZ_BIT(3),
38  Subdirectories = EZ_BIT(4)
39  };
40 
41  struct Bits
42  {
43  StorageType Reads : 1;
44  StorageType Writes : 1;
45  StorageType Creates : 1;
46  StorageType Renames : 1;
47  StorageType Subdirectories : 1;
48  };
49  };
50 
53 
58  ezResult OpenDirectory(const ezString& absolutePath, ezBitflags<Watch> whatToWatch);
59 
62  void CloseDirectory();
63 
66  const char* GetDirectory() const { return m_sDirectoryPath; }
67 
73  void EnumerateChanges(ezDelegate<void(const char* filename, ezDirectoryWatcherAction action)> func);
74 
75 private:
76  ezString m_sDirectoryPath;
77  ezDirectoryWatcherImpl* m_pImpl;
78 };
79 
81 
Enum
Enum values.
Definition: DirectoryWatcher.h:32
What to watch out for.
Definition: DirectoryWatcher.h:27
#define EZ_BIT(n)
Creates a bit mask with only the n-th Bit set. Useful when creating enum values for flags...
Definition: PreprocessorUtils.h:23
Watches file actions in a directory. Changes need to be polled.
Definition: DirectoryWatcher.h:23
The ezBitflags class allows you to work with type-safe bitflags.
Definition: Bitflags.h:80
#define EZ_DECLARE_FLAGS_OPERATORS(FlagsType)
This macro will define the operator| and operator& function that is required for class FlagsType to w...
Definition: Bitflags.h:214
const char * GetDirectory() const
Returns the opened directory, will be empty if no directory was opened.
Definition: DirectoryWatcher.h:66
Definition: DirectoryWatcher_posix.h:5
Definition: DirectoryWatcher.h:41
A generic delegate class which supports static functions and member functions.
Definition: MathExpression.h:11
Default enum for returning failure or success, instead of using a bool.
Definition: Types.h:51