Compare commits

...

1 Commits

Author SHA1 Message Date
Akash Mozumdar
70843acfce Revert "temporary remove regex replacement"
This reverts commit fcd735283de751dc1c5b13701a55fb5b6961ac69.
2021-01-30 23:57:42 -07:00
2 changed files with 29 additions and 6 deletions

View File

@ -24,6 +24,7 @@ public:
ui.setupUi(this); ui.setupUi(this);
connect(ui.regexEdit, &QLineEdit::textEdited, this, &Window::SetRegex); connect(ui.regexEdit, &QLineEdit::textEdited, this, &Window::SetRegex);
connect(ui.replaceEdit, &QLineEdit::textEdited, this, &Window::SetReplace);
connect(ui.saveButton, &QPushButton::clicked, this, &Window::Save); connect(ui.saveButton, &QPushButton::clicked, this, &Window::Save);
setWindowTitle(REGEX_FILTER); setWindowTitle(REGEX_FILTER);
@ -40,13 +41,21 @@ public:
ui.output->setText(QString(CURRENT_FILTER).arg(regex)); ui.output->setText(QString(CURRENT_FILTER).arg(regex));
} }
void SetReplace(QString replace)
{
ui.replaceEdit->setText(replace);
std::scoped_lock lock(m);
::replace = S(replace);
}
private: private:
void Save() void Save()
{ {
auto formatted = FormatString( auto formatted = FormatString(
L"\xfeff|PROCESS|%s|FILTER|%s|END|\r\n", L"\xfeff|PROCESS|%s|FILTER|%s|REPLACE|%s|END|\r\n",
GetModuleFilename(GetSelectedProcessId()).value_or(FormatString(L"Error getting name of process 0x%X", GetSelectedProcessId())), GetModuleFilename(GetSelectedProcessId()).value_or(FormatString(L"Error getting name of process 0x%X", GetSelectedProcessId())),
S(ui.regexEdit->text()) S(ui.regexEdit->text()),
S(ui.replaceEdit->text())
); );
std::ofstream(REGEX_SAVE_FILE, std::ios::binary | std::ios::app).write((const char*)formatted.c_str(), formatted.size() * sizeof(wchar_t)); std::ofstream(REGEX_SAVE_FILE, std::ios::binary | std::ios::app).write((const char*)formatted.c_str(), formatted.size() * sizeof(wchar_t));
} }
@ -61,10 +70,14 @@ bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
if (sentenceInfo["current select"] && !regex) if (auto processName = GetModuleFilename(sentenceInfo["process id"])) if (sentenceInfo["current select"] && !regex) if (auto processName = GetModuleFilename(sentenceInfo["process id"]))
{ {
std::ifstream stream(REGEX_SAVE_FILE, std::ios::binary); std::ifstream stream(REGEX_SAVE_FILE, std::ios::binary);
BlockMarkupIterator savedFilters(stream, Array<std::wstring_view>{ L"|PROCESS|", L"|FILTER|" }); BlockMarkupIterator savedFilters(stream, Array<std::wstring_view>{ L"|PROCESS|", L"|FILTER|", L"|REPLACE|" });
std::vector<std::wstring> regexes; std::vector<std::array<std::wstring, 3>> regexes;
while (auto read = savedFilters.Next()) if (read->at(0) == processName) regexes.push_back(std::move(read->at(1))); while (auto read = savedFilters.Next()) if (read->at(0) == processName) regexes.push_back(std::move(read.value()));
if (!regexes.empty()) QMetaObject::invokeMethod(&window, std::bind(&Window::SetRegex, &window, S(regexes.back())), Qt::BlockingQueuedConnection); if (!regexes.empty()) QMetaObject::invokeMethod(&window, [regex = S(regexes.back()[1]), replace = S(regexes.back()[2])]
{
window.SetRegex(regex);
window.SetReplace(replace);
}, Qt::BlockingQueuedConnection);
} }
std::shared_lock lock(m); std::shared_lock lock(m);
if (regex) sentence = std::regex_replace(sentence, regex.value(), replace); if (regex) sentence = std::regex_replace(sentence, regex.value(), replace);

View File

@ -16,6 +16,16 @@
<item> <item>
<widget class="QLineEdit" name="regexEdit"/> <widget class="QLineEdit" name="regexEdit"/>
</item> </item>
<item>
<widget class="QLabel">
<property name="text">
<string>=></string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="replaceEdit"/>
</item>
</layout> </layout>
</item> </item>
<item> <item>