Set home directory so file paths work properly when running from shortcuts
| 234 | |
| 235 | // Set home directory so file paths work properly when running from shortcuts |
| 236 | void chdirToBasePath(char *argv0) { |
| 237 | basic_string<uint32_t> path_utf32; |
| 238 | { |
| 239 | wchar_t path_utf16_buf[kPathSize]; |
| 240 | GetModuleFileNameW(NULL, path_utf16_buf, kPathSize); |
| 241 | |
| 242 | // Convert path from UTF16 to UTF32 by way of UTF8 |
| 243 | string path_utf8; |
| 244 | utf8::utf16to8(path_utf16_buf, &path_utf16_buf[wcsnlen(path_utf16_buf, kPathSize) - 1], back_inserter(path_utf8)); |
| 245 | utf8::utf8to32(path_utf8.begin(), path_utf8.end(), back_inserter(path_utf32)); |
| 246 | } |
| 247 | |
| 248 | // Eliminate everything after final '\\' |
| 249 | path_utf32 = path_utf32.substr(0, path_utf32.rfind('\\')); |
| 250 | |
| 251 | wstring path_utf16; |
| 252 | { |
| 253 | // Convert path from UTF32 to UTF16 by way of UTF8 |
| 254 | string path_utf8; |
| 255 | utf8::utf32to8(path_utf32.begin(), path_utf32.end(), back_inserter(path_utf8)); |
| 256 | utf8::utf8to16(path_utf8.begin(), path_utf8.end(), back_inserter(path_utf16)); |
| 257 | } |
| 258 | |
| 259 | _wchdir(path_utf16.c_str()); |
| 260 | } |
| 261 | |
| 262 | void SetWorkingDir(const char *path) { |
| 263 | _wchdir(UTF16fromUTF8(path).c_str()); |