diff --git a/GUI/extenwindow.cpp b/GUI/extenwindow.cpp index 80d1d4b..0948b2a 100644 --- a/GUI/extenwindow.cpp +++ b/GUI/extenwindow.cpp @@ -1,6 +1,5 @@ #include "extenwindow.h" #include "ui_extenwindow.h" -#include "defs.h" #include #include #include diff --git a/GUI/mainwindow.cpp b/GUI/mainwindow.cpp index 164e97c..38c5779 100644 --- a/GUI/mainwindow.cpp +++ b/GUI/mainwindow.cpp @@ -159,7 +159,7 @@ namespace std::wstring path = std::wstring(process).erase(process.rfind(L'\\')); PROCESS_INFORMATION info = {}; - auto useLocale = QSettings(CONFIG_FILE, QSettings::IniFormat).value(CONFIG_JP_LOCALE, PROMPT).toInt(); + auto useLocale = openSettings().value(CONFIG_JP_LOCALE, PROMPT).toInt(); if (!x64 && (useLocale == ALWAYS || (useLocale == PROMPT && QMessageBox::question(This, SELECT_PROCESS, USE_JP_LOCALE) == QMessageBox::Yes))) { if (HMODULE localeEmulator = LoadLibraryW(L"LoaderDll")) @@ -196,7 +196,7 @@ namespace { if (auto processName = GetModuleFilename(selectedProcessId)) if (int last = processName->rfind(L'\\') + 1) { - std::wstring configFile = std::wstring(processName.value()).replace(last, std::wstring::npos, L"TextractorConfig.txt"); + std::wstring configFile = std::wstring(processName.value()).replace(last, std::wstring::npos, GAME_CONFIG_FILE); if (!std::filesystem::exists(configFile)) QTextFile(S(configFile), QFile::WriteOnly).write("see https://github.com/Artikash/Textractor/wiki/Game-configuration-file"); _wspawnlp(_P_DETACH, L"notepad", L"notepad", configFile.c_str(), NULL); } @@ -665,7 +665,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) MainWindow::~MainWindow() { - QSettings(CONFIG_FILE, QSettings::IniFormat).setValue(WINDOW, geometry()); + openSettings().setValue(WINDOW, geometry()); CleanupExtensions(); SetErrorMode(SEM_NOGPFAULTERRORBOX); ExitProcess(0); diff --git a/extensions/extrawindow.cpp b/extensions/extrawindow.cpp index 8e1543d..6bc4159 100644 --- a/extensions/extrawindow.cpp +++ b/extensions/extrawindow.cpp @@ -1,7 +1,6 @@ #include "qtcommon.h" #include "extension.h" #include "ui_extrawindow.h" -#include "defs.h" #include "blockmarkup.h" #include #include @@ -77,7 +76,7 @@ struct PrettyWindow : QDialog protected: QMenu menu{ ui.display }; - QSettings settings{ CONFIG_FILE, QSettings::IniFormat, this }; + QSettings settings{ openSettings(this) }; private: void RequestFont() diff --git a/extensions/translatewrapper.cpp b/extensions/translatewrapper.cpp index 43e6a93..8234a3b 100644 --- a/extensions/translatewrapper.cpp +++ b/extensions/translatewrapper.cpp @@ -1,6 +1,5 @@ #include "qtcommon.h" #include "extension.h" -#include "defs.h" #include "blockmarkup.h" #include "network.h" #include @@ -21,7 +20,6 @@ const char* LANGUAGE = u8"Language"; const std::string TRANSLATION_CACHE_FILE = FormatString("%sCache.txt", TRANSLATION_PROVIDER); Synchronized translateTo = L"en"; -QSettings settings(CONFIG_FILE, QSettings::IniFormat); Synchronized> translationCache; int savedSize; @@ -41,6 +39,7 @@ BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved { case DLL_PROCESS_ATTACH: { + static QSettings settings = openSettings(); settings.beginGroup(TRANSLATION_PROVIDER); if (settings.contains(LANGUAGE)) translateTo->assign(S(settings.value(LANGUAGE).toString())); else QTimer::singleShot(0, [] diff --git a/include/defs.h b/include/defs.h index 28e9b48..a1ec112 100644 --- a/include/defs.h +++ b/include/defs.h @@ -24,10 +24,6 @@ constexpr auto PIPE_AVAILABLE_EVENT = L"TEXTRACTOR_PIPE_AVAILABLE"; // Files constexpr auto ITH_DLL = L"texthook"; // .dll but LoadLibrary automatically adds that -constexpr auto CONFIG_FILE = u8"Textractor.ini"; - -// Misc - -constexpr auto WINDOW = u8"Window"; +constexpr auto& GAME_CONFIG_FILE = L"TextractorConfig.txt"; // EOF diff --git a/include/qtcommon.h b/include/qtcommon.h index a483224..0525f24 100644 --- a/include/qtcommon.h +++ b/include/qtcommon.h @@ -22,6 +22,10 @@ static thread_local bool ok; +constexpr auto CONFIG_FILE = u8"Textractor.ini"; +constexpr auto WINDOW = u8"Window"; +inline QSettings openSettings(QObject* parent = nullptr) { return { CONFIG_FILE, QSettings::IniFormat, parent }; } + struct QTextFile : QFile { QTextFile(QString name, QIODevice::OpenMode mode) : QFile(name) { open(mode | QIODevice::Text); } }; inline std::wstring S(const QString& s) { return { s.toStdWString() }; } inline QString S(const std::string& s) { return QString::fromStdString(s); } diff --git a/test/main.cpp b/test/main.cpp index d87682b..f72f564 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -1,5 +1,4 @@ #include "common.h" -#include "defs.h" #include "resource.h" #include #include diff --git a/texthook/engine/match.cc b/texthook/engine/match.cc index cbc177e..7643153 100644 --- a/texthook/engine/match.cc +++ b/texthook/engine/match.cc @@ -1,6 +1,7 @@ #include "match.h" #include "engine.h" #include "main.h" +#include "defs.h" #include "native/pchooks.h" extern const char* HIJACK_ERROR; @@ -43,9 +44,9 @@ namespace Engine { GetModuleFileNameW(nullptr, processPath, MAX_PATH); processName = wcsrchr(processPath, L'\\') + 1; - wchar_t configFilename[MAX_PATH + sizeof(L"TextractorConfig.txt")]; + wchar_t configFilename[MAX_PATH + std::size(GAME_CONFIG_FILE)]; wcsncpy_s(configFilename, processPath, MAX_PATH - 1); - wcscpy_s(wcsrchr(configFilename, L'\\') + 1, sizeof(L"TextractorConfig.txt"), L"TextractorConfig.txt"); + wcscpy_s(wcsrchr(configFilename, L'\\') + 1, std::size(GAME_CONFIG_FILE), GAME_CONFIG_FILE); if (AutoHandle<> configFile = CreateFileW(configFilename, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) { if (ReadFile(configFile, configFileData, sizeof(configFileData) - 1, DUMMY, nullptr)) ConsoleOutput("Textractor: game configuration loaded");