OpenXcom  1.0
Open-source clone of the original X-Com
CrossPlatform.h
1 #pragma once
2 /*
3  * Copyright 2010-2016 OpenXcom Developers.
4  *
5  * This file is part of OpenXcom.
6  *
7  * OpenXcom is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * OpenXcom is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
19  */
20 #include <SDL.h>
21 #include <string>
22 #include <vector>
23 #include <utility>
24 
25 namespace OpenXcom
26 {
27 
32 namespace CrossPlatform
33 {
34 #ifdef _WIN32
35  const char PATH_SEPARATOR = '\\';
36 #else
37  const char PATH_SEPARATOR = '/';
38 #endif
39 
41  void getErrorDialog();
43  void showError(const std::string &error);
45  std::vector<std::string> findDataFolders();
47  std::vector<std::string> findUserFolders();
49  std::string findConfigFolder();
53  std::string searchDataFile(const std::string &filename);
57  std::string searchDataFolder(const std::string &foldername);
59  bool createFolder(const std::string &path);
61  std::string endPath(const std::string &path);
63  std::vector<std::string> getFolderContents(const std::string &path, const std::string &ext = "");
65  bool folderExists(const std::string &path);
67  bool fileExists(const std::string &path);
69  bool deleteFile(const std::string &path);
71  std::string baseFilename(const std::string &path);
73  std::string sanitizeFilename(const std::string &filename);
75  std::string noExt(const std::string &file);
77  std::string getExt(const std::string &file);
79  bool compareExt(const std::string &file, const std::string &extension);
81  std::string getLocale();
83  bool isQuitShortcut(const SDL_Event &ev);
85  time_t getDateModified(const std::string &path);
87  std::pair<std::string, std::string> timeToString(time_t time);
89  bool moveFile(const std::string &src, const std::string &dest);
91  void flashWindow();
93  std::string getDosPath();
95  void setWindowIcon(int winResource, const std::string &unixPath);
97  void stackTrace(void *ctx);
99  std::string now();
101  void crashDump(void *ex, const std::string &err);
102 }
103 
104 }
std::string baseFilename(const std::string &path)
Returns only the filename from a specified path.
Definition: CrossPlatform.cpp:552
std::string searchDataFolder(const std::string &foldername)
Searches the data folders and returns the full path for a folder when given a relative path...
Definition: CrossPlatform.cpp:377
bool folderExists(const std::string &path)
Checks if a certain path exists and is a folder.
Definition: CrossPlatform.cpp:492
time_t getDateModified(const std::string &path)
Gets the last modified date of a file.
Definition: CrossPlatform.cpp:721
std::string noExt(const std::string &filename)
Removes the extension from a filename.
Definition: CrossPlatform.cpp:601
bool compareExt(const std::string &filename, const std::string &extension)
Compares the extension in a filename (case-insensitive).
Definition: CrossPlatform.cpp:633
void crashDump(void *ex, const std::string &err)
Logs the details of this crash and shows an error.
Definition: CrossPlatform.cpp:1090
void getErrorDialog()
Determines the available Linux error dialogs.
Definition: CrossPlatform.cpp:89
void setWindowIcon(int, const std::string &unixPath)
Sets the window titlebar icon.
Definition: CrossPlatform.cpp:897
void stackTrace(void *ctx)
Logs the stack back trace leading up to this function call.
Definition: CrossPlatform.cpp:913
void showError(const std::string &error)
Displays a message box with an error message.
Definition: CrossPlatform.cpp:112
std::string getLocale()
Gets the current locale of the system in language-COUNTRY format.
Definition: CrossPlatform.cpp:654
bool isQuitShortcut(const SDL_Event &ev)
Checks if the system&#39;s default quit shortcut was pressed.
Definition: CrossPlatform.cpp:701
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...
Definition: CrossPlatform.cpp:347
bool moveFile(const std::string &src, const std::string &dest)
Moves a file from one path to another, replacing any existing file.
Definition: CrossPlatform.cpp:787
std::string findConfigFolder()
Finds the Config folder according to the running system.
Definition: CrossPlatform.cpp:317
bool deleteFile(const std::string &path)
Removes a file from the specified path.
Definition: CrossPlatform.cpp:538
std::string sanitizeFilename(const std::string &filename)
Replaces invalid filesystem characters with _.
Definition: CrossPlatform.cpp:576
std::string getExt(const std::string &filename)
Returns the extension from a filename.
Definition: CrossPlatform.cpp:617
std::string endPath(const std::string &path)
Adds an ending slash to a path if necessary.
Definition: CrossPlatform.cpp:437
std::vector< std::string > findDataFolders()
Builds a list of predefined paths for the Data folder according to the running system.
Definition: CrossPlatform.cpp:155
void flashWindow()
Notifies the user that maybe he should have a look.
Definition: CrossPlatform.cpp:816
std::pair< std::string, std::string > timeToString(time_t time)
Converts a date/time into a human-readable string using the ISO 8601 standard.
Definition: CrossPlatform.cpp:755
bool fileExists(const std::string &path)
Checks if a certain path exists and is a file.
Definition: CrossPlatform.cpp:515
std::string now()
Generates a timestamp of the current time.
Definition: CrossPlatform.cpp:1062
std::string getDosPath()
Gets the executable path in DOS-style (short) form.
Definition: CrossPlatform.cpp:834
std::vector< std::string > findUserFolders()
Builds a list of predefined paths for the User folder according to the running system.
Definition: CrossPlatform.cpp:244
Definition: BaseInfoState.cpp:40
bool createFolder(const std::string &path)
Creates a folder at the specified path.
Definition: CrossPlatform.cpp:413
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.
Definition: CrossPlatform.cpp:451