From 0d9976b0c4d6c1414a754b68d8ca5798141b17a9 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Mon, 28 Jan 2019 07:25:58 -0500 Subject: [PATCH] fix single byte hooks --- GUI/host/textthread.cpp | 6 ++++++ GUI/host/textthread.h | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/GUI/host/textthread.cpp b/GUI/host/textthread.cpp index 7a71b31..0eed0ba 100644 --- a/GUI/host/textthread.cpp +++ b/GUI/host/textthread.cpp @@ -28,6 +28,12 @@ void TextThread::Push(const BYTE* data, int len) { if (len < 0) return; std::scoped_lock lock(bufferMutex); + + BYTE doubleByteChar[2]; + if (len == 1) // doublebyte characters must be processed as pairs + if (leadByte) std::tie(doubleByteChar[0], doubleByteChar[1], data, len, leadByte) = std::tuple(leadByte, data[0], doubleByteChar, 2, 0 ); + else if (IsDBCSLeadByteEx(hp.codepage ? hp.codepage : Host::defaultCodepage, data[0])) std::tie(leadByte, len) = std::tuple(data[0], 0); + if (hp.type & USING_UNICODE) buffer += std::wstring((wchar_t*)data, len / 2); else if (auto converted = Util::StringToWideString(std::string((char*)data, len), hp.codepage ? hp.codepage : Host::defaultCodepage)) buffer += converted.value(); else Host::AddConsoleOutput(INVALID_CODEPAGE); diff --git a/GUI/host/textthread.h b/GUI/host/textthread.h index 9c1979e..c5216fb 100644 --- a/GUI/host/textthread.h +++ b/GUI/host/textthread.h @@ -32,9 +32,10 @@ private: void Flush(); std::wstring buffer; + BYTE leadByte = 0; std::unordered_set repeatingChars; std::mutex bufferMutex; - DWORD lastPushTime; + DWORD lastPushTime = 0; ThreadSafe> queuedSentences; struct TimerDeleter { void operator()(HANDLE h) { DeleteTimerQueueTimer(NULL, h, INVALID_HANDLE_VALUE); } }; AutoHandle timer = NULL; // this needs to be last so it's destructed first