OLD | NEW |
1 #ifndef UTILS_H | 1 #ifndef UTILS_H |
2 #define UTILS_H | 2 #define UTILS_H |
3 | 3 |
4 #include <algorithm> | 4 #include <algorithm> |
5 #include <locale> | 5 #include <locale> |
6 #include <functional> | 6 #include <functional> |
7 #include <string> | 7 #include <string> |
8 | 8 #include <memory> |
9 | 9 |
10 bool IsWindowsVistaOrLater(); | 10 bool IsWindowsVistaOrLater(); |
11 | 11 |
12 std::string ToUtf8String(const std::wstring& str); | 12 std::string ToUtf8String(const std::wstring& str); |
13 std::wstring ToUtf16String(const std::string& str); | 13 std::wstring ToUtf16String(const std::string& str); |
14 std::wstring GetDllDir(); | 14 std::wstring GetDllDir(); |
15 std::wstring GetAppDataPath(); | 15 std::wstring GetAppDataPath(); |
16 | 16 |
17 template<class T> | 17 template<class T> |
18 T TrimString(T text) | 18 T TrimString(T text) |
19 { | 19 { |
20 // Via http://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-st
dstring | 20 // Via http://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-st
dstring |
21 T trimmed(text); | 21 T trimmed(text); |
22 std::function<bool(T::value_type)> isspace = std::bind(&std::isspace<T::value_
type>, std::placeholders::_1, std::locale::classic()); | 22 std::function<bool(T::value_type)> isspace = std::bind(&std::isspace<T::value_
type>, std::placeholders::_1, std::locale::classic()); |
23 trimmed.erase(trimmed.begin(), std::find_if(trimmed.begin(), trimmed.end(), st
d::not1(isspace))); | 23 trimmed.erase(trimmed.begin(), std::find_if(trimmed.begin(), trimmed.end(), st
d::not1(isspace))); |
24 trimmed.erase(std::find_if(trimmed.rbegin(), trimmed.rend(), std::not1(isspace
)).base(), trimmed.end()); | 24 trimmed.erase(std::find_if(trimmed.rbegin(), trimmed.rend(), std::not1(isspace
)).base(), trimmed.end()); |
25 return trimmed; | 25 return trimmed; |
26 } | 26 } |
27 | 27 |
| 28 class Location { |
| 29 public: |
| 30 /** |
| 31 * Fully-qualified path to the file name of the engine executable. |
| 32 */ |
| 33 static std::wstring engine(); |
| 34 |
| 35 /** |
| 36 * Fully-qualified path to the locales/ directory. Ends in a backslash. |
| 37 */ |
| 38 static std::wstring locales_dir(); |
| 39 |
| 40 /** |
| 41 * Fully-qualified path to the html/ directory. Ends in a backslash. |
| 42 */ |
| 43 static std::wstring html_dir(); |
| 44 |
| 45 /** |
| 46 * Check that all the locations are known in the registry. |
| 47 * |
| 48 * While not a complete check of installation validity, this is a quick check
to ensure that at least |
| 49 * all the relevant registry keys are present. Strictly speaking, this is a d
evelopment-cycle function, |
| 50 * ensuring that the development environment is properly set up for testing. |
| 51 */ |
| 52 static bool all_known(); |
| 53 }; |
| 54 |
28 #endif // UTILS_H | 55 #endif // UTILS_H |
OLD | NEW |