DataPaths Class Reference

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. More...
 
QStringList canWrite () const
 Checks if all directories can be written to. More...
 
QList< DirErrnocreateDirectories ()
 Creates necessary directories for application run. More...
 
QStringList defaultWadPaths () const
 Returns a list of the default file paths for WAD files. More...
 
QString demosDirectoryPath () const
 
QString documentsLocationPath (const QString &subpath=QString()) const
 Path to the "My Documents" directory with Doomseeker's own subpath suffix. More...
 
bool isPortableModeOn () const
 
QString localDataLocationPath (const QString &subpath=QString()) const
 Path to the directory where large data should be saved. More...
 
QString pluginDocumentsLocationPath (const EnginePlugin &plugin) const
 Place where EnginePlugin can store its "My Documents" content. More...
 
QString pluginLocalDataLocationPath (const EnginePlugin &plugin) const
 Place where EnginePlugin can store its local files. More...
 
QStringList pluginSearchLocationPaths () const
 Ordered locations were plugin libraries could be loaded from. More...
 
QString programsDataDirectoryPath () const
 Path to directory where this concrete application should store its data. More...
 
void setWorkingDirectory (const QString &workingDirectory)
 Changes the location returned by workingDirectory. More...
 
QString systemAppDataDirectory (QString append=QString()) const
 Gets path to the root directory for data storage. More...
 
bool validateAppDataDirectory ()
 Checks if the root directory for Doomseeker data storage is accessible. More...
 
const QString & workingDirectory () const
 Program working directory. More...
 

Static Public Member Functions

static DataPathsdefaultInstance ()
 Retrieves default instance that is used throughout the program. More...
 
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. More...
 

Static Public Attributes

static const QString CHATLOGS_DIR_NAME = "chatlogs"
 
static const QString TRANSLATIONS_DIR_NAME = "translations"
 
static const QString UPDATE_PACKAGE_FILENAME_PREFIX = "doomseeker-update-pkg-"
 
static const QString UPDATE_PACKAGES_DIR_NAME = "updates"
 

Protected Member Functions

DirErrno tryCreateDirectory (const QDir &rootDir, const QString &dirToCreate) const
 If directory already exists true is returned. More...
 

Static Protected Member Functions

static bool validateDir (const QString &path)
 

Detailed Description

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:

  • programsDataDirectoryPath() is the "Roaming" directory. It should be used to store relatively small amount of data - like config files.
  • cacheDataLocationPath() is used to store larger, non-critical data.
  • localDataLocationPath() is the "Local" directory. It can be used to store data that's large or only valid to the particular machine that is running Doomseeker (like demos).
  • documentsLocationPath() is the "My Documents" directory with "doomseeker" appended to it. Store here files that should also be normally accessible to the user through directory navigation. On Windows platform it has also a benefit of additional hard drive space as it is very easy to move "My Documents" dir to a different partition or drive.
Note
You might've noticed that Doomseeker itself doesn't always follow these rules of thumb. This unfortunate behavior is the result of insufficient knowledge at the time when this was first developed on how to properly design system like these and how to utilize Qt framework, which already has convenient functions that help to solve this problem. This behavior might change in future versions of Doomseeker.

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 82 of file datapaths.h.

Member Function Documentation

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 168 of file datapaths.cpp.

QStringList DataPaths::canWrite ( ) const

Checks if all directories can be written to.

Returns
List of directories for which the test FAILED.

Definition at line 173 of file datapaths.cpp.

QList< DataPaths::DirErrno > DataPaths::createDirectories ( )

Creates necessary directories for application run.

If directories exist nothing happens.

Returns
List of errnos strings generated while trying to create them. The errno notifying that the directory already exists is deliberately overwritten by 0, since that means the dir does exist, which is a desired state.

Definition at line 186 of file datapaths.cpp.

DataPaths * DataPaths::defaultInstance ( )
static

Retrieves default instance that is used throughout the program.

This instance must first be init with initDefault().

Definition at line 270 of file datapaths.cpp.

QStringList DataPaths::defaultWadPaths ( ) const

Returns a list of the default file paths for WAD files.

Returns
List of directories to use by default for finding WAD files.

Definition at line 276 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.

Parameters
subpathAdditional subpath in the "My Documents/Doomseeker" subpath.

Definition at line 296 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.

Parameters
subpathIf specified then this path is appended to the returned path.

Definition at line 334 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.

Parameters
pluginPlugin must pass reference to its implementation of EnginePlugin.

Definition at line 345 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.

Parameters
pluginPlugin must pass reference to its implementation of EnginePlugin.

Definition at line 339 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 351 of file datapaths.cpp.

QString DataPaths::programFilesDirectory ( MachineType  machineType)
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 372 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 413 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 418 of file datapaths.cpp.

QStringList DataPaths::staticDataSearchDirs ( const QString &  subdir = QString())
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.

Parameters
subdirIf this sub-path is specified then then it's appended to all returned paths.

Definition at line 423 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.

Deprecated:
Use more specific functions. Internal use only.
Parameters
append- this string will be appended to the returned path.
Returns
Empty string if directory doesn't pass validateDir() check. Otherwise the path returned is always absolute.

Definition at line 443 of file datapaths.cpp.

DataPaths::DirErrno DataPaths::tryCreateDirectory ( const QDir &  rootDir,
const QString &  dirToCreate 
) const
protected

If directory already exists true is returned.

Definition at line 483 of file datapaths.cpp.

bool DataPaths::validateAppDataDirectory ( )

Checks if the root directory for Doomseeker data storage is accessible.

Definition at line 534 of file datapaths.cpp.

bool DataPaths::validateDir ( const QString &  path)
staticprotected
Returns
True if path is a directory that exists and can be written to.

Definition at line 539 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 550 of file datapaths.cpp.


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