xoreos  0.0.5
Static Public Member Functions | List of all members
Common::FilePath Class Reference

Utility class for manipulating file paths. More...

#include <filepath.h>

Static Public Member Functions

static bool isRegularFile (const UString &p)
 Does specified path exist and is it a regular file? More...
 
static bool isDirectory (const UString &p)
 Does specified path exist and is it a directory? More...
 
static size_t getFileSize (const UString &p)
 Return a file's size. More...
 
static UString getFile (const UString &p)
 Return a file name without its path. More...
 
static UString getStem (const UString &p)
 Return a file name's stem. More...
 
static UString getExtension (const UString &p)
 Return a file name's extension. More...
 
static UString changeExtension (const UString &p, const UString &ext="")
 Change a file name's extension. More...
 
static UString getDirectory (const UString &p)
 Return a path's directory. More...
 
static bool isAbsolute (const UString &p)
 Is the given string an absolute path? More...
 
static UString absolutize (const UString &p)
 Return the absolute path. More...
 
static UString relativize (const UString &basePath, const UString &path)
 Return the path relative to the base path. More...
 
static UString normalize (const UString &p, bool resolveSymLinks=true)
 Normalize a path. More...
 
static UString canonicalize (const UString &p, bool resolveSymLinks=true)
 Return the canonical, absolutized and normalized path. More...
 
static UString findSubDirectory (const UString &directory, const UString &subDirectory, bool caseInsensitive=false)
 Find a directory's subdirectory. More...
 
static bool getSubDirectories (const UString &directory, std::list< UString > &subDirectories)
 Collect all direct subdirectories of a directory in a list. More...
 
static bool createDirectories (const UString &path)
 Create all directories in this path. More...
 
static UString escapeStringLiteral (const UString &str)
 Escape a string literal for use in a regexp. More...
 
static UString getHumanReadableSize (size_t size)
 Format this file size into a human readable string. More...
 
static UString getHomeDirectory ()
 Return the OS-specific path of the user's home directory. More...
 
static UString getConfigDirectory ()
 Return the OS-specific path of the config directory. More...
 
static UString getUserDataDirectory ()
 Return the OS-specific path of the user data directory. More...
 
static UString getUserDataFile (UString file)
 Return a path suitable for writing into. More...
 

Detailed Description

Utility class for manipulating file paths.

Definition at line 38 of file filepath.h.

Member Function Documentation

◆ absolutize()

UString Common::FilePath::absolutize ( const UString p)
static

Return the absolute path.

If the path is already absolute, just return that path. If not, interpret it as relative to the program starting path and then return an absolute path of that.

In addition, a path starting with a ~ directory will be changed to point to the user's home directory.

Parameters
pThe path to absolutize.
Returns
The absolutized path.

Definition at line 125 of file filepath.cpp.

References Common::UString::c_str(), Common::convertToSlash(), and getHomeDirectory().

Referenced by canonicalize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ canonicalize()

UString Common::FilePath::canonicalize ( const UString p,
bool  resolveSymLinks = true 
)
static

Return the canonical, absolutized and normalized path.

Calls absolutize() and normalize() on the path.

The effect is very similar to boost::filesystem::canonical(), except:

  • boost::filesystem::canonical() does not resolve ~ to the user's home directory
  • boost::filesystem::canonical() fails on paths that don't exist, normalize() does not
Parameters
pThe path to canonicalize.
resolveSymLinksShould symbolic links be resolved?
Returns
The canonicalized path.

Definition at line 230 of file filepath.cpp.

References absolutize(), and normalize().

Referenced by Common::FileList::addDirectory(), Common::FileList::addSubDirectories(), Common::ConfigManager::createGame(), Common::ConfigManager::createGameID(), Common::ConfigManager::findGame(), Common::Platform::getConfigDirectory(), Common::Platform::getUserDataDirectory(), getUserDataFile(), main(), Common::DebugManager::openLogFile(), Engines::ConsoleWindow::openLogFile(), Aurora::ResourceManager::registerDataBase(), and Common::ConfigManager::save().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ changeExtension()

UString Common::FilePath::changeExtension ( const UString p,
const UString ext = "" 
)
static

Change a file name's extension.

Example: "/path/to/file.ext", ".bar" -> "/path/to/file.bar"

Parameters
pThe path to manipulate.
extThe path's new extension.
Returns
The new path.

Definition at line 99 of file filepath.cpp.

References Common::UString::c_str().

Referenced by Aurora::ResourceManager::findArchive(), Graphics::Aurora::Model_DragonAge::ParserContext::open(), Engines::NWN::Module::preparePremiumModule(), and Aurora::FileTypeManager::setFileType().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createDirectories()

bool Common::FilePath::createDirectories ( const UString path)
static

Create all directories in this path.

For example, if called on the path "/foo/bar/quux/", this will create the directories "/foo/", "/foo/bar/" and "/foo/bar/quux/" if necessary.

Parameters
pathThe path to create.
Returns
true if at least one directory was created.

Definition at line 342 of file filepath.cpp.

References Common::UString::c_str().

Referenced by Common::WriteFile::open(), Common::DebugManager::openLogFile(), Engines::ConsoleWindow::openLogFile(), and Common::ConfigManager::save().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ escapeStringLiteral()

UString Common::FilePath::escapeStringLiteral ( const UString str)
static

Escape a string literal for use in a regexp.

Definition at line 350 of file filepath.cpp.

References Common::UString::c_str().

Here is the call graph for this function:

◆ findSubDirectory()

UString Common::FilePath::findSubDirectory ( const UString directory,
const UString subDirectory,
bool  caseInsensitive = false 
)
static

Find a directory's subdirectory.

Parameters
directoryThe directory in which to look.
subDirectoryThe subdirectory to find.
caseInsensitiveShould the case of the subdirectory be ignored?
Returns
The path of the subdirectory or "" if not found.

Definition at line 318 of file filepath.cpp.

References Common::UString::c_str(), Common::UString::empty(), Common::findSubDirectory_internal(), and Common::splitDirectories().

Referenced by Engines::DragonAge::DragonAgeEngine::detectLanguages(), Engines::DragonAge2::DragonAge2Engine::detectLanguages(), Engines::Witcher::WitcherEngine::detectLanguages(), Engines::KotOR::Version::detectMacOSX(), Engines::NWN::Version::detectMacOSX(), Engines::Jade::findAndroidVOLanguageDir(), Engines::DragonAge::Campaigns::findCampaigns(), Engines::DragonAge2::Campaigns::findCampaigns(), Engines::Jade::findTLKs(), Engines::NWN2::Campaign::getDirectory(), Aurora::ResourceManager::hasResourceDir(), Aurora::ResourceManager::indexResourceDir(), Engines::Jade::JadeEngine::initGameConfig(), Engines::KotOR2::KotOR2Engine::initGameConfig(), Engines::NWN2::NWN2Engine::initGameConfig(), Engines::Witcher::WitcherEngine::initGameConfig(), Engines::KotOR::KotOREngine::initGameConfig(), Engines::NWN::NWNEngine::initGameConfig(), Engines::DragonAge::Game::loadResourceDir(), Engines::DragonAge2::Game::loadResourceDir(), Engines::DragonAge2::Game::loadResources(), Engines::DragonAge::Game::loadTalkTables(), Engines::DragonAge2::Game::loadTalkTables(), Engines::Witcher::EngineProbe::probe(), Engines::DragonAge::EngineProbeXbox360::probe(), Engines::NWN::EngineProbeMac::probe(), Engines::KotOR2::EngineProbeLinux::probe(), Engines::KotOR::EngineProbeMac::probe(), Engines::KotOR::EngineProbeXbox::probe(), Engines::KotOR2::EngineProbeMac::probe(), Engines::KotOR::EngineProbeAndroid::probe(), Engines::KotOR2::EngineProbeXbox::probe(), Engines::KotOR::Console::updateMusic(), Engines::KotOR2::Console::updateMusic(), and Engines::Witcher::Console::updateMusic().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getConfigDirectory()

UString Common::FilePath::getConfigDirectory ( )
static

Return the OS-specific path of the config directory.

This is where the xoreos.conf is put by default.

  • On GNU/Linux, this will evaluate to $XDG_CONFIG_HOME/xoreos/
  • On Mac OS X, this will evaluate to $HOME/Library/Preferences/xoreos/
  • On Windows, this will evaluate to either $APPDATA/xoreos/, $USERPROFILE/xoreos/ or the current directory, depending on the Windows version.

Definition at line 375 of file filepath.cpp.

References Common::Platform::getConfigDirectory().

Referenced by Common::ConfigManager::getDefaultConfigFile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getDirectory()

UString Common::FilePath::getDirectory ( const UString p)
static

Return a path's directory.

Example: "/path/to/file.ext" -> "/path/to/"

Parameters
pThe path to manipulate.
Returns
The path's directory.

Definition at line 107 of file filepath.cpp.

References Common::UString::c_str().

Referenced by Engines::NWN2::Game::getCampaigns(), Engines::Witcher::Campaign::getDirectory(), Engines::Jade::getTLKDirectory(), Common::WriteFile::open(), Common::DebugManager::openLogFile(), Engines::ConsoleWindow::openLogFile(), and Common::ConfigManager::save().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getExtension()

UString Common::FilePath::getExtension ( const UString p)
static

◆ getFile()

UString Common::FilePath::getFile ( const UString p)
static

Return a file name without its path.

Example: "/path/to/file.ext" > "file.ext"

Parameters
pThe path to manipulate.
Returns
The path's file name.

Definition at line 81 of file filepath.cpp.

References Common::UString::c_str().

Referenced by Engines::Witcher::Module::findModule(), Engines::KotOR::SaveLoadMenu::getBaseNameFromDirectory(), Engines::NWN2::Game::getCampaigns(), Engines::Witcher::Campaign::getDirectory(), Engines::NWN::Game::isPremiumModule(), and Engines::Witcher::Campaign::openMMD().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getFileSize()

size_t Common::FilePath::getFileSize ( const UString p)
static

Return a file's size.

Parameters
pThe file to look up.
Returns
The size of the file or kFileInvalid if not a valid file.

Definition at line 60 of file filepath.cpp.

References Common::UString::c_str(), Common::kFileInvalid, and warning().

Referenced by Aurora::ResourceManager::getResourceSize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getHomeDirectory()

UString Common::FilePath::getHomeDirectory ( )
static

Return the OS-specific path of the user's home directory.

If no home directory was accessible, an empty string is returned.

Definition at line 371 of file filepath.cpp.

References Common::Platform::getHomeDirectory().

Referenced by absolutize(), and normalize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getHumanReadableSize()

UString Common::FilePath::getHumanReadableSize ( size_t  size)
static

Format this file size into a human readable string.

Definition at line 357 of file filepath.cpp.

References ARRAYSIZE, and Common::UString::format().

Here is the call graph for this function:

◆ getStem()

UString Common::FilePath::getStem ( const UString p)
static

◆ getSubDirectories()

bool Common::FilePath::getSubDirectories ( const UString directory,
std::list< UString > &  subDirectories 
)
static

Collect all direct subdirectories of a directory in a list.

For example, if the specified directory contains the directories "foo" and "bar", and the file "quux", the list will contain the directories "foo" and "bar".

Parameters
directoryThe directory in which to look.
subDirectoriesThe list to add the directories to.
Returns
false if the specified path was not a directory or could not be searched; true otherwise.

Definition at line 234 of file filepath.cpp.

References Common::UString::c_str().

Referenced by Engines::Jade::findAndroidVOLanguageDir(), Engines::DragonAge::Campaigns::findCampaigns(), and Engines::DragonAge2::Campaigns::findCampaigns().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getUserDataDirectory()

UString Common::FilePath::getUserDataDirectory ( )
static

Return the OS-specific path of the user data directory.

This is where user data like the log or game saves are put by default.

  • On GNU/Linux, this will evaluate to $XDG_DATA_HOME/xoreos/
  • On Mac OS X, this will evaluate to $HOME/Library/Application\ Support/xoreos/
  • On Windows, this will be the same place as getConfigDirectory()

Definition at line 379 of file filepath.cpp.

References Common::Platform::getUserDataDirectory().

Referenced by Common::DebugManager::getDefaultLogFile(), getUserDataFile(), and Engines::ConsoleWindow::openLogFile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getUserDataFile()

UString Common::FilePath::getUserDataFile ( UString  file)
static

Return a path suitable for writing into.

If the file is an absolute path, return it as is. Otherwise, prepend the user data directory.

Definition at line 383 of file filepath.cpp.

References canonicalize(), getUserDataDirectory(), and isAbsolute().

Referenced by Engines::Console::cmdDump2DA(), Engines::Console::cmdDumpAll2DA(), Engines::Console::cmdDumpRes(), Engines::Console::cmdDumpResList(), Engines::Console::cmdDumpTGA(), Graphics::constructFilename(), and Engines::ConsoleWindow::setRedirect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isAbsolute()

bool Common::FilePath::isAbsolute ( const UString p)
static

Is the given string an absolute path?

Parameters
pThe path to check.
Returns
true if the string describes an absolute path, false otherwise.

Definition at line 113 of file filepath.cpp.

References Common::UString::c_str().

Referenced by Aurora::ResourceManager::findArchive(), and getUserDataFile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isDirectory()

bool Common::FilePath::isDirectory ( const UString p)
static

Does specified path exist and is it a directory?

Parameters
pThe path to look up.
Returns
true if the path exists and is a directory, false otherwise.

Definition at line 56 of file filepath.cpp.

References Common::UString::c_str().

Referenced by Common::FileList::addDirectory(), Common::FileList::addSubDirectories(), main(), Engines::GameInstanceEngine::probe(), and Aurora::ResourceManager::registerDataBase().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isRegularFile()

bool Common::FilePath::isRegularFile ( const UString p)
static

Does specified path exist and is it a regular file?

Parameters
pThe path to look up.
Returns
true if the path exists and is a regular file, false otherwise.

Definition at line 52 of file filepath.cpp.

References Common::UString::c_str().

Referenced by Graphics::constructFilename(), Common::ConfigManager::fileExists(), Aurora::ResourceManager::indexResourceFile(), Common::ConfigManager::load(), main(), Engines::GameInstanceEngine::probe(), and Aurora::ResourceManager::registerDataBase().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ normalize()

UString Common::FilePath::normalize ( const UString p,
bool  resolveSymLinks = true 
)
static

Normalize a path.

A normalized path contains no consecutive '/', uses '/' as a directory path separator, starts with either "/", "[A-Za-z]:/" or "./" and does not end with a '/'.

In addition, "." and "..", symbolic links and ~ are resolved.

NOTE: If the resolving of symbolic links is disabled, ".." will not be resolved either, as ".." following a symbolic links should modify the destination of that symbolic link and not remove it.

The effect is very similar to boost::filesystem::canonical(), except:

  • boost::filesystem::canonical() does not resolve ~ to the user's home directory
  • boost::filesystem::canonical() absolutizes a path, normalize() does not
  • boost::filesystem::canonical() fails on paths that don't exist, normalize() does not
Parameters
pThe path to normalize.
resolveSymLinksShould symbolic links be resolved?
Returns
The normalized path.

Definition at line 154 of file filepath.cpp.

References Common::UString::c_str(), Common::convertToSlash(), and getHomeDirectory().

Referenced by Engines::KotOR::SaveLoadMenu::addSavedGameItems(), canonicalize(), Aurora::ResourceManager::findArchive(), Aurora::ResourceManager::indexResourceFile(), Engines::KotOR::SavedGame::load(), Common::WriteFile::open(), and relativize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ relativize()

UString Common::FilePath::relativize ( const UString basePath,
const UString path 
)
static

Return the path relative to the base path.

If the path does not start with the base path, an empty path will be returned;

Parameters
basePathThe path to make relative to.
pathThe path to make relative.
Returns
The relative path.

Definition at line 142 of file filepath.cpp.

References Common::UString::beginsWith(), Common::UString::end(), Common::UString::getPosition(), normalize(), Common::UString::size(), and Common::UString::substr().

Referenced by Engines::Jade::findAndroidVOLanguageDir(), Engines::DragonAge::Campaigns::findCampaigns(), Engines::DragonAge2::Campaigns::findCampaigns(), Engines::Witcher::Module::findModule(), Engines::NWN2::Game::getCampaigns(), Engines::NWN2::Campaign::getDirectory(), Engines::Witcher::Campaign::getDirectory(), Engines::Jade::getTLKDirectory(), and Common::FileList::relativize().

Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following files: