Revert "Update host.cpp"

This reverts commit e414c95d9bb732488085b43020ed98988cdb0a7b.

Reapply "Update host.cpp"

This reverts commit b9c986c136963ba00908a1e472b1d568dae68989.

Revert "Update host.cpp"

This reverts commit e414c95d9bb732488085b43020ed98988cdb0a7b.
This commit is contained in:
恍兮惚兮 2024-05-12 14:16:21 +08:00
parent c6fb89599a
commit 9d24674326
4 changed files with 15 additions and 18 deletions

View File

@ -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){

View File

@ -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)
{

View File

@ -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<std::wstring> 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<bool(ThreadParam)> removeIf)
{
std::vector<TextThread*> 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);
}

View File

@ -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);