diff options
Diffstat (limited to 'src/common/Utilities/Util.cpp')
-rw-r--r-- | src/common/Utilities/Util.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/common/Utilities/Util.cpp b/src/common/Utilities/Util.cpp index 4406dc673e0..a595f654ec7 100644 --- a/src/common/Utilities/Util.cpp +++ b/src/common/Utilities/Util.cpp @@ -785,6 +785,40 @@ bool Utf8ToUpperOnlyLatin(std::string& utf8String) return WStrToUtf8(wstr, utf8String); } +#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS +bool ReadWinConsole(std::string& str, size_t size /*= 256*/) +{ + wchar_t* commandbuf = new wchar_t[size + 1]; + HANDLE hConsole = GetStdHandle(STD_INPUT_HANDLE); + DWORD read; + + if (!ReadConsoleW(hConsole, commandbuf, size, &read, NULL)) + { + delete[] commandbuf; + return false; + } + + commandbuf[read] = 0; + + bool ok = WStrToUtf8(commandbuf, wcslen(commandbuf), str); + delete[] commandbuf; + return ok; +} + +bool WriteWinConsole(std::string_view str, bool error /*= false*/) +{ + std::wstring wstr; + if (!Utf8toWStr(str, wstr)) + return false; + + HANDLE hConsole = GetStdHandle(error ? STD_ERROR_HANDLE : STD_OUTPUT_HANDLE); + DWORD toWrite = wstr.size(); + DWORD write; + + return WriteConsoleW(hConsole, wstr.c_str(), wstr.size(), &write, NULL); +} +#endif + std::string Trinity::Impl::ByteArrayToHexStr(uint8 const* bytes, size_t arrayLen, bool reverse /* = false */) { int32 init = 0; |