add settings dialog box
This commit is contained in:
parent
97d0528550
commit
f351148b3d
@ -10,6 +10,7 @@ set(gui_SRCS
|
||||
mainwindow.cpp
|
||||
misc.cpp
|
||||
extenwindow.cpp
|
||||
setdialog.cpp
|
||||
tests.cpp
|
||||
host/host.cc
|
||||
host/textthread.cc
|
||||
|
@ -5,7 +5,6 @@
|
||||
#include "host.h"
|
||||
#include "const.h"
|
||||
#include "defs.h"
|
||||
#include "text.h"
|
||||
#include "../vnrhook/hijack/texthook.h"
|
||||
|
||||
namespace
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "common.h"
|
||||
#include "textthread.h"
|
||||
#include "text.h"
|
||||
|
||||
typedef std::function<void(DWORD)> ProcessEventCallback;
|
||||
typedef std::function<void(std::shared_ptr<TextThread>)> ThreadEventCallback;
|
||||
@ -30,12 +31,19 @@ namespace Host
|
||||
void AddConsoleOutput(std::wstring text);
|
||||
}
|
||||
|
||||
inline UINT CURRENT_CODEPAGE = SHIFT_JIS;
|
||||
inline std::wstring StringToWideString(const std::string& text, UINT encoding = CURRENT_CODEPAGE)
|
||||
inline std::wstring StringToWideString(const std::string& text, UINT encoding = CP_UTF8)
|
||||
{
|
||||
std::wstring ret(text.size() + 1, 0);
|
||||
ret.resize(MultiByteToWideChar(encoding, 0, text.c_str(), -1, ret.data(), ret.capacity()) - 1);
|
||||
if (int len = MultiByteToWideChar(encoding, 0, text.c_str(), -1, ret.data(), ret.capacity()))
|
||||
{
|
||||
ret.resize(len - 1);
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
Host::AddConsoleOutput(INVALID_CODEPAGE);
|
||||
return L"";
|
||||
}
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
@ -37,7 +37,7 @@ void TextThread::Push(const BYTE* data, int len)
|
||||
LOCK(threadMutex);
|
||||
buffer += hp.type & USING_UNICODE
|
||||
? std::wstring((wchar_t*)data, len / 2)
|
||||
: StringToWideString(std::string((char*)data, len), hp.codepage != 0 ? hp.codepage : CURRENT_CODEPAGE);
|
||||
: StringToWideString(std::string((char*)data, len), hp.codepage != 0 ? hp.codepage : defaultCodepage);
|
||||
if (std::all_of(buffer.begin(), buffer.end(), [&](wchar_t c) { return repeatingChars.count(c) > 0; })) buffer.clear();
|
||||
lastPushTime = GetTickCount();
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ 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::wstring name);
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "ui_mainwindow.h"
|
||||
#include "text.h"
|
||||
#include "extenwindow.h"
|
||||
#include "setdialog.h"
|
||||
#include "misc.h"
|
||||
#include <QInputDialog>
|
||||
|
||||
@ -16,11 +17,10 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
ttCombo = findChild<QComboBox*>("ttCombo");
|
||||
textOutput = findChild<QPlainTextEdit*>("textOutput");
|
||||
|
||||
if (settings.contains(WINDOW)) this->setGeometry(settings.value(WINDOW).toRect());
|
||||
// TODO: add GUI for changing these
|
||||
if (settings.contains(DEFAULT_CODEPAGE)) CURRENT_CODEPAGE = settings.value(DEFAULT_CODEPAGE).toInt();
|
||||
if (settings.contains(WINDOW)) setGeometry(settings.value(WINDOW).toRect());
|
||||
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();
|
||||
if (settings.contains(DEFAULT_CODEPAGE)) TextThread::defaultCodepage = settings.value(DEFAULT_CODEPAGE).toInt();
|
||||
|
||||
qRegisterMetaType<std::shared_ptr<TextThread>>();
|
||||
|
||||
@ -42,13 +42,9 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
settings.setValue(WINDOW, this->geometry());
|
||||
settings.setValue(DEFAULT_CODEPAGE, CURRENT_CODEPAGE);
|
||||
settings.setValue(FLUSH_DELAY, TextThread::flushDelay);
|
||||
settings.setValue(MAX_BUFFER_SIZE, TextThread::maxBufferSize);
|
||||
settings.setValue(WINDOW, geometry());
|
||||
settings.sync();
|
||||
delete ui;
|
||||
|
||||
Host::Close();
|
||||
}
|
||||
|
||||
@ -228,6 +224,11 @@ void MainWindow::on_saveButton_clicked()
|
||||
file.write((hookList + "\r\n").toUtf8());
|
||||
}
|
||||
|
||||
void MainWindow::on_setButton_clicked()
|
||||
{
|
||||
SetDialog(this).exec();
|
||||
}
|
||||
|
||||
void MainWindow::on_extenButton_clicked()
|
||||
{
|
||||
extenWindow->activateWindow();
|
||||
|
@ -41,6 +41,7 @@ private slots:
|
||||
void on_unhookButton_clicked();
|
||||
void on_hookButton_clicked();
|
||||
void on_saveButton_clicked();
|
||||
void on_setButton_clicked();
|
||||
void on_extenButton_clicked();
|
||||
void on_ttCombo_activated(int index);
|
||||
|
||||
|
@ -101,6 +101,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="setButton">
|
||||
<property name="text">
|
||||
<string>Settings</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="extenButton">
|
||||
<property name="text">
|
||||
|
@ -5,5 +5,6 @@
|
||||
#include <QVector>
|
||||
#include <QHash>
|
||||
#include <QMainWindow>
|
||||
#include <QDialog>
|
||||
#include <QFile>
|
||||
#include <QRegularExpression>
|
||||
|
40
GUI/setdialog.cpp
Normal file
40
GUI/setdialog.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
#include "setdialog.h"
|
||||
#include "ui_setdialog.h"
|
||||
#include "defs.h"
|
||||
#include "host/host.h"
|
||||
#include <QSettings>
|
||||
|
||||
SetDialog::SetDialog(QWidget* parent) :
|
||||
QDialog(parent, Qt::WindowCloseButtonHint),
|
||||
ui(new Ui::SetDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
QFormLayout* layout = findChild<QFormLayout*>("layout");
|
||||
|
||||
auto addSpinBox = [&](QString label, int value)
|
||||
{
|
||||
auto spinbox = new QSpinBox(this);
|
||||
spinbox->setMaximum(INT_MAX);
|
||||
spinbox->setValue(value);
|
||||
layout->insertRow(0, label, spinbox);
|
||||
return spinbox;
|
||||
};
|
||||
flushDelay = addSpinBox(FLUSH_DELAY, TextThread::flushDelay);
|
||||
maxBufferSize = addSpinBox(MAX_BUFFER_SIZE, TextThread::maxBufferSize);
|
||||
defaultCodepage = addSpinBox(DEFAULT_CODEPAGE, TextThread::defaultCodepage);
|
||||
}
|
||||
|
||||
SetDialog::~SetDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void SetDialog::on_buttonBox_accepted()
|
||||
{
|
||||
QSettings settings(CONFIG_FILE, QSettings::IniFormat);
|
||||
settings.setValue(FLUSH_DELAY, TextThread::flushDelay = flushDelay->value());
|
||||
settings.setValue(MAX_BUFFER_SIZE, TextThread::maxBufferSize = maxBufferSize->value());
|
||||
settings.setValue(DEFAULT_CODEPAGE, TextThread::defaultCodepage = defaultCodepage->value());
|
||||
settings.sync();
|
||||
}
|
30
GUI/setdialog.h
Normal file
30
GUI/setdialog.h
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef SETDIALOG_H
|
||||
#define SETDIALOG_H
|
||||
|
||||
#include "qtcommon.h"
|
||||
#include <QSpinBox>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class SetDialog;
|
||||
}
|
||||
|
||||
class SetDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SetDialog(QWidget* parent = nullptr);
|
||||
~SetDialog();
|
||||
|
||||
private slots:
|
||||
void on_buttonBox_accepted();
|
||||
|
||||
private:
|
||||
Ui::SetDialog* ui;
|
||||
QSpinBox* flushDelay;
|
||||
QSpinBox* maxBufferSize;
|
||||
QSpinBox* defaultCodepage;
|
||||
};
|
||||
|
||||
#endif // SETDIALOG_H
|
44
GUI/setdialog.ui
Normal file
44
GUI/setdialog.ui
Normal file
@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>SetDialog</class>
|
||||
<widget class="QDialog" name="SetDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>300</width>
|
||||
<height>120</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Settings</string>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="layout">
|
||||
<item row="0" column="1">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>SetDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>SetDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
@ -27,8 +27,8 @@ constexpr auto EXTEN_SAVE_FILE = u8"Extensions.txt";
|
||||
// Settings
|
||||
|
||||
constexpr auto WINDOW = u8"Window";
|
||||
constexpr auto DEFAULT_CODEPAGE = u8"Default_Codepage";
|
||||
constexpr auto FLUSH_DELAY = u8"Flush_Delay";
|
||||
constexpr auto MAX_BUFFER_SIZE = u8"Max_Buffer_Size";
|
||||
constexpr auto DEFAULT_CODEPAGE = u8"Default Codepage";
|
||||
constexpr auto FLUSH_DELAY = u8"Flush Delay";
|
||||
constexpr auto MAX_BUFFER_SIZE = u8"Max Buffer Size";
|
||||
|
||||
// EOF
|
||||
|
@ -28,3 +28,4 @@ constexpr auto ARCHITECTURE_MISMATCH = L"Textractor: ERROR: architecture mismatc
|
||||
constexpr auto INJECT_FAILED = L"Textractor: ERROR: couldn't inject";
|
||||
constexpr auto INVALID_CODE = L"Textractor: invalid code";
|
||||
constexpr auto NO_HOOKS = L"Textractor: no hooks detected";
|
||||
constexpr auto INVALID_CODEPAGE = L"Textractor: ERROR: couldn't convert text (invalid codepage?)";
|
||||
|
Loading…
Reference in New Issue
Block a user