From 103c805cfe2ccc104cd60c30e53715bbcfeaa816 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Sat, 5 Jan 2019 03:47:32 -0500 Subject: [PATCH] always use codepage when searching --- GUI/host/host.h | 2 ++ GUI/host/textthread.cpp | 2 +- GUI/host/textthread.h | 4 ++-- GUI/mainwindow.cpp | 4 ++-- GUI/misc.cpp | 5 +++++ 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/GUI/host/host.h b/GUI/host/host.h index 52c001d..fa6e1ef 100644 --- a/GUI/host/host.h +++ b/GUI/host/host.h @@ -16,4 +16,6 @@ namespace Host std::shared_ptr GetThread(ThreadParam tp); void AddConsoleOutput(std::wstring text); + + inline int defaultCodepage = SHIFT_JIS; } diff --git a/GUI/host/textthread.cpp b/GUI/host/textthread.cpp index bd870e5..7ce96be 100644 --- a/GUI/host/textthread.cpp +++ b/GUI/host/textthread.cpp @@ -29,7 +29,7 @@ void TextThread::Push(const BYTE* data, int len) if (len < 0) return; LOCK(bufferMutex); if (hp.type & USING_UNICODE) buffer += std::wstring((wchar_t*)data, len / 2); - else if (auto converted = Util::StringToWideString(std::string((char*)data, len), hp.codepage ? hp.codepage : defaultCodepage)) buffer += converted.value(); + else if (auto converted = Util::StringToWideString(std::string((char*)data, len), hp.codepage ? hp.codepage : Host::defaultCodepage)) buffer += converted.value(); else Host::AddConsoleOutput(INVALID_CODEPAGE); lastPushTime = GetTickCount(); diff --git a/GUI/host/textthread.h b/GUI/host/textthread.h index 43c5fe2..3100786 100644 --- a/GUI/host/textthread.h +++ b/GUI/host/textthread.h @@ -13,8 +13,6 @@ public: inline static int flushDelay = 400; // flush every 400ms by default inline static int maxBufferSize = 1000; - inline static int defaultCodepage = SHIFT_JIS; - inline static int threadCounter = 0; TextThread(ThreadParam tp, HookParam hp, std::optional name = {}); ~TextThread(); @@ -29,6 +27,8 @@ public: const HookParam hp; private: + inline static int threadCounter = 0; + void Flush(); struct TimerDeleter { void operator()(void* h) { DeleteTimerQueueTimer(NULL, h, INVALID_HANDLE_VALUE); } }; diff --git a/GUI/mainwindow.cpp b/GUI/mainwindow.cpp index ff8f59e..c0423d1 100644 --- a/GUI/mainwindow.cpp +++ b/GUI/mainwindow.cpp @@ -40,7 +40,7 @@ MainWindow::MainWindow(QWidget *parent) : setGeometry(settings.value(WINDOW, geometry()).toRect()); TextThread::flushDelay = settings.value(FLUSH_DELAY, TextThread::flushDelay).toInt(); TextThread::maxBufferSize = settings.value(MAX_BUFFER_SIZE, TextThread::maxBufferSize).toInt(); - TextThread::defaultCodepage = settings.value(DEFAULT_CODEPAGE, TextThread::defaultCodepage).toInt(); + Host::defaultCodepage = settings.value(DEFAULT_CODEPAGE, Host::defaultCodepage).toInt(); Host::Start( [this](DWORD processId) { ProcessConnected(processId); }, @@ -242,7 +242,7 @@ void MainWindow::Settings() save->setText(SAVE_SETTINGS); layout->addWidget(save); for (auto[value, label] : Array>{ - { TextThread::defaultCodepage, DEFAULT_CODEPAGE }, + { Host::defaultCodepage, DEFAULT_CODEPAGE }, { TextThread::maxBufferSize, MAX_BUFFER_SIZE }, { TextThread::flushDelay, FLUSH_DELAY }, }) diff --git a/GUI/misc.cpp b/GUI/misc.cpp index 6db111a..2d8a280 100644 --- a/GUI/misc.cpp +++ b/GUI/misc.cpp @@ -1,6 +1,7 @@ #include "misc.h" #include "const.h" #include "defs.h" +#include "host/host.h" #include "host/util.h" #include #include @@ -65,6 +66,10 @@ namespace hp.codepage = codepage.captured(1).toInt(); SCode.remove(0, codepage.captured(0).length()); } + else + { + hp.codepage = Host::defaultCodepage; + } wcscpy_s(hp.text, S(SCode).c_str());