mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-03-06 14:27:43 +00:00
Merge pull request #624 from Teklad/reliable-exe-path
Use platform-specific methods for setExePath
This commit is contained in:
commit
ef186e7bd6
|
@ -194,8 +194,21 @@ namespace Utils
|
||||||
|
|
||||||
void setExePath(const std::string& _path)
|
void setExePath(const std::string& _path)
|
||||||
{
|
{
|
||||||
exePath = getCanonicalPath(_path);
|
constexpr int path_max = 32767;
|
||||||
|
#if defined(_WIN32)
|
||||||
|
std::wstring result(path_max, 0);
|
||||||
|
if(GetModuleFileNameW(nullptr, &result[0], path_max) != 0)
|
||||||
|
exePath = convertFromWideString(result);
|
||||||
|
#else
|
||||||
|
std::string result(path_max, 0);
|
||||||
|
if(readlink("/proc/self/exe", &result[0], path_max) != -1)
|
||||||
|
exePath = result;
|
||||||
|
#endif
|
||||||
|
exePath = getCanonicalPath(exePath);
|
||||||
|
|
||||||
|
// Fallback to argv[0] if everything else fails
|
||||||
|
if (exePath.empty())
|
||||||
|
exePath = getCanonicalPath(_path);
|
||||||
if(isRegularFile(exePath))
|
if(isRegularFile(exePath))
|
||||||
exePath = getParent(exePath);
|
exePath = getParent(exePath);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue