28 #define WIN32_LEAN_AND_MEAN 42 #include <boost/locale.hpp> 43 #include <boost/filesystem/path.hpp> 58 boost::filesystem::path::imbue(boost::locale::generator().generate(
""));
59 }
catch (std::exception &se) {
72 wchar_t **argv = CommandLineToArgvW(GetCommandLineW(), &argc);
80 for (
int i = 0; i < argc; i++)
94 for (
int i = 0; i < argc; i++)
95 args.push_back(argv[i]);
108 static const wchar_t *
const modeStrings[
kFileModeMAX] = { L
"rb", L
"wb" };
110 file = _wfopen(boost::filesystem::path(fileName.
c_str()).c_str(), modeStrings[(
uint) mode]);
112 static const char *
const modeStrings[
kFileModeMAX] = {
"rb",
"wb" };
114 file = std::fopen(boost::filesystem::path(fileName.
c_str()).c_str(), modeStrings[(
uint) mode]);
124 enum WindowsVersion {
125 kWindowsVersionUnknown = 0x00000000,
126 kWindowsVersion2000 = 0x00050000,
127 kWindowsVersionXP = 0x00050001,
128 kWindowsVersionXPProf = 0x00050002,
129 kWindowsVersionVista = 0x00060000,
130 kWindowsVersion7 = 0x00060001,
131 kWindowsVersion8 = 0x00060002,
132 kWindowsVersion8_1 = 0x00060003,
133 kWindowsVersion10 = 0x000A0000
136 static bool isWindowsVersionOrGreater(
uint16 majorVersion,
uint16 minorVersion) {
137 OSVERSIONINFOEX osvi = {
sizeof(osvi), 0, 0, 0, 0, {0}, 0, 0 };
139 DWORDLONG condition =
140 VerSetConditionMask(VerSetConditionMask(
141 0, VER_MAJORVERSION, VER_GREATER_EQUAL),
142 VER_MINORVERSION, VER_GREATER_EQUAL);
144 osvi.dwMajorVersion = majorVersion;
145 osvi.dwMinorVersion = minorVersion;
147 return VerifyVersionInfo(&osvi, VER_MAJORVERSION | VER_MINORVERSION, condition) != 0;
150 static WindowsVersion getWindowsVersion() {
151 static const int16 kWindowsVersionMax = 20;
153 for (
int16 i = kWindowsVersionMax; i >= 0; i--)
154 for (
int16 j = 5; j >= 0; j--)
155 if (isWindowsVersionOrGreater(i, j))
156 return (WindowsVersion) ((i << 16) + j);
158 return kWindowsVersionUnknown;
161 static inline UString getWindowsVariable(
const wchar_t *variable) {
162 DWORD length = GetEnvironmentVariableW(variable, 0, 0);
166 const size_t size = length *
sizeof(wchar_t);
167 ScopedArray<byte> data(
new byte[size]);
169 DWORD newLength = GetEnvironmentVariableW(variable, reinterpret_cast<wchar_t *>(data.get()), length);
170 if (!newLength || (newLength > length))
186 directory = getWindowsVariable(L
"USERPROFILE");
191 const char *pathStr = getenv(
"HOME");
193 struct passwd *pwd = getpwuid(getuid());
195 pathStr = pwd->pw_dir;
212 const WindowsVersion windowsVersion = getWindowsVersion();
214 if (windowsVersion >= kWindowsVersion2000) {
216 directory = getWindowsVariable(L
"APPDATA");
217 if (!directory.
empty())
218 directory +=
"\\xoreos";
221 if (directory.
empty()) {
222 directory = getWindowsVariable(L
"USERPROFILE");
223 if (!directory.
empty())
224 directory +=
"\\xoreos";
229 if (directory.
empty())
232 #elif defined(MACOSX) 236 if (!directory.
empty())
237 directory +=
"/Library/Preferences/xoreos";
239 if (directory.
empty())
245 const char *pathStr = getenv(
"XDG_CONFIG_HOME");
247 directory =
UString(pathStr) +
"/xoreos";
250 if (!directory.
empty())
251 directory +=
"/.config/xoreos";
254 if (directory.
empty())
272 #elif defined(MACOSX) 276 if (!directory.
empty())
277 directory +=
"/Library/Application Support/xoreos";
279 if (directory.
empty())
285 const char *pathStr = getenv(
"XDG_DATA_HOME");
287 directory =
UString(pathStr) +
"/xoreos";
290 if (!directory.
empty())
291 directory +=
"/.local/share/xoreos";
294 if (directory.
empty())
A class holding an UTF-8 string.
UTF-16 LE (little endian).
A simple scoped smart pointer template.
Basic exceptions to throw.
const char * c_str() const
Return the (utf8 encoded) string data.
static UString canonicalize(const UString &p, bool resolveSymLinks=true)
Return the canonical, absolutized and normalized path.
Utility functions for working with differing string encodings.
bool empty() const
Is the string empty?
Low-level detection of architecture/system properties.
UString readString(SeekableReadStream &stream, Encoding encoding)
Read a string with the given encoding of a stream.
Utility class for manipulating file paths.