ezEngine  Milestone 7
FileSystem.h
1 #pragma once
2 
3 #include <Foundation/IO/FileSystem/Implementation/DataDirType.h>
4 #include <Foundation/Containers/HybridArray.h>
5 #include <Foundation/Communication/Event.h>
6 #include <Foundation/Threading/Mutex.h>
7 
40 class EZ_FOUNDATION_DLL ezFileSystem
41 {
42 public:
44  struct FileEventType;
45 
47  struct FileEvent;
48 
50  static void RegisterEventHandler(ezEvent<const FileEvent&>::Handler handler);
51 
53  static void UnregisterEventHandler(ezEvent<const FileEvent&>::Handler handler);
54 
56  static ezMutex& GetFileSystemMutex();
57 
58 public:
68  typedef ezDataDirectoryType* (*ezDataDirFactory)(const char* szDataDirectory);
69 
71  static void RegisterDataDirectoryFactory(ezDataDirFactory Factory) { s_Data->m_DataDirFactories.PushBack(Factory); }
72 
74  static void ClearAllDataDirectoryFactories() { s_Data->m_DataDirFactories.Clear(); }
75 
78  {
79  ReadOnly,
80  AllowWrites,
81  };
82 
99  static ezResult AddDataDirectory(const char* szDataDirectory, DataDirUsage Usage = AllowWrites, const char* szGroup = "", const char* szCategory = "");
100 
102  static ezUInt32 RemoveDataDirectoryGroup(const char* szGroup);
103 
105  static void ClearAllDataDirectories();
106 
108  static ezUInt32 GetNumDataDirectories();
109 
111  static ezDataDirectoryType* GetDataDirectory(ezUInt32 uiDataDirIndex);
112 
114  static void ReloadAllExternalDataDirectoryConfigs();
115 
116 public:
117 
123  static void DeleteFile(const char* szFile);
124 
128  static bool ExistsFile(const char* szFile);
129 
143  static ezResult ResolvePath(const char* szPath, bool bForWriting, ezString* out_sAbsolutePath, ezString* out_sDataDirRelativePath);
144 
145 
146 private:
147  friend class ezDataDirectoryReaderWriterBase;
148  friend class ezFileReaderBase;
149  friend class ezFileWriterBase;
150 
158  static ezDataDirectoryReader* GetFileReader(const char* szFile, bool bAllowFileEvents);
159 
167  static ezDataDirectoryWriter* GetFileWriter(const char* szFile, bool bAllowFileEvents);
168 
169 
170 private:
171  EZ_MAKE_SUBSYSTEM_STARTUP_FRIEND(Foundation, FileSystem);
172 
174  static void Startup();
175 
177  static void Shutdown();
178 
179 private:
181  static const char* ExtractDataDirsToSearch(const char* szPath, ezHybridArray<ezString, 4>& SearchDirs);
182 
184  static const char* GetDataDirRelativePath(const char* szPath, ezUInt32 uiDataDir);
185 
187  {
188  DataDirUsage m_Usage;
189 
190  ezString m_sCategory;
191  ezString m_sGroup;
192  ezDataDirectoryType* m_pDataDirectory;
193  };
194 
196  {
197  ezHybridArray<ezDataDirFactory, 4> m_DataDirFactories;
198  ezHybridArray<DataDirectory, 16> m_DataDirectories;
200  ezMutex m_Mutex;
201  };
202 
203  static FileSystemData* s_Data;
204 };
205 
208 {
209  enum Enum
210  {
223  };
224 };
225 
228 {
229  FileEvent();
230 
233 
235  const char* m_szFileOrDirectory;
236 
238  const char* m_szOther;
239 
242 };
243