| 49 | std::filesystem::path binaryDirectory; |
| 50 | |
| 51 | void init(int argc, char *argv[]) |
| 52 | { |
| 53 | (void)argc; |
| 54 | #ifdef _WIN32 |
| 55 | wchar_t wpath[1024] = {0}; |
| 56 | GetModuleFileNameW(NULL, wpath, MAX_PATH); |
| 57 | binaryDirectory = wpath; |
| 58 | binaryDirectory.remove_filename(); |
| 59 | #else |
| 60 | std::string argv0; // path+name of the executable binary, as given by argv[0] |
| 61 | std::string binaryPath; // path of the executable |
| 62 | std::string workingDirectory; // path of the working directory |
| 63 | |
| 64 | // extract the path+name of the executable binary |
| 65 | argv0 = argv[0]; |
| 66 | |
| 67 | // extract the working directory |
| 68 | workingDirectory = ""; |
| 69 | char buff[40000]; |
| 70 | char *cwd = GETCWD(buff, 40000); |
| 71 | if (cwd) |
| 72 | workingDirectory = cwd; |
| 73 | |
| 74 | const std::string pathSeparator = "/"; |
| 75 | |
| 76 | // extract the binary directory path from argv0 |
| 77 | binaryPath = argv0; |
| 78 | size_t pos = binaryPath.find_last_of("\\/"); |
| 79 | if (pos == std::string::npos) |
| 80 | binaryPath = "." + pathSeparator; |
| 81 | else |
| 82 | binaryPath.resize(pos + 1); |
| 83 | |
| 84 | // pattern replacement: "./" at the start of path is replaced by the working directory |
| 85 | if (binaryPath.find("." + pathSeparator) == 0) |
| 86 | binaryPath.replace(0, 1, workingDirectory); |
| 87 | |
| 88 | binaryDirectory = binaryPath; |
| 89 | #endif |
| 90 | } |
| 91 | |
| 92 | std::filesystem::path getDefaultConfigPath() |
| 93 | { |
no test coverage detected