diff options
author | Riccardo Spagni <ric@spagni.net> | 2018-10-05 23:12:42 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2018-10-06 11:15:43 +0200 |
commit | 9556ba0d66bd1ec76d15feaadee8e10355912497 (patch) | |
tree | 120d691a64d2014a60a481ee46bc73f08223da9d /src/common/util.cpp | |
parent | Merge pull request #4492 (diff) | |
download | monero-9556ba0d66bd1ec76d15feaadee8e10355912497.tar.xz |
Merge pull request #4390
a0613532 secure_pwd_reader: Add proper Unicode handling [Ryo contribution] (fireice-uk)
579383c2 simplewallet: Add Unicode input_line [Ryo backport] (fireice-uk)
Diffstat (limited to 'src/common/util.cpp')
-rw-r--r-- | src/common/util.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/common/util.cpp b/src/common/util.cpp index c56c77505..2a1d49af0 100644 --- a/src/common/util.cpp +++ b/src/common/util.cpp @@ -939,4 +939,32 @@ std::string get_nix_version_display_string() } return newval; } + +#ifdef _WIN32 + std::string input_line_win() + { + HANDLE hConIn = CreateFileW(L"CONIN$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, 0, nullptr); + DWORD oldMode; + + FlushConsoleInputBuffer(hConIn); + GetConsoleMode(hConIn, &oldMode); + SetConsoleMode(hConIn, ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT); + + wchar_t buffer[1024]; + DWORD read; + + ReadConsoleW(hConIn, buffer, sizeof(buffer)/sizeof(wchar_t)-1, &read, nullptr); + buffer[read] = 0; + + SetConsoleMode(hConIn, oldMode); + CloseHandle(hConIn); + + int size_needed = WideCharToMultiByte(CP_UTF8, 0, buffer, -1, NULL, 0, NULL, NULL); + std::string buf(size_needed, '\0'); + WideCharToMultiByte(CP_UTF8, 0, buffer, -1, &buf[0], size_needed, NULL, NULL); + buf.pop_back(); //size_needed includes null that we needed to have space for + return buf; + } +#endif + } |