fix single byte hooks

This commit is contained in:
Akash Mozumdar 2019-01-28 07:25:58 -05:00
parent 4e9df97991
commit 0d9976b0c4
2 changed files with 8 additions and 1 deletions

View File

@ -28,6 +28,12 @@ void TextThread::Push(const BYTE* data, int len)
{ {
if (len < 0) return; if (len < 0) return;
std::scoped_lock lock(bufferMutex); 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); 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 if (auto converted = Util::StringToWideString(std::string((char*)data, len), hp.codepage ? hp.codepage : Host::defaultCodepage)) buffer += converted.value();
else Host::AddConsoleOutput(INVALID_CODEPAGE); else Host::AddConsoleOutput(INVALID_CODEPAGE);

View File

@ -32,9 +32,10 @@ private:
void Flush(); void Flush();
std::wstring buffer; std::wstring buffer;
BYTE leadByte = 0;
std::unordered_set<wchar_t> repeatingChars; std::unordered_set<wchar_t> repeatingChars;
std::mutex bufferMutex; std::mutex bufferMutex;
DWORD lastPushTime; DWORD lastPushTime = 0;
ThreadSafe<std::vector<std::wstring>> queuedSentences; ThreadSafe<std::vector<std::wstring>> queuedSentences;
struct TimerDeleter { void operator()(HANDLE h) { DeleteTimerQueueTimer(NULL, h, INVALID_HANDLE_VALUE); } }; struct TimerDeleter { void operator()(HANDLE h) { DeleteTimerQueueTimer(NULL, h, INVALID_HANDLE_VALUE); } };
AutoHandle<TimerDeleter> timer = NULL; // this needs to be last so it's destructed first AutoHandle<TimerDeleter> timer = NULL; // this needs to be last so it's destructed first