From 9711ce94c999b939534f61876ff5eecacdcaeef2 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Sat, 25 Apr 2020 20:34:53 -0600 Subject: [PATCH] thread linker doesn't append sentences anymore --- GUI/host/textthread.cpp | 8 ++++++++ GUI/host/textthread.h | 1 + GUI/mainwindow.cpp | 5 +++++ extensions/threadlinker.cpp | 2 +- 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/GUI/host/textthread.cpp b/GUI/host/textthread.cpp index 0740a64..7a70c4a 100644 --- a/GUI/host/textthread.cpp +++ b/GUI/host/textthread.cpp @@ -70,6 +70,14 @@ void TextThread::Push(BYTE* data, int length) } } +void TextThread::Push(const wchar_t* data) +{ + std::scoped_lock lock(bufferMutex); + // not sure if this should filter repetition + lastPushTime = GetTickCount(); + buffer += data; +} + void TextThread::Flush() { { diff --git a/GUI/host/textthread.h b/GUI/host/textthread.h index 7171c78..c796561 100644 --- a/GUI/host/textthread.h +++ b/GUI/host/textthread.h @@ -19,6 +19,7 @@ public: void Stop(); void AddSentence(std::wstring sentence); void Push(BYTE* data, int length); + void Push(const wchar_t* data); Synchronized storage; const int64_t handle; diff --git a/GUI/mainwindow.cpp b/GUI/mainwindow.cpp index 3bc8289..303df32 100644 --- a/GUI/mainwindow.cpp +++ b/GUI/mainwindow.cpp @@ -105,6 +105,10 @@ namespace std::array GetSentenceInfo(TextThread& thread) { + void (*AddText)(int64_t, const wchar_t*) = [](int64_t number, const wchar_t* text) + { + QMetaObject::invokeMethod(This, [number, text = std::wstring(text)] { if (TextThread* thread = Host::GetThread(number)) thread->Push(text.c_str()); }); + }; void (*AddSentence)(int64_t, const wchar_t*) = [](int64_t number, const wchar_t* sentence) { // pointer from Host::GetThread may not stay valid unless on main thread @@ -121,6 +125,7 @@ namespace { "text handle", thread.handle }, { "text name", (int64_t)thread.name.c_str() }, { "void (*AddSentence)(int64_t number, const wchar_t* sentence)", (int64_t)AddSentence }, + { "void (*AddText)(int64_t number, const wchar_t* text)", (int64_t)AddText }, { "DWORD (*GetSelectedProcessId)()", (int64_t)GetSelectedProcessId }, { nullptr, 0 } // nullptr marks end of info array } }; diff --git a/extensions/threadlinker.cpp b/extensions/threadlinker.cpp index 5ed95b1..1414536 100644 --- a/extensions/threadlinker.cpp +++ b/extensions/threadlinker.cpp @@ -62,7 +62,7 @@ bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo) int64_t textHandle = sentenceInfo["text number"]; for (auto linkedHandle : linkedTextHandles[textHandle]) - ((void(*)(int64_t, const wchar_t*))sentenceInfo["void (*AddSentence)(int64_t number, const wchar_t* sentence)"])(linkedHandle, sentence.c_str()); + ((void(*)(int64_t, const wchar_t*))sentenceInfo["void (*AddText)(int64_t number, const wchar_t* text)"])(linkedHandle, sentence.c_str()); return false; }