Skip to content

Commit

Permalink
Merge bitcoin#18: Use utf-8 to decode filename
Browse files Browse the repository at this point in the history
f8e797a Use utf-8 to decode filename (Chun Kuan Lee)

Pull request description:

  See bitcoin#13869

  Enable unicode support for leveldb on Windows

  CI result for applying this change is available in bitcoin#13787

Tree-SHA512: 860261f973ec7aec8d3051632be8154d87854df8a604ef10b9171701f132c4ba9855ca97fc6e2d529ba322a8100e1e160d5d0f2afe558158bde89979815b5246
  • Loading branch information
laanwj committed Jan 26, 2019
2 parents 2fc1148 + f8e797a commit f545dfa
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions util/env_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,24 +203,16 @@ class Win32Env : public Env

void ToWidePath(const std::string& value, std::wstring& target) {
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;
}

void ToNarrowPath(const std::wstring& value, std::string& target) {
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;
}

std::string GetCurrentDir()
{
CHAR path[MAX_PATH];
::GetModuleFileNameA(::GetModuleHandleA(NULL),path,MAX_PATH);
*strrchr(path,'\\') = 0;
return std::string(path);
}

std::wstring GetCurrentDirW()
{
WCHAR path[MAX_PATH];
Expand All @@ -229,6 +221,13 @@ std::wstring GetCurrentDirW()
return std::wstring(path);
}

std::string GetCurrentDir()
{
std::string path;
ToNarrowPath(GetCurrentDirW(), path);
return path;
}

std::string& ModifyPath(std::string& path)
{
if(path[0] == '/' || path[0] == '\\'){
Expand Down

0 comments on commit f545dfa

Please sign in to comment.