Represents directories used by Doomseeker to store data. More...
#include <datapaths.h>
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 |
QList< DirErrno > | createDirectories () |
QStringList | defaultWadPaths () const |
Returns a list of the default file paths for WAD files. | |
QString | demosDirectoryPath () const |
The 'managed' directory for demo recordings. | |
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 'managed' data should be saved. | |
QString | pluginDocumentsLocationPath (const EnginePlugin &plugin) const |
Place where an EnginePlugin can store its "My Documents" content. | |
QString | pluginLocalDataLocationPath (const EnginePlugin &plugin) const |
Place where an EnginePlugin can store its local 'managed' files. | |
QStringList | pluginSearchLocationPaths () const |
QString | portablizePath (const QString &path) const |
Try to create a relative path suitable for the portable mode. | |
QString | programsDataDirectoryPath () const |
Path to directory where Doomseeker should store its roaming data. | |
void | setBaseDir (const QDir &baseDir) |
void | setWorkingDirectory (const QString &workingDirectory) |
QString | systemAppDataDirectory (QString append=QString()) const |
bool | validateAppDataDirectory () |
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 the program should search for its static data. | |
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 and the 'cache' dir. Doomseeker makes this logical distinction, but, depending on the OS and user's preference, all these directories may be in the same location. These three directories are the 'managed data' directories. For the 'unmanaged' data, DataPaths provides a convenient way of obtaining a path to user's storage location (the 'Documents' directory).
If the portable mode is disabled (the default) and the user didn't change their base with setBaseDir(), these directories are created in accordance to the current Operating System standards. In the portable mode, all directories are created where Doomseeker's executable resides.
What are the exact names of these directories and where they're physically located should be inconsequential. The contract here is that it's ensured that these directories are in places that are normally writable for the current OS user, and that the program data can be stored there.
Furthermore, enabling the portable mode forces Doomseeker's working directory to the directory where Doomseeker's executable is located. This directory becomes the "portable root directory". All paths that are stored in the configuration should be stored as relative to that directory if possible. Use the portablizePath() method to do that.
The base path for the 'managed data' directories can be changed in bulk with setBaseDir(). This overrides the OS default paths for programsDataDirectoryPath(), cacheDataLocationPath() localDataLocationPath() and pluginLocalDataLocationPath(). The 'unmanaged' paths are unaffected.
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 88 of file datapaths.h.
QString DataPaths::cacheLocationPath | ( | ) | const |
Path to the cache directory with Doomseeker's own subpath suffix.
If the portable mode is on this will be the program directory with the cache dir's name appended to it. Since Doomseeker 1.4 this depends also on setBaseDir().
Definition at line 173 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 212 of file datapaths.cpp.
QStringList DataPaths::defaultWadPaths | ( | ) | const |
Returns a list of the default file paths for WAD files.
Definition at line 218 of file datapaths.cpp.
QString DataPaths::demosDirectoryPath | ( | ) | const |
The 'managed' directory for demo recordings.
Definition at line 246 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 the portable mode is on this will be the program's directory with storage
appended to it.
subpath | Additional subpath in the "My Documents/Doomseeker" subpath. |
Definition at line 251 of file datapaths.cpp.
QString DataPaths::localDataLocationPath | ( | const QString & | subpath = QString() | ) | const |
Path to the directory where large 'managed' data should be saved.
This path is supposed to hold data stored only on the local file system (ie. not roaming). If the portable mode is on, this returns the path to the program's directory with .static
appended. If the portable mode is off this returns path to QDesktopServices::DataLocation
with QCoreApplication::applicationName() appended.
Since Doomseeker 1.4 this depends also on setBaseDir().
subpath | If specified then this path is appended to the returned path. |
Definition at line 284 of file datapaths.cpp.
QString DataPaths::pluginDocumentsLocationPath | ( | const EnginePlugin & | plugin | ) | const |
Place where an 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 | The plugin must pass a reference to its implementation of EnginePlugin. |
Definition at line 295 of file datapaths.cpp.
QString DataPaths::pluginLocalDataLocationPath | ( | const EnginePlugin & | plugin | ) | const |
Place where an EnginePlugin can store its local 'managed' 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 the portable mode into consideration. Since Doomseeker 1.4 it also depends on setBaseDir().
It's not ensured that the directory will exist.
This method is to be used from the plugins.
plugin | The plugin must pass a reference to its implementation of EnginePlugin. |
Definition at line 289 of file datapaths.cpp.
QString DataPaths::portablizePath | ( | const QString & | path | ) | const |
Try to create a relative path suitable for the portable mode.
Definition at line 322 of file datapaths.cpp.
|
static |
Retrieves the correct path to the "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). On *nix systems there is no equivalent, so it will return an empty string.
Definition at line 335 of file datapaths.cpp.
QString DataPaths::programsDataDirectoryPath | ( | ) | const |
Path to directory where Doomseeker should store its roaming data.
Depending on the mode (portable or not) and the operating system this can point to a different directory. Since Doomseeker 1.4 it also depends on setBaseDir().
Definition at line 377 of file datapaths.cpp.
|
static |
Paths to directories where the 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 394 of file datapaths.cpp.
|
staticprotected |
Definition at line 422 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::applicationDirPath().
Definition at line 433 of file datapaths.cpp.