33#ifndef DVD_PLATFORM_FILE_FILE_MANAGEMENT_H_
34#define DVD_PLATFORM_FILE_FILE_MANAGEMENT_H_
38enum class FileError :
U8 {
49 FILE_TARGET_BUFFER_ERROR,
55 static const char* fileError[] = {
56 "NONE",
"FILE_NOT_FOUND",
"FILE_EMPTY",
"FILE_CREATE_ERROR",
"FILE_READ_ERROR",
"FILE_OPEN_ERROR",
"FILE_WRITE_ERROR",
"FILE_DELETE_ERROR",
"FILE_OVERWRITE_ERROR",
"FILE_COPY_ERROR",
"FILE_TARGET_BUFFER_ERROR",
"UNKNOWN"
63 constexpr static const char g_pathSeparator =
64#if defined(IS_WINDOWS_BUILD)
70 static ResourcePath g_logPath;
71 static ResourcePath g_screenshotPath;
72 static ResourcePath g_assetsLocation;
73 static ResourcePath g_modelsLocation;
74 static ResourcePath g_shadersLocation;
75 static ResourcePath g_texturesLocation;
76 static ResourcePath g_proceduralTexturesLocation;
77 static ResourcePath g_heightmapLocation;
78 static ResourcePath g_climatesLowResLocation;
79 static ResourcePath g_climatesMedResLocation;
80 static ResourcePath g_climatesHighResLocation;
81 static ResourcePath g_imagesLocation;
82 static ResourcePath g_materialsLocation;
83 static ResourcePath g_soundsLocation;
84 static ResourcePath g_xmlDataLocation;
85 static ResourcePath g_navMeshesLocation;
86 static ResourcePath g_scenesLocation;
87 static ResourcePath g_projectsLocation;
88 static ResourcePath g_saveLocation;
89 static ResourcePath g_nodesSaveLocation;
90 static ResourcePath g_GUILocation;
91 static ResourcePath g_fontsPath;
92 static ResourcePath g_iconsPath;
93 static ResourcePath g_localisationPath;
94 static ResourcePath g_cacheLocation;
95 static ResourcePath g_buildTypeLocation;
96 static ResourcePath g_terrainCacheLocation;
97 static ResourcePath g_geometryCacheLocation;
98 static ResourcePath g_collisionMeshCacheLocation;
101 static ResourcePath g_saveLocation;
105 static ResourcePath g_scriptsLocation;
106 static ResourcePath g_scriptsAtomsLocation;
110 static ResourcePath g_metadataLocation;
111 static Str<8> g_ddsExtension;
115 static ResourcePath g_cacheLocation;
116 static ResourcePath g_cacheLocationGL;
117 static ResourcePath g_cacheLocationVK;
118 static ResourcePath g_cacheLocationText;
119 static ResourcePath g_cacheLocationSpv;
120 static ResourcePath g_cacheLocationRefl;
122 static Str<8> g_ReflectionExt;
123 static Str<8> g_SPIRVExt;
125 static ResourcePath g_SPIRVShaderLoc;
129 static Str<8> g_fragAtomExt;
130 static Str<8> g_vertAtomExt;
131 static Str<8> g_geomAtomExt;
132 static Str<8> g_tescAtomExt;
133 static Str<8> g_teseAtomExt;
134 static Str<8> g_compAtomExt;
135 static Str<8> g_comnAtomExt;
138 static ResourcePath g_GLSLShaderLoc;
140 static ResourcePath g_fragAtomLoc;
141 static ResourcePath g_vertAtomLoc;
142 static ResourcePath g_geomAtomLoc;
143 static ResourcePath g_tescAtomLoc;
144 static ResourcePath g_teseAtomLoc;
145 static ResourcePath g_compAtomLoc;
146 static ResourcePath g_comnAtomLoc;
151 static constexpr auto g_includePattern = ctll::fixed_string{ R
"(\s*#\s*include\s+["<]([^">]+)*[">])" };
153 static constexpr auto g_definePattern = ctll::fixed_string{ R
"(([#!][A-z]{2,}[\s]{1,}?([A-z]{2,}[\s]{1,}?)?)([\\(]?[^\s\\)]{1,}[\\)]?)?)" };
155 static constexpr auto g_usePattern = ctll::fixed_string{ R
"(\s*use\s*\(\s*\"(.+)\"\s*\).*)" };
157 static constexpr auto g_uniformPattern = ctll::fixed_string{ R
"(\s*uniform\s+\s*([^),^;^\s]*)\s+([^),^;^\s]*\[*\s*\]*)\s*(?:=*)\s*(?:\d*.*)\s*(?:;+).*)" };
159 static constexpr auto g_useProjectPattern = ctll::fixed_string{ R
"((--project\s*=\s*)([0-9a-zA-Z]*))" };
161 static void initPaths();
166 ResourcePath _name{};
167 U64 _lastWriteTime{0u};
169using FileList = vector<FileEntry>;
173[[nodiscard]]
bool pathExists(
const ResourcePath& filePath);
175[[nodiscard]]
bool fileExists(
const ResourcePath& filePathAndName);
176[[nodiscard]]
bool fileExists(
const ResourcePath& filePath, std::string_view fileName);
178[[nodiscard]]
bool fileIsEmpty(
const ResourcePath& filePathAndName);
179[[nodiscard]]
bool fileIsEmpty(
const ResourcePath& filePath, std::string_view fileName);
184[[nodiscard]]
bool createFile(
const ResourcePath& filePathAndName,
bool overwriteExisting);
186[[nodiscard]]
bool deleteAllFiles(
const ResourcePath& filePath,
const char* extensionNoDot =
nullptr,
const char* extensionToSkip =
nullptr);
188[[nodiscard]]
bool getAllFilesInDirectory(
const ResourcePath& filePath, FileList& listInOut,
const char* extensionNoDot =
nullptr);
191[[nodiscard]] FileError
fileLastWriteTime(
const ResourcePath& filePath, std::string_view fileName,
U64& timeOutSec);
196[[nodiscard]] FileError
readFile(
const ResourcePath& filePath, std::string_view fileName,
FileType fileType, std::ifstream& sreamOut);
197[[nodiscard]] FileError
readFile(
const ResourcePath& filePath, std::string_view fileName,
FileType fileType,
string& contentOut);
198[[nodiscard]] FileError
readFile(
const ResourcePath& filePath, std::string_view fileName,
FileType fileType, std::string& contentOut);
199[[nodiscard]] FileError
readFile(
const ResourcePath& filePath, std::string_view fileName,
FileType fileType,
Byte* contentOut,
size_t& sizeInOut);
201[[nodiscard]] FileError
openFile(
const ResourcePath& filePath, std::string_view fileName);
202[[nodiscard]] FileError
openFile(std::string_view cmd,
const ResourcePath& filePath, std::string_view fileName);
204[[nodiscard]] FileError
writeFile(
const ResourcePath& filePath, std::string_view fileName,
bufferPtr content,
size_t length,
FileType fileType);
205[[nodiscard]] FileError
writeFile(
const ResourcePath& filePath, std::string_view fileName,
const char* content,
size_t length,
FileType fileType);
207[[nodiscard]] FileError
deleteFile(
const ResourcePath& filePath, std::string_view fileName);
209[[nodiscard]] FileError
copyFile(
const ResourcePath& sourcePath, std::string_view sourceName,
const ResourcePath& targetPath, std::string_view targetName,
bool overwrite);
211[[nodiscard]] FileError
copyDirectory(
const ResourcePath& sourcePath,
const ResourcePath& targetPath,
bool recursively,
bool overwrite);
213[[nodiscard]] FileError
findFile(
const ResourcePath& filePath, std::string_view fileName,
string& foundPath);
215[[nodiscard]]
bool hasExtension(std::string_view fileName, std::string_view extensionNoDot);
217[[nodiscard]]
bool hasExtension(
const ResourcePath& filePath, std::string_view extensionNoDot);
219[[nodiscard]]
string getExtension(std::string_view fileName );
221[[nodiscard]]
string getExtension(
const ResourcePath& filePath );
225[[nodiscard]]
string stripExtension(std::string_view fileName )
noexcept;
227[[nodiscard]] ResourcePath
stripExtension(
const ResourcePath& filePath)
noexcept;
229[[nodiscard]]
string stripQuotes( std::string_view input);
Handle console commands that start with a forward slash.
FileError removeDirectory(const ResourcePath &path)
FileError openFile(const std::string_view cmd, const ResourcePath &filePath, const std::string_view fileName)
ResourcePath getTopLevelFolderName(const ResourcePath &filePath)
bool hasExtension(const ResourcePath &filePath, const std::string_view extensionNoDot)
FileError writeFile(const ResourcePath &filePath, const std::string_view fileName, const char *content, const size_t length, const FileType fileType)
FileError readFile(const ResourcePath &filePath, std::string_view fileName, FileType fileType, std::ifstream &sreamOut)
size_t numberOfFilesInDirectory(const ResourcePath &path)
ResourcePath getWorkingDirectory()
bool deleteAllFiles(const ResourcePath &filePath, const char *extension, const char *extensionToSkip)
string getExtension(const std::string_view fileName)
FileError createDirectory(const ResourcePath &path)
FileError copyFile(const ResourcePath &sourcePath, const std::string_view sourceName, const ResourcePath &targetPath, const std::string_view targetName, const bool overwrite)
bool fileIsEmpty(const ResourcePath &filePathAndName)
bool getAllFilesInDirectory(const ResourcePath &filePath, FileList &listInOut, const char *extensionNoDot)
FileError findFile(const ResourcePath &filePath, const std::string_view fileName, string &foundPath)
string stripExtension(const std::string_view fileName) noexcept
FileError copyDirectory(const ResourcePath &sourcePath, const ResourcePath &targetPath, bool recursively, bool overwrite)
FileError deleteFile(const ResourcePath &filePath, const std::string_view fileName)
bool fileExists(const ResourcePath &filePathAndName)
bool pathExists(const ResourcePath &filePath)
string extractFilePathAndName(char *argv0)
FileError fileLastWriteTime(const ResourcePath &filePathAndName, U64 &timeOutSec)
FileNameAndPath splitPathToNameAndLocation(const ResourcePath &input)
bool createFile(const ResourcePath &filePathAndName, const bool overwriteExisting)
string stripQuotes(const std::string_view input)