From b4b26d50ca8eb25cb2146bcf9d274717235e0517 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Mon, 2 Mar 2020 23:49:31 -0700 Subject: [PATCH] attach to current process --- extensions/regexfilter.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/extensions/regexfilter.cpp b/extensions/regexfilter.cpp index 7391bdc..7a8f187 100644 --- a/extensions/regexfilter.cpp +++ b/extensions/regexfilter.cpp @@ -13,7 +13,7 @@ const char* REGEX_SAVE_FILE = "SavedRegexFilters.txt"; std::optional regex; std::shared_mutex m; -std::atomic selectedProcessId; +DWORD (*GetSelectedProcessId)() = nullptr; class Window : public QMainWindow { @@ -44,7 +44,7 @@ private: { auto formatted = FormatString( L"\xfeff|PROCESS|%s|FILTER|%s|END|\r\n", - GetModuleFilename(selectedProcessId.load()).value_or(FormatString(L"Error getting name of process 0x%X", selectedProcessId.load())), + GetModuleFilename(GetSelectedProcessId()).value_or(FormatString(L"Error getting name of process 0x%X", GetSelectedProcessId())), S(ui.input->text()) ); std::ofstream(REGEX_SAVE_FILE, std::ios::binary | std::ios::app).write((const char*)formatted.c_str(), formatted.size() * sizeof(wchar_t)); @@ -55,18 +55,15 @@ private: bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo) { + static auto _ = GetSelectedProcessId = (DWORD(*)())sentenceInfo["DWORD (*GetSelectedProcessId)()"]; if (sentenceInfo["text number"] == 0) return false; - if (sentenceInfo["current select"]) + if (sentenceInfo["current select"] && !regex) if (auto processName = GetModuleFilename(sentenceInfo["process id"])) { - selectedProcessId = sentenceInfo["process id"]; - if (!regex) if (auto processName = GetModuleFilename(sentenceInfo["process id"])) - { - std::ifstream stream(REGEX_SAVE_FILE, std::ios::binary); - BlockMarkupIterator savedFilters(stream, Array{ L"|PROCESS|", L"|FILTER|" }); - std::vector regexes; - while (auto read = savedFilters.Next()) if (read->at(0) == processName) regexes.push_back(std::move(read->at(1))); - if (!regexes.empty()) QMetaObject::invokeMethod(&window, [regex = S(regexes.back())]{ window.setRegex(regex); }, Qt::BlockingQueuedConnection); - } + std::ifstream stream(REGEX_SAVE_FILE, std::ios::binary); + BlockMarkupIterator savedFilters(stream, Array{ L"|PROCESS|", L"|FILTER|" }); + std::vector regexes; + while (auto read = savedFilters.Next()) if (read->at(0) == processName) regexes.push_back(std::move(read->at(1))); + if (!regexes.empty()) QMetaObject::invokeMethod(&window, [regex = S(regexes.back())] { window.setRegex(regex); }, Qt::BlockingQueuedConnection); } std::shared_lock l(m); if (regex) sentence = std::regex_replace(sentence, regex.value(), L"");