Represents directories used by Doomseeker to store data. More...
#include <datapaths.h>
Classes | |
struct | DirErrno |
Struct which contains the relevant QDir, the errno reported, and the QString generated by the errno. More... | |
Public Types | |
enum | MachineType { x86, x64, Preferred } |
Public Member Functions | |
DataPaths (bool bPortableModeOn=false) | |
QString | cacheLocationPath () const |
Path to the cache directory with Doomseeker's own subpath suffix. | |
QStringList | canWrite () const |
Checks if all directories can be written to. | |
QList< DirErrno > | createDirectories () |
Creates necessary directories for application run. | |
QStringList | defaultWadPaths () const |
Returns a list of the default file paths for WAD files. | |
QString | demosDirectoryPath () const |
QString | documentsLocationPath (const QString &subpath=QString()) const |
Path to the "My Documents" directory with Doomseeker's own subpath suffix. | |
bool | isPortableModeOn () const |
QString | localDataLocationPath (const QString &subpath=QString()) const |
Path to the directory where large data should be saved. | |
QString | pluginDocumentsLocationPath (const EnginePlugin &plugin) const |
Place where EnginePlugin can store its "My Documents" content. | |
QString | pluginLocalDataLocationPath (const EnginePlugin &plugin) const |
Place where EnginePlugin can store its local files. | |
QStringList | pluginSearchLocationPaths () const |
Ordered locations were plugin libraries could be loaded from. | |
QString | programsDataDirectoryPath () const |
Path to directory where this concrete application should store its data. | |
void | setWorkingDirectory (const QString &workingDirectory) |
Changes the location returned by workingDirectory. | |
QString | systemAppDataDirectory (QString append=QString()) const |
Gets path to the root directory for data storage. | |
bool | validateAppDataDirectory () |
Checks if the root directory for Doomseeker data storage is accessible. | |
const QString & | workingDirectory () const |
Program working directory. | |
Static Public Member Functions | |
static DataPaths * | defaultInstance () |
Retrieves default instance that is used throughout the program. | |
static void | initDefault (bool bPortableModeOn) |
static QString | programFilesDirectory (MachineType machineType) |
static QStringList | staticDataSearchDirs (const QString &subdir=QString()) |
Paths to directories where program should search for its static data. | |
Protected Member Functions | |
DirErrno | tryCreateDirectory (const QDir &rootDir, const QString &dirToCreate) const |
If directory already exists true is returned. | |
Static Protected Member Functions | |
static bool | validateDir (const QString &path) |
Represents directories used by Doomseeker to store data.
Doomseeker data is stored in three general directories: the 'configuration storage' dir, the 'local data storage' dir (using Windows nomenclature: Roaming & Local, respectively), and the 'My Documents' dir. If portable mode is disabled (the default), these directories are created in according to the current Operating System standards or according to historical behavior of older Doomseeker versions. Also if portable mode is disabled then, depending on the platform and its configuration, some of those directories might be on a Network File System. For portable model both directories are created where Doomseeker's executable resides.
What are the exact names of those directories and where they're physically located should be inconsequential. The contract here is that it's ensured that those directories are writable, however the paths may change between Doomseeker versions. To preserve specific directory, it's preferable to store its path in a configuration setting and allow user to modify it. The rule of thumb for picking directory type is this:
Plugins, to store their "Local" data, can use pluginLocalDataLocationPath() method to obtain the path where this data can be stored. To store "Documents" data, use pluginDocumentsLocationPath().
Definition at line 83 of file datapaths.h.
QString DataPaths::cacheLocationPath | ( | ) | const |
Path to the cache directory with Doomseeker's own subpath suffix.
If portable mode is on this will be the program directory with cache dir name appended to it.
Definition at line 154 of file datapaths.cpp.
QStringList DataPaths::canWrite | ( | ) | const |
Checks if all directories can be written to.
Definition at line 159 of file datapaths.cpp.
QList< DataPaths::DirErrno > DataPaths::createDirectories | ( | ) |
Creates necessary directories for application run.
If directories exist nothing happens.
Definition at line 170 of file datapaths.cpp.
|
static |
Retrieves default instance that is used throughout the program.
This instance must first be init with initDefault().
Definition at line 251 of file datapaths.cpp.
QStringList DataPaths::defaultWadPaths | ( | ) | const |
Returns a list of the default file paths for WAD files.
Definition at line 257 of file datapaths.cpp.
QString DataPaths::documentsLocationPath | ( | const QString & | subpath = QString() | ) | const |
Path to the "My Documents" directory with Doomseeker's own subpath suffix.
If portable mode is on this will be the program directory with "storage" appended to it.
subpath | Additional subpath in the "My Documents/Doomseeker" subpath. |
Definition at line 277 of file datapaths.cpp.
QString DataPaths::localDataLocationPath | ( | const QString & | subpath = QString() | ) | const |
Path to the directory where large data should be saved.
This path is supposed to hold data which should be stored only the local file system. If portable mode is on this returns path to program directory with "/.static" appended. If portable mode is off this returns path to QDesktopServices::DataLocation with "/QCoreApplication::applicationName()" appended.
subpath | If specified then this path is appended to the returned path. |
Definition at line 307 of file datapaths.cpp.
QString DataPaths::pluginDocumentsLocationPath | ( | const EnginePlugin & | plugin | ) | const |
Place where EnginePlugin can store its "My Documents" content.
This path is a directory path created by documentsDataLocationPath() with suffix unique for each plugin. The suffix is derived in the same way as in pluginLocalDataLocationPath().
This method is to be used by plugins.
plugin | Plugin must pass reference to its implementation of EnginePlugin. |
Definition at line 318 of file datapaths.cpp.
QString DataPaths::pluginLocalDataLocationPath | ( | const EnginePlugin & | plugin | ) | const |
Place where EnginePlugin can store its local files.
This path is a directory path created by localDataLocationPath() with suffix unique for each plugin. The suffix is partially derived from EnginePlugin::nameCanonical() and ensured to remain constant as long as EnginePlugin::nameCanonical() doesn't change for given plugin. It also takes portable mode into consideration. However, it's not ensured that the directory will exist.
This method is to be used from plugins.
plugin | Plugin must pass reference to its implementation of EnginePlugin. |
Definition at line 312 of file datapaths.cpp.
QStringList DataPaths::pluginSearchLocationPaths | ( | ) | const |
Ordered locations were plugin libraries could be loaded from.
Provides an ordered list of locations where PluginLoader will attempt to load EnginePlugins from.
Definition at line 324 of file datapaths.cpp.
|
static |
Retrieves correct path to "Program Files" directory. Windows only.
This exploits environmental variables such as PROGRAMFILES%, PROGRAMFILES(X86)% and ProgramW6432. This method is used to determine the correct path to the "Program Files" directory on Windows (XP and above). Since on *nix systems there is no equivalent it will return an empty string.
Definition at line 345 of file datapaths.cpp.
QString DataPaths::programsDataDirectoryPath | ( | ) | const |
Path to directory where this concrete application should store its data.
Depending on model (portable or not) and operating system this might point to a number of different directories. However the root dir is determined by calling the systemAppDataDirectory() method and appending string returned by programDirName() getter.
Definition at line 387 of file datapaths.cpp.
void DataPaths::setWorkingDirectory | ( | const QString & | workingDirectory | ) |
Changes the location returned by workingDirectory.
No longer used internally. Previously this was used to logically set the "working directory" to the location of the application binary. This makes the name of the functions something of a misnomer.
Definition at line 392 of file datapaths.cpp.
|
static |
Paths to directories where program should search for its static data.
By static data we understand read only files which come preinstalled with the program. These files should reside in known locations.
subdir | If this sub-path is specified then then it's appended to all returned paths. |
Definition at line 397 of file datapaths.cpp.
QString DataPaths::systemAppDataDirectory | ( | QString | append = QString() | ) | const |
Gets path to the root directory for data storage.
If portable mode is ON this points to the application's directory. Otherwise:
For Windows this is determined based on APPDATA% environment variable. If this cannot be found then QDir::home() is used.
On other systems QDir::home() is used directly.
append | - this string will be appended to the returned path. |
Definition at line 415 of file datapaths.cpp.
|
protected |
If directory already exists true is returned.
Definition at line 451 of file datapaths.cpp.
bool DataPaths::validateAppDataDirectory | ( | ) |
Checks if the root directory for Doomseeker data storage is accessible.
Definition at line 500 of file datapaths.cpp.
|
staticprotected |
Definition at line 505 of file datapaths.cpp.
const QString & DataPaths::workingDirectory | ( | ) | const |
Program working directory.
Despite the name of the function, for historical reasons, this actually returns the binary's location as determined by QCoreApplication::applicationDataPath.
Definition at line 516 of file datapaths.cpp.