xoreos
0.0.5
|
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... | |
Utility class for manipulating file paths.
Definition at line 38 of file filepath.h.
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.
p | The path to absolutize. |
Definition at line 125 of file filepath.cpp.
References Common::UString::c_str(), Common::convertToSlash(), and getHomeDirectory().
Referenced by canonicalize().
Return the canonical, absolutized and normalized path.
Calls absolutize() and normalize() on the path.
The effect is very similar to boost::filesystem::canonical(), except:
p | The path to canonicalize. |
resolveSymLinks | Should symbolic links be resolved? |
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().
Change a file name's extension.
Example: "/path/to/file.ext", ".bar" -> "/path/to/file.bar"
p | The path to manipulate. |
ext | The path's new extension. |
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().
|
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.
path | The path to create. |
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().
Escape a string literal for use in a regexp.
Definition at line 350 of file filepath.cpp.
References Common::UString::c_str().
|
static |
Find a directory's subdirectory.
directory | The directory in which to look. |
subDirectory | The subdirectory to find. |
caseInsensitive | Should the case of the subdirectory be ignored? |
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().
|
static |
Return the OS-specific path of the config directory.
This is where the xoreos.conf is put by default.
Definition at line 375 of file filepath.cpp.
References Common::Platform::getConfigDirectory().
Referenced by Common::ConfigManager::getDefaultConfigFile().
Return a path's directory.
Example: "/path/to/file.ext" -> "/path/to/"
p | The path to manipulate. |
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().
Return a file name's extension.
Example: "/path/to/file.ext" -> ".ext"
p | The path to manipulate. |
Definition at line 93 of file filepath.cpp.
References Common::UString::c_str().
Referenced by Aurora::ResourceManager::findArchive(), Engines::Witcher::Game::getCampaigns(), Engines::NWN2::Game::getCharacters(), Engines::NWN::Game::getCharacters(), Engines::NWN::Module::getDescriptionCampaign(), Engines::NWN::Module::getDescriptionExtra(), Aurora::FileTypeManager::getFileType(), Engines::NWN::Game::getModules(), Engines::NWN2::Game::getModules(), Engines::Witcher::Game::getModules(), Engines::DragonAge::Game::loadResourceDir(), Engines::DragonAge2::Game::loadResourceDir(), Aurora::ResourceManager::openKEYBIFs(), Engines::KotOR2::Console::updateMusic(), and Engines::KotOR::Console::updateMusic().
Return a file name without its path.
Example: "/path/to/file.ext" > "file.ext"
p | The path to manipulate. |
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().
|
static |
Return a file's size.
p | The file to look up. |
Definition at line 60 of file filepath.cpp.
References Common::UString::c_str(), Common::kFileInvalid, and warning().
Referenced by Aurora::ResourceManager::getResourceSize().
|
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().
|
static |
Format this file size into a human readable string.
Definition at line 357 of file filepath.cpp.
References ARRAYSIZE, and Common::UString::format().
Return a file name's stem.
Example: "/path/to/file.ext" -> "file"
p | The path to manipulate. |
Definition at line 87 of file filepath.cpp.
References Common::UString::c_str().
Referenced by Aurora::ResourceManager::addResource(), Common::ConfigManager::createGameID(), Engines::Witcher::Game::getCampaigns(), Engines::NWN2::Game::getCharacters(), Engines::NWN::Game::getCharacters(), Engines::KotOR2::Game::getModules(), Engines::KotOR::Game::getModules(), Engines::NWN::Game::getModules(), Engines::NWN2::Game::getModules(), Engines::Witcher::Game::getModules(), Engines::NWN::Game::getPremiumModules(), Aurora::ResourceManager::indexArchive(), Aurora::ZIPFile::load(), Sound::XACTWaveBank_ASCII::load(), Engines::DragonAge::Campaign::read(), Engines::DragonAge2::Campaign::read(), Engines::DragonAge2::Campaigns::readCampaign(), Engines::DragonAge::Campaigns::readCampaign(), Aurora::GFXFile::readImportAssets(), Aurora::HERFFile::readResList(), Engines::KotOR::Console::updateMusic(), Engines::KotOR2::Console::updateMusic(), and Engines::Witcher::Console::updateMusic().
|
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".
directory | The directory in which to look. |
subDirectories | The list to add the directories to. |
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().
|
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.
Definition at line 379 of file filepath.cpp.
References Common::Platform::getUserDataDirectory().
Referenced by Common::DebugManager::getDefaultLogFile(), getUserDataFile(), and Engines::ConsoleWindow::openLogFile().
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().
|
static |
Is the given string an absolute path?
p | The path to check. |
Definition at line 113 of file filepath.cpp.
References Common::UString::c_str().
Referenced by Aurora::ResourceManager::findArchive(), and getUserDataFile().
|
static |
Does specified path exist and is it a directory?
p | The path to look up. |
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().
|
static |
Does specified path exist and is it a regular file?
p | The path to look up. |
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().
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:
p | The path to normalize. |
resolveSymLinks | Should symbolic links be resolved? |
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().
Return the path relative to the base path.
If the path does not start with the base path, an empty path will be returned;
basePath | The path to make relative to. |
path | The path to make relative. |
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().