reorganize config files

This commit is contained in:
Akash Mozumdar 2020-03-05 01:51:36 -07:00
parent aa4b980422
commit 3ff31e0ac6
8 changed files with 13 additions and 16 deletions

View File

@ -1,6 +1,5 @@
#include "extenwindow.h"
#include "ui_extenwindow.h"
#include "defs.h"
#include <concrt.h>
#include <QMenu>
#include <QFileDialog>

View File

@ -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);

View File

@ -1,7 +1,6 @@
#include "qtcommon.h"
#include "extension.h"
#include "ui_extrawindow.h"
#include "defs.h"
#include "blockmarkup.h"
#include <fstream>
#include <process.h>
@ -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()

View File

@ -1,6 +1,5 @@
#include "qtcommon.h"
#include "extension.h"
#include "defs.h"
#include "blockmarkup.h"
#include "network.h"
#include <map>
@ -21,7 +20,6 @@ const char* LANGUAGE = u8"Language";
const std::string TRANSLATION_CACHE_FILE = FormatString("%sCache.txt", TRANSLATION_PROVIDER);
Synchronized<std::wstring> translateTo = L"en";
QSettings settings(CONFIG_FILE, QSettings::IniFormat);
Synchronized<std::map<std::wstring, std::wstring>> 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, []

View File

@ -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

View File

@ -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); }

View File

@ -1,5 +1,4 @@
#include "common.h"
#include "defs.h"
#include "resource.h"
#include <fstream>
#include <sstream>

View File

@ -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");