| OLD | NEW |
| 1 #include "PluginStdAfx.h" | 1 #include "PluginStdAfx.h" |
| 2 #include <algorithm> | 2 #include <algorithm> |
| 3 #include <stdexcept> | 3 #include <stdexcept> |
| 4 #include <vector> | 4 #include <vector> |
| 5 | 5 |
| 6 #include "../shared/Utils.h" |
| 6 #include "PluginUtil.h" | 7 #include "PluginUtil.h" |
| 7 #include "PluginSettings.h" | 8 #include "PluginSettings.h" |
| 8 | 9 |
| 9 BString::BString(const std::wstring& value) | 10 BString::BString(const std::wstring& value) |
| 10 : value(::SysAllocString(value.c_str())) | 11 : value(::SysAllocString(value.c_str())) |
| 11 { | 12 { |
| 12 } | 13 } |
| 13 | 14 |
| 14 BString::~BString() | 15 BString::~BString() |
| 15 { | 16 { |
| 16 ::SysFreeString(value); | 17 ::SysFreeString(value); |
| 17 } | 18 } |
| 18 | 19 |
| 19 BString::operator BSTR() | 20 BString::operator BSTR() |
| 20 { | 21 { |
| 21 return value; | 22 return value; |
| 22 } | 23 } |
| 23 | 24 |
| 24 std::wstring DllDir() | |
| 25 { | |
| 26 std::vector<WCHAR> path(MAX_PATH); | |
| 27 DWORD length = GetModuleFileNameW((HINSTANCE)&__ImageBase, &path[0], path.size
()); | |
| 28 | |
| 29 while (length == path.size()) | |
| 30 { | |
| 31 // Buffer too small, double buffer size | |
| 32 path.resize(path.size() * 2); | |
| 33 length = GetModuleFileNameW((HINSTANCE)&__ImageBase, &path[0], path.size()); | |
| 34 } | |
| 35 | |
| 36 try | |
| 37 { | |
| 38 if (length == 0) | |
| 39 throw std::runtime_error("Failed determining module path"); | |
| 40 | |
| 41 std::vector<WCHAR>::reverse_iterator it = std::find(path.rbegin(), path.rend
(), L'\\'); | |
| 42 if (it == path.rend()) | |
| 43 throw std::runtime_error("Unexpected plugin path, no backslash found"); | |
| 44 | |
| 45 return std::wstring(path.begin(), it.base()); | |
| 46 } | |
| 47 catch (const std::exception& e) | |
| 48 { | |
| 49 DEBUG_GENERAL(e.what()); | |
| 50 return std::wstring(); | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 std::wstring UserSettingsFileUrl() | 25 std::wstring UserSettingsFileUrl() |
| 55 { | 26 { |
| 56 return FileUrl(DllDir() + L"html\\templates\\index.html"); | 27 return FileUrl(GetDllDir() + L"html\\templates\\index.html"); |
| 57 } | 28 } |
| 58 | 29 |
| 59 std::wstring FileUrl(const std::wstring& path) | 30 std::wstring FileUrl(const std::wstring& path) |
| 60 { | 31 { |
| 61 std::wstring url = path; | 32 std::wstring url = path; |
| 62 std::replace(url.begin(), url.end(), L'\\', L'/'); | 33 std::replace(url.begin(), url.end(), L'\\', L'/'); |
| 63 return L"file:///" + url; | 34 return L"file:///" + url; |
| 64 } | 35 } |
| 65 | 36 |
| OLD | NEW |