Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/shared/Utils.cpp

Issue 6505394822184960: Issue 1109 - Support notifications (Closed)
Patch Set: Created May 11, 2015, 10:01 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/engine/NotificationWindow.html ('K') | « src/shared/Utils.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)
« src/engine/NotificationWindow.html ('K') | « src/shared/Utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld