yeah...that was never a class. improve performance and add current process function

This commit is contained in:
Akash Mozumdar 2020-03-02 23:38:51 -07:00
parent 49432f689d
commit fcb525df36
5 changed files with 533 additions and 557 deletions

View File

@ -5,7 +5,7 @@
namespace Host namespace Host
{ {
using ProcessEventHandler = std::function<void(DWORD)>; using ProcessEventHandler = void(*)(DWORD);
using ThreadEventHandler = std::function<void(TextThread&)>; using ThreadEventHandler = std::function<void(TextThread&)>;
using HookEventHandler = std::function<void(HookParam, std::wstring text)>; using HookEventHandler = std::function<void(HookParam, std::wstring text)>;
void Start(ProcessEventHandler Connect, ProcessEventHandler Disconnect, ThreadEventHandler Create, ThreadEventHandler Destroy, TextThread::OutputCallback Output); void Start(ProcessEventHandler Connect, ProcessEventHandler Disconnect, ThreadEventHandler Create, ThreadEventHandler Destroy, TextThread::OutputCallback Output);

View File

@ -77,7 +77,7 @@ void TextThread::Flush()
if (storage->size() > maxHistorySize) storage->erase(0, storage->size() - maxHistorySize); // https://github.com/Artikash/Textractor/issues/127#issuecomment-486882983 if (storage->size() > maxHistorySize) storage->erase(0, storage->size() - maxHistorySize); // https://github.com/Artikash/Textractor/issues/127#issuecomment-486882983
} }
std::deque<std::wstring> sentences; std::vector<std::wstring> sentences;
queuedSentences->swap(sentences); queuedSentences->swap(sentences);
int totalSize = 0; int totalSize = 0;
for (auto& sentence : sentences) for (auto& sentence : sentences)

View File

@ -6,7 +6,7 @@
class TextThread class TextThread
{ {
public: public:
using OutputCallback = std::function<bool(TextThread&, std::wstring&)>; using OutputCallback = bool(*)(TextThread&, std::wstring&);
inline static OutputCallback Output; inline static OutputCallback Output;
inline static bool filterRepetition = true; inline static bool filterRepetition = true;
@ -37,7 +37,7 @@ private:
std::unordered_set<wchar_t> repeatingChars; std::unordered_set<wchar_t> repeatingChars;
std::mutex bufferMutex; std::mutex bufferMutex;
DWORD lastPushTime = 0; DWORD lastPushTime = 0;
Synchronized<std::deque<std::wstring>> queuedSentences; Synchronized<std::vector<std::wstring>> queuedSentences;
struct TimerDeleter { void operator()(HANDLE h) { DeleteTimerQueueTimer(NULL, h, INVALID_HANDLE_VALUE); } }; struct TimerDeleter { void operator()(HANDLE h) { DeleteTimerQueueTimer(NULL, h, INVALID_HANDLE_VALUE); } };
AutoHandle<TimerDeleter> timer = NULL; AutoHandle<TimerDeleter> timer = NULL;
}; };

File diff suppressed because it is too large Load Diff

View File

@ -1,56 +1,12 @@
#pragma once #pragma once
#include "qtcommon.h" #include "qtcommon.h"
#include "extenwindow.h"
#include "host/host.h"
namespace Ui
{
class MainWindow;
}
class MainWindow : public QMainWindow class MainWindow : public QMainWindow
{ {
public: public:
explicit MainWindow(QWidget *parent = nullptr); explicit MainWindow(QWidget *parent = nullptr);
~MainWindow(); ~MainWindow();
private: private:
inline static constexpr auto HOOK_SAVE_FILE = u8"SavedHooks.txt"; void closeEvent(QCloseEvent*);
inline static constexpr auto GAME_SAVE_FILE = u8"SavedGames.txt";
void closeEvent(QCloseEvent*) override;
void ProcessConnected(DWORD processId);
void ProcessDisconnected(DWORD processId);
void ThreadAdded(TextThread& thread);
void ThreadRemoved(TextThread& thread);
bool SentenceReceived(TextThread& thread, std::wstring& sentence);
void OutputContextMenu(QPoint point);
QString TextThreadString(TextThread& thread);
ThreadParam ParseTextThreadString(QString ttString);
DWORD GetSelectedProcessId();
std::array<InfoForExtension, 10> GetSentenceInfo(TextThread& thread);
std::optional<std::wstring> UserSelectedProcess();
void AttachProcess();
void LaunchProcess();
void DetachProcess();
void ForgetProcess();
void AddHook();
void AddHook(QString hook);
void RemoveHooks();
void SaveHooks();
void FindHooks();
void Settings();
void Extensions();
void ViewThread(int index);
void SetOutputFont(QString font);
Ui::MainWindow* ui;
ExtenWindow* extenWindow;
std::unordered_set<DWORD> alreadyAttached;
bool autoAttach = false, autoAttachSavedOnly = true;
bool showSystemProcesses = false;
uint64_t savedThreadCtx = 0, savedThreadCtx2 = 0;
wchar_t savedThreadCode[1000] = {};
TextThread* current = nullptr;
}; };