forked from Public-Mirror/Textractor
temporary remove regex replacement
This commit is contained in:
parent
a03c939043
commit
fcd735283d
@ -24,7 +24,6 @@ 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);
|
||||||
@ -41,21 +40,13 @@ 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|REPLACE|%s|END|\r\n",
|
L"\xfeff|PROCESS|%s|FILTER|%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));
|
||||||
}
|
}
|
||||||
@ -70,16 +61,12 @@ 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|", L"|REPLACE|" });
|
BlockMarkupIterator savedFilters(stream, Array<std::wstring_view>{ L"|PROCESS|", L"|FILTER|" });
|
||||||
std::vector<std::array<std::wstring, 3>> regexes;
|
std::vector<std::wstring> regexes;
|
||||||
while (auto read = savedFilters.Next()) if (read->at(0) == processName) regexes.push_back(std::move(read.value()));
|
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()[1]), replace = S(regexes.back()[2])]
|
if (!regexes.empty()) QMetaObject::invokeMethod(&window, std::bind(&Window::SetRegex, &window, S(regexes.back())), Qt::BlockingQueuedConnection);
|
||||||
{
|
|
||||||
window.SetRegex(regex);
|
|
||||||
window.SetReplace(replace);
|
|
||||||
}, Qt::BlockingQueuedConnection);
|
|
||||||
}
|
}
|
||||||
std::shared_lock l(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);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -16,16 +16,6 @@
|
|||||||
<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>
|
||||||
|
@ -121,7 +121,7 @@ bool ProcessSentence(std::wstring& sentence, SentenceInfo)
|
|||||||
{
|
{
|
||||||
UpdateReplacements();
|
UpdateReplacements();
|
||||||
|
|
||||||
std::shared_lock l(m);
|
std::shared_lock lock(m);
|
||||||
sentence = trie.Replace(sentence);
|
sentence = trie.Replace(sentence);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ private:
|
|||||||
|
|
||||||
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
|
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
|
||||||
{
|
{
|
||||||
std::shared_lock l(m);
|
std::shared_lock lock(m);
|
||||||
int64_t textHandle = sentenceInfo["text number"];
|
int64_t textHandle = sentenceInfo["text number"];
|
||||||
|
|
||||||
for (auto linkedHandle : linkedTextHandles[textHandle])
|
for (auto linkedHandle : linkedTextHandles[textHandle])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user