refactor extension code and add error handling
This commit is contained in:
parent
a978df2655
commit
ca749691f8
@ -26,7 +26,7 @@ std::map<int, QString> LoadExtensions()
|
||||
return extensionNames;
|
||||
}
|
||||
|
||||
std::wstring DispatchSentenceToExtensions(std::wstring sentence, std::unordered_map<std::string, int> miscInfo)
|
||||
bool DispatchSentenceToExtensions(std::wstring& sentence, std::unordered_map<std::string, int> miscInfo)
|
||||
{
|
||||
wchar_t* sentenceBuffer = (wchar_t*)malloc((sentence.size() + 1) * sizeof(wchar_t));
|
||||
wcscpy(sentenceBuffer, sentence.c_str());
|
||||
@ -34,15 +34,19 @@ std::wstring DispatchSentenceToExtensions(std::wstring sentence, std::unordered_
|
||||
InfoForExtension* miscInfoTraverser = miscInfoLinkedList;
|
||||
for (auto& i : miscInfo) miscInfoTraverser = miscInfoTraverser->nextProperty = new InfoForExtension{ i.first.c_str(), i.second, nullptr };
|
||||
extenMutex.lock_shared();
|
||||
for (auto i : extensions)
|
||||
try
|
||||
{
|
||||
wchar_t* prev = sentenceBuffer;
|
||||
sentenceBuffer = i.second(sentenceBuffer, miscInfoLinkedList);
|
||||
if (sentenceBuffer != prev) free((void*)prev);
|
||||
for (auto i : extensions)
|
||||
{
|
||||
wchar_t* prev = sentenceBuffer;
|
||||
sentenceBuffer = i.second(sentenceBuffer, miscInfoLinkedList);
|
||||
if (sentenceBuffer != prev) free((void*)prev);
|
||||
}
|
||||
}
|
||||
catch (...) { sentenceBuffer[0] = 0; }
|
||||
extenMutex.unlock_shared();
|
||||
delete miscInfoLinkedList;
|
||||
std::wstring newSentence = std::wstring(sentenceBuffer);
|
||||
sentence = std::wstring(sentenceBuffer);
|
||||
free((void*)sentenceBuffer);
|
||||
return newSentence;
|
||||
return sentence.size() > 0;
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <map>
|
||||
|
||||
std::map<int, QString> LoadExtensions();
|
||||
std::wstring DispatchSentenceToExtensions(std::wstring sentence, std::unordered_map<std::string, int> miscInfo);
|
||||
bool DispatchSentenceToExtensions(std::wstring& sentence, std::unordered_map<std::string, int> miscInfo);
|
||||
struct InfoForExtension
|
||||
{
|
||||
~InfoForExtension() { if (nextProperty) delete nextProperty; };
|
||||
|
@ -84,9 +84,11 @@ void MainWindow::AddThread(TextThread* thread)
|
||||
);
|
||||
thread->RegisterOutputCallBack([&](TextThread* thread, std::wstring output)
|
||||
{
|
||||
output = DispatchSentenceToExtensions(output, GetInfoForExtensions(thread));
|
||||
output += L"\r\n";
|
||||
emit SigThreadOutput(thread, QString::fromStdWString(output));
|
||||
if (DispatchSentenceToExtensions(output, GetInfoForExtensions(thread)))
|
||||
{
|
||||
output += L"\r\n";
|
||||
emit SigThreadOutput(thread, QString::fromStdWString(output));
|
||||
}
|
||||
return output;
|
||||
});
|
||||
}
|
||||
@ -150,7 +152,8 @@ std::unordered_map<std::string, int> MainWindow::GetInfoForExtensions(TextThread
|
||||
{ "text number", 0 },
|
||||
{ "process id", thread->GetThreadParam().pid },
|
||||
{ "hook address", (int)thread->GetThreadParam().hook },
|
||||
{ "hook address (upper 32 bits)", (int)(thread->GetThreadParam().hook >> 32) }
|
||||
{ "hook address (upper 32 bits)", (int)(thread->GetThreadParam().hook >> 32) },
|
||||
{ "text handle", (int)thread }
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user