summaryrefslogtreecommitdiff
path: root/Source/Core/Common/FileUtil.cpp
diff options
context:
space:
mode:
authorPierre Bourdon <delroth@gmail.com>2018-03-23 00:29:03 +0100
committerPierre Bourdon <delroth@gmail.com>2018-03-23 11:10:25 +0100
commit9628333b864aa517a4a22dfe1b162c49ef23adf1 (patch)
treec0d322d7a8eee5fedb33e712a6762eec5d15af80 /Source/Core/Common/FileUtil.cpp
parent773ec975f398d19b38b2cf6caf345bf9e80b902c (diff)
AutoUpdater: support optionally restarting Dolphin after update
Diffstat (limited to 'Source/Core/Common/FileUtil.cpp')
-rw-r--r--Source/Core/Common/FileUtil.cpp45
1 files changed, 27 insertions, 18 deletions
diff --git a/Source/Core/Common/FileUtil.cpp b/Source/Core/Common/FileUtil.cpp
index b86b9f9dd4..74d2855659 100644
--- a/Source/Core/Common/FileUtil.cpp
+++ b/Source/Core/Common/FileUtil.cpp
@@ -664,33 +664,42 @@ std::string GetBundleDirectory()
}
#endif
-std::string& GetExeDirectory()
+std::string GetExePath()
{
- static std::string DolphinPath;
- if (DolphinPath.empty())
+ static std::string dolphin_path;
+ if (dolphin_path.empty())
{
#ifdef _WIN32
- TCHAR Dolphin_exe_Path[2048];
- TCHAR Dolphin_exe_Clean_Path[MAX_PATH];
- GetModuleFileName(nullptr, Dolphin_exe_Path, 2048);
- if (_tfullpath(Dolphin_exe_Clean_Path, Dolphin_exe_Path, MAX_PATH) != nullptr)
- DolphinPath = TStrToUTF8(Dolphin_exe_Clean_Path);
+ 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
- DolphinPath = TStrToUTF8(Dolphin_exe_Path);
- DolphinPath = DolphinPath.substr(0, DolphinPath.find_last_of('\\'));
+ dolphin_path = TStrToUTF8(dolphin_exe_path);
#else
- char Dolphin_exe_Path[PATH_MAX];
- ssize_t len = ::readlink("/proc/self/exe", Dolphin_exe_Path, sizeof(Dolphin_exe_Path));
- if (len == -1 || len == sizeof(Dolphin_exe_Path))
+ char dolphin_exe_path[PATH_MAX];
+ ssize_t len = ::readlink("/proc/self/exe", dolphin_exe_path, sizeof(dolphin_exe_path));
+ if (len == -1 || len == sizeof(dolphin_exe_path))
{
len = 0;
}
- Dolphin_exe_Path[len] = '\0';
- DolphinPath = Dolphin_exe_Path;
- DolphinPath = DolphinPath.substr(0, DolphinPath.rfind('/'));
+ dolphin_exe_path[len] = '\0';
+ dolphin_path = dolphin_exe_path;
#endif
}
- return DolphinPath;
+ return dolphin_path;
+}
+
+std::string GetExeDirectory()
+{
+ std::string exe_path = GetExePath();
+#ifdef _WIN32
+ return exe_path.substr(0, exe_path.rfind('\\'));
+#else
+ return exe_path.substr(0, exe_path.rfind('/'));
+#endif
}
std::string GetSysDirectory()
@@ -882,4 +891,4 @@ bool ReadFileToString(const std::string& filename, std::string& str)
return retval;
}
-} // namespace
+} // namespace File