finally decouple Config from the core. baahhahahahah

This commit is contained in:
Arisotura
2021-11-18 01:17:51 +01:00
parent 65c2a844ac
commit 19ddaee13b
35 changed files with 128 additions and 236 deletions

View File

@ -22,7 +22,6 @@
#include "types.h"
#include "Platform.h"
#include "Config.h"
#include "PlatformConfig.h"
#include "AudioSettingsDialog.h"
#include "ui_AudioSettingsDialog.h"

View File

@ -4,6 +4,7 @@ SET(SOURCES_QT_SDL
main.cpp
main_shaders.h
CheatsDialog.cpp
Config.cpp
EmuSettingsDialog.cpp
InputConfig/InputConfigDialog.cpp
InputConfig/MapButton.h
@ -22,7 +23,6 @@ SET(SOURCES_QT_SDL
OSD_shaders.h
font.h
Platform.cpp
PlatformConfig.cpp
QPathInput.h
ArchiveUtil.h
@ -33,6 +33,7 @@ SET(SOURCES_QT_SDL
../Util_Audio.cpp
../FrontendUtil.h
../mic_blow.h
../SharedConfig.h
${CMAKE_SOURCE_DIR}/res/melon.qrc
)

View File

@ -24,7 +24,6 @@
#include "types.h"
#include "Platform.h"
#include "Config.h"
#include "PlatformConfig.h"
#include "CheatsDialog.h"
#include "ui_CheatsDialog.h"

View File

@ -19,7 +19,9 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "PlatformConfig.h"
#include "Platform.h"
#include "Config.h"
namespace Config
{
@ -112,6 +114,7 @@ int DirectLAN;
int SavestateRelocSRAM;
int AudioInterp;
int AudioBitrate;
int AudioVolume;
int MicInputType;
char MicWavPath[1024];
@ -127,7 +130,10 @@ int MouseHideSeconds;
int PauseLostFocus;
ConfigEntry PlatformConfigFile[] =
const char* kConfigFile = "melonDS.ini";
ConfigEntry ConfigFile[] =
{
{"Key_A", 0, &KeyMapping[0], -1, NULL, 0},
{"Key_B", 0, &KeyMapping[1], -1, NULL, 0},
@ -265,6 +271,7 @@ ConfigEntry PlatformConfigFile[] =
{"SavStaRelocSRAM", 0, &SavestateRelocSRAM, 0, NULL, 0},
{"AudioInterp", 0, &AudioInterp, 0, NULL, 0},
{"AudioBitrate", 0, &AudioBitrate, 0, NULL, 0},
{"AudioVolume", 0, &AudioVolume, 256, NULL, 0},
{"MicInputType", 0, &MicInputType, 1, NULL, 0},
{"MicWavPath", 1, MicWavPath, 0, "", 1023},
@ -291,4 +298,81 @@ ConfigEntry PlatformConfigFile[] =
{"", -1, NULL, 0, NULL, 0}
};
void Load()
{
ConfigEntry* entry = &ConfigFile[0];
for (;;)
{
if (!entry->Value) break;
if (entry->Type == 0)
*(int*)entry->Value = entry->DefaultInt;
else
{
strncpy((char*)entry->Value, entry->DefaultStr, entry->StrLength);
((char*)entry->Value)[entry->StrLength] = '\0';
}
entry++;
}
FILE* f = Platform::OpenLocalFile(kConfigFile, "r");
if (!f) return;
char linebuf[1024];
char entryname[32];
char entryval[1024];
while (!feof(f))
{
if (fgets(linebuf, 1024, f) == nullptr)
break;
int ret = sscanf(linebuf, "%31[A-Za-z_0-9]=%[^\t\r\n]", entryname, entryval);
entryname[31] = '\0';
if (ret < 2) continue;
ConfigEntry* entry = &ConfigFile[0];
for (;;)
{
if (!entry->Value) break;
if (!strncmp(entry->Name, entryname, 32))
{
if (entry->Type == 0)
*(int*)entry->Value = strtol(entryval, NULL, 10);
else
strncpy((char*)entry->Value, entryval, entry->StrLength);
break;
}
entry++;
}
}
fclose(f);
}
void Save()
{
FILE* f = Platform::OpenLocalFile(kConfigFile, "w");
if (!f) return;
ConfigEntry* entry = &ConfigFile[0];
for (;;)
{
if (!entry->Value) break;
if (entry->Type == 0)
fprintf(f, "%s=%d\r\n", entry->Name, *(int*)entry->Value);
else
fprintf(f, "%s=%s\r\n", entry->Name, (char*)entry->Value);
entry++;
}
fclose(f);
}
}

View File

@ -19,8 +19,6 @@
#ifndef PLATFORMCONFIG_H
#define PLATFORMCONFIG_H
#include "Config.h"
enum
{
HK_Lid = 0,
@ -40,6 +38,17 @@ enum
namespace Config
{
struct ConfigEntry
{
char Name[32];
int Type;
void* Value;
int DefaultInt;
const char* DefaultStr;
int StrLength; // should be set to actual array length minus one
};
extern int KeyMapping[12];
extern int JoyMapping[12];
@ -128,6 +137,7 @@ extern int DirectLAN;
extern int SavestateRelocSRAM;
extern int AudioInterp;
extern int AudioBitrate;
extern int AudioVolume;
extern int MicInputType;
extern char MicWavPath[1024];
@ -142,6 +152,10 @@ extern int MouseHide;
extern int MouseHideSeconds;
extern int PauseLostFocus;
void Load();
void Save();
}
#endif // PLATFORMCONFIG_H

View File

@ -25,7 +25,6 @@
#include "types.h"
#include "Platform.h"
#include "Config.h"
#include "PlatformConfig.h"
#include "EmuSettingsDialog.h"
#include "ui_EmuSettingsDialog.h"

View File

@ -16,7 +16,7 @@
with melonDS. If not, see http://www.gnu.org/licenses/.
*/
#include "PlatformConfig.h"
#include "Config.h"
#include "FirmwareSettingsDialog.h"
#include "ui_FirmwareSettingsDialog.h"

View File

@ -20,7 +20,7 @@
#include <SDL2/SDL.h>
#include "Input.h"
#include "PlatformConfig.h"
#include "Config.h"
namespace Input

View File

@ -25,7 +25,6 @@
#include "types.h"
#include "Config.h"
#include "PlatformConfig.h"
#include "MapButton.h"
#include "Input.h"

View File

@ -22,7 +22,6 @@
#include "types.h"
#include "Platform.h"
#include "Config.h"
#include "PlatformConfig.h"
InterfaceSettingsDialog* InterfaceSettingsDialog::currentDlg = nullptr;

View File

@ -25,7 +25,7 @@
#include <pcap/pcap.h>
#include "../Wifi.h"
#include "LAN_PCap.h"
#include "PlatformConfig.h"
#include "Config.h"
#ifdef __WIN32__
#include <iphlpapi.h>

View File

@ -23,7 +23,6 @@
#include <string.h>
#include "Wifi.h"
#include "LAN_Socket.h"
#include "Config.h"
#include "FIFO.h"
#include <slirp/libslirp.h>

View File

@ -29,7 +29,7 @@
#include "OSD_shaders.h"
#include "font.h"
#include "PlatformConfig.h"
#include "Config.h"
extern MainWindow* mainWindow;

View File

@ -51,7 +51,7 @@
#include <QOpenGLContext>
#include "Platform.h"
#include "PlatformConfig.h"
#include "Config.h"
#include "LAN_Socket.h"
#include "LAN_PCap.h"
#include <string>
@ -140,6 +140,8 @@ int GetConfigInt(ConfigEntry entry)
case Firm_BirthdayMonth: return Config::FirmwareBirthdayMonth;
case Firm_BirthdayDay: return Config::FirmwareBirthdayDay;
case Firm_Color: return Config::FirmwareFavouriteColour;
case AudioBitrate: return Config::AudioBitrate;
}
return 0;

View File

@ -25,7 +25,6 @@
#include "NDSCart.h"
#include "Platform.h"
#include "Config.h"
#include "PlatformConfig.h"
QString IntToHex(u64 num)
{

View File

@ -23,7 +23,6 @@
#include "types.h"
#include "Platform.h"
#include "Config.h"
#include "PlatformConfig.h"
#include "FrontendUtil.h"
#include "DSi_NAND.h"

View File

@ -23,7 +23,6 @@
#include "types.h"
#include "Platform.h"
#include "Config.h"
#include "PlatformConfig.h"
#include "VideoSettingsDialog.h"
#include "ui_VideoSettingsDialog.h"

View File

@ -22,7 +22,6 @@
#include "types.h"
#include "Platform.h"
#include "Config.h"
#include "PlatformConfig.h"
#include "LAN_Socket.h"
#include "LAN_PCap.h"

View File

@ -75,7 +75,6 @@
#include "Wifi.h"
#include "Platform.h"
#include "Config.h"
#include "PlatformConfig.h"
#include "Savestate.h"