From adb5760604f66d04b16f70e34496c0566bc09602 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Fri, 5 Apr 2024 23:00:19 +0200 Subject: [PATCH] push temp. shito --- src/Platform.h | 3 ++ src/frontend/qt_sdl/Config.cpp | 71 ++++++++++++++++---------------- src/frontend/qt_sdl/Platform.cpp | 11 +++-- 3 files changed, 46 insertions(+), 39 deletions(-) diff --git a/src/Platform.h b/src/Platform.h index 425c712c..04be94d4 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -188,6 +188,9 @@ enum class FileSeekOrigin */ struct FileHandle; +// retrieves the path to a local file, without opening the file +std::string GetLocalFilePath(const std::string& filename); + // Simple fopen() wrapper that supports UTF8. // Can be optionally restricted to only opening a file that already exists. FileHandle* OpenFile(const std::string& path, FileMode mode); diff --git a/src/frontend/qt_sdl/Config.cpp b/src/frontend/qt_sdl/Config.cpp index 2fdfc3ba..76d51caf 100644 --- a/src/frontend/qt_sdl/Config.cpp +++ b/src/frontend/qt_sdl/Config.cpp @@ -20,6 +20,8 @@ #include #include #include +#include +#include "toml/toml.hpp" #include "Platform.h" #include "Config.h" @@ -163,8 +165,10 @@ bool GdbARM9BreakOnStartup; CameraConfig Camera[2]; -const char* kConfigFile = "melonDS.ini"; -const char* kUniqueConfigFile = "melonDS.%d.ini"; +const char* kConfigFile = "melonDS.toml"; + +const char* kLegacyConfigFile = "melonDS.ini"; +const char* kLegacyUniqueConfigFile = "melonDS.%d.ini"; ConfigEntry ConfigFile[] = { @@ -384,16 +388,16 @@ bool LoadFile(int inst, int actualinst) if (inst > 0) { char name[100] = {0}; - snprintf(name, 99, kUniqueConfigFile, inst+1); + snprintf(name, 99, kLegacyUniqueConfigFile, inst+1); f = Platform::OpenLocalFile(name, Platform::FileMode::ReadText); if (!Platform::CheckLocalFileWritable(name)) return false; } else { - f = Platform::OpenLocalFile(kConfigFile, Platform::FileMode::ReadText); + f = Platform::OpenLocalFile(kLegacyConfigFile, Platform::FileMode::ReadText); - if (actualinst == 0 && !Platform::CheckLocalFileWritable(kConfigFile)) return false; + if (actualinst == 0 && !Platform::CheckLocalFileWritable(kLegacyConfigFile)) return false; } if (!f) return true; @@ -434,9 +438,8 @@ bool LoadFile(int inst, int actualinst) return true; } -bool Load() +bool LoadLegacy() { - for (ConfigEntry* entry = &ConfigFile[0]; entry->Value; entry++) { switch (entry->Type) @@ -457,37 +460,33 @@ bool Load() return ret; } +bool Load() +{ + auto cfgpath = Platform::GetLocalFilePath(kConfigFile); + + if (!Platform::CheckFileWritable(cfgpath)) + return false; + + if (!Platform::FileExists(cfgpath)) + return LoadLegacy(); + + toml::table tbl; + try + { + tbl = toml::parse_file(cfgpath); + printf("toml worked\n"); + } + catch (toml::parse_error& err) + { + printf("toml shat itself :(\n"); + } + + return true; +} + void Save() { - int inst = Platform::InstanceID(); - - Platform::FileHandle* f; - if (inst > 0) - { - char name[100] = {0}; - snprintf(name, 99, kUniqueConfigFile, inst+1); - f = Platform::OpenLocalFile(name, Platform::FileMode::WriteText); - } - else - f = Platform::OpenLocalFile(kConfigFile, Platform::FileMode::WriteText); - - if (!f) return; - - for (ConfigEntry* entry = &ConfigFile[0]; entry->Value; entry++) - { - if ((inst > 0) && (!entry->InstanceUnique)) - continue; - - switch (entry->Type) - { - case 0: Platform::FileWriteFormatted(f, "%s=%d\n", entry->Name, *(int*)entry->Value); break; - case 1: Platform::FileWriteFormatted(f, "%s=%d\n", entry->Name, *(bool*)entry->Value ? 1:0); break; - case 2: Platform::FileWriteFormatted(f, "%s=%s\n", entry->Name, (*(std::string*)entry->Value).c_str()); break; - case 3: Platform::FileWriteFormatted(f, "%s=%" PRId64 "\n", entry->Name, *(int64_t*)entry->Value); break; - } - } - - CloseFile(f); + // } } diff --git a/src/frontend/qt_sdl/Platform.cpp b/src/frontend/qt_sdl/Platform.cpp index 0cd4f615..c77bdfd3 100644 --- a/src/frontend/qt_sdl/Platform.cpp +++ b/src/frontend/qt_sdl/Platform.cpp @@ -282,9 +282,9 @@ FileHandle* OpenFile(const std::string& path, FileMode mode) } } -FileHandle* OpenLocalFile(const std::string& path, FileMode mode) +std::string GetLocalFilePath(const std::string& filename) { - QString qpath = QString::fromStdString(path); + QString qpath = QString::fromStdString(filename); QDir dir(qpath); QString fullpath; @@ -298,7 +298,12 @@ FileHandle* OpenLocalFile(const std::string& path, FileMode mode) fullpath = QString::fromStdString(EmuDirectory) + QDir::separator() + qpath; } - return OpenFile(fullpath.toStdString(), mode); + return fullpath.toStdString(); +} + +FileHandle* OpenLocalFile(const std::string& path, FileMode mode) +{ + return OpenFile(GetLocalFilePath(path), mode); } bool CloseFile(FileHandle* file)