mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 05:09:34 -06:00
Move GetModuleName to Common
This unifies GetModuleFileName calls between Dolphin and WinUpdater and allows to gracefully remove MAX_PATH limit from GetExePath
This commit is contained in:
@ -674,22 +674,26 @@ std::string GetBundleDirectory()
|
||||
|
||||
std::string GetExePath()
|
||||
{
|
||||
static std::string dolphin_path;
|
||||
if (dolphin_path.empty())
|
||||
{
|
||||
static const std::string dolphin_path = [] {
|
||||
std::string result;
|
||||
#ifdef _WIN32
|
||||
TCHAR dolphin_exe_path[2048];
|
||||
TCHAR dolphin_exe_expanded_path[MAX_PATH];
|
||||
GetModuleFileName(nullptr, dolphin_exe_path, ARRAYSIZE(dolphin_exe_path));
|
||||
if (_tfullpath(dolphin_exe_expanded_path, dolphin_exe_path,
|
||||
ARRAYSIZE(dolphin_exe_expanded_path)) != nullptr)
|
||||
dolphin_path = TStrToUTF8(dolphin_exe_expanded_path);
|
||||
else
|
||||
dolphin_path = TStrToUTF8(dolphin_exe_path);
|
||||
auto dolphin_exe_path = GetModuleName(nullptr);
|
||||
if (dolphin_exe_path)
|
||||
{
|
||||
std::unique_ptr<TCHAR[], decltype(&std::free)> dolphin_exe_expanded_path{
|
||||
_tfullpath(nullptr, dolphin_exe_path->c_str(), 0), std::free};
|
||||
if (dolphin_exe_expanded_path)
|
||||
{
|
||||
result = TStrToUTF8(dolphin_exe_expanded_path.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
result = TStrToUTF8(*dolphin_exe_path);
|
||||
}
|
||||
}
|
||||
#elif defined(__APPLE__)
|
||||
dolphin_path = GetBundleDirectory();
|
||||
dolphin_path =
|
||||
dolphin_path.substr(0, dolphin_path.find_last_of("Dolphin.app/Contents/MacOS") + 1);
|
||||
result = GetBundleDirectory();
|
||||
result = result.substr(0, result.find_last_of("Dolphin.app/Contents/MacOS") + 1);
|
||||
#else
|
||||
char dolphin_exe_path[PATH_MAX];
|
||||
ssize_t len = ::readlink("/proc/self/exe", dolphin_exe_path, sizeof(dolphin_exe_path));
|
||||
@ -698,9 +702,10 @@ std::string GetExePath()
|
||||
len = 0;
|
||||
}
|
||||
dolphin_exe_path[len] = '\0';
|
||||
dolphin_path = dolphin_exe_path;
|
||||
result = dolphin_exe_path;
|
||||
#endif
|
||||
}
|
||||
return result;
|
||||
}();
|
||||
return dolphin_path;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user