let user change max buffer size

This commit is contained in:
Akash Mozumdar 2018-09-23 22:29:33 -04:00
parent e31c9563ef
commit d2c9e5a6f5
4 changed files with 9 additions and 8 deletions

View File

@ -27,7 +27,7 @@ void TextThread::Flush()
std::wstring sentence; std::wstring sentence;
{ {
LOCK(ttMutex); LOCK(ttMutex);
if (buffer.size() < 400 && (GetTickCount() - timestamp < FlushDelay || buffer.size() < 2)) return; if (buffer.size() < MaxBufferSize && (GetTickCount() - timestamp < FlushDelay || buffer.size() < 2)) return;
sentence = status & USING_UNICODE sentence = status & USING_UNICODE
? std::wstring((wchar_t*)buffer.data(), buffer.size() / 2) ? std::wstring((wchar_t*)buffer.data(), buffer.size() / 2)
: StringToWideString(std::string(buffer.data(), buffer.size()), status & USING_UTF8 ? CP_UTF8 : SHIFT_JIS); : StringToWideString(std::string(buffer.data(), buffer.size()), status & USING_UTF8 ? CP_UTF8 : SHIFT_JIS);

View File

@ -25,6 +25,7 @@ public:
const ThreadParam tp; const ThreadParam tp;
inline static int FlushDelay = 250; // flush every 250ms by default inline static int FlushDelay = 250; // flush every 250ms by default
inline static int MaxBufferSize = 500;
inline static int ThreadCounter = 0; inline static int ThreadCounter = 0;
private: private:
@ -35,7 +36,7 @@ private:
std::recursive_mutex ttMutex; std::recursive_mutex ttMutex;
HANDLE deletionEvent = CreateEventW(nullptr, FALSE, FALSE, NULL); HANDLE deletionEvent = CreateEventW(nullptr, FALSE, FALSE, NULL);
std::thread flushThread = std::thread([&] { while (WaitForSingleObject(deletionEvent, 100) == WAIT_TIMEOUT) Flush(); }); std::thread flushThread = std::thread([&] { while (WaitForSingleObject(deletionEvent, 10) == WAIT_TIMEOUT) Flush(); });
DWORD timestamp = GetTickCount(); DWORD timestamp = GetTickCount();
ThreadOutputCallback Output; ThreadOutputCallback Output;

View File

@ -5,18 +5,16 @@
#include <QCoreApplication> #include <QCoreApplication>
#include <QInputDialog> #include <QInputDialog>
#include <QFileDialog> #include <QFileDialog>
#include <QSettings>
MainWindow::MainWindow(QWidget *parent) : MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent), QMainWindow(parent),
ui(new Ui::MainWindow) ui(new Ui::MainWindow)
{ {
ui->setupUi(this); ui->setupUi(this);
QSettings settings("NextHooker.ini", QSettings::IniFormat);
if (settings.contains("Window")) this->setGeometry(settings.value("Window").toRect()); if (settings.contains("Window")) this->setGeometry(settings.value("Window").toRect());
// TODO: add GUI for changing this // TODO: add GUI for changing these
if (settings.contains("Flush_Delay")) TextThread::FlushDelay = settings.value("Flush_Delay").toUInt(); if (settings.contains("Flush_Delay")) TextThread::FlushDelay = settings.value("Flush_Delay").toInt();
if (settings.contains("Max_Buffer_Size")) TextThread::MaxBufferSize = settings.value("Max_Buffer_Size").toInt();
processCombo = findChild<QComboBox*>("processCombo"); processCombo = findChild<QComboBox*>("processCombo");
ttCombo = findChild<QComboBox*>("ttCombo"); ttCombo = findChild<QComboBox*>("ttCombo");
@ -41,9 +39,9 @@ MainWindow::MainWindow(QWidget *parent) :
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
QSettings settings("NextHooker.ini", QSettings::IniFormat);
settings.setValue("Window", this->geometry()); settings.setValue("Window", this->geometry());
settings.setValue("Flush_Delay", TextThread::FlushDelay); settings.setValue("Flush_Delay", TextThread::FlushDelay);
settings.setValue("Max_Buffer_Size", TextThread::MaxBufferSize);
settings.sync(); settings.sync();
Host::Close(); Host::Close();
delete ui; delete ui;

View File

@ -5,6 +5,7 @@
#include <QMainWindow> #include <QMainWindow>
#include <QPlainTextEdit> #include <QPlainTextEdit>
#include <QComboBox> #include <QComboBox>
#include <QSettings>
#include "host/host.h" #include "host/host.h"
namespace Ui namespace Ui
@ -51,6 +52,7 @@ private:
QVector<HookParam> GetAllHooks(DWORD processId); QVector<HookParam> GetAllHooks(DWORD processId);
Ui::MainWindow* ui; Ui::MainWindow* ui;
QSettings settings = QSettings("NextHooker.ini", QSettings::IniFormat);
QComboBox* processCombo; QComboBox* processCombo;
QComboBox* ttCombo; QComboBox* ttCombo;
QComboBox* extenCombo; QComboBox* extenCombo;