HoverRace  2.0
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
HoverRace::Util::Config Class Reference

Global configuration manager, shared by all aspects of the system. More...

#include <Config.h>

Classes

struct  app_t
 
struct  audio_t
 
struct  cameraHash_t
 
struct  controlsHash_t
 See Client/Control/Controller.h for the hash function. More...
 
struct  i18n_t
 
struct  misc_t
 
struct  net_t
 
struct  player_t
 
struct  runtime_t
 
struct  ui_t
 
struct  video_t
 

Public Member Functions

 ~Config ()
 
OS::path_t GenerateScreenshotPath (const std::string &ext) const
 Generates a new unique file for the screenshot. More...
 
OS::path_t GetBaseConfigPath () const
 Determine the OS-specific private configuration directory. More...
 
OS::path_t GetBaseDataPath () const
 Determine the OS-specific private data directory. More...
 
const int & GetBuild () const
 Retrieve the build number of the version. More...
 
OS::path_t GetConfigFilename () const
 
const std::string & GetDefaultFontName () const
 Retrieve the default UI font name. More...
 
OS::path_t GetDefaultMediaPath ()
 Retrieve the OS-specific default media path. More...
 
const std::string & GetDefaultMonospaceFontName () const
 Retrieve the default font name for monospace text (e.g. More...
 
const std::string & GetDefaultSymbolFontName () const
 Retrieve the default font name for symbols. More...
 
const std::string & GetFullVersion () const
 Retrieve the long form (x.x.x.x) of the version number. More...
 
LocaleGetLocale ()
 
const OS::path_tGetMediaPath () const
 Retrieve the directory for media files. More...
 
OS::path_t GetMediaPath (const std::string &file) const
 Retrieve the path to a media file. More...
 
const OS::path_tGetProfilePath () const
 Retrieve the path to where local user profiles are stored. More...
 
OS::path_t GetProfilePath (const std::string &uid) const
 Retrieve the path to a specific user profile. More...
 
Parcel::ResBundleGetResBundle () const
 
OS::path_t GetScriptHelpPath (const std::string &className) const
 Retrieve the path to the help file for a class in the scripting API. More...
 
Parcel::TrackBundleGetTrackBundle () const
 
const std::string & GetUserAgentId () const
 Retrieve the user agent identifier used for HTTP requests. More...
 
const OS::path_tGetUserTrackPath () const
 Retrieve the path to where downloaded and user-installed tracks are stored. More...
 
OS::path_t GetUserTrackPath (const std::string &name) const
 Retrieve the path to a downloaded track. More...
 
const std::string & GetVersion () const
 Retrieve the short form (x.x or x.x.x) of the version number. More...
 
bool IsPrerelease () const
 Check if this build is a prerelease (development) version. More...
 
bool IsUnlinked () const
 Check if saving the config to disk is disabled. More...
 
void Load ()
 Load the configuration. More...
 
void ResetToDefaults ()
 Resets the configuration to the default "factory" settings. More...
 
void Save () const
 Save the configuration. More...
 
void SetUnlinked (bool unlinked)
 Enable or disable saving the configuration to disk. More...
 
std::shared_ptr< Parcel::ResBundleShareResBundle () const
 
std::shared_ptr< Parcel::TrackBundleShareTrackBundle () const
 Retrieve the track bundle. More...
 

Static Public Member Functions

static OS::path_t GetDefaultChatLogPath ()
 Retrieve the default path for the chat log. More...
 
static std::string GetDefaultRoomListUrl ()
 Retrieve the default URL for the IMR room list. More...
 
static OS::path_t GetDefaultScreenshotPath ()
 Retrieve the default path for screenshots. More...
 
static std::string GetDefaultUpdateServerUrl ()
 Retrieve the default URL for the update server list. More...
 
static ConfigGetInstance ()
 
static ConfigInit (const std::string &packageName, int verMajor, int verMinor, int verPatch, int verBuild, bool prerelease, const OS::path_t &mediaPath, const OS::path_t &sysCfgPath, const OS::path_t &path={})
 Initialize the singleton instance. More...
 

Public Attributes

struct HoverRace::Util::Config::app_t app
 
struct HoverRace::Util::Config::audio_t audio
 
struct HoverRace::Util::Config::cameraHash_t cameraHash
 
struct HoverRace::Util::Config::controlsHash_t controlsHash [MAX_PLAYERS]
 
struct HoverRace::Util::Config::i18n_t i18n
 
struct HoverRace::Util::Config::misc_t misc
 
struct HoverRace::Util::Config::net_t net
 
struct HoverRace::Util::Config::player_t player
 
struct HoverRace::Util::Config::runtime_t runtime
 
struct HoverRace::Util::Config::ui_t ui
 
struct HoverRace::Util::Config::video_t video
 

Static Public Attributes

static const int MAX_PLAYERS = 4
 
static const std::string TRACK_EXT
 

Private Member Functions

 Config (const std::string &packageName, int verMajor, int verMinor, int verPatch, int verBuild, bool prerelease, const OS::path_t &mediaPath, const OS::path_t &sysCfgPath, const OS::path_t &path={})
 Create a new instance using the specified directory. More...
 
void AppendPackageSubdir (OS::path_t &path) const
 Append our package namespace to the base configuration directory. More...
 
void LoadSystem ()
 
void LoadSystem (const OS::path_t &path)
 
void SaveVersion (yaml::Emitter &) const
 

Static Private Member Functions

static OS::path_t GetDefaultBasePath ()
 Determine the OS-specific default configuration directory. More...
 

Private Attributes

OS::path_t cfgPath
 Base path for config files. More...
 
OS::path_t dataPath
 Base path for data files. More...
 
std::string defaultFontName
 
std::string defaultMonospaceFontName
 
std::string defaultSymbolFontName
 
std::string fullVersion
 
std::unique_ptr< Localelocale
 
OS::path_t mediaPath
 
std::string packageName
 
bool prerelease
 
OS::path_t profilePath
 
std::shared_ptr< Parcel::ResBundleresBundle
 
std::string shortVersion
 
OS::path_t sysCfgPath
 
std::shared_ptr< Parcel::TrackBundletrackBundle
 
bool unlinked
 if true, will prevent saving config. More...
 
std::string userAgentId
 
OS::path_t userTrackPath
 
int verBuild
 
xdgHandle * xdg
 

Static Private Attributes

static std::unique_ptr< Configinstance {}
 

Detailed Description

Global configuration manager, shared by all aspects of the system.

Constructor & Destructor Documentation

HoverRace::Util::Config::Config ( const std::string &  packageName,
int  verMajor,
int  verMinor,
int  verPatch,
int  verBuild,
bool  prerelease,
const OS::path_t mediaPath,
const OS::path_t sysCfgPath,
const OS::path_t path = { } 
)
private

Create a new instance using the specified directory.

Parameters
packageNameThe name of the application for shared data files.
verMajorThe major (first) component of the version number.
verMinorThe minor (second) component of the version number.
verPatchThe patch (third) component of the version number.
verBuildThe build (fourth) component of the version number.
prereleaseWhether this build is a development version.
mediaPath(Optional) The directory for finding media files. The default is to use GetDefaultMediaPath().
sysCfgPath(Optional) The directory to use for the system config file. The default is to search a platform-specific list of directories.
path(Optional) The directory for storing configuration data. The default is to use GetBaseDataPath() and GetBaseConfigPath().
HoverRace::Util::Config::~Config ( )

Member Function Documentation

void HoverRace::Util::Config::AppendPackageSubdir ( OS::path_t path) const
private

Append our package namespace to the base configuration directory.

Parameters
pathThe path to append the namespace onto.
OS::path_t HoverRace::Util::Config::GenerateScreenshotPath ( const std::string &  ext) const

Generates a new unique file for the screenshot.

Parameters
extThe extension to use on the generated filename.
Returns
The generated path. The file will exist and will be empty, ready for writing.
Exceptions
ExceptionThe path could not be generated.
OS::path_t HoverRace::Util::Config::GetBaseConfigPath ( ) const

Determine the OS-specific private configuration directory.

Returns
The path to where we can store user configuration files.
OS::path_t HoverRace::Util::Config::GetBaseDataPath ( ) const

Determine the OS-specific private data directory.

Returns
The path to where we can store user data files.
const int & HoverRace::Util::Config::GetBuild ( ) const

Retrieve the build number of the version.

Returns
The build number (that was passed to the constructor).
OS::path_t HoverRace::Util::Config::GetConfigFilename ( ) const
OS::path_t HoverRace::Util::Config::GetDefaultBasePath ( )
staticprivate

Determine the OS-specific default configuration directory.

Note: This is the top-level directory for per-user data, without our package namespace.

Returns
The fully-qualified path.
Exceptions
ConfigExnif unable to retrieve the default directory.
OS::path_t HoverRace::Util::Config::GetDefaultChatLogPath ( )
static

Retrieve the default path for the chat log.

Returns
The fully-qualified path (may be empty if base path could not be retrieved from the system).
const std::string & HoverRace::Util::Config::GetDefaultFontName ( ) const

Retrieve the default UI font name.

Returns
The font name (never empty).
OS::path_t HoverRace::Util::Config::GetDefaultMediaPath ( )

Retrieve the OS-specific default media path.

First, we look for a config file in the current directory, then in the system-global directory (if applicable), then finally the relative directory.

Returns
The directory path (may be relative).
const std::string & HoverRace::Util::Config::GetDefaultMonospaceFontName ( ) const

Retrieve the default font name for monospace text (e.g.

the console).

Returns
The font name (never emepty).
std::string HoverRace::Util::Config::GetDefaultRoomListUrl ( )
static

Retrieve the default URL for the IMR room list.

Returns
The URL (without the initial "http://").
OS::path_t HoverRace::Util::Config::GetDefaultScreenshotPath ( )
static

Retrieve the default path for screenshots.

Returns
The fully-qualified path (may be empty if base path could not be retrieved from the system).
const std::string & HoverRace::Util::Config::GetDefaultSymbolFontName ( ) const

Retrieve the default font name for symbols.

Returns
The font name (never emepty).
std::string HoverRace::Util::Config::GetDefaultUpdateServerUrl ( )
static

Retrieve the default URL for the update server list.

Returns
The URL (without the initial "http://").
const std::string & HoverRace::Util::Config::GetFullVersion ( ) const

Retrieve the long form (x.x.x.x) of the version number.

Returns
The version number (the same that was passed to the constructor).
static Config* HoverRace::Util::Config::GetInstance ( )
inlinestatic
Locale& HoverRace::Util::Config::GetLocale ( )
inline
const OS::path_t & HoverRace::Util::Config::GetMediaPath ( ) const

Retrieve the directory for media files.

Returns
The directory path (may be relative).
OS::path_t HoverRace::Util::Config::GetMediaPath ( const std::string &  file) const

Retrieve the path to a media file.

Parameters
fileThe media filename (may not be blank).
Returns
The file path (may be relative).
const OS::path_t & HoverRace::Util::Config::GetProfilePath ( ) const

Retrieve the path to where local user profiles are stored.

Returns
The path (never empty, may be relative).
OS::path_t HoverRace::Util::Config::GetProfilePath ( const std::string &  uid) const

Retrieve the path to a specific user profile.

Note
The path is returned even if it does not exist. It is up to the caller to create the directory if necessary.
Parameters
uidThe UID of the profile, as a string.
Returns
The path (never empty, may be relative).
Exceptions
Player::ProfileExnThe UID was in an invalid format.
Parcel::ResBundle& HoverRace::Util::Config::GetResBundle ( ) const
inline
OS::path_t HoverRace::Util::Config::GetScriptHelpPath ( const std::string &  className) const

Retrieve the path to the help file for a class in the scripting API.

Parameters
classNameThe name of the class.
Returns
The directory path (may be relative).
Parcel::TrackBundle& HoverRace::Util::Config::GetTrackBundle ( ) const
inline
const std::string & HoverRace::Util::Config::GetUserAgentId ( ) const

Retrieve the user agent identifier used for HTTP requests.

Returns
The user agent string.
const OS::path_t & HoverRace::Util::Config::GetUserTrackPath ( ) const

Retrieve the path to where downloaded and user-installed tracks are stored.

Returns
The path (never empty, may be relative).
OS::path_t HoverRace::Util::Config::GetUserTrackPath ( const std::string &  name) const

Retrieve the path to a downloaded track.

Parameters
nameThe track filename (may not be blank). If the filename does not end in ".trk", it will be appended automatically.
Returns
The directory path (may be relative).
const std::string & HoverRace::Util::Config::GetVersion ( ) const

Retrieve the short form (x.x or x.x.x) of the version number.

Returns
The version number (always at least two components).
Config & HoverRace::Util::Config::Init ( const std::string &  packageName,
int  verMajor,
int  verMinor,
int  verPatch,
int  verBuild,
bool  prerelease,
const OS::path_t mediaPath,
const OS::path_t sysCfgPath,
const OS::path_t path = { } 
)
static

Initialize the singleton instance.

Parameters
packageNameThe name of the application for shared data files.
verMajorThe major (first) component of the version number.
verMinorThe minor (second) component of the version number.
verPatchThe patch (third) component of the version number.
verBuildThe build (fourth) component of the version number.
prereleaseWhether this build is a development version.
mediaPath(Optional) The directory for finding media files. The default is to use GetDefaultMediaPath().
sysCfgPath(Optional) The directory to use for the system config file. The default is to search a platform-specific list of directories.
path(Optional) The directory for storing configuration data. The default is to use GetBaseDataPath() and GetBaseConfigPath().
Returns
The config instance.
bool HoverRace::Util::Config::IsPrerelease ( ) const

Check if this build is a prerelease (development) version.

Returns
true if prerelease.
bool HoverRace::Util::Config::IsUnlinked ( ) const

Check if saving the config to disk is disabled.

Returns
true if saving is disabled.
See also
SetUnlinked(bool)
void HoverRace::Util::Config::Load ( )

Load the configuration.

Does nothing if the configuration file doesn't exist.

Exceptions
ConfigExnIf an error occurs while reading.
void HoverRace::Util::Config::LoadSystem ( )
private
void HoverRace::Util::Config::LoadSystem ( const OS::path_t path)
private
void HoverRace::Util::Config::ResetToDefaults ( )

Resets the configuration to the default "factory" settings.

void HoverRace::Util::Config::Save ( ) const

Save the configuration.

Exceptions
std::exceptionIf an error occurs while saving.
void HoverRace::Util::Config::SaveVersion ( yaml::Emitter emitter) const
private
void HoverRace::Util::Config::SetUnlinked ( bool  unlinked)

Enable or disable saving the configuration to disk.

This is useful for testing, since it allows temporary changes without overwriting the config previously saved to disk.

Parameters
unlinkedtrue to prevent saving config to disk.
std::shared_ptr<Parcel::ResBundle> HoverRace::Util::Config::ShareResBundle ( ) const
inline
std::shared_ptr<Parcel::TrackBundle> HoverRace::Util::Config::ShareTrackBundle ( ) const
inline

Retrieve the track bundle.

Returns
The track bundle (never nullptr).

Member Data Documentation

struct HoverRace::Util::Config::app_t HoverRace::Util::Config::app
struct HoverRace::Util::Config::audio_t HoverRace::Util::Config::audio
struct HoverRace::Util::Config::cameraHash_t HoverRace::Util::Config::cameraHash
OS::path_t HoverRace::Util::Config::cfgPath
private

Base path for config files.

struct HoverRace::Util::Config::controlsHash_t HoverRace::Util::Config::controlsHash[MAX_PLAYERS]
OS::path_t HoverRace::Util::Config::dataPath
private

Base path for data files.

std::string HoverRace::Util::Config::defaultFontName
private
std::string HoverRace::Util::Config::defaultMonospaceFontName
private
std::string HoverRace::Util::Config::defaultSymbolFontName
private
std::string HoverRace::Util::Config::fullVersion
private
struct HoverRace::Util::Config::i18n_t HoverRace::Util::Config::i18n
std::unique_ptr< Config > HoverRace::Util::Config::instance {}
staticprivate
std::unique_ptr<Locale> HoverRace::Util::Config::locale
private
const int HoverRace::Util::Config::MAX_PLAYERS = 4
static
OS::path_t HoverRace::Util::Config::mediaPath
private
struct HoverRace::Util::Config::misc_t HoverRace::Util::Config::misc
struct HoverRace::Util::Config::net_t HoverRace::Util::Config::net
std::string HoverRace::Util::Config::packageName
private
struct HoverRace::Util::Config::player_t HoverRace::Util::Config::player
bool HoverRace::Util::Config::prerelease
private
OS::path_t HoverRace::Util::Config::profilePath
private
std::shared_ptr<Parcel::ResBundle> HoverRace::Util::Config::resBundle
private
struct HoverRace::Util::Config::runtime_t HoverRace::Util::Config::runtime
std::string HoverRace::Util::Config::shortVersion
private
OS::path_t HoverRace::Util::Config::sysCfgPath
private
const std::string HoverRace::Util::Config::TRACK_EXT
static
std::shared_ptr<Parcel::TrackBundle> HoverRace::Util::Config::trackBundle
private
struct HoverRace::Util::Config::ui_t HoverRace::Util::Config::ui
bool HoverRace::Util::Config::unlinked
private

if true, will prevent saving config.

std::string HoverRace::Util::Config::userAgentId
private
OS::path_t HoverRace::Util::Config::userTrackPath
private
int HoverRace::Util::Config::verBuild
private
struct HoverRace::Util::Config::video_t HoverRace::Util::Config::video
xdgHandle* HoverRace::Util::Config::xdg
private

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