Skip to content

Commit

Permalink
Use utf-8 to decode filename
Browse files Browse the repository at this point in the history
  • Loading branch information
ken2812221 committed Jan 22, 2019
1 parent 2fc1148 commit f8e797a
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 f8e797a

Please sign in to comment.