OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Functions
OpenXcom::CrossPlatform Namespace Reference

Generic purpose functions that need different implementations for different platforms. More...

Functions

void showError (const std::string &error)
 Displays a message box with an error message. More...
 
std::vector< std::string > findDataFolders ()
 Builds a list of predefined paths for the Data folder according to the running system. More...
 
std::vector< std::string > findUserFolders ()
 Builds a list of predefined paths for the User folder according to the running system. More...
 
std::string findConfigFolder ()
 Finds the Config folder according to the running system. More...
 
std::string caseInsensitive (const std::string &base, const std::string &path)
 Takes a path and tries to find it based on the system's case-sensitivity. More...
 
std::string caseInsensitiveFolder (const std::string &base, const std::string &path)
 Takes a path and tries to find it based on the system's case-sensitivity. More...
 
std::string getDataFile (const std::string &filename)
 Takes a filename and tries to find it in the game's Data folders, accounting for the system's case-sensitivity and path style. More...
 
std::string getDataFolder (const std::string &foldername)
 Takes a foldername and tries to find it in the game's Data folders, accounting for the system's case-sensitivity and path style. More...
 
bool createFolder (const std::string &path)
 Creates a folder at the specified path. More...
 
std::string endPath (const std::string &path)
 Adds an ending slash to a path if necessary. More...
 
std::vector< std::string > getFolderContents (const std::string &path, const std::string &ext)
 Gets the name of all the files contained in a certain folder. More...
 
std::vector< std::string > getDataContents (const std::string &folder, const std::string &ext)
 Gets the name of all the files contained in a Data subfolder. More...
 
bool folderExists (const std::string &path)
 Checks if a certain path exists and is a folder. More...
 
bool fileExists (const std::string &path)
 Checks if a certain path exists and is a file. More...
 
bool deleteFile (const std::string &path)
 Removes a file from the specified path. More...
 
std::string baseFilename (const std::string &path, int(*transform)(int))
 Gets the base filename of a path. More...
 
std::string sanitizeFilename (const std::string &filename)
 Replaces invalid filesystem characters with _. More...
 
std::string noExt (const std::string &filename)
 Removes the extension from a filename. More...
 
std::string getLocale ()
 Gets the current locale of the system in language-COUNTRY format. More...
 
bool isQuitShortcut (const SDL_Event &ev)
 Checks if the system's default quit shortcut was pressed. More...
 
time_t getDateModified (const std::string &path)
 Gets the last modified date of a file. More...
 
std::pair< std::wstring,
std::wstring > 
timeToString (time_t time)
 Converts a date/time into a human-readable string using the ISO 8601 standard. More...
 
bool naturalCompare (const std::wstring &a, const std::wstring &b)
 Compares two Unicode strings using natural human ordering. More...
 
bool moveFile (const std::string &src, const std::string &dest)
 Moves a file from one path to another, replacing any existing file. More...
 
void flashWindow ()
 Notifies the user that maybe he should have a look. More...
 
std::string getDosPath ()
 Gets the executable path in DOS-style (short) form. More...
 
void setWindowIcon (int winResource, const std::string &unixPath)
 Sets the window icon.
 

Detailed Description

Generic purpose functions that need different implementations for different platforms.

Function Documentation

std::string OpenXcom::CrossPlatform::baseFilename ( const std::string &  path,
int(*)(int)  transform 
)

Gets the base filename of a path.

Gets the basename of a file.

Parameters
pathFull path to file.
transformOptional function to transform the filename.
Returns
Base filename.
std::string OpenXcom::CrossPlatform::caseInsensitive ( const std::string &  base,
const std::string &  path 
)

Takes a path and tries to find it based on the system's case-sensitivity.

Parameters
baseBase unaltered path.
pathFull path to check for casing.
Returns
Correct filename or "" if it doesn't exist.
Note
There's no actual method for figuring out the correct filename on case-sensitive systems, this is just a workaround.
std::string OpenXcom::CrossPlatform::caseInsensitiveFolder ( const std::string &  base,
const std::string &  path 
)

Takes a path and tries to find it based on the system's case-sensitivity.

Parameters
baseBase unaltered path.
pathFull path to check for casing.
Returns
Correct foldername or "" if it doesn't exist.
Note
There's no actual method for figuring out the correct foldername on case-sensitive systems, this is just a workaround.
bool OpenXcom::CrossPlatform::createFolder ( const std::string &  path)

Creates a folder at the specified path.

Creates a folder.

Note
Only creates the last folder on the path.
Parameters
pathFull path.
Returns
Folder created or not.
bool OpenXcom::CrossPlatform::deleteFile ( const std::string &  path)

Removes a file from the specified path.

Deletes the specified file.

Parameters
pathFull path to file.
Returns
True if the operation succeeded, False otherwise.
std::string OpenXcom::CrossPlatform::endPath ( const std::string &  path)

Adds an ending slash to a path if necessary.

Terminates a path.

Parameters
pathFolder path.
Returns
Terminated path.
bool OpenXcom::CrossPlatform::fileExists ( const std::string &  path)

Checks if a certain path exists and is a file.

Checks if the path is an existing file.

Parameters
pathFull path to file.
Returns
Does it exist?
std::string OpenXcom::CrossPlatform::findConfigFolder ( )

Finds the Config folder according to the running system.

Finds the game's config folder in the system.

Returns
Config path.
std::vector< std::string > OpenXcom::CrossPlatform::findDataFolders ( )

Builds a list of predefined paths for the Data folder according to the running system.

Finds the game's data folders in the system.

Returns
List of data paths.
std::vector< std::string > OpenXcom::CrossPlatform::findUserFolders ( )

Builds a list of predefined paths for the User folder according to the running system.

Finds the game's user folders in the system.

Returns
List of data paths.
void OpenXcom::CrossPlatform::flashWindow ( )

Notifies the user that maybe he should have a look.

Flashes the game window.

bool OpenXcom::CrossPlatform::folderExists ( const std::string &  path)

Checks if a certain path exists and is a folder.

Checks if the path is an existing folder.

Parameters
pathFull path to folder.
Returns
Does it exist?
std::vector< std::string > OpenXcom::CrossPlatform::getDataContents ( const std::string &  folder,
const std::string &  ext 
)

Gets the name of all the files contained in a Data subfolder.

Returns the list of files in a data folder.

Repeated files are ignored.

Parameters
folderPath to the data folder.
extExtension of files ("" if it doesn't matter).
Returns
Ordered list of all the files.
std::string OpenXcom::CrossPlatform::getDataFile ( const std::string &  filename)

Takes a filename and tries to find it in the game's Data folders, accounting for the system's case-sensitivity and path style.

Gets the path for a data file.

Parameters
filenameOriginal filename.
Returns
Correct filename or "" if it doesn't exist.
std::string OpenXcom::CrossPlatform::getDataFolder ( const std::string &  foldername)

Takes a foldername and tries to find it in the game's Data folders, accounting for the system's case-sensitivity and path style.

Gets the path for a data folder.

Parameters
foldernameOriginal foldername.
Returns
Correct foldername or "" if it doesn't exist.
time_t OpenXcom::CrossPlatform::getDateModified ( const std::string &  path)

Gets the last modified date of a file.

Gets the modified date of a file.

Parameters
pathFull path to file.
Returns
The timestamp in integral format.
std::string OpenXcom::CrossPlatform::getDosPath ( )

Gets the executable path in DOS-style (short) form.

Gets the DOS-style executable path.

For non-Windows systems, just use a dummy path.

Returns
Executable path.
std::vector< std::string > OpenXcom::CrossPlatform::getFolderContents ( const std::string &  path,
const std::string &  ext 
)

Gets the name of all the files contained in a certain folder.

Returns the list of files in a folder.

Parameters
pathFull path to folder.
extExtension of files ("" if it doesn't matter).
Returns
Ordered list of all the files.
std::string OpenXcom::CrossPlatform::getLocale ( )

Gets the current locale of the system in language-COUNTRY format.

Gets the system locale.

Returns
Locale string.
bool OpenXcom::CrossPlatform::isQuitShortcut ( const SDL_Event &  ev)

Checks if the system's default quit shortcut was pressed.

Checks if an event is a quit shortcut.

Parameters
evSDL event.
Returns
Is quitting necessary?
bool OpenXcom::CrossPlatform::moveFile ( const std::string &  src,
const std::string &  dest 
)

Moves a file from one path to another, replacing any existing file.

Move/rename a file between paths.

Parameters
srcSource path.
destDestination path.
Returns
True if the operation succeeded, False otherwise.
bool OpenXcom::CrossPlatform::naturalCompare ( const std::wstring &  a,
const std::wstring &  b 
)

Compares two Unicode strings using natural human ordering.

Compares two strings by natural order.

Parameters
aString A.
bString B.
Returns
String A comes before String B.
std::string OpenXcom::CrossPlatform::noExt ( const std::string &  filename)

Removes the extension from a filename.

Removes the extension from a file.

Parameters
filenameOriginal filename.
Returns
Filename without the extension.
std::string OpenXcom::CrossPlatform::sanitizeFilename ( const std::string &  filename)

Replaces invalid filesystem characters with _.

Sanitizes the characters in a filename.

Parameters
filenameOriginal filename.
Returns
Filename without invalid characters
void OpenXcom::CrossPlatform::showError ( const std::string &  error)

Displays a message box with an error message.

Displays an error message.

Parameters
errorError message.
std::pair< std::wstring, std::wstring > OpenXcom::CrossPlatform::timeToString ( time_t  time)

Converts a date/time into a human-readable string using the ISO 8601 standard.

Converts a timestamp to a string.

Parameters
timeValue in timestamp format.
Returns
String pair with date and time.