1 #ifndef _RAG_FILE_SYSTEM_H_
2 #define _RAG_FILE_SYSTEM_H_
22 File(
const std::string& path,
bool bundle =
true,
bool logEnabled =
true);
26 static std::string
load(std::string filename,
bool bundle =
true, std::string mode =
"rb",
bool showErrors =
true);
29 bool open(std::string mode =
"rb",
bool showErrors =
true);
35 size_t read(
void* buffer,
size_t count);
41 size_t write(
const void * ptr,
size_t size,
size_t count);
50 static bool existsPath(
const std::string& path);
53 static bool makePath(
const std::string& path);
59 static void setPatchFile(
const std::string& filename,
const std::string& filepath);
62 static const std::map<std::string, std::string>&
getPatchFiles();
72 static bool sPatchFilesLoaded;
73 static std::map<std::string, std::string> patchFiles;
86 path(
const std::string& name =
""):
94 size_t found = name.find_last_of(
'/');
95 if (found != std::string::npos)
96 return name.substr(0, found);
101 path extension()
const
103 if (!has_extension())
106 size_t dot = name.find_last_of(
'.');
107 return name.substr(dot);
110 bool has_parent_path()
112 return name.find(
'/') != std::string::npos;
115 bool has_extension()
const
117 size_t dot = name.find_last_of(
'.');
120 if (dot == std::string::npos)
124 size_t slash = name.find_last_of(
'/');
125 if (slash == std::string::npos)
132 path& replace_extension(
const std::string extension)
134 size_t dot = name.find_last_of(
'.');
135 if (dot != std::string::npos)
138 name = name.substr(0, dot) + extension;
143 name = name + extension;
148 path filename()
const
150 size_t slash = name.find_last_of(
"/\\");
151 if (slash == std::string::npos)
155 return name.substr(slash+1);
159 std::string string()
const
164 const path operator/(
const path &rhs)
const
166 return name +
"/" + rhs.string();
size_t read(void *buffer, size_t count)
Read into buffer the number of 'count' bytes.
static void setPatchFile(const std::string &filename, const std::string &filepath)
Override files in bundle.
static const std::map< std::string, std::string > & getPatchFiles()
Returns overrided files in bundle.
size_t write(const void *ptr, size_t size, size_t count)
Writes into the file.
static void clearPatchFiles()
Clean overrided files in bundle.
static std::string load(std::string filename, bool bundle=true, std::string mode="rb", bool showErrors=true)
Convenient function to load files without deal with low level api.
Definition: File.cpp:16
File multiplatform abstraction to read contents of a file.
Definition: File.h:11
static bool makePath(const std::string &path)
Creates a folder.
Definition: File.cpp:226
void close()
Close the file.
const std::string & getFullPath()
Returns the full path of the file, may contain bundle folder.
bool exists()
Returns true if the file exists.
bool open(std::string mode="rb", bool showErrors=true)
Open the file.
long getSize()
Returns the size of the file.
File(const std::string &path, bool bundle=true, bool logEnabled=true)
Creates a File object.
Definition: File.cpp:32
Mimics boost fs::path class with some limited functionality.
Definition: File.h:81
static bool existsPath(const std::string &path)
Returns true if the path exists.
Definition: File.cpp:210