MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / chdirToBasePath

Function chdirToBasePath

Source/Compat/Win/win_compat.cpp:236–260  ·  view source on GitHub ↗

Set home directory so file paths work properly when running from shortcuts

Source from the content-addressed store, hash-verified

234
235// Set home directory so file paths work properly when running from shortcuts
236void 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
262void SetWorkingDir(const char *path) {
263 _wchdir(UTF16fromUTF8(path).c_str());

Callers 1

SetUpEnvironmentFunction · 0.50

Calls 7

utf16to8Function · 0.50
utf8to32Function · 0.50
utf32to8Function · 0.50
utf8to16Function · 0.50
beginMethod · 0.45
endMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected