DataPaths Class Reference

Represents directories used by Doomseeker to store data. More...

#include <datapaths.h>

List of all members.

Public Types

enum  MachineType { x86, x64, Preferred }

Public Member Functions

 DataPaths (bool bPortableModeOn=false)
QStringList canWrite () const
 Checks if all directories can be written to.
bool createDirectories ()
 Creates necessary directories for application run.
QString demosDirectoryPath () const
QStringList directoriesExist () const
 Checks if all necessary directories exist.
const QString & directoryNameForProgram () const
QString localDataLocationPath (const QString &subpath=QString()) const
 Path to the directory where large data should be saved.
QString programsDataDirectoryPath () const
 Path to directory where this concrete application should store it's data.
QString programsDataSupportDirectoryPath () const
 Allows switching from Preferences to Application Support on OS X.
bool isPortableModeOn () const
void setPortableModeOn (bool b)
void setDirectoryNameForProgram (const QString &name)
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.

Static Public Member Functions

static QString programFilesDirectory (MachineType machineType)
static QStringList staticDataSearchDirs (const QString &subdir=QString())
 Paths to directories where program should search for its static data.

Static Public Attributes

static const QString PROGRAMS_APPDATA_DIR_NAME = ".doomseeker"
static const QString PROGRAMS_APPDATASUPPORT_DIR_NAME = ""
static const QString DEMOS_DIR_NAME = "demos"
static const QString TRANSLATIONS_DIR_NAME = "translations"
static const QString UPDATE_PACKAGES_DIR_NAME = "updates"
static const QString UPDATE_PACKAGE_FILENAME_PREFIX = "doomseeker-update-pkg-"

Protected Member Functions

bool 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)

Protected Attributes

bool bIsPortableModeOn
QString programsDirectoryName
 Defaults to PROGRAMS_APPDATA_DIR_NAME.
QString programsSupportDirectoryName
QString demosDirectoryName

Detailed Description

Represents directories used by Doomseeker to store data.

Since Doomseeker doesn't need to store much all data is stored in a single directory. For portable model this is the same directory as in which Doomseeker.exe resides. Otherwise .doomseeker/ directory can be created in a path depending on the operating system.


Member Function Documentation

QStringList DataPaths::canWrite (  )  const

Checks if all directories can be written to.

Returns:
List of directories for which the test FAILED.
bool DataPaths::createDirectories (  ) 

Creates necessary directories for application run.

If directories exist nothing happens.

Returns:
If it was impossible to create at least one of the required directories false will be returned. True is returned only on full success.
See also:
directoriesExist()
QStringList DataPaths::directoriesExist (  )  const

Checks if all necessary directories exist.

Returns:
List of directories that DO NOT exist.
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 "/.PROGRAMS_APPDATA_DIR_NAME" appended.

Parameters:
subpath If specified then this path is appended to the returned path.
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.

QString DataPaths::programsDataDirectoryPath (  )  const

Path to directory where this concrete application should store it's 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 contained in programsDirectoryName member.

QString DataPaths::programsDataSupportDirectoryPath (  )  const

Allows switching from Preferences to Application Support on OS X.

Same as programsDataDirectoryPath() on other systems or in portable mode.

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:
subdir If this sub-path is specified then then it's appended to all returned paths.
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.

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.
bool DataPaths::validateDir ( const QString &  path  )  [static, protected]
Returns:
True if path is a directory that exists and can be written to.

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