Changeset View
Changeset View
Standalone View
Standalone View
src/leveldb/util/env_win.cc
Show First 20 Lines • Show All 194 Lines • ▼ Show 20 Lines | public: | ||||
virtual uint64_t NowMicros(); | virtual uint64_t NowMicros(); | ||||
virtual void SleepForMicroseconds(int micros); | virtual void SleepForMicroseconds(int micros); | ||||
}; | }; | ||||
void ToWidePath(const std::string& value, std::wstring& target) { | void ToWidePath(const std::string& value, std::wstring& target) { | ||||
wchar_t buffer[MAX_PATH]; | wchar_t buffer[MAX_PATH]; | ||||
MultiByteToWideChar(CP_ACP, 0, value.c_str(), -1, buffer, MAX_PATH); | MultiByteToWideChar(CP_UTF8, 0, value.c_str(), -1, buffer, MAX_PATH); | ||||
target = buffer; | target = buffer; | ||||
} | } | ||||
void ToNarrowPath(const std::wstring& value, std::string& target) { | void ToNarrowPath(const std::wstring& value, std::string& target) { | ||||
char buffer[MAX_PATH]; | char buffer[MAX_PATH]; | ||||
WideCharToMultiByte(CP_ACP, 0, value.c_str(), -1, buffer, MAX_PATH, NULL, NULL); | WideCharToMultiByte(CP_UTF8, 0, value.c_str(), -1, buffer, MAX_PATH, NULL, NULL); | ||||
target = buffer; | target = buffer; | ||||
} | } | ||||
std::string GetCurrentDir() | |||||
{ | |||||
CHAR path[MAX_PATH]; | |||||
::GetModuleFileNameA(::GetModuleHandleA(NULL),path,MAX_PATH); | |||||
*strrchr(path,'\\') = 0; | |||||
return std::string(path); | |||||
} | |||||
std::wstring GetCurrentDirW() | std::wstring GetCurrentDirW() | ||||
{ | { | ||||
WCHAR path[MAX_PATH]; | WCHAR path[MAX_PATH]; | ||||
::GetModuleFileNameW(::GetModuleHandleW(NULL),path,MAX_PATH); | ::GetModuleFileNameW(::GetModuleHandleW(NULL),path,MAX_PATH); | ||||
*wcsrchr(path,L'\\') = 0; | *wcsrchr(path,L'\\') = 0; | ||||
return std::wstring(path); | return std::wstring(path); | ||||
} | } | ||||
std::string GetCurrentDir() | |||||
{ | |||||
std::string path; | |||||
ToNarrowPath(GetCurrentDirW(), path); | |||||
return path; | |||||
} | |||||
std::string& ModifyPath(std::string& path) | std::string& ModifyPath(std::string& path) | ||||
{ | { | ||||
if(path[0] == '/' || path[0] == '\\'){ | if(path[0] == '/' || path[0] == '\\'){ | ||||
path = CurrentDir + path; | path = CurrentDir + path; | ||||
} | } | ||||
std::replace(path.begin(),path.end(),'/','\\'); | std::replace(path.begin(),path.end(),'/','\\'); | ||||
return path; | return path; | ||||
▲ Show 20 Lines • Show All 519 Lines • ▼ Show 20 Lines | |||||
#define GetTickCount64 GetTickCount | #define GetTickCount64 GetTickCount | ||||
#endif | #endif | ||||
return (uint64_t)(GetTickCount64()*1000); | return (uint64_t)(GetTickCount64()*1000); | ||||
} | } | ||||
static Status CreateDirInner( const std::string& dirname ) | static Status CreateDirInner( const std::string& dirname ) | ||||
{ | { | ||||
Status sRet; | Status sRet; | ||||
DWORD attr = ::GetFileAttributes(dirname.c_str()); | std::wstring dirnameW; | ||||
ToWidePath(dirname, dirnameW); | |||||
DWORD attr = ::GetFileAttributesW(dirnameW.c_str()); | |||||
if (attr == INVALID_FILE_ATTRIBUTES) { // doesn't exist: | if (attr == INVALID_FILE_ATTRIBUTES) { // doesn't exist: | ||||
std::size_t slash = dirname.find_last_of("\\"); | std::size_t slash = dirname.find_last_of("\\"); | ||||
if (slash != std::string::npos){ | if (slash != std::string::npos){ | ||||
sRet = CreateDirInner(dirname.substr(0, slash)); | sRet = CreateDirInner(dirname.substr(0, slash)); | ||||
if (!sRet.ok()) return sRet; | if (!sRet.ok()) return sRet; | ||||
} | } | ||||
BOOL result = ::CreateDirectory(dirname.c_str(), NULL); | BOOL result = ::CreateDirectoryW(dirnameW.c_str(), NULL); | ||||
if (result == FALSE) { | if (result == FALSE) { | ||||
sRet = Status::IOError(dirname, "Could not create directory."); | sRet = Status::IOError(dirname, "Could not create directory."); | ||||
return sRet; | return sRet; | ||||
} | } | ||||
} | } | ||||
return sRet; | return sRet; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 119 Lines • Show Last 20 Lines |