2018-12-17 20:48:14 -05:00
|
|
|
#include "extension.h"
|
2019-06-03 19:29:37 -04:00
|
|
|
#include "ui_regexfilter.h"
|
2018-12-17 20:48:14 -05:00
|
|
|
#include <QTimer>
|
|
|
|
|
2019-02-27 11:33:17 -05:00
|
|
|
extern const char* REGEX_FILTER;
|
|
|
|
extern const char* INVALID_REGEX;
|
|
|
|
extern const char* CURRENT_FILTER;
|
|
|
|
|
2018-12-17 20:48:14 -05:00
|
|
|
std::wregex regex;
|
2019-01-23 13:59:34 -05:00
|
|
|
std::shared_mutex m;
|
2018-12-17 20:48:14 -05:00
|
|
|
|
2018-12-21 14:18:43 -05:00
|
|
|
struct : QMainWindow
|
|
|
|
{
|
2018-12-21 15:11:12 -05:00
|
|
|
void launch()
|
2018-12-17 20:48:14 -05:00
|
|
|
{
|
2019-06-03 19:29:37 -04:00
|
|
|
ui.setupUi(this);
|
|
|
|
connect(ui.input, &QLineEdit::textEdited, [=](QString newRegex)
|
2018-12-17 20:48:14 -05:00
|
|
|
{
|
|
|
|
std::lock_guard l(m);
|
|
|
|
try { regex = newRegex.toStdWString(); }
|
2019-06-09 07:33:26 -04:00
|
|
|
catch (std::regex_error) { return ui.output->setText(INVALID_REGEX); }
|
2019-06-03 19:29:37 -04:00
|
|
|
ui.output->setText(QString(CURRENT_FILTER).arg(newRegex));
|
2018-12-17 20:48:14 -05:00
|
|
|
});
|
2018-12-21 14:18:43 -05:00
|
|
|
setWindowTitle(REGEX_FILTER);
|
|
|
|
show();
|
2018-12-17 20:48:14 -05:00
|
|
|
}
|
2019-06-03 19:29:37 -04:00
|
|
|
|
|
|
|
Ui::FilterWindow ui;
|
2018-12-17 20:48:14 -05:00
|
|
|
}*window = nullptr;
|
|
|
|
|
|
|
|
BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
|
|
|
|
{
|
|
|
|
switch (ul_reason_for_call)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
{
|
2018-12-18 12:15:18 -05:00
|
|
|
QTimer::singleShot(0, []
|
|
|
|
{
|
|
|
|
std::lock_guard l(m);
|
2018-12-21 15:11:12 -05:00
|
|
|
(window = new std::remove_pointer_t<decltype(window)>)->launch();
|
2018-12-18 12:15:18 -05:00
|
|
|
});
|
2018-12-17 20:48:14 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DLL_PROCESS_DETACH:
|
|
|
|
{
|
|
|
|
if (lpReserved == NULL) // https://blogs.msdn.microsoft.com/oldnewthing/20120105-00/?p=8683
|
|
|
|
{
|
2018-12-18 12:15:18 -05:00
|
|
|
std::lock_guard l(m);
|
2018-12-17 20:48:14 -05:00
|
|
|
delete window;
|
|
|
|
window = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
|
|
|
|
{
|
2019-01-23 13:59:34 -05:00
|
|
|
std::shared_lock l(m);
|
2019-02-21 13:09:44 -05:00
|
|
|
if (sentenceInfo["text number"] == 0) return false;
|
2018-12-17 20:48:14 -05:00
|
|
|
sentence = std::regex_replace(sentence, regex, L"");
|
|
|
|
return true;
|
|
|
|
}
|