switch to toml11

This commit is contained in:
Arisotura
2024-04-14 20:25:11 +02:00
parent adb5760604
commit c6427d2501
26 changed files with 11290 additions and 21 deletions

View File

@ -20,11 +20,13 @@
#include <string.h>
#include <stdlib.h>
#include <inttypes.h>
#include <string_view>
#include "toml/toml.hpp"
#include "Platform.h"
#include "Config.h"
#include <iostream>
#include <fstream>
#include "toml/toml.hpp"
namespace Config
{
@ -170,6 +172,217 @@ const char* kConfigFile = "melonDS.toml";
const char* kLegacyConfigFile = "melonDS.ini";
const char* kLegacyUniqueConfigFile = "melonDS.%d.ini";
toml::value RootTable;
LegacyEntry LegacyFile[] =
{
{"Key_A", 0, "Keyboard.A", true},
{"Key_B", 0, "Keyboard.B", true},
{"Key_Select", 0, "Keyboard.Select", true},
{"Key_Start", 0, "Keyboard.Start", true},
{"Key_Right", 0, "Keyboard.Right", true},
{"Key_Left", 0, "Keyboard.Left", true},
{"Key_Up", 0, "Keyboard.Up", true},
{"Key_Down", 0, "Keyboard.Down", true},
{"Key_R", 0, "Keyboard.R", true},
{"Key_L", 0, "Keyboard.L", true},
{"Key_X", 0, "Keyboard.X", true},
{"Key_Y", 0, "Keyboard.Y", true},
{"Joy_A", 0, "Joystick.A", true},
{"Joy_B", 0, "Joystick.B", true},
{"Joy_Select", 0, "Joystick.Select", true},
{"Joy_Start", 0, "Joystick.Start", true},
{"Joy_Right", 0, "Joystick.Right", true},
{"Joy_Left", 0, "Joystick.Left", true},
{"Joy_Up", 0, "Joystick.Up", true},
{"Joy_Down", 0, "Joystick.Down", true},
{"Joy_R", 0, "Joystick.R", true},
{"Joy_L", 0, "Joystick.L", true},
{"Joy_X", 0, "Joystick.X", true},
{"Joy_Y", 0, "Joystick.Y", true},
{"HKKey_Lid", 0, "Keyboard.HK_Lid", true},
{"HKKey_Mic", 0, "Keyboard.HK_Mic", true},
{"HKKey_Pause", 0, "Keyboard.HK_Pause", true},
{"HKKey_Reset", 0, "Keyboard.HK_Reset", true},
{"HKKey_FastForward", 0, "Keyboard.HK_FastForward", true},
{"HKKey_FastForwardToggle", 0, "Keyboard.HK_FastForwardToggle", true},
{"HKKey_FullscreenToggle", 0, "Keyboard.HK_FullscreenToggle", true},
{"HKKey_SwapScreens", 0, "Keyboard.HK_SwapScreens", true},
{"HKKey_SwapScreenEmphasis", 0, "Keyboard.HK_SwapScreenEmphasis", true},
{"HKKey_SolarSensorDecrease", 0, "Keyboard.HK_SolarSensorDecrease", true},
{"HKKey_SolarSensorIncrease", 0, "Keyboard.HK_SolarSensorIncrease", true},
{"HKKey_FrameStep", 0, "Keyboard.HK_FrameStep", true},
{"HKKey_PowerButton", 0, "Keyboard.HK_PowerButton", true},
{"HKKey_VolumeUp", 0, "Keyboard.HK_VolumeUp", true},
{"HKKey_VolumeDown", 0, "Keyboard.HK_VolumeDown", true},
{"HKJoy_Lid", 0, "Joystick.HK_Lid", true},
{"HKJoy_Mic", 0, "Joystick.HK_Mic", true},
{"HKJoy_Pause", 0, "Joystick.HK_Pause", true},
{"HKJoy_Reset", 0, "Joystick.HK_Reset", true},
{"HKJoy_FastForward", 0, "Joystick.HK_FastForward", true},
{"HKJoy_FastForwardToggle", 0, "Joystick.HK_FastForwardToggle", true},
{"HKJoy_FullscreenToggle", 0, "Joystick.HK_FullscreenToggle", true},
{"HKJoy_SwapScreens", 0, "Joystick.HK_SwapScreens", true},
{"HKJoy_SwapScreenEmphasis", 0, "Joystick.HK_SwapScreenEmphasis", true},
{"HKJoy_SolarSensorDecrease", 0, "Joystick.HK_SolarSensorDecrease", true},
{"HKJoy_SolarSensorIncrease", 0, "Joystick.HK_SolarSensorIncrease", true},
{"HKJoy_FrameStep", 0, "Joystick.HK_FrameStep", true},
{"HKJoy_PowerButton", 0, "Joystick.HK_PowerButton", true},
{"HKJoy_VolumeUp", 0, "Joystick.HK_VolumeUp", true},
{"HKJoy_VolumeDown", 0, "Joystick.HK_VolumeDown", true},
{"JoystickID", 0, "Joystick.JoystickID", true},
{"WindowWidth", 0, "Window0.Width", true},
{"WindowHeight", 0, "Window0.Height", true},
{"WindowMax", 1, "Window0.Maximized", true},
{"ScreenRotation", 0, "Window0.ScreenRotation", true},
{"ScreenGap", 0, "Window0.ScreenGap", true},
{"ScreenLayout", 0, "Window0.ScreenLayout", true},
{"ScreenSwap", 1, "Window0.ScreenSwap", true},
{"ScreenSizing", 0, "Window0.ScreenSizing", true},
{"IntegerScaling", 1, "Window0.IntegerScaling", true},
{"ScreenAspectTop",0, "Window0.ScreenAspectTop", true},
{"ScreenAspectBot",0, "Window0.ScreenAspectBot", true},
{"ScreenFilter", 1, "Screen.Filter", true},
{"ScreenUseGL", 1, "Screen.UseGL", false},
{"ScreenVSync", 1, "Screen.VSync", false},
{"ScreenVSyncInterval", 0, "Screen.VSyncInterval", false},
{"3DRenderer", 0, "3D.Renderer", false},
{"Threaded3D", 1, "3D.Soft.Threaded3D", false},
{"GL_ScaleFactor", 0, "3D.GL.ScaleFactor", false},
{"GL_BetterPolygons", 1, "3D.GL.BetterPolygons", false},
{"LimitFPS", 1, "LimitFPS", false},
{"MaxFPS", 0, "MaxFPS", false},
{"AudioSync", 1, "AudioSync", false},
{"ShowOSD", 1, "Window0.ShowOSD", false},
{"ConsoleType", 0, "Emu.ConsoleType", false},
{"DirectBoot", 1, "Emu.DirectBoot", false},
#ifdef JIT_ENABLED
{"JIT_Enable", 1, "JIT.Enable", false},
{"JIT_MaxBlockSize", 0, "JIT.MaxBlockSize", false},
{"JIT_BranchOptimisations", 1, "JIT.BranchOptimisations", false},
{"JIT_LiteralOptimisations", 1, "JIT.LiteralOptimisations", false},
#ifdef __APPLE__
{"JIT_FastMemory", 1, "JIT.FastMemory", false},
#else
{"JIT_FastMemory", 1, "JIT.FastMemory", false},
#endif
#endif
{"ExternalBIOSEnable", 1, "Emu.ExternalBIOSEnable", false},
{"BIOS9Path", 2, "DS.BIOS9Path", false},
{"BIOS7Path", 2, "DS.BIOS7Path", false},
{"FirmwarePath", 2, "DS.FirmwarePath", false},
{"DSiBIOS9Path", 2, "DSi.BIOS9Path", false},
{"DSiBIOS7Path", 2, "DSi.BIOS7Path", false},
{"DSiFirmwarePath", 2, "DSi.FirmwarePath", false},
{"DSiNANDPath", 2, "DSi.NANDPath", false},
{"DLDIEnable", 1, "DLDI.Enable", false},
{"DLDISDPath", 2, "DLDI.ImagePath", false},
{"DLDISize", 0, "DLDI.ImageSize", false},
{"DLDIReadOnly", 1, "DLDI.ReadOnly", false},
{"DLDIFolderSync", 1, "DLDI.FolderSync", false},
{"DLDIFolderPath", 2, "DLDI.FolderPath", false},
{"DSiSDEnable", 1, "DSi.SD.Enable", false},
{"DSiSDPath", 2, "DSi.SD.ImagePath", false},
{"DSiSDSize", 0, "DSi.SD.ImageSize", false},
{"DSiSDReadOnly", 1, "DSi.SD.ReadOnly", false},
{"DSiSDFolderSync", 1, "DSi.SD.FolderSync", false},
{"DSiSDFolderPath", 2, "DSi.SD.FolderPath", false},
{"FirmwareOverrideSettings", 1, "Firmware.OverrideSettings", true},
{"FirmwareUsername", 2, "Firmware.Username", true},
{"FirmwareLanguage", 0, "Firmware.Language", true},
{"FirmwareBirthdayMonth", 0, "Firmware.BirthdayMonth", true},
{"FirmwareBirthdayDay", 0, "Firmware.BirthdayDay", true},
{"FirmwareFavouriteColour", 0, "Firmware.FavouriteColour", true},
{"FirmwareMessage", 2, "Firmware.Message", true},
{"FirmwareMAC", 2, "Firmware.MAC", true},
{"MPAudioMode", 0, "MP.AudioMode", false},
{"MPRecvTimeout", 0, "MP.RecvTimeout", false},
{"LANDevice", 2, "LAN.Device", false},
{"DirectLAN", 1, "LAN.DirectMode", false},
{"SavStaRelocSRAM", 1, "SaveState.RelocSRAM", false},
{"AudioInterp", 0, "Audio.Interpolation", false},
{"AudioBitDepth", 0, "Audio.BitDepth", false},
{"AudioVolume", 0, "Audio.Volume", true},
{"DSiVolumeSync", 1, "Audio.DSiVolumeSync", true},
{"MicInputType", 0, "Mic.InputType", false},
{"MicDevice", 2, "Mic.Device", false},
{"MicWavPath", 2, "Mic.WavPath", false},
{"LastROMFolder", 2, "LastROMFolder", false},
{"LastBIOSFolder", 2, "LastBIOSFolder", false},
{"RecentROM_0", 2, "RecentROM[0]", false},
{"RecentROM_1", 2, "RecentROM[1]", false},
{"RecentROM_2", 2, "RecentROM[2]", false},
{"RecentROM_3", 2, "RecentROM[3]", false},
{"RecentROM_4", 2, "RecentROM[4]", false},
{"RecentROM_5", 2, "RecentROM[5]", false},
{"RecentROM_6", 2, "RecentROM[6]", false},
{"RecentROM_7", 2, "RecentROM[7]", false},
{"RecentROM_8", 2, "RecentROM[8]", false},
{"RecentROM_9", 2, "RecentROM[9]", false},
{"SaveFilePath", 2, "SaveFilePath", true},
{"SavestatePath", 2, "SavestatePath", true},
{"CheatFilePath", 2, "CheatFilePath", true},
{"EnableCheats", 1, "EnableCheats", true},
{"MouseHide", 1, "Mouse.Hide", false},
{"MouseHideSeconds", 0, "Mouse.HideSeconds", false},
{"PauseLostFocus", 1, "PauseLostFocus", false},
{"UITheme", 2, "UITheme", false},
{"RTCOffset", 3, "RTC.Offset", true},
{"DSBatteryLevelOkay", 1, "DS.Battery.LevelOkay", true},
{"DSiBatteryLevel", 0, "DSi.Battery.Level", true},
{"DSiBatteryCharging", 1, "DSi.Battery.Charging", true},
{"DSiFullBIOSBoot", 1, "DSi.FullBIOSBoot", true},
#ifdef GDBSTUB_ENABLED
{"GdbEnabled", 1, "Gdb.Enabled", false},
{"GdbPortARM7", 0, "Gdb.ARM7.Port", true},
{"GdbPortARM9", 0, "Gdb.ARM9.Port", true},
{"GdbARM7BreakOnStartup", 1, "Gdb.ARM7.BreakOnStartup", true},
{"GdbARM9BreakOnStartup", 1, "Gdb.ARM9.BreakOnStartup", true},
#endif
{"Camera0_InputType", 0, "DSi.Camera0.InputType", false},
{"Camera0_ImagePath", 2, "DSi.Camera0.ImagePath", false},
{"Camera0_CamDeviceName", 2, "DSi.Camera0.DeviceName", false},
{"Camera0_XFlip", 1, "DSi.Camera0.XFlip", false},
{"Camera1_InputType", 0, "DSi.Camera1.InputType", false},
{"Camera1_ImagePath", 2, "DSi.Camera1.ImagePath", false},
{"Camera1_CamDeviceName", 2, "DSi.Camera1.DeviceName", false},
{"Camera1_XFlip", 1, "DSi.Camera1.XFlip", false},
{"", -1, "", false}
};
ConfigEntry ConfigFile[] =
{
{"Key_A", 0, &KeyMapping[0], -1, true},
@ -438,26 +651,80 @@ bool LoadFile(int inst, int actualinst)
return true;
}
bool LoadLegacy()
bool LoadLegacyFile(int inst)
{
for (ConfigEntry* entry = &ConfigFile[0]; entry->Value; entry++)
/*Platform::FileHandle* f;
if (inst > 0)
{
switch (entry->Type)
char name[100] = {0};
snprintf(name, 99, kLegacyUniqueConfigFile, inst+1);
f = Platform::OpenLocalFile(name, Platform::FileMode::ReadText);
}
else
{
f = Platform::OpenLocalFile(kLegacyConfigFile, Platform::FileMode::ReadText);
}
if (!f) return true;
auto table = GetLocalTable(inst);
char linebuf[1024];
char entryname[32];
char entryval[1024];
while (!Platform::IsEndOfFile(f))
{
if (!Platform::FileReadLine(linebuf, 1024, f))
break;
int ret = sscanf(linebuf, "%31[A-Za-z_0-9]=%[^\t\r\n]", entryname, entryval);
entryname[31] = '\0';
if (ret < 2) continue;
for (LegacyEntry* entry = &LegacyFile[0]; entry->Type != -1; entry++)
{
case 0: *(int*)entry->Value = std::get<int>(entry->Default); break;
case 1: *(bool*)entry->Value = std::get<bool>(entry->Default); break;
case 2: *(std::string*)entry->Value = std::get<std::string>(entry->Default); break;
case 3: *(int64_t*)entry->Value = std::get<int64_t>(entry->Default); break;
if (!strncmp(entry->Name, entryname, 32))
{
if (entry->InstanceUnique ^ (inst == -1))
break;
const char* path = entry->TOMLPath;
auto node = table.at_path(path);
switch (entry->Type)
{
case 0:
node.value<int>() = strtol(entryval, NULL, 10);
break;
case 1:
node.value<bool>() = !!strtol(entryval, NULL, 10);
break;
case 2:
node.value<std::string>() = entryval;
break;
case 3:
node.value<int64_t>() = strtoll(entryval, NULL, 10);
break;
}
break;
}
}
}
int inst = Platform::InstanceID();
bool ret = LoadFile(0, inst);
if (inst > 0)
ret = LoadFile(inst, inst);
CloseFile(f);*/
return true;
}
return ret;
bool LoadLegacy()
{
for (int i = -1; i < 16; i++)
LoadLegacyFile(i);
return true;
}
bool Load()
@ -467,26 +734,50 @@ bool Load()
if (!Platform::CheckFileWritable(cfgpath))
return false;
/*RootTable = toml::table();
if (!Platform::FileExists(cfgpath))
return LoadLegacy();
toml::table tbl;
try
{
tbl = toml::parse_file(cfgpath);
printf("toml worked\n");
RootTable = toml::parse_file(cfgpath);
}
catch (toml::parse_error& err)
{
printf("toml shat itself :(\n");
}
//RootTable = toml::table();
}*/
return true;
}
void Save()
{
//
auto cfgpath = Platform::GetLocalFilePath(kConfigFile);
printf("save\n");
if (!Platform::CheckFileWritable(cfgpath))
return;
printf("zirz\n");
RootTable["test"] = 4444;
//std::string derp = "sfsdf";
//toml::serializer<std::string> vorp(RootTable);
//toml::serializer<toml::string> zarp;
std::cout << RootTable;
printf("blarg\n");
std::ofstream file;
file.open(cfgpath, std::ofstream::out | std::ofstream::trunc);
file << RootTable;
file.close();
}
/*toml::node_view<toml::node> GetLocalTable(int instance)
{
if (instance == -1)
return toml::node_view(RootTable);
else
return RootTable["Instance" + std::to_string(instance)];
}*/
}