![]() |
Gorgon Game Engine
|
Contains filesystem functions. More...
Namespaces | |
internal | |
Classes | |
class | EntryPoint |
This class represents filesystem entry points (roots, drives). More... | |
class | Iterator |
This iterator allows iteration of directories. More... | |
class | PathNotFoundError |
This object is thrown from functions that return information rather than status. More... | |
Functions | |
std::string | Canonical (const std::string &path) |
Canonicalizes a given relative path. More... | |
bool | ChangeDirectory (const std::string &path) |
Changes current working directory. More... | |
template<template< class > class C_> | |
bool | Copy (const C_< std::string > &source, const std::string &target) |
Copies list of files and/or directories from the given source to destination. More... | |
template<template< class, class > class C_, class A_ > | |
bool | Copy (const C_< std::string, A_ > &source, const std::string &target) |
Copies list of files and/or directories from the given source to destination. More... | |
template<class I_ > | |
bool | Copy (const I_ &begin, const I_ &end, const std::string &target) |
Copies list of files and/or directories from the given source to destination. More... | |
bool | Copy (const std::string &source, const std::string &target) |
Copies a file or directory from the given source to destination. More... | |
template<template< class > class C_> | |
bool | Copy (const std::string &sourcedir, const C_< std::string > &source, const std::string &target) |
Copies list of files and/or directories from the given source to destination. More... | |
template<class I_ > | |
bool | Copy (const std::string &sourcedir, const I_ &begin, const I_ &end, const std::string &target) |
Copies list of files and/or directories from the given source to destination. More... | |
bool | CreateDirectory (const std::string &path) |
Creates a new directory. More... | |
std::string | CurrentDirectory () |
Returns the current working directory. More... | |
bool | Delete (const std::string &path) |
Deletes the given file or directory. More... | |
std::vector< EntryPoint > | EntryPoints () |
This function returns all entry points in the current system. More... | |
std::string | ExeDirectory () |
Returns the directory where the program resides. More... | |
std::string | ExePath () |
Returns the the full path of the application. More... | |
std::string | GetBasename (std::string path) |
Returns the filename from the given path, without extension. More... | |
std::string | GetDirectory (std::string filepath) |
Returns the directory portion of a file path. More... | |
std::string | GetExtension (std::string path) |
Returns the extension of the given path, also converts the extension to lower case. More... | |
std::string | GetFilename (std::string path) |
Returns the filename portion of a file path. More... | |
void | Initialize () |
Initializes the filesystem module. More... | |
bool | IsDirectory (const std::string &path) |
Checks whether the given path is a directory. More... | |
bool | IsExists (const std::string &path) |
Checks whether the given path exists. More... | |
bool | IsFile (const std::string &path) |
Checks whether the given path is a file. More... | |
bool | IsHidden (const std::string &path) |
Checks whether the given path is hidden. More... | |
bool | IsWritable (const std::string &path) |
Checks whether the given path is writable. More... | |
std::string | Join (std::string path1, const std::string &path2) |
Joins two given paths or a path and filename. More... | |
std::string | Load (const std::string &filename) |
Loads the given file and returns it in a string form. More... | |
std::string | LocateResource (const std::string &path, const std::string &directory="", bool localonly=true) |
Locates the given file or directory. More... | |
bool | Move (const std::string &source, const std::string &target) |
Moves a given file or directory. More... | |
std::string | Relative (std::string path, std::string base=".") |
Determine shortest relative path from the given path. More... | |
bool | Save (const std::string &filename, const std::string &data, bool append=false) |
Saves a given data into the filename. More... | |
unsigned long long | Size (const std::string &filename) |
Returns the size of the given file. More... | |
std::string | StartupDirectory () |
Returns the directory where the program is started from. More... | |
void | swap (Iterator &l, Iterator &r) |
Swaps two iterators. More... | |
Contains filesystem functions.
All file related functions in Gorgon uses forward slash as directory separator. This includes return values from these functions as well.
std::string Canonical | ( | const std::string & | path | ) |
Canonicalizes a given relative path.
This method always return with a path that contains at least one slash. However, a slash should be appended to string as it never leaves a slash at the end unless, the path is a root path therefore, it is save to append an extra slash.
path | is the file/directory to be canonized. Should contain forward slash as directory separator. |
PathNotFoundError | if canonize fails. |
bool ChangeDirectory | ( | const std::string & | path | ) |
Changes current working directory.
path | is the directory to become current directory. Should contain forward slash as directory separator. |
bool Gorgon::Filesystem::Copy | ( | const C_< std::string > & | source, |
const std::string & | target | ||
) |
Copies list of files and/or directories from the given source to destination.
Hard link sources will be copied instead of links themselves.
source | list of source files or directories |
target | is directory to copy files or directories into. This directory should exist before calling this function |
References Copy(), and GetFilename().
bool Gorgon::Filesystem::Copy | ( | const C_< std::string, A_ > & | source, |
const std::string & | target | ||
) |
Copies list of files and/or directories from the given source to destination.
Hard link sources will be copied instead of links themselves.
source | list of source files or directories |
target | is directory to copy files or directories into. This directory should exist before calling this function |
References Copy(), and GetFilename().
bool Gorgon::Filesystem::Copy | ( | const I_ & | begin, |
const I_ & | end, | ||
const std::string & | target | ||
) |
Copies list of files and/or directories from the given source to destination.
Hard link sources will be copied instead of links themselves.
begin | starting iterator |
end | ending iterator, will not be dereferenced |
target | is directory to copy files or directories into. This directory should exist before calling this function |
References Gorgon::begin(), Copy(), Gorgon::end(), and GetFilename().
bool Copy | ( | const std::string & | source, |
const std::string & | target | ||
) |
Copies a file or directory from the given source to destination.
Hard link sources will be copied instead of links themselves.
source | file or directory. Should either be a single file, or single directory |
target | is the new filename or directory name |
References IsDirectory(), and IsFile().
bool Gorgon::Filesystem::Copy | ( | const std::string & | sourcedir, |
const C_< std::string > & | source, | ||
const std::string & | target | ||
) |
Copies list of files and/or directories from the given source to destination.
Hard link sources will be copied instead of links themselves.
sourcedir | the directory contains source files |
source | list of source files or directories |
target | is directory to copy files or directories into. This directory should exist before calling this function |
References Copy().
bool Gorgon::Filesystem::Copy | ( | const std::string & | sourcedir, |
const I_ & | begin, | ||
const I_ & | end, | ||
const std::string & | target | ||
) |
Copies list of files and/or directories from the given source to destination.
Hard link sources will be copied instead of links themselves.
sourcedir | the directory contains source files |
begin | starting iterator |
end | ending iterator, will not be dereferenced |
target | is directory to copy files or directories into. This directory should exist before calling this function |
References Gorgon::begin(), Copy(), and Gorgon::end().
bool CreateDirectory | ( | const std::string & | path | ) |
Creates a new directory.
This function works recursively to create any missing parent directories as well. If directory exists, this function returns true.
path | is the path of the directory to be created. Should contain forward slash as directory separator. |
References IsDirectory().
std::string CurrentDirectory | ( | ) |
Returns the current working directory.
bool Delete | ( | const std::string & | path | ) |
Deletes the given file or directory.
If the directory is not empty, this function will delete all its contents.
path | is the file/directory to be deleted. Should contain forward slash as directory separator. |
References IsDirectory(), Iterator::IsValid(), and Iterator::Next().
std::vector< EntryPoint > EntryPoints | ( | ) |
This function returns all entry points in the current system.
This function does not perform caching and should be used sparingly. It may cause Windows systems to read external devices. On Linux systems, home, root and removable devices are listed.
References Canonical(), IsDirectory(), Iterator::IsValid(), Load(), EntryPoint::Name, Iterator::Next(), EntryPoint::Path, EntryPoint::Readable, EntryPoint::Removable, and EntryPoint::Writable.
std::string ExeDirectory | ( | ) |
Returns the directory where the program resides.
Can be used to locate resources. May not be same as StartupDirectory
References Canonical(), and GetDirectory().
std::string ExePath | ( | ) |
Returns the the full path of the application.
References Canonical().
std::string Gorgon::Filesystem::GetBasename | ( | std::string | path | ) |
Returns the filename from the given path, without extension.
References GetFilename().
std::string Gorgon::Filesystem::GetDirectory | ( | std::string | filepath | ) |
Returns the directory portion of a file path.
If the file path does not contain any directory related information, this method returns current directory. This function expects the input to have / as directory separator.
filepath | path that contains the filename |
References CurrentDirectory().
std::string GetExtension | ( | std::string | path | ) |
Returns the extension of the given path, also converts the extension to lower case.
References Gorgon::String::ToLower().
std::string Gorgon::Filesystem::GetFilename | ( | std::string | path | ) |
Returns the filename portion of a file path.
This function expects the input to have / as directory separator. If path does not contain any /, it will return whole input.
path | path that contains the filename |
void Initialize | ( | ) |
Initializes the filesystem module.
Gorgon system requires every module to have initialization function even if they are not used. Currently used for following tasks:
References CurrentDirectory().
bool IsDirectory | ( | const std::string & | path | ) |
Checks whether the given path is a directory.
path | is the directory to be checked. Should contain forward slash as directory separator. |
bool IsExists | ( | const std::string & | path | ) |
Checks whether the given path exists.
path | is the file to be checked. Should contain forward slash as directory separator. |
bool IsFile | ( | const std::string & | path | ) |
Checks whether the given path is a file.
path | is the file to be checked. Should contain forward slash as directory separator. |
bool IsHidden | ( | const std::string & | path | ) |
Checks whether the given path is hidden.
path | is the directory to be checked. Should contain forward slash as directory separator. |
bool IsWritable | ( | const std::string & | path | ) |
Checks whether the given path is writable.
This does not check if the file is locked or not. Also, even if the file is not marked as writable, a write operation might succeed.
path | is the directory or file to be checked. Should contain forward slash as directory separator. |
std::string Gorgon::Filesystem::Join | ( | std::string | path1, |
const std::string & | path2 | ||
) |
Joins two given paths or a path and filename.
std::string Load | ( | const std::string & | filename | ) |
Loads the given file and returns it in a string form.
Notice that there is no size restriction over the file. This function can handle binary data. Throws PathNotFoundError if the file cannot be found. Before deciding on file is not found, this function checks if there is a lzma compressed file as filename.lzma
filename | is the file to be loaded |
PathNotFoundError | if the file cannot be read or does not exits |
References Gorgon::end().
std::string Gorgon::Filesystem::LocateResource | ( | const std::string & | path, |
const std::string & | directory = "" , |
||
bool | localonly = true |
||
) |
Locates the given file or directory.
If localonly is true, this function only searches locations that are in the working directory. If it is set to false standard system locations like user home directory or application data directory is also searched. While looking for the resource, if the directory parameter is not empty, the resource is expected to be in the given directory under the local or system wide directory. Additionally, if the file is found as a lzma compressed file, it will be extracted. For instance, if directory parameter is "images", localonly is false, systemname is system and we are looking for icon.png, this function checks whether file exists in the following forms. The first one found is returned, if none exists, PathNotFoundError exception is thrown. The following list assume user path to be ~ application data path to be ~/apps images/icon.png, ../images/icon.png, icon.png, ../icon.png, images/icon.png.lzma, ../images/icon.png.lzma, icon.png.lzma, ../icon.png.lzma, ~/.system/images/icon.png, ~/.system/images/icon.png.lzma, ~/apps/.system/images/icon.png, ~/apps/.system/images/icon.png.lzma, ~/system/images/icon.png, ~/system/images/icon.png.lzma, ~/apps/system/images/icon.png, ~/apps/system/images/icon.png.lzma, ~/images/icon.png, ~/images/icon.png.lzma, ~/apps/images/icon.png, ~/apps/images/icon.png.lzma, ~/system/icon.png, ~/system/icon.png.lzma, ~/apps/system/icon.png, ~/apps/system/icon.png.lzma If compressed file is found, it will be extracted in place, and the extracted filename will be returned. Therefore, its not necessary to check if the file is compressed or not.
path | is the filename or directory to be searched. Only compressed files are handled. |
directory | is the directory the resource expected to be in. Should be relative. |
localonly | if set, no system or user directories will be searched |
PathNotFoundError | if the file cannot be found |
std::runtime_error | if the file cannot be read |
bool Move | ( | const std::string & | source, |
const std::string & | target | ||
) |
Moves a given file or directory.
Target is the new path rather than the target directory. This function can also be used to rename a file or directory.
source | file or directory to be moved or renamed |
target | path |
std::string Relative | ( | std::string | path, |
std::string | base = "." |
||
) |
Determine shortest relative path from the given path.
Using "." in second parameter will return the path relative to current directory. This function never returns a path ending with a slash unless its safe to append another slash (i.e. a root path)
path | is the path to be relativized. |
base | is the base path that will be used to find relative path |
References Canonical().
bool Save | ( | const std::string & | filename, |
const std::string & | data, | ||
bool | append = false |
||
) |
Saves a given data into the filename.
If the file exists, it will be appended if append parameter is set to true. This function can handle binary data.
unsigned long long Size | ( | const std::string & | filename | ) |
Returns the size of the given file.
If the file is not found 0 is returned.
filename | is the name of the file |
std::string StartupDirectory | ( | ) |
Returns the directory where the program is started from.
This will always return the same value through out the execution.
Swaps two iterators.
References Iterator::Swap().