Index: src/shared/Utils.cpp |
diff --git a/src/shared/Utils.cpp b/src/shared/Utils.cpp |
index 7a14db81c33c4b8a426344f45549afc4b902df1f..71c07e5a54ca45340fec4ed4572bf497d18b1263 100644 |
--- a/src/shared/Utils.cpp |
+++ b/src/shared/Utils.cpp |
@@ -91,35 +91,48 @@ std::vector<std::wstring> ToUtf16Strings(const std::vector<std::string>& values) |
return result; |
} |
-std::wstring GetDllDir() |
+namespace |
{ |
- std::vector<WCHAR> path(MAX_PATH); |
- int length = GetModuleFileNameW((HINSTANCE)&__ImageBase, &path[0], static_cast<DWORD>(path.size())); |
- |
- while (length == path.size()) |
+ std::wstring GetModulePath(HINSTANCE hInstance) |
{ |
- // Buffer too small, double buffer size |
- path.resize(path.size() * 2); |
- length = GetModuleFileNameW((HINSTANCE)&__ImageBase, &path[0], static_cast<DWORD>(path.size())); |
- } |
+ std::vector<WCHAR> path(MAX_PATH); |
+ int length = GetModuleFileNameW(hInstance, &path[0], static_cast<DWORD>(path.size())); |
- try |
- { |
- if (length == 0) |
- throw std::runtime_error("Failed determining module path"); |
+ while (length == path.size()) |
+ { |
+ // Buffer too small, double buffer size |
+ path.resize(path.size() * 2); |
+ length = GetModuleFileNameW(hInstance, &path[0], static_cast<DWORD>(path.size())); |
+ } |
- std::vector<WCHAR>::reverse_iterator it = std::find(path.rbegin(), path.rend(), L'\\'); |
- if (it == path.rend()) |
- throw std::runtime_error("Unexpected plugin path, no backslash found"); |
+ try |
+ { |
+ if (length == 0) |
+ throw std::runtime_error("Failed determining module path"); |
- return std::wstring(path.begin(), it.base()); |
- } |
- catch (const std::exception&) |
- { |
- return std::wstring(); |
+ std::vector<WCHAR>::reverse_iterator it = std::find(path.rbegin(), path.rend(), L'\\'); |
+ if (it == path.rend()) |
+ throw std::runtime_error("Unexpected plugin path, no backslash found"); |
+ |
+ return std::wstring(path.begin(), it.base()); |
+ } |
+ catch (const std::exception&) |
+ { |
+ return std::wstring(); |
+ } |
} |
} |
+std::wstring GetDllDir() |
+{ |
+ return GetModulePath((HINSTANCE)&__ImageBase); |
+} |
+ |
+std::wstring GetExeDir() |
+{ |
+ return GetModulePath(nullptr); |
+} |
+ |
std::wstring GetAppDataPath() |
{ |
if (appDataPath.empty()) |
@@ -147,7 +160,7 @@ std::wstring GetAppDataPath() |
return appDataPath; |
} |
-void ReplaceString(std::wstring& input, const std::wstring placeholder, const std::wstring replacement) |
+void ReplaceString(std::wstring& input, const std::wstring& placeholder, const std::wstring& replacement) |
{ |
size_t replaceStart = input.find(placeholder); |
if (replaceStart != std::string::npos) |