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

Side by Side Diff: src/plugin/PluginUtil.cpp

Issue 10825021: Move settings page into the application directory (Closed)
Patch Set: Created June 3, 2013, 11:40 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« src/plugin/PluginUtil.h ('K') | « src/plugin/PluginUtil.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include "PluginStdAfx.h" 1 #include "PluginStdAfx.h"
2 #include <algorithm>
3 #include <stdexcept>
4 #include <vector>
5
2 #include "PluginUtil.h" 6 #include "PluginUtil.h"
3 #include "PluginSettings.h" 7 #include "PluginSettings.h"
4 8
5 static CString sDllDir() 9 BString::BString(const std::wstring& value)
10 : value(::SysAllocString(value.c_str()))
6 { 11 {
7 TCHAR filePath[MAX_PATH + 1]; 12 }
8 filePath[0] = L'\0';
9 13
10 if (GetModuleFileName(_AtlBaseModule.GetModuleInstance(), filePath, countof(fi lePath) - 1)) 14 BString::~BString()
15 {
16 ::SysFreeString(value);
17 }
18
19 BString::operator BSTR()
20 {
21 return value;
22 }
23
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())
11 { 30 {
12 TCHAR* pLastBackslash = wcsrchr(filePath, L'\\'); 31 // Buffer too small, double buffer size
13 if (pLastBackslash) 32 path.resize(path.size() * 2);
14 { 33 length = GetModuleFileNameW((HINSTANCE)&__ImageBase, &path[0], path.size());
15 *(pLastBackslash + 1) = L'\0';
16 }
17 } 34 }
18 35
19 return filePath; 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 }
20 } 52 }
21 53
22 const CString& DllDir() 54 std::wstring UserSettingsFileUrl()
23 { 55 {
24 static CString s_dllDir = sDllDir(); 56 return FileUrl(DllDir() + L"html\\templates\\index.html");
25 return s_dllDir;
26 } 57 }
27 58
28 const CString& UserSettingsFileUrl() 59 std::wstring FileUrl(const std::wstring& path)
29 { 60 {
30 static CString s_url = FileUrl(CPluginSettings::GetDataPath("html\\templates\\ index.html")); 61 std::wstring url = path;
31 return s_url; 62 std::replace(url.begin(), url.end(), L'\\', L'/');
63 return L"file:///" + url;
32 } 64 }
33 65
34 CString FileUrl(const CString& url)
35 {
36 CString tmpUrl = url;
37 tmpUrl.Replace(L'\\', L'/');
38
39 return CString("file:///") + tmpUrl;
40 }
41
OLDNEW
« src/plugin/PluginUtil.h ('K') | « src/plugin/PluginUtil.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld