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

Side by Side Diff: src/DefaultFileSystem.cpp

Issue 10369004: File system path resolving (Closed)
Patch Set: Comments addressed Created April 30, 2013, 8:09 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
OLDNEW
1 #include <AdblockPlus/DefaultFileSystem.h> 1 #include <AdblockPlus/DefaultFileSystem.h>
2 #include <cstdio> 2 #include <cstdio>
3 #include <cstring> 3 #include <cstring>
4 #include <fstream> 4 #include <fstream>
5 #include <stdexcept> 5 #include <stdexcept>
6 6
7 #include <cerrno> 7 #include <cerrno>
8 #include <sys/types.h> 8 #include <sys/types.h>
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 10
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 FileSystem::StatResult result; 78 FileSystem::StatResult result;
79 result.exists = true; 79 result.exists = true;
80 result.isFile = S_ISREG(nativeStat.st_mode); 80 result.isFile = S_ISREG(nativeStat.st_mode);
81 result.isDirectory = S_ISDIR(nativeStat.st_mode); 81 result.isDirectory = S_ISDIR(nativeStat.st_mode);
82 result.lastModified = static_cast<int64_t>(nativeStat.st_mtime) * 1000; 82 result.lastModified = static_cast<int64_t>(nativeStat.st_mtime) * 1000;
83 return result; 83 return result;
84 } 84 }
85 85
86 std::string DefaultFileSystem::Resolve(const std::string& path) const 86 std::string DefaultFileSystem::Resolve(const std::string& path) const
87 { 87 {
88 #ifdef WIN32 88 return basePath + "\\" + path;
Felix Dahlke 2013/04/30 09:14:52 \\ won't work on UNIX, but I think / should work e
Wladimir Palant 2013/04/30 09:29:50 1) This path separator is Windows-specific. Please
89 // Resolve to LocalLow folder 89 }
90 90
91 OSVERSIONINFOEX osvi; 91 void DefaultFileSystem::SetBasePath(const std::string& path)
92 ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); 92 {
93 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
94 BOOL res = GetVersionEx((OSVERSIONINFO*) &osvi);
95 93
96 if(res == 0 ) return std::string(path); 94 if (path.rfind('\\') == (path.length() - 1))
Felix Dahlke 2013/04/30 09:14:52 How about if (*path.rbegin() == '\\')? This also
Wladimir Palant 2013/04/30 09:29:50 Please search for PATH_SEPARATOR here as well, not
97
98 std::wstring resolvedW = L"";
99 wchar_t resolvedPath[MAX_PATH];
100 HRESULT hr;
101 if (osvi.dwMajorVersion >= 6)
102 { 95 {
103 hr = SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, 0, 0, resolvedPath); 96 basePath = path.substr(0, path.length() - 1);
Felix Dahlke 2013/04/30 09:14:52 Never used this, but basePath.pop_back(); seems to
104 } 97 }
105 else 98 else
106 { 99 {
107 hr = SHGetFolderPath(NULL, CSIDL_APPDATA, 0, 0, resolvedPath); 100 basePath = path;
108 } 101 }
109 if (FAILED(hr))
110 return std::string(path);
111 resolvedW.assign(resolvedPath);
112
113 // TODO: Better conversion here
114 std::string resolved(resolvedW.begin(), resolvedW.end());
115 if (osvi.dwMajorVersion >= 6)
116 {
117 resolved.append("Low\\AdblockPlus\\");
118 }
119 else
120 {
121 resolved.append("\\AdblockPlus\\");
122 }
123 resolved.append(path);
124 return resolved;
125 #else
126 return std::string(path);
127 #endif
128 } 102 }
129 103
OLDNEW

Powered by Google App Engine
This is Rietveld