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;
{
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
? std::wstring((wchar_t*)buffer.data(), buffer.size() / 2)
: StringToWideString(std::string(buffer.data(), buffer.size()), status & USING_UTF8 ? CP_UTF8 : SHIFT_JIS);

View File

@ -25,6 +25,7 @@ public:
const ThreadParam tp;
inline static int FlushDelay = 250; // flush every 250ms by default
inline static int MaxBufferSize = 500;
inline static int ThreadCounter = 0;
private:
@ -35,7 +36,7 @@ private:
std::recursive_mutex ttMutex;
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();
ThreadOutputCallback Output;

View File

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

View File

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