 |
Gorgon Game Engine
|
Go to the documentation of this file.
18 namespace Filesystem {
89 bool IsFile(
const std::string &path);
95 bool IsExists(
const std::string &path);
109 bool IsHidden(
const std::string &path);
122 std::string
Canonical(
const std::string &path);
132 std::string
Relative(std::string path, std::string base=
".");
140 bool Delete(
const std::string &path);
154 inline std::string
Join(std::string path1,
const std::string &path2) {
155 if(path1.empty() || path1.back()!=
'/') {
156 path1.push_back(
'/');
168 auto pos=filepath.find_last_of(
'/');
170 if(pos!=filepath.npos) {
171 filepath=filepath.substr(0,pos);
184 auto pos=path.find_last_of(
'/');
187 path=path.substr(pos+1);
200 auto pos = path.find_last_of(
'.');
202 if(pos == path.npos)
return path;
204 path = path.substr(0, pos);
214 bool Copy(
const std::string &source,
const std::string &target);
222 template<
template<
class>
class C_>
223 bool Copy(
const C_<std::string> &source,
const std::string &target) {
224 for(
const auto &s : source) {
237 template<
template<
class,
class>
class C_,
class A_>
238 bool Copy(
const C_<std::string, A_> &source,
const std::string &target) {
239 for(
const auto &s : source) {
269 template<
template<
class>
class C_>
270 bool Copy(
const std::string &sourcedir,
const C_<std::string> &source,
const std::string &target) {
271 for(
const auto &s : source) {
272 if(!
Copy(sourcedir+
"/"+s, target+
"/"+s))
return false;
287 bool Copy(
const std::string &sourcedir,
const I_ &
begin,
const I_ &
end,
const std::string &target) {
289 if(!
Copy(sourcedir+
"/"+*it, target+
"/"+*it))
return false;
302 bool Move(
const std::string &source,
const std::string &target);
307 unsigned long long Size(
const std::string &filename);
311 bool Save(
const std::string &filename,
const std::string &data,
bool append=
false);
320 std::string
Load(
const std::string &filename);
366 std::string
LocateResource(
const std::string &path,
const std::string &directory=
"",
bool localonly=
true);
std::string Path
The path of the entry point.
Definition: Filesystem.h:44
std::string GetFilename(std::string path)
Returns the filename portion of a file path.
Definition: Filesystem.h:183
bool Move(const std::string &source, const std::string &target)
Moves a given file or directory.
Definition: Linux.cpp:216
bool Writable
Whether the entry point is writable.
Definition: Filesystem.h:53
bool ChangeDirectory(const std::string &path)
Changes current working directory.
Definition: Linux.cpp:145
std::vector< T_ >::const_iterator begin(enum_type_id< T_ >)
Definition: Enum.h:283
This object is thrown from functions that return information rather than status.
Definition: Filesystem.h:22
std::string Relative(std::string path, std::string base)
Determine shortest relative path from the given path.
Definition: Filesystem.cpp:67
std::string GetDirectory(std::string filepath)
Returns the directory portion of a file path.
Definition: Filesystem.h:167
bool IsDirectory(const std::string &path)
Checks whether the given path is a directory.
Definition: Linux.cpp:32
std::string Join(std::string path1, const std::string &path2)
Joins two given paths or a path and filename.
Definition: Filesystem.h:154
bool IsHidden(const std::string &path)
Checks whether the given path is hidden.
Definition: Linux.cpp:73
bool Copy(const std::string &source, const std::string &target)
Copies a file or directory from the given source to destination.
Definition: Linux.cpp:180
std::string ExeDirectory()
Returns the directory where the program resides.
Definition: Linux.cpp:220
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
std::string Load(const std::string &filename)
Loads the given file and returns it in a string form.
Definition: Filesystem.cpp:45
std::string StartupDirectory()
Returns the directory where the program is started from.
Definition: Filesystem.cpp:18
bool IsExists(const std::string &path)
Checks whether the given path exists.
Definition: Linux.cpp:60
std::string GetExtension(std::string path)
Returns the extension of the given path, also converts the extension to lower case.
Definition: Filesystem.cpp:140
std::string LocateResource(const std::string &path, const std::string &directory="", bool localonly=true)
Locates the given file or directory.
bool Save(const std::string &filename, const std::string &data, bool append)
Saves a given data into the filename.
Definition: Filesystem.cpp:31
PathNotFoundError(const std::string &what)
Constructor that sets error text.
Definition: Filesystem.h:30
unsigned long long Size(const std::string &filename)
Returns the size of the given file.
Definition: Filesystem.cpp:22
bool Readable
Whether the entry point is readable. Currently all entry points are readable.
Definition: Filesystem.h:47
std::string Name
Name or label of the entry point.
Definition: Filesystem.h:59
bool Delete(const std::string &path)
Deletes the given file or directory.
Definition: Linux.cpp:106
std::string ExePath()
Returns the the full path of the application.
Definition: Linux.cpp:226
bool Removable
Whether the device is removable.
Definition: Filesystem.h:56
bool IsFile(const std::string &path)
Checks whether the given path is a file.
Definition: Linux.cpp:46
bool IsWritable(const std::string &path)
Checks whether the given path is writable.
Definition: Linux.cpp:64
std::vector< T_ >::const_iterator end(enum_type_id< T_ >)
Definition: Enum.h:288
void Initialize()
Initializes the filesystem module.
Definition: Filesystem.cpp:14
std::string GetBasename(std::string path)
Returns the filename from the given path, without extension.
Definition: Filesystem.h:197
std::string CurrentDirectory()
Returns the current working directory.
Definition: Linux.cpp:149
std::vector< EntryPoint > EntryPoints()
This function returns all entry points in the current system.
Definition: Linux.cpp:232
std::string Canonical(const std::string &path)
Canonicalizes a given relative path.
Definition: Linux.cpp:94
This class represents filesystem entry points (roots, drives).
Definition: Filesystem.h:36
PathNotFoundError()
Default constructor.
Definition: Filesystem.h:26
bool CreateDirectory(const std::string &path)
Creates a new directory.
Definition: Linux.cpp:19
EntryPoint()
Default constructor.
Definition: Filesystem.h:41