diff --git a/LunaHost/GUI/LunaHost.cpp b/LunaHost/GUI/LunaHost.cpp index ead42d5..5ff1ee4 100644 --- a/LunaHost/GUI/LunaHost.cpp +++ b/LunaHost/GUI/LunaHost.cpp @@ -410,7 +410,6 @@ bool LunaHost::on_text_recv(TextThread& thread, std::wstring& output){ if(currentselect==thread.handle){ showtext(output,false); } - output+=L'\n'; return true; } void LunaHost::on_thread_create(TextThread& thread){ diff --git a/LunaHost/LunaHostDll.cpp b/LunaHost/LunaHostDll.cpp index f715a6d..b0cf053 100644 --- a/LunaHost/LunaHostDll.cpp +++ b/LunaHost/LunaHostDll.cpp @@ -43,12 +43,7 @@ C_LUNA_API void Luna_Start(ProcessEvent Connect, ProcessEvent Disconnect, Thread [=](TextThread &thread, std::wstring &output) { XXXX - if(Output(hookcode, name, thread.tp, output.c_str())) - { - output+=L'\n'; - return true; - } - else return false; + return Output(hookcode, name, thread.tp, output.c_str()); }, [=](std::wstring &output) { diff --git a/LunaHost/host.cpp b/LunaHost/host.cpp index 3c694ed..e3b668d 100644 --- a/LunaHost/host.cpp +++ b/LunaHost/host.cpp @@ -67,6 +67,16 @@ namespace Host::ConsoleHandler OnConsole=0; Host::HookInsertHandler HookInsert=0; Host::EmbedCallback embedcallback=0; + bool CreateThread(const ThreadParam& tp, const HookParam& hp,std::optional name){ + auto thread = textThreadsByParams->find(tp); + if (thread == textThreadsByParams->end()) + { + try { thread = textThreadsByParams->try_emplace(tp, tp, hp ,name ).first; } + catch (std::out_of_range) { return false; } // probably garbage data in pipe, try again + OnCreate(thread->second); + } + return true; + } void RemoveThreads(std::function removeIf) { std::vector threadsToRemove; @@ -158,14 +168,9 @@ namespace auto data=(TextOutput_T*)buffer; auto length= bytesRead - sizeof(TextOutput_T); auto tp = data->tp; - auto textThreadsByParams = ::textThreadsByParams.Acquire(); + if(!CreateThread(tp,processRecordsByIds->at(tp.processId).GetHook(tp.addr).hp,{})) + continue; auto thread = textThreadsByParams->find(tp); - if (thread == textThreadsByParams->end()) - { - try { thread = textThreadsByParams->try_emplace(tp, tp, processRecordsByIds->at(tp.processId).GetHook(tp.addr).hp).first; } - catch (std::out_of_range) { continue; } // probably garbage data in pipe, try again - OnCreate(thread->second); - } thread->second.hp.type=data->type; thread->second.Push(data->data, length); @@ -204,10 +209,8 @@ namespace Host OnDestroy = [=](TextThread& thread) {thread.Stop(); {std::lock_guard _(syncmutex); Destroy(thread);} }; TextThread::Output = [=](auto &&...args){std::lock_guard _(syncmutex);return Output(args...);}; - textThreadsByParams->try_emplace(console, console, HookParam{}, CONSOLE); - if(createconsole){ - OnCreate(GetThread(console)); + CreateThread(console,HookParam{},CONSOLE); Host::AddConsoleOutput(ProjectHomePage); } diff --git a/LunaHost/textthread.cpp b/LunaHost/textthread.cpp index 6700f53..af5292e 100644 --- a/LunaHost/textthread.cpp +++ b/LunaHost/textthread.cpp @@ -106,7 +106,7 @@ void TextThread::Flush() { totalSize += sentence.size(); sentence.erase(std::remove(sentence.begin(), sentence.end(), 0), sentence.end()); - if (Output(*this, sentence)) storage->append(sentence); + if (Output(*this, sentence)) storage->append(sentence+L"\n"); } std::scoped_lock lock(bufferMutex);