OpenXcom  1.0
Open-source clone of the original X-Com
Functions
OpenXcom::CrossPlatform Namespace Reference

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

Functions

void getErrorDialog ()
 Determines the available Linux error dialogs. More...
 
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 searchDataFile (const std::string &filename)
 Searches the data folders and returns the full path for a data file when given a relative path, like "units/zombie.pck". returns the passed-in filename if the file is not found.
 
std::string searchDataFolder (const std::string &foldername)
 Searches the data folders and returns the full path for a folder when given a relative path, like "common". returns the passed-in dir name if the folder is not found.
 
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...
 
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)
 Returns only the filename from a specified 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 getExt (const std::string &filename)
 Returns the extension from a filename. More...
 
bool compareExt (const std::string &filename, const std::string &extension)
 Compares the extension in a filename (case-insensitive). 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::string, std::string > timeToString (time_t time)
 Converts a date/time into a human-readable string using the ISO 8601 standard. 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, const std::string &unixPath)
 Sets the window titlebar icon. More...
 
void stackTrace (void *ctx)
 Logs the stack back trace leading up to this function call. More...
 
std::string now ()
 Generates a timestamp of the current time. More...
 
void crashDump (void *ex, const std::string &err)
 Logs the details of this crash and shows an error. More...
 

Detailed Description

Generic purpose functions that need different implementations for different platforms.

Function Documentation

◆ baseFilename()

std::string OpenXcom::CrossPlatform::baseFilename ( const std::string &  path)

Returns only the filename from a specified path.

Gets the pathless filename of a file.

Parameters
pathFull path.
Returns
Filename component.

◆ compareExt()

bool OpenXcom::CrossPlatform::compareExt ( const std::string &  filename,
const std::string &  extension 
)

Compares the extension in a filename (case-insensitive).

Compares the extension of a filename.

Parameters
filenameFilename to compare.
extensionExtension to compare to.
Returns
If the extensions match.

◆ crashDump()

void OpenXcom::CrossPlatform::crashDump ( void *  ex,
const std::string &  err 
)

Logs the details of this crash and shows an error.

Produces a crash dump.

Parameters
exPointer to exception data (PEXCEPTION_POINTERS on Windows, signal int on Unix)
errException message, if any.

◆ createFolder()

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.

◆ deleteFile()

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.

◆ endPath()

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.

◆ fileExists()

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?

◆ findConfigFolder()

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.

◆ findDataFolders()

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.

◆ findUserFolders()

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.

◆ flashWindow()

void OpenXcom::CrossPlatform::flashWindow ( )

Notifies the user that maybe he should have a look.

Flashes the game window.

◆ folderExists()

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?

◆ getDateModified()

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.

◆ getDosPath()

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.

◆ getErrorDialog()

void OpenXcom::CrossPlatform::getErrorDialog ( )

Determines the available Linux error dialogs.

Gets the available error dialog.

◆ getExt()

std::string OpenXcom::CrossPlatform::getExt ( const std::string &  filename)

Returns the extension from a filename.

Gets the extension from a filename.

Only the last dot is considered.

Parameters
filenameOriginal filename.
Returns
Extension component, includes dot.

◆ getFolderContents()

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.

◆ getLocale()

std::string OpenXcom::CrossPlatform::getLocale ( )

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

Gets the system locale.

Returns
Locale string.

◆ isQuitShortcut()

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?

◆ moveFile()

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.

◆ noExt()

std::string OpenXcom::CrossPlatform::noExt ( const std::string &  filename)

Removes the extension from a filename.

Only the last dot is considered.

Parameters
filenameOriginal filename.
Returns
Filename without the extension.

◆ now()

std::string OpenXcom::CrossPlatform::now ( )

Generates a timestamp of the current time.

Produces a quick timestamp.

Returns
String in D-M-Y_H-M-S format.

◆ sanitizeFilename()

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.

◆ setWindowIcon()

void OpenXcom::CrossPlatform::setWindowIcon ( int  ,
const std::string &  unixPath 
)

Sets the window titlebar icon.

Sets the window icon.

For Windows, use the embedded resource icon. For other systems, use a PNG icon.

Parameters
winResourceID for Windows icon.
unixPathPath to PNG icon for Unix.

◆ showError()

void OpenXcom::CrossPlatform::showError ( const std::string &  error)

Displays a message box with an error message.

Displays an error message.

Parameters
errorError message.

◆ stackTrace()

void OpenXcom::CrossPlatform::stackTrace ( void *  ctx)

Logs the stack back trace leading up to this function call.

Produces a stack trace.

Parameters
ctxPointer to stack context (PCONTEXT on Windows), NULL to use current context.

◆ timeToString()

std::pair< std::string, std::string > 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.