forked from Public-Mirror/Textractor
rename
This commit is contained in:
parent
96f235732c
commit
9415e83511
@ -65,13 +65,13 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
bool DispatchSentenceToExtensions(std::wstring& sentence, const InfoForExtension* miscInfo)
|
||||
bool DispatchSentenceToExtensions(std::wstring& sentence, const InfoForExtension* sentenceInfo)
|
||||
{
|
||||
wchar_t* sentenceBuffer = (wchar_t*)HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, (sentence.size() + 1) * sizeof(wchar_t));
|
||||
wcscpy_s(sentenceBuffer, sentence.size() + 1, sentence.c_str());
|
||||
concurrency::reader_writer_lock::scoped_lock_read readLock(extenMutex);
|
||||
for (const auto& extension : extensions)
|
||||
if (*(sentenceBuffer = extension.callback(sentenceBuffer, miscInfo)) == L'\0') break;
|
||||
if (*(sentenceBuffer = extension.callback(sentenceBuffer, sentenceInfo)) == L'\0') break;
|
||||
sentence = sentenceBuffer;
|
||||
HeapFree(GetProcessHeap(), 0, sentenceBuffer);
|
||||
return !sentence.empty();
|
||||
|
@ -13,7 +13,7 @@ struct InfoForExtension
|
||||
int64_t value;
|
||||
};
|
||||
|
||||
bool DispatchSentenceToExtensions(std::wstring& sentence, const InfoForExtension* miscInfo);
|
||||
bool DispatchSentenceToExtensions(std::wstring& sentence, const InfoForExtension* sentenceInfo);
|
||||
void CleanupExtensions(); // must call this before exiting the program, only way to uphold guarantee that DllMain and OnNewSentence won't be called concurrently
|
||||
|
||||
class ExtenWindow : public QMainWindow
|
||||
|
@ -208,7 +208,7 @@ void MainWindow::ThreadRemoved(TextThread& thread)
|
||||
|
||||
bool MainWindow::SentenceReceived(TextThread& thread, std::wstring& sentence)
|
||||
{
|
||||
if (!DispatchSentenceToExtensions(sentence, GetMiscInfo(thread).data())) return false;
|
||||
if (!DispatchSentenceToExtensions(sentence, GetSentenceInfo(thread).data())) return false;
|
||||
sentence += L'\n';
|
||||
if (current == &thread) QMetaObject::invokeMethod(this, [this, sentence]
|
||||
{
|
||||
@ -248,7 +248,7 @@ DWORD MainWindow::GetSelectedProcessId()
|
||||
return ui->processCombo->currentText().split(":")[0].toULong(nullptr, 16);
|
||||
}
|
||||
|
||||
std::array<InfoForExtension, 10> MainWindow::GetMiscInfo(TextThread& thread)
|
||||
std::array<InfoForExtension, 10> MainWindow::GetSentenceInfo(TextThread& thread)
|
||||
{
|
||||
void(*AddSentence)(MainWindow*, int64_t, const wchar_t*) = [](MainWindow* This, int64_t number, const wchar_t* sentence)
|
||||
{
|
||||
|
@ -31,7 +31,7 @@ private:
|
||||
QString TextThreadString(TextThread& thread);
|
||||
ThreadParam ParseTextThreadString(QString ttString);
|
||||
DWORD GetSelectedProcessId();
|
||||
std::array<InfoForExtension, 10> GetMiscInfo(TextThread& thread);
|
||||
std::array<InfoForExtension, 10> GetSentenceInfo(TextThread& thread);
|
||||
std::optional<std::wstring> UserSelectedProcess();
|
||||
void AttachProcess();
|
||||
void LaunchProcess();
|
||||
|
@ -8,18 +8,18 @@ bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo);
|
||||
This can be modified. Textractor uses the modified sentence for future processing and display. If empty (starts with null terminator), Textractor will destroy it.
|
||||
Textractor will display the sentence after all extensions have had a chance to process and/or modify it.
|
||||
The buffer is allocated using HeapAlloc(). If you want to make it larger, please use HeapReAlloc().
|
||||
Param miscInfo: pointer to array containing misc info about the sentence. End of array is marked with name being nullptr.
|
||||
Param sentenceInfo: pointer to array containing misc info about the sentence. End of array is marked with name being nullptr.
|
||||
Return value: the buffer used for the sentence. Remember to return a new pointer if HeapReAlloc() gave you one.
|
||||
This function may be run concurrently with itself: please make sure it's thread safe.
|
||||
It will not be run concurrently with DllMain.
|
||||
*/
|
||||
extern "C" __declspec(dllexport) wchar_t* OnNewSentence(wchar_t* sentence, const InfoForExtension* miscInfo)
|
||||
extern "C" __declspec(dllexport) wchar_t* OnNewSentence(wchar_t* sentence, const InfoForExtension* sentenceInfo)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::wstring sentenceStr(sentence);
|
||||
int origLength = sentenceStr.size();
|
||||
if (ProcessSentence(sentenceStr, SentenceInfo{ miscInfo }))
|
||||
if (ProcessSentence(sentenceStr, SentenceInfo{ sentenceInfo }))
|
||||
{
|
||||
if (sentenceStr.size() > origLength) sentence = (wchar_t*)HeapReAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, sentence, (sentenceStr.size() + 1) * sizeof(wchar_t));
|
||||
wcscpy_s(sentence, sentenceStr.size() + 1, sentenceStr.c_str());
|
||||
|
Loading…
x
Reference in New Issue
Block a user