mirror of
https://github.com/Artikash/Textractor.git
synced 2024-12-23 08:54:12 +08:00
reorganize includes
This commit is contained in:
parent
1f5edecbf6
commit
a64fa9b3dd
@ -1,10 +1,8 @@
|
||||
include(QtUtils)
|
||||
msvc_registry_search()
|
||||
find_qt5(Core Widgets)
|
||||
set(AUTOMOC OFF)
|
||||
|
||||
set(RESOURCE_FILES Textractor.rc Textractor.ico)
|
||||
set(gui_src
|
||||
add_executable(${PROJECT_NAME} WIN32
|
||||
main.cpp
|
||||
mainwindow.cpp
|
||||
extenwindow.cpp
|
||||
@ -12,9 +10,9 @@ set(gui_src
|
||||
host/host.cpp
|
||||
host/textthread.cpp
|
||||
host/util.cpp
|
||||
${RESOURCE_FILES}
|
||||
Textractor.rc
|
||||
Textractor.ico
|
||||
)
|
||||
add_executable(${PROJECT_NAME} WIN32 ${gui_src})
|
||||
target_link_libraries(${PROJECT_NAME} Qt5::Widgets winhttp)
|
||||
target_link_libraries(${PROJECT_NAME} Qt5::Widgets shell32 winhttp)
|
||||
|
||||
install_qt5_libs(${PROJECT_NAME}) # can be commented out for consecutive builds
|
||||
#install_qt5_libs(${PROJECT_NAME}) # can be commented out for consecutive builds
|
||||
|
@ -2,7 +2,6 @@
|
||||
#include "ui_extenwindow.h"
|
||||
#include "defs.h"
|
||||
#include "text.h"
|
||||
#include "types.h"
|
||||
#include "misc.h"
|
||||
#include <concrt.h>
|
||||
#include <QDragEnterEvent>
|
||||
|
@ -22,6 +22,8 @@ public:
|
||||
~ExtenWindow();
|
||||
|
||||
private:
|
||||
inline static constexpr auto EXTEN_SAVE_FILE = u8"SavedExtensions.txt";
|
||||
|
||||
void Add(QFileInfo extenFile);
|
||||
void Sync();
|
||||
bool eventFilter(QObject* target, QEvent* event) override;
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "host.h"
|
||||
#include "const.h"
|
||||
#include "text.h"
|
||||
#include "defs.h"
|
||||
#include "util.h"
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "textthread.h"
|
||||
#include "const.h"
|
||||
#include "text.h"
|
||||
#include "host.h"
|
||||
#include "util.h"
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "util.h"
|
||||
#include "defs.h"
|
||||
#include "host.h"
|
||||
#include <sstream>
|
||||
#include <Psapi.h>
|
||||
|
@ -16,6 +16,9 @@ public:
|
||||
~MainWindow();
|
||||
|
||||
private:
|
||||
inline static constexpr auto HOOK_SAVE_FILE = u8"SavedHooks.txt";
|
||||
inline static constexpr auto GAME_SAVE_FILE = u8"SavedGames.txt";
|
||||
|
||||
inline static thread_local bool ok = false;
|
||||
|
||||
void closeEvent(QCloseEvent*) override;
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "extension.h"
|
||||
#include "defs.h"
|
||||
#include "text.h"
|
||||
#include "network.h"
|
||||
#include <QInputDialog>
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "extension.h"
|
||||
#include "defs.h"
|
||||
#include "text.h"
|
||||
#include "util.h"
|
||||
#include "network.h"
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include "extension.h"
|
||||
#include "util.h"
|
||||
#include "text.h"
|
||||
#include "defs.h"
|
||||
#include <fstream>
|
||||
#include <QMainWindow>
|
||||
#include <QLayout>
|
||||
@ -9,6 +8,8 @@
|
||||
#include <QPushButton>
|
||||
#include <QTimer>
|
||||
|
||||
constexpr auto LUA_SAVE_FILE = u8"Textractor.lua";
|
||||
|
||||
extern "C" // Lua library
|
||||
{
|
||||
enum LuaType { LUA_TNIL, LUA_TBOOLEAN, LUA_TLIGHTUSERDATA, LUA_TNUMBER, LUA_TSTRING, LUA_TTABLE, LUA_TFUNCTION, LUA_TUSERDATA, LUA_TTHREAD };
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "extension.h"
|
||||
#include "defs.h"
|
||||
|
||||
void RemoveRepeatedChars(std::wstring& sentence)
|
||||
{
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "extension.h"
|
||||
#include "defs.h"
|
||||
#include "text.h"
|
||||
#include <cwctype>
|
||||
#include <fstream>
|
||||
@ -7,6 +6,8 @@
|
||||
#include <filesystem>
|
||||
#include <process.h>
|
||||
|
||||
constexpr auto REPLACE_SAVE_FILE = u8"SavedReplacements.txt";
|
||||
|
||||
std::atomic<std::filesystem::file_time_type> replaceFileLastWrite;
|
||||
|
||||
struct
|
||||
|
@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
|
||||
class RateLimiter
|
||||
{
|
||||
|
@ -18,3 +18,54 @@
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <cassert>
|
||||
|
||||
template <typename T> using Array = T[];
|
||||
|
||||
template<typename E, typename M = std::mutex>
|
||||
class ThreadSafe
|
||||
{
|
||||
public:
|
||||
template <typename... Args>
|
||||
ThreadSafe(Args&&... args) : contents(std::forward<Args>(args)...) {}
|
||||
auto operator->()
|
||||
{
|
||||
struct
|
||||
{
|
||||
E* operator->() { return ptr; }
|
||||
std::unique_lock<M> lock;
|
||||
E* ptr;
|
||||
} lockedProxy{ std::unique_lock(mtx), &contents };
|
||||
return lockedProxy;
|
||||
}
|
||||
|
||||
private:
|
||||
E contents;
|
||||
M mtx;
|
||||
};
|
||||
|
||||
template <auto F>
|
||||
struct Functor
|
||||
{
|
||||
template <typename... Args>
|
||||
auto operator()(Args&&... args) const { return std::invoke(F, std::forward<Args>(args)...); }
|
||||
};
|
||||
|
||||
template <typename HandleCloser = Functor<CloseHandle>>
|
||||
class AutoHandle
|
||||
{
|
||||
public:
|
||||
AutoHandle(HANDLE h) : h(h) {}
|
||||
operator HANDLE() { return h.get(); }
|
||||
PHANDLE operator&() { static_assert(sizeof(*this) == sizeof(HANDLE)); return (PHANDLE)this; }
|
||||
operator bool() { return h.get() != NULL && h.get() != INVALID_HANDLE_VALUE; }
|
||||
|
||||
private:
|
||||
struct HandleCleaner { void operator()(void* h) { if (h != INVALID_HANDLE_VALUE) HandleCloser()(h); } };
|
||||
std::unique_ptr<void, HandleCleaner> h;
|
||||
};
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define TEST(...) inline AutoHandle<> TEST__RUNNER__DUMMY = CreateThread(nullptr, 0, [](auto) { __VA_ARGS__; return 0UL; }, NULL, 0, nullptr);
|
||||
#else
|
||||
#define TEST(...)
|
||||
#endif
|
||||
|
@ -3,8 +3,6 @@
|
||||
// vnrhook/defs.h
|
||||
// 8/23/2013 jichi
|
||||
|
||||
#include "common.h"
|
||||
|
||||
// Pipes
|
||||
|
||||
constexpr auto HOOK_PIPE = L"\\\\.\\pipe\\TEXTRACTOR_HOOK";
|
||||
@ -27,38 +25,9 @@ constexpr auto PIPE_AVAILABLE_EVENT = L"TEXTRACTOR_PIPE_AVAILABLE";
|
||||
|
||||
constexpr auto ITH_DLL = L"vnrhook"; // .dll but LoadLibrary automatically adds that
|
||||
constexpr auto CONFIG_FILE = u8"Textractor.ini";
|
||||
constexpr auto HOOK_SAVE_FILE = u8"SavedHooks.txt";
|
||||
constexpr auto GAME_SAVE_FILE = u8"SavedGames.txt";
|
||||
constexpr auto EXTEN_SAVE_FILE = u8"SavedExtensions.txt";
|
||||
constexpr auto REPLACE_SAVE_FILE = u8"SavedReplacements.txt";
|
||||
constexpr auto LUA_SAVE_FILE = u8"Textractor.lua";
|
||||
|
||||
// Misc
|
||||
|
||||
constexpr auto DEFAULT_EXTENSIONS = u8"Remove Repetition>Lua>Copy to Clipboard>Bing Translate>Extra Window>Extra Newlines";
|
||||
|
||||
inline SECURITY_ATTRIBUTES allAccess = std::invoke([] // allows non-admin processes to access kernel objects made by admin processes
|
||||
{
|
||||
static SECURITY_DESCRIPTOR sd = {};
|
||||
InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
|
||||
SetSecurityDescriptorDacl(&sd, TRUE, NULL, FALSE);
|
||||
return SECURITY_ATTRIBUTES{ sizeof(SECURITY_ATTRIBUTES), &sd, FALSE };
|
||||
});
|
||||
|
||||
// Functions
|
||||
|
||||
template <typename... Args>
|
||||
inline void FORMAT_MESSAGE(const char* format, Args... args)
|
||||
{
|
||||
char buffer[250] = {};
|
||||
sprintf_s<250>(buffer, format, args...);
|
||||
MessageBoxA(NULL, buffer, "Textractor Message", MB_OK);
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define TEST(...) inline auto TEST__RUNNER__DUMMY = (CloseHandle(CreateThread(nullptr, 0, [](auto) { __VA_ARGS__; return 0UL; }, NULL, 0, nullptr)), 0);
|
||||
#else
|
||||
#define TEST(...)
|
||||
#endif
|
||||
|
||||
// EOF
|
||||
|
@ -3,51 +3,6 @@
|
||||
#include "common.h"
|
||||
#include "const.h"
|
||||
|
||||
template <typename T> using Array = T[];
|
||||
|
||||
template <auto F>
|
||||
struct Functor
|
||||
{
|
||||
template <typename... Args>
|
||||
auto operator()(Args&&... args) const { return std::invoke(F, std::forward<Args>(args)...); }
|
||||
};
|
||||
|
||||
template<typename E, typename M = std::mutex>
|
||||
class ThreadSafe
|
||||
{
|
||||
public:
|
||||
template <typename... Args>
|
||||
ThreadSafe(Args&&... args) : contents(std::forward<Args>(args)...) {}
|
||||
auto operator->()
|
||||
{
|
||||
struct
|
||||
{
|
||||
E* operator->() { return ptr; }
|
||||
std::unique_lock<M> lock;
|
||||
E* ptr;
|
||||
} lockedProxy{ std::unique_lock(mtx), &contents };
|
||||
return lockedProxy;
|
||||
}
|
||||
|
||||
private:
|
||||
E contents;
|
||||
M mtx;
|
||||
};
|
||||
|
||||
template <typename HandleCloser = Functor<CloseHandle>>
|
||||
class AutoHandle
|
||||
{
|
||||
public:
|
||||
AutoHandle(HANDLE h) : h(h) {}
|
||||
operator HANDLE() { return h.get(); }
|
||||
PHANDLE operator&() { static_assert(sizeof(*this) == sizeof(HANDLE)); return (PHANDLE)this; }
|
||||
operator bool() { return h.get() != NULL && h.get() != INVALID_HANDLE_VALUE; }
|
||||
|
||||
private:
|
||||
struct HandleCleaner { void operator()(void* h) { if (h != INVALID_HANDLE_VALUE) HandleCloser()(h); } };
|
||||
std::unique_ptr<void, HandleCleaner> h;
|
||||
};
|
||||
|
||||
class WinMutex // Like CMutex but works with scoped_lock
|
||||
{
|
||||
public:
|
||||
@ -59,6 +14,14 @@ private:
|
||||
AutoHandle<> m;
|
||||
};
|
||||
|
||||
inline SECURITY_ATTRIBUTES allAccess = std::invoke([] // allows non-admin processes to access kernel objects made by admin processes
|
||||
{
|
||||
static SECURITY_DESCRIPTOR sd = {};
|
||||
InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
|
||||
SetSecurityDescriptorDacl(&sd, TRUE, NULL, FALSE);
|
||||
return SECURITY_ATTRIBUTES{ sizeof(SECURITY_ATTRIBUTES), &sd, FALSE };
|
||||
});
|
||||
|
||||
// jichi 3/7/2014: Add guessed comment
|
||||
struct HookParam
|
||||
{
|
||||
|
@ -6,8 +6,6 @@
|
||||
#include "texthook.h"
|
||||
#include "engine/match.h"
|
||||
#include "main.h"
|
||||
#include "const.h"
|
||||
#include "defs.h"
|
||||
#include "text.h"
|
||||
#include "ithsys/ithsys.h"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user