xyginext  0.2.0
Second generation of xygine game creation framework
Static Public Member Functions | List of all members
xy::FileSystem Class Referencefinal

Utilities for manipulating the current file system. More...

#include <FileSystem.hpp>

Static Public Member Functions

static std::vector< std::string > listFiles (std::string path)
 Lists all the files in the given directory.
 
static std::string getFileExtension (const std::string &path)
 Attempts to return a string containing the file extension of a given path, including the period (.)
 
static std::string getFileName (const std::string &path)
 Attempts to return the name of a file at the end of a given file path.
 
static std::string getFilePath (const std::string &path)
 Attempts to return the path of a given filepath without the file name, including trailing separator char.
 
static bool fileExists (const std::string &)
 Returns true if a file exists with the name at the given path.
 
static bool createDirectory (const std::string &)
 Tries to create a directory relative to the executable or via an absolute path. More...
 
static bool directoryExists (const std::string &)
 Attempts to determine if a directory at the given path exists. More...
 
static std::vector< std::string > listDirectories (const std::string &)
 Returns a vector of strings containing the names of directories found in the given path.
 
static std::string getCurrentDirectory ()
 Returns the absolute path of the current working directory.
 
static bool setCurrentDirectory (std::string path)
 Sets the current working directory to the given absolute path. More...
 
static std::string getRelativePath (std::string path, const std::string &root)
 Attempts to convert the given absolute path to a path relative to the given root directory. More...
 
static std::string getConfigDirectory (const std::string &appName)
 Returns a path to the current user's config directory. Config files should generally be written to this directory, rather than the current working directory. Output is usually in the form of the following: More...
 
static std::string openFileDialogue (const std::string &defaultDir="", const std::string &filter="")
 Show a native file dialog to open a file. More...
 
static std::string openFolderDialogue ()
 Show a native file dialog to open a folder. More...
 
static std::string saveFileDialogue (const std::string &defaultDir="", const std::string &filter="")
 Show a platform native file dialogue for saving files. More...
 
static std::string getResourcePath ()
 Currently only relevant on macOS when creating an app bundle. Basically a wrapper around the SFML resourcePath() function. Might potentially provide some portable way of bundling resources nicely in the future. More...
 
static void setResourceDirectory (const std::string &path)
 Sets the resource directory relative to the working directory. When using getResourcePath() this path will be appended to the working directory. Used, for example, when setting a sub-directory as a resource directory.
 

Detailed Description

Utilities for manipulating the current file system.

Member Function Documentation

◆ createDirectory()

static bool xy::FileSystem::createDirectory ( const std::string &  )
static

Tries to create a directory relative to the executable or via an absolute path.

Returns
false if creation fails and attempts to log the reason, else returns true.
Parameters
std::stringPath to create.

◆ directoryExists()

static bool xy::FileSystem::directoryExists ( const std::string &  )
static

Attempts to determine if a directory at the given path exists.

Returns
true if the directory exists, else false. Attempts to log any errors to the console.

◆ getConfigDirectory()

static std::string xy::FileSystem::getConfigDirectory ( const std::string &  appName)
static

Returns a path to the current user's config directory. Config files should generally be written to this directory, rather than the current working directory. Output is usually in the form of the following:

Windows: C:\Users\squidward\AppData\Roaming\appname\
Linux: /home/squidward/.config/appname/
Mac: /Users/squidward/Library/Application Support/appname/

WARNING some linux distros are known to return the current working directory instead. This should be considered when using configuration files with the same name as another which is expected to be stored in a unique directory.

Parameters
appNameName of the current application used to create the appname directory
Returns
Above formatted string, or an empty string if something went wrong

◆ getRelativePath()

static std::string xy::FileSystem::getRelativePath ( std::string  path,
const std::string &  root 
)
static

Attempts to convert the given absolute path to a path relative to the given root directory.

Parameters
pathAbsolute path to convert
rootAbsolute path to root directory to which the result should be relative

◆ getResourcePath()

static std::string xy::FileSystem::getResourcePath ( )
static

Currently only relevant on macOS when creating an app bundle. Basically a wrapper around the SFML resourcePath() function. Might potentially provide some portable way of bundling resources nicely in the future.

Returns
path to the resource directory

◆ openFileDialogue()

static std::string xy::FileSystem::openFileDialogue ( const std::string &  defaultDir = "",
const std::string &  filter = "" 
)
static

Show a native file dialog to open a file.

Parameters
defaultDirDefault path to open (optional)
filterFile extention filter in the format "png,jpg,bmp"
Returns
path the path selected by the user

◆ openFolderDialogue()

static std::string xy::FileSystem::openFolderDialogue ( )
static

Show a native file dialog to open a folder.

Returns
path the path selected by the user

◆ saveFileDialogue()

static std::string xy::FileSystem::saveFileDialogue ( const std::string &  defaultDir = "",
const std::string &  filter = "" 
)
static

Show a platform native file dialogue for saving files.

Parameters
defaultDirDefault directory to save to - optional
filterString containing file extension filter in the format "png,jpg,bmp"
Returns
string containing the selected file path

◆ setCurrentDirectory()

static bool xy::FileSystem::setCurrentDirectory ( std::string  path)
static

Sets the current working directory to the given absolute path.

Parameters
pathString containing the path to attempt to set to cwd
Returns
false on failure