| 11 | #endif |
| 12 | |
| 13 | path config::loader_dir() |
| 14 | { |
| 15 | #if OS_WIN |
| 16 | static std::wstring path; |
| 17 | if (path.empty()) |
| 18 | { |
| 19 | // Get this dll path. |
| 20 | WCHAR thisPath[2048]; |
| 21 | GetModuleFileNameW((HINSTANCE)&__ImageBase, thisPath, ARRAYSIZE(thisPath) - 1); |
| 22 | |
| 23 | DWORD attr = GetFileAttributesW(thisPath); |
| 24 | if ((attr & FILE_ATTRIBUTE_REPARSE_POINT) != FILE_ATTRIBUTE_REPARSE_POINT) |
| 25 | { |
| 26 | path = thisPath; |
| 27 | return path = path.substr(0, path.find_last_of(L"/\\")); |
| 28 | } |
| 29 | |
| 30 | OFSTRUCT of{}; |
| 31 | WCHAR finalPath[2048]; |
| 32 | // Get final path. |
| 33 | HANDLE file = CreateFileW(thisPath, GENERIC_READ, 0x1, NULL, OPEN_EXISTING, 0, NULL); |
| 34 | DWORD pathLength = GetFinalPathNameByHandleW(file, finalPath, 2048, FILE_NAME_OPENED); |
| 35 | CloseHandle(file); |
| 36 | |
| 37 | std::wstring dir{ finalPath, pathLength }; |
| 38 | // Remove prepended '\\?\' by GetFinalPathNameByHandle() |
| 39 | if (dir.rfind(L"\\\\?\\", 0) == 0) |
| 40 | dir.erase(0, 4); |
| 41 | |
| 42 | // Get parent folder. |
| 43 | return path = dir.substr(0, dir.find_last_of(L"/\\")); |
| 44 | } |
| 45 | #elif OS_MAC |
| 46 | static std::string path; |
| 47 | if (path.empty()) |
| 48 | { |
| 49 | Dl_info info; |
| 50 | if (dladdr((const void *)&loader_dir, &info)) |
| 51 | { |
| 52 | path = info.dli_fname; |
| 53 | path = path.substr(0, path.rfind('/')); |
| 54 | } |
| 55 | } |
| 56 | #endif |
| 57 | return path; |
| 58 | } |
| 59 | |
| 60 | path config::datastore_path() |
| 61 | { |