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: Created April 24, 2013, 2:10 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
11 #ifdef _WIN32 11 #ifdef _WIN32
12 #ifndef S_ISDIR 12 #ifndef S_ISDIR
13 #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) 13 #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
14 #include <Shlobj.h>
14 #endif 15 #endif
15 16
16 #ifndef S_ISREG 17 #ifndef S_ISREG
17 #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) 18 #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
18 #endif 19 #endif
19 #endif 20 #endif
20 21
21 #include "../src/Utils.h" 22 #include "../src/Utils.h"
22 23
23 using namespace AdblockPlus; 24 using namespace AdblockPlus;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 return FileSystem::StatResult(); 75 return FileSystem::StatResult();
75 throw RuntimeErrorWithErrno("Unable to stat " + path); 76 throw RuntimeErrorWithErrno("Unable to stat " + path);
76 } 77 }
77 FileSystem::StatResult result; 78 FileSystem::StatResult result;
78 result.exists = true; 79 result.exists = true;
79 result.isFile = S_ISREG(nativeStat.st_mode); 80 result.isFile = S_ISREG(nativeStat.st_mode);
80 result.isDirectory = S_ISDIR(nativeStat.st_mode); 81 result.isDirectory = S_ISDIR(nativeStat.st_mode);
81 result.lastModified = static_cast<int64_t>(nativeStat.st_mtime) * 1000; 82 result.lastModified = static_cast<int64_t>(nativeStat.st_mtime) * 1000;
82 return result; 83 return result;
83 } 84 }
85
86 std::string DefaultFileSystem::Resolve(const std::string& path) const
87 {
88 #ifdef WIN32
89 // Resolve to LocalLow folder
90 wchar_t* resolvedPath;
91 HRESULT hr = SHGetKnownFolderPath(FOLDERID_LocalAppDataLow, 0, NULL, &resolved Path);
92 if (FAILED(hr))
93 return std::string(path);
Wladimir Palant 2013/04/24 09:17:35 Why not just return path; here?
94 std::wstring resolvedW(resolvedPath);
95 CoTaskMemFree(resolvedPath);
96
97 // TODO: Better conversion here
98 std::string resolved(resolvedW.begin(), resolvedW.end());
Wladimir Palant 2013/04/24 09:17:35 Please use Utils::ToUTF8String() here (and we are
99 resolved.append("\\AdblockPlus\\");
100 resolved.append(path);
101 return resolved;
102 #else
103 return std::string(path);
Wladimir Palant 2013/04/24 09:17:35 Why not just return path; here?
104 #endif
105 }
106
OLDNEW
« no previous file with comments | « lib/io.js ('k') | src/FileSystemJsObject.cpp » ('j') | src/FileSystemJsObject.cpp » ('J')

Powered by Google App Engine
This is Rietveld