diff --git a/src/frontend/FrontendUtil.h b/src/frontend/FrontendUtil.h index f52dced6..d2fbee24 100644 --- a/src/frontend/FrontendUtil.h +++ b/src/frontend/FrontendUtil.h @@ -21,6 +21,7 @@ #include "types.h" +#include #include namespace Frontend @@ -93,17 +94,17 @@ void AnimatedROMIcon(u8 (&data)[8][512], u16 (&palette)[8][16], u16 (&sequence)[ int Reset(); // get the filename associated with the given savestate slot (1-8) -void GetSavestateName(int slot, char* filename, int len); +std::string GetSavestateName(int slot); // determine whether the given savestate slot does contain a savestate bool SavestateExists(int slot); // load the given savestate file // if successful, emulation will continue from the savestate's point -bool LoadState(const char* filename); +bool LoadState(std::string filename); // save the current emulator state to the given file -bool SaveState(const char* filename); +bool SaveState(std::string filename); // undo the latest savestate load void UndoStateLoad(); diff --git a/src/frontend/SharedConfig.h b/src/frontend/SharedConfig.h index 3598e744..01c8d699 100644 --- a/src/frontend/SharedConfig.h +++ b/src/frontend/SharedConfig.h @@ -19,23 +19,25 @@ #ifndef SHAREDCONFIG_H #define SHAREDCONFIG_H +#include + namespace Config { extern int ConsoleType; -extern int DirectBoot; -extern int SavestateRelocSRAM; +extern bool DirectBoot; +extern bool SavestateRelocSRAM; -extern int ExternalBIOSEnable; +extern bool ExternalBIOSEnable; -extern char BIOS9Path[1024]; -extern char BIOS7Path[1024]; -extern char FirmwarePath[1024]; +extern std::string BIOS9Path; +extern std::string BIOS7Path; +extern std::string FirmwarePath; -extern char DSiBIOS9Path[1024]; -extern char DSiBIOS7Path[1024]; -extern char DSiFirmwarePath[1024]; -extern char DSiNANDPath[1024]; +extern std::string DSiBIOS9Path; +extern std::string DSiBIOS7Path; +extern std::string DSiFirmwarePath; +extern std::string DSiNANDPath; } diff --git a/src/frontend/Util_ROM.cpp b/src/frontend/Util_ROM.cpp index 4d23c705..0e0da0f6 100644 --- a/src/frontend/Util_ROM.cpp +++ b/src/frontend/Util_ROM.cpp @@ -666,9 +666,11 @@ int Reset() // SAVESTATE TODO // * configurable paths. not everyone wants their ROM directory to be polluted, I guess. -void GetSavestateName(int slot, char* filename, int len) +std::string GetSavestateName(int slot) { int pos; + char filename[1024] = {0}; + int len = 1024; if (ROMPath[ROMSlot_NDS][0] == '\0') // running firmware, no ROM { @@ -699,16 +701,17 @@ void GetSavestateName(int slot, char* filename, int len) strcpy(&filename[pos], ".ml"); filename[pos+3] = '0'+slot; filename[pos+4] = '\0'; + + return filename; } bool SavestateExists(int slot) { - char ssfile[1024]; - GetSavestateName(slot, ssfile, 1024); + std::string ssfile = GetSavestateName(slot); return Platform::FileExists(ssfile); } -bool LoadState(const char* filename) +bool LoadState(std::string filename) { u32 oldGBACartCRC = GBACart::CartCRC; @@ -719,7 +722,7 @@ bool LoadState(const char* filename) bool failed = false; - Savestate* state = new Savestate(filename, false); + Savestate* state = new Savestate(filename.c_str(), false); if (state->Error) { delete state; @@ -740,7 +743,7 @@ bool LoadState(const char* filename) { strncpy(PrevSRAMPath[ROMSlot_NDS], SRAMPath[0], 1024); - strncpy(SRAMPath[ROMSlot_NDS], filename, 1019); + strncpy(SRAMPath[ROMSlot_NDS], filename.c_str(), 1019); int len = strlen(SRAMPath[ROMSlot_NDS]); strcpy(&SRAMPath[ROMSlot_NDS][len], ".sav"); SRAMPath[ROMSlot_NDS][len+4] = '\0'; @@ -775,9 +778,9 @@ bool LoadState(const char* filename) return !failed; } -bool SaveState(const char* filename) +bool SaveState(std::string filename) { - Savestate* state = new Savestate(filename, true); + Savestate* state = new Savestate(filename.c_str(), true); if (state->Error) { delete state; @@ -790,7 +793,7 @@ bool SaveState(const char* filename) if (Config::SavestateRelocSRAM && ROMPath[ROMSlot_NDS][0]!='\0') { - strncpy(SRAMPath[ROMSlot_NDS], filename, 1019); + strncpy(SRAMPath[ROMSlot_NDS], filename.c_str(), 1019); int len = strlen(SRAMPath[ROMSlot_NDS]); strcpy(&SRAMPath[ROMSlot_NDS][len], ".sav"); SRAMPath[ROMSlot_NDS][len+4] = '\0'; diff --git a/src/frontend/qt_sdl/AudioSettingsDialog.cpp b/src/frontend/qt_sdl/AudioSettingsDialog.cpp index d4ce678b..dff30558 100644 --- a/src/frontend/qt_sdl/AudioSettingsDialog.cpp +++ b/src/frontend/qt_sdl/AudioSettingsDialog.cpp @@ -62,7 +62,7 @@ AudioSettingsDialog::AudioSettingsDialog(QWidget* parent) : QDialog(parent), ui( connect(grpMicMode, SIGNAL(buttonClicked(int)), this, SLOT(onChangeMicMode(int))); grpMicMode->button(Config::MicInputType)->setChecked(true); - ui->txtMicWavPath->setText(Config::MicWavPath); + ui->txtMicWavPath->setText(QString::fromStdString(Config::MicWavPath)); bool iswav = (Config::MicInputType == 3); ui->txtMicWavPath->setEnabled(iswav); @@ -77,7 +77,7 @@ AudioSettingsDialog::~AudioSettingsDialog() void AudioSettingsDialog::on_AudioSettingsDialog_accepted() { Config::MicInputType = grpMicMode->checkedId(); - strncpy(Config::MicWavPath, ui->txtMicWavPath->text().toStdString().c_str(), 1023); Config::MicWavPath[1023] = '\0'; + Config::MicWavPath = ui->txtMicWavPath->text().toStdString(); Config::Save(); closeDlg(); diff --git a/src/frontend/qt_sdl/Config.cpp b/src/frontend/qt_sdl/Config.cpp index 30babafb..e4300346 100644 --- a/src/frontend/qt_sdl/Config.cpp +++ b/src/frontend/qt_sdl/Config.cpp @@ -36,284 +36,283 @@ int JoystickID; int WindowWidth; int WindowHeight; -int WindowMaximized; +bool WindowMaximized; int ScreenRotation; int ScreenGap; int ScreenLayout; -int ScreenSwap; +bool ScreenSwap; int ScreenSizing; -int IntegerScaling; +bool IntegerScaling; int ScreenAspectTop; int ScreenAspectBot; -int ScreenFilter; +bool ScreenFilter; -int ScreenUseGL; -int ScreenVSync; +bool ScreenUseGL; +bool ScreenVSync; int ScreenVSyncInterval; int _3DRenderer; -int Threaded3D; +bool Threaded3D; int GL_ScaleFactor; -int GL_BetterPolygons; +bool GL_BetterPolygons; -int LimitFPS; -int AudioSync; -int ShowOSD; +bool LimitFPS; +bool AudioSync; +bool ShowOSD; int ConsoleType; -int DirectBoot; +bool DirectBoot; #ifdef JIT_ENABLED -int JIT_Enable = false; +bool JIT_Enable = false; int JIT_MaxBlockSize = 32; -int JIT_BranchOptimisations = true; -int JIT_LiteralOptimisations = true; -int JIT_FastMemory = true; +bool JIT_BranchOptimisations = true; +bool JIT_LiteralOptimisations = true; +bool JIT_FastMemory = true; #endif -int ExternalBIOSEnable; +bool ExternalBIOSEnable; -char BIOS9Path[1024]; -char BIOS7Path[1024]; -char FirmwarePath[1024]; +std::string BIOS9Path; +std::string BIOS7Path; +std::string FirmwarePath; -char DSiBIOS9Path[1024]; -char DSiBIOS7Path[1024]; -char DSiFirmwarePath[1024]; -char DSiNANDPath[1024]; +std::string DSiBIOS9Path; +std::string DSiBIOS7Path; +std::string DSiFirmwarePath; +std::string DSiNANDPath; -int DLDIEnable; -char DLDISDPath[1024]; +bool DLDIEnable; +std::string DLDISDPath; int DLDISize; -int DLDIReadOnly; -int DLDIFolderSync; -char DLDIFolderPath[1024]; +bool DLDIReadOnly; +bool DLDIFolderSync; +std::string DLDIFolderPath; -int DSiSDEnable; -char DSiSDPath[1024]; +bool DSiSDEnable; +std::string DSiSDPath; int DSiSDSize; -int DSiSDReadOnly; -int DSiSDFolderSync; -char DSiSDFolderPath[1024]; +bool DSiSDReadOnly; +bool DSiSDFolderSync; +std::string DSiSDFolderPath; -int FirmwareOverrideSettings; -char FirmwareUsername[64]; +bool FirmwareOverrideSettings; +std::string FirmwareUsername; int FirmwareLanguage; int FirmwareBirthdayMonth; int FirmwareBirthdayDay; int FirmwareFavouriteColour; -char FirmwareMessage[1024]; -char FirmwareMAC[18]; -int RandomizeMAC; +std::string FirmwareMessage; +std::string FirmwareMAC; +bool RandomizeMAC; -int SocketBindAnyAddr; -char LANDevice[128]; -int DirectLAN; +bool SocketBindAnyAddr; +std::string LANDevice; +bool DirectLAN; -int SavestateRelocSRAM; +bool SavestateRelocSRAM; int AudioInterp; int AudioBitrate; int AudioVolume; int MicInputType; -char MicWavPath[1024]; +std::string MicWavPath; -char LastROMFolder[1024]; +std::string LastROMFolder; -char RecentROMList[10][1024]; +std::string RecentROMList[10]; -int EnableCheats; +bool EnableCheats; -int MouseHide; +bool MouseHide; int MouseHideSeconds; -int PauseLostFocus; +bool PauseLostFocus; const char* kConfigFile = "melonDS.ini"; ConfigEntry ConfigFile[] = { - {"Key_A", 0, &KeyMapping[0], -1, NULL, 0}, - {"Key_B", 0, &KeyMapping[1], -1, NULL, 0}, - {"Key_Select", 0, &KeyMapping[2], -1, NULL, 0}, - {"Key_Start", 0, &KeyMapping[3], -1, NULL, 0}, - {"Key_Right", 0, &KeyMapping[4], -1, NULL, 0}, - {"Key_Left", 0, &KeyMapping[5], -1, NULL, 0}, - {"Key_Up", 0, &KeyMapping[6], -1, NULL, 0}, - {"Key_Down", 0, &KeyMapping[7], -1, NULL, 0}, - {"Key_R", 0, &KeyMapping[8], -1, NULL, 0}, - {"Key_L", 0, &KeyMapping[9], -1, NULL, 0}, - {"Key_X", 0, &KeyMapping[10], -1, NULL, 0}, - {"Key_Y", 0, &KeyMapping[11], -1, NULL, 0}, + {"Key_A", 0, &KeyMapping[0], -1}, + {"Key_B", 0, &KeyMapping[1], -1}, + {"Key_Select", 0, &KeyMapping[2], -1}, + {"Key_Start", 0, &KeyMapping[3], -1}, + {"Key_Right", 0, &KeyMapping[4], -1}, + {"Key_Left", 0, &KeyMapping[5], -1}, + {"Key_Up", 0, &KeyMapping[6], -1}, + {"Key_Down", 0, &KeyMapping[7], -1}, + {"Key_R", 0, &KeyMapping[8], -1}, + {"Key_L", 0, &KeyMapping[9], -1}, + {"Key_X", 0, &KeyMapping[10], -1}, + {"Key_Y", 0, &KeyMapping[11], -1}, - {"Joy_A", 0, &JoyMapping[0], -1, NULL, 0}, - {"Joy_B", 0, &JoyMapping[1], -1, NULL, 0}, - {"Joy_Select", 0, &JoyMapping[2], -1, NULL, 0}, - {"Joy_Start", 0, &JoyMapping[3], -1, NULL, 0}, - {"Joy_Right", 0, &JoyMapping[4], -1, NULL, 0}, - {"Joy_Left", 0, &JoyMapping[5], -1, NULL, 0}, - {"Joy_Up", 0, &JoyMapping[6], -1, NULL, 0}, - {"Joy_Down", 0, &JoyMapping[7], -1, NULL, 0}, - {"Joy_R", 0, &JoyMapping[8], -1, NULL, 0}, - {"Joy_L", 0, &JoyMapping[9], -1, NULL, 0}, - {"Joy_X", 0, &JoyMapping[10], -1, NULL, 0}, - {"Joy_Y", 0, &JoyMapping[11], -1, NULL, 0}, + {"Joy_A", 0, &JoyMapping[0], -1}, + {"Joy_B", 0, &JoyMapping[1], -1}, + {"Joy_Select", 0, &JoyMapping[2], -1}, + {"Joy_Start", 0, &JoyMapping[3], -1}, + {"Joy_Right", 0, &JoyMapping[4], -1}, + {"Joy_Left", 0, &JoyMapping[5], -1}, + {"Joy_Up", 0, &JoyMapping[6], -1}, + {"Joy_Down", 0, &JoyMapping[7], -1}, + {"Joy_R", 0, &JoyMapping[8], -1}, + {"Joy_L", 0, &JoyMapping[9], -1}, + {"Joy_X", 0, &JoyMapping[10], -1}, + {"Joy_Y", 0, &JoyMapping[11], -1}, - {"HKKey_Lid", 0, &HKKeyMapping[HK_Lid], -1, NULL, 0}, - {"HKKey_Mic", 0, &HKKeyMapping[HK_Mic], -1, NULL, 0}, - {"HKKey_Pause", 0, &HKKeyMapping[HK_Pause], -1, NULL, 0}, - {"HKKey_Reset", 0, &HKKeyMapping[HK_Reset], -1, NULL, 0}, - {"HKKey_FastForward", 0, &HKKeyMapping[HK_FastForward], -1, NULL, 0}, - {"HKKey_FastForwardToggle", 0, &HKKeyMapping[HK_FastForwardToggle], -1, NULL, 0}, - {"HKKey_FullscreenToggle", 0, &HKKeyMapping[HK_FullscreenToggle], -1, NULL, 0}, - {"HKKey_SwapScreens", 0, &HKKeyMapping[HK_SwapScreens], -1, NULL, 0}, - {"HKKey_SolarSensorDecrease", 0, &HKKeyMapping[HK_SolarSensorDecrease], -1, NULL, 0}, - {"HKKey_SolarSensorIncrease", 0, &HKKeyMapping[HK_SolarSensorIncrease], -1, NULL, 0}, - {"HKKey_FrameStep", 0, &HKKeyMapping[HK_FrameStep], -1, NULL, 0}, + {"HKKey_Lid", 0, &HKKeyMapping[HK_Lid], -1}, + {"HKKey_Mic", 0, &HKKeyMapping[HK_Mic], -1}, + {"HKKey_Pause", 0, &HKKeyMapping[HK_Pause], -1}, + {"HKKey_Reset", 0, &HKKeyMapping[HK_Reset], -1}, + {"HKKey_FastForward", 0, &HKKeyMapping[HK_FastForward], -1}, + {"HKKey_FastForwardToggle", 0, &HKKeyMapping[HK_FastForwardToggle], -1}, + {"HKKey_FullscreenToggle", 0, &HKKeyMapping[HK_FullscreenToggle], -1}, + {"HKKey_SwapScreens", 0, &HKKeyMapping[HK_SwapScreens], -1}, + {"HKKey_SolarSensorDecrease", 0, &HKKeyMapping[HK_SolarSensorDecrease], -1}, + {"HKKey_SolarSensorIncrease", 0, &HKKeyMapping[HK_SolarSensorIncrease], -1}, + {"HKKey_FrameStep", 0, &HKKeyMapping[HK_FrameStep], -1}, - {"HKJoy_Lid", 0, &HKJoyMapping[HK_Lid], -1, NULL, 0}, - {"HKJoy_Mic", 0, &HKJoyMapping[HK_Mic], -1, NULL, 0}, - {"HKJoy_Pause", 0, &HKJoyMapping[HK_Pause], -1, NULL, 0}, - {"HKJoy_Reset", 0, &HKJoyMapping[HK_Reset], -1, NULL, 0}, - {"HKJoy_FastForward", 0, &HKJoyMapping[HK_FastForward], -1, NULL, 0}, - {"HKJoy_FastForwardToggle", 0, &HKJoyMapping[HK_FastForwardToggle], -1, NULL, 0}, - {"HKJoy_FullscreenToggle", 0, &HKJoyMapping[HK_FullscreenToggle], -1, NULL, 0}, - {"HKJoy_SwapScreens", 0, &HKJoyMapping[HK_SwapScreens], -1, NULL, 0}, - {"HKJoy_SolarSensorDecrease", 0, &HKJoyMapping[HK_SolarSensorDecrease], -1, NULL, 0}, - {"HKJoy_SolarSensorIncrease", 0, &HKJoyMapping[HK_SolarSensorIncrease], -1, NULL, 0}, - {"HKJoy_FrameStep", 0, &HKJoyMapping[HK_FrameStep], -1, NULL, 0}, + {"HKJoy_Lid", 0, &HKJoyMapping[HK_Lid], -1}, + {"HKJoy_Mic", 0, &HKJoyMapping[HK_Mic], -1}, + {"HKJoy_Pause", 0, &HKJoyMapping[HK_Pause], -1}, + {"HKJoy_Reset", 0, &HKJoyMapping[HK_Reset], -1}, + {"HKJoy_FastForward", 0, &HKJoyMapping[HK_FastForward], -1}, + {"HKJoy_FastForwardToggle", 0, &HKJoyMapping[HK_FastForwardToggle], -1}, + {"HKJoy_FullscreenToggle", 0, &HKJoyMapping[HK_FullscreenToggle], -1}, + {"HKJoy_SwapScreens", 0, &HKJoyMapping[HK_SwapScreens], -1}, + {"HKJoy_SolarSensorDecrease", 0, &HKJoyMapping[HK_SolarSensorDecrease], -1}, + {"HKJoy_SolarSensorIncrease", 0, &HKJoyMapping[HK_SolarSensorIncrease], -1}, + {"HKJoy_FrameStep", 0, &HKJoyMapping[HK_FrameStep], -1}, - {"JoystickID", 0, &JoystickID, 0, NULL, 0}, + {"JoystickID", 0, &JoystickID, 0}, - {"WindowWidth", 0, &WindowWidth, 256, NULL, 0}, - {"WindowHeight", 0, &WindowHeight, 384, NULL, 0}, - {"WindowMax", 0, &WindowMaximized, 0, NULL, 0}, + {"WindowWidth", 0, &WindowWidth, 256}, + {"WindowHeight", 0, &WindowHeight, 384}, + {"WindowMax", 1, &WindowMaximized, false}, - {"ScreenRotation", 0, &ScreenRotation, 0, NULL, 0}, - {"ScreenGap", 0, &ScreenGap, 0, NULL, 0}, - {"ScreenLayout", 0, &ScreenLayout, 0, NULL, 0}, - {"ScreenSwap", 0, &ScreenSwap, 0, NULL, 0}, - {"ScreenSizing", 0, &ScreenSizing, 0, NULL, 0}, - {"IntegerScaling", 0, &IntegerScaling, 0, NULL, 0}, - {"ScreenAspectTop",0, &ScreenAspectTop,0, NULL, 0}, - {"ScreenAspectBot",0, &ScreenAspectBot,0, NULL, 0}, - {"ScreenFilter", 0, &ScreenFilter, 1, NULL, 0}, + {"ScreenRotation", 0, &ScreenRotation, 0}, + {"ScreenGap", 0, &ScreenGap, 0}, + {"ScreenLayout", 0, &ScreenLayout, 0}, + {"ScreenSwap", 1, &ScreenSwap, false}, + {"ScreenSizing", 0, &ScreenSizing, 0}, + {"IntegerScaling", 1, &IntegerScaling, false}, + {"ScreenAspectTop",0, &ScreenAspectTop,0}, + {"ScreenAspectBot",0, &ScreenAspectBot,0}, + {"ScreenFilter", 1, &ScreenFilter, true}, - {"ScreenUseGL", 0, &ScreenUseGL, 0, NULL, 0}, - {"ScreenVSync", 0, &ScreenVSync, 0, NULL, 0}, - {"ScreenVSyncInterval", 0, &ScreenVSyncInterval, 1, NULL, 0}, + {"ScreenUseGL", 1, &ScreenUseGL, false}, + {"ScreenVSync", 1, &ScreenVSync, false}, + {"ScreenVSyncInterval", 0, &ScreenVSyncInterval, 1}, - {"3DRenderer", 0, &_3DRenderer, 0, NULL, 0}, - {"Threaded3D", 0, &Threaded3D, 1, NULL, 0}, + {"3DRenderer", 0, &_3DRenderer, 0}, + {"Threaded3D", 1, &Threaded3D, true}, - {"GL_ScaleFactor", 0, &GL_ScaleFactor, 1, NULL, 0}, - {"GL_BetterPolygons", 0, &GL_BetterPolygons, 0, NULL, 0}, + {"GL_ScaleFactor", 0, &GL_ScaleFactor, 1}, + {"GL_BetterPolygons", 1, &GL_BetterPolygons, false}, - {"LimitFPS", 0, &LimitFPS, 1, NULL, 0}, - {"AudioSync", 0, &AudioSync, 0, NULL, 0}, - {"ShowOSD", 0, &ShowOSD, 1, NULL, 0}, + {"LimitFPS", 1, &LimitFPS, true}, + {"AudioSync", 1, &AudioSync, false}, + {"ShowOSD", 1, &ShowOSD, true}, - {"ConsoleType", 0, &ConsoleType, 0, NULL, 0}, - {"DirectBoot", 0, &DirectBoot, 1, NULL, 0}, + {"ConsoleType", 0, &ConsoleType, 0}, + {"DirectBoot", 1, &DirectBoot, true}, #ifdef JIT_ENABLED - {"JIT_Enable", 0, &JIT_Enable, 0, NULL, 0}, - {"JIT_MaxBlockSize", 0, &JIT_MaxBlockSize, 32, NULL, 0}, - {"JIT_BranchOptimisations", 0, &JIT_BranchOptimisations, 1, NULL, 0}, - {"JIT_LiteralOptimisations", 0, &JIT_LiteralOptimisations, 1, NULL, 0}, + {"JIT_Enable", 1, &JIT_Enable, false}, + {"JIT_MaxBlockSize", 0, &JIT_MaxBlockSize, 32}, + {"JIT_BranchOptimisations", 1, &JIT_BranchOptimisations, true}, + {"JIT_LiteralOptimisations", 1, &JIT_LiteralOptimisations, true}, #ifdef __APPLE__ - {"JIT_FastMemory", 0, &JIT_FastMemory, 0, NULL, 0}, + {"JIT_FastMemory", 1, &JIT_FastMemory, false}, #else - {"JIT_FastMemory", 0, &JIT_FastMemory, 1, NULL, 0}, + {"JIT_FastMemory", 1, &JIT_FastMemory, true}, #endif #endif - {"ExternalBIOSEnable", 0, &ExternalBIOSEnable, 0, NULL, 0}, + {"ExternalBIOSEnable", 1, &ExternalBIOSEnable, false}, - {"BIOS9Path", 1, BIOS9Path, 0, "", 1023}, - {"BIOS7Path", 1, BIOS7Path, 0, "", 1023}, - {"FirmwarePath", 1, FirmwarePath, 0, "", 1023}, + {"BIOS9Path", 2, &BIOS9Path, ""}, + {"BIOS7Path", 2, &BIOS7Path, ""}, + {"FirmwarePath", 2, &FirmwarePath, ""}, - {"DSiBIOS9Path", 1, DSiBIOS9Path, 0, "", 1023}, - {"DSiBIOS7Path", 1, DSiBIOS7Path, 0, "", 1023}, - {"DSiFirmwarePath", 1, DSiFirmwarePath, 0, "", 1023}, - {"DSiNANDPath", 1, DSiNANDPath, 0, "", 1023}, + {"DSiBIOS9Path", 2, &DSiBIOS9Path, ""}, + {"DSiBIOS7Path", 2, &DSiBIOS7Path, ""}, + {"DSiFirmwarePath", 2, &DSiFirmwarePath, ""}, + {"DSiNANDPath", 2, &DSiNANDPath, ""}, - {"DLDIEnable", 0, &DLDIEnable, 0, NULL, 0}, - {"DLDISDPath", 1, DLDISDPath, 0, "dldi.bin", 1023}, - {"DLDISize", 0, &DLDISize, 0, NULL, 0}, - {"DLDIReadOnly", 0, &DLDIReadOnly, 0, NULL, 0}, - {"DLDIFolderSync", 0, &DLDIFolderSync, 0, NULL, 0}, - {"DLDIFolderPath", 1, DLDIFolderPath, 0, "", 1023}, + {"DLDIEnable", 1, &DLDIEnable, false}, + {"DLDISDPath", 2, &DLDISDPath, "dldi.bin"}, + {"DLDISize", 0, &DLDISize, 0}, + {"DLDIReadOnly", 1, &DLDIReadOnly, false}, + {"DLDIFolderSync", 1, &DLDIFolderSync, false}, + {"DLDIFolderPath", 2, &DLDIFolderPath, ""}, - {"DSiSDEnable", 0, &DSiSDEnable, 0, NULL, 0}, - {"DSiSDPath", 1, DSiSDPath, 0, "dsisd.bin", 1023}, - {"DSiSDSize", 0, &DSiSDSize, 0, NULL, 0}, - {"DSiSDReadOnly", 0, &DSiSDReadOnly, 0, NULL, 0}, - {"DSiSDFolderSync", 0, &DSiSDFolderSync, 0, NULL, 0}, - {"DSiSDFolderPath", 1, DSiSDFolderPath, 0, "", 1023}, + {"DSiSDEnable", 1, &DSiSDEnable, false}, + {"DSiSDPath", 2, &DSiSDPath, "dsisd.bin"}, + {"DSiSDSize", 0, &DSiSDSize, 0}, + {"DSiSDReadOnly", 1, &DSiSDReadOnly, false}, + {"DSiSDFolderSync", 1, &DSiSDFolderSync, false}, + {"DSiSDFolderPath", 2, &DSiSDFolderPath, ""}, - {"FirmwareOverrideSettings", 0, &FirmwareOverrideSettings, false, NULL, 0}, - {"FirmwareUsername", 1, FirmwareUsername, 0, "melonDS", 63}, - {"FirmwareLanguage", 0, &FirmwareLanguage, 1, NULL, 0}, - {"FirmwareBirthdayMonth", 0, &FirmwareBirthdayMonth, 0, NULL, 0}, - {"FirmwareBirthdayDay", 0, &FirmwareBirthdayDay, 0, NULL, 0}, - {"FirmwareFavouriteColour", 0, &FirmwareFavouriteColour, 0, NULL, 0}, - {"FirmwareMessage", 1, FirmwareMessage, 0, "", 1023}, - {"FirmwareMAC", 1, FirmwareMAC, 0, "", 17}, - {"RandomizeMAC", 0, &RandomizeMAC, 0, NULL, 0}, + {"FirmwareOverrideSettings", 1, &FirmwareOverrideSettings, false}, + {"FirmwareUsername", 2, &FirmwareUsername, "melonDS"}, + {"FirmwareLanguage", 0, &FirmwareLanguage, 1}, + {"FirmwareBirthdayMonth", 0, &FirmwareBirthdayMonth, 1}, + {"FirmwareBirthdayDay", 0, &FirmwareBirthdayDay, 1}, + {"FirmwareFavouriteColour", 0, &FirmwareFavouriteColour, 0}, + {"FirmwareMessage", 2, &FirmwareMessage, ""}, + {"FirmwareMAC", 2, &FirmwareMAC, ""}, + {"RandomizeMAC", 1, &RandomizeMAC, false}, - {"SockBindAnyAddr", 0, &SocketBindAnyAddr, 0, NULL, 0}, - {"LANDevice", 1, LANDevice, 0, "", 127}, - {"DirectLAN", 0, &DirectLAN, 0, NULL, 0}, + {"SockBindAnyAddr", 1, &SocketBindAnyAddr, false}, + {"LANDevice", 2, &LANDevice, ""}, + {"DirectLAN", 1, &DirectLAN, false}, - {"SavStaRelocSRAM", 0, &SavestateRelocSRAM, 0, NULL, 0}, + {"SavStaRelocSRAM", 1, &SavestateRelocSRAM, false}, - {"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}, + {"AudioInterp", 0, &AudioInterp, 0}, + {"AudioBitrate", 0, &AudioBitrate, 0}, + {"AudioVolume", 0, &AudioVolume, 256}, + {"MicInputType", 0, &MicInputType, 1}, + {"MicWavPath", 2, &MicWavPath, ""}, - {"LastROMFolder", 1, LastROMFolder, 0, "", 1023}, + {"LastROMFolder", 2, &LastROMFolder, ""}, - {"RecentROM_0", 1, RecentROMList[0], 0, "", 1023}, - {"RecentROM_1", 1, RecentROMList[1], 0, "", 1023}, - {"RecentROM_2", 1, RecentROMList[2], 0, "", 1023}, - {"RecentROM_3", 1, RecentROMList[3], 0, "", 1023}, - {"RecentROM_4", 1, RecentROMList[4], 0, "", 1023}, - {"RecentROM_5", 1, RecentROMList[5], 0, "", 1023}, - {"RecentROM_6", 1, RecentROMList[6], 0, "", 1023}, - {"RecentROM_7", 1, RecentROMList[7], 0, "", 1023}, - {"RecentROM_8", 1, RecentROMList[8], 0, "", 1023}, - {"RecentROM_9", 1, RecentROMList[9], 0, "", 1023}, + {"RecentROM_0", 2, &RecentROMList[0], ""}, + {"RecentROM_1", 2, &RecentROMList[1], ""}, + {"RecentROM_2", 2, &RecentROMList[2], ""}, + {"RecentROM_3", 2, &RecentROMList[3], ""}, + {"RecentROM_4", 2, &RecentROMList[4], ""}, + {"RecentROM_5", 2, &RecentROMList[5], ""}, + {"RecentROM_6", 2, &RecentROMList[6], ""}, + {"RecentROM_7", 2, &RecentROMList[7], ""}, + {"RecentROM_8", 2, &RecentROMList[8], ""}, + {"RecentROM_9", 2, &RecentROMList[9], ""}, - {"EnableCheats", 0, &EnableCheats, 0, NULL, 0}, + {"EnableCheats", 1, &EnableCheats, false}, - {"MouseHide", 0, &MouseHide, 0, NULL, 0}, - {"MouseHideSeconds", 0, &MouseHideSeconds, 5, NULL, 0}, - {"PauseLostFocus", 0, &PauseLostFocus, 0, NULL, 0}, + {"MouseHide", 1, &MouseHide, false}, + {"MouseHideSeconds", 0, &MouseHideSeconds, 5}, + {"PauseLostFocus", 1, &PauseLostFocus, false}, - {"", -1, NULL, 0, NULL, 0} + {"", -1, nullptr, 0} }; void Load() -{ +{printf("LOADZORZ\n"); ConfigEntry* entry = &ConfigFile[0]; for (;;) { if (!entry->Value) break; - - if (entry->Type == 0) - *(int*)entry->Value = entry->DefaultInt; - else +printf("GETTING ENTRY %s %d\n", entry->Name, entry->Type); + switch (entry->Type) { - strncpy((char*)entry->Value, entry->DefaultStr, entry->StrLength); - ((char*)entry->Value)[entry->StrLength] = '\0'; + case 0: *(int*)entry->Value = std::get(entry->Default); break; + case 1: *(bool*)entry->Value = std::get(entry->Default); break; + case 2: *(std::string*)entry->Value = std::get(entry->Default); break; } entry++; @@ -341,10 +340,12 @@ void Load() 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); + switch (entry->Type) + { + case 0: *(int*)entry->Value = strtol(entryval, NULL, 10); break; + case 1: *(bool*)entry->Value = strtol(entryval, NULL, 10) ? true:false; break; + case 2: *(std::string*)entry->Value = entryval; break; + } break; } @@ -366,10 +367,12 @@ void Save() { 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); + switch (entry->Type) + { + case 0: fprintf(f, "%s=%d\r\n", entry->Name, *(int*)entry->Value); break; + case 1: fprintf(f, "%s=%d\r\n", entry->Name, *(bool*)entry->Value ? 1:0); break; + case 2: fprintf(f, "%s=%s\r\n", entry->Name, (*(std::string*)entry->Value).c_str()); break; + } entry++; } diff --git a/src/frontend/qt_sdl/Config.h b/src/frontend/qt_sdl/Config.h index ad9b4c62..f276114b 100644 --- a/src/frontend/qt_sdl/Config.h +++ b/src/frontend/qt_sdl/Config.h @@ -19,6 +19,9 @@ #ifndef PLATFORMCONFIG_H #define PLATFORMCONFIG_H +#include +#include + enum { HK_Lid = 0, @@ -41,11 +44,9 @@ 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 + int Type; // 0=int 1=bool 2=string + void* Value; // pointer to the value variable + std::variant Default; }; @@ -59,99 +60,99 @@ extern int JoystickID; extern int WindowWidth; extern int WindowHeight; -extern int WindowMaximized; +extern bool WindowMaximized; extern int ScreenRotation; extern int ScreenGap; extern int ScreenLayout; -extern int ScreenSwap; +extern bool ScreenSwap; extern int ScreenSizing; extern int ScreenAspectTop; extern int ScreenAspectBot; -extern int IntegerScaling; -extern int ScreenFilter; +extern bool IntegerScaling; +extern bool ScreenFilter; -extern int ScreenUseGL; -extern int ScreenVSync; +extern bool ScreenUseGL; +extern bool ScreenVSync; extern int ScreenVSyncInterval; extern int _3DRenderer; -extern int Threaded3D; +extern bool Threaded3D; extern int GL_ScaleFactor; -extern int GL_BetterPolygons; +extern bool GL_BetterPolygons; -extern int LimitFPS; -extern int AudioSync; -extern int ShowOSD; +extern bool LimitFPS; +extern bool AudioSync; +extern bool ShowOSD; extern int ConsoleType; -extern int DirectBoot; +extern bool DirectBoot; #ifdef JIT_ENABLED -extern int JIT_Enable; +extern bool JIT_Enable; extern int JIT_MaxBlockSize; -extern int JIT_BranchOptimisations; -extern int JIT_LiteralOptimisations; -extern int JIT_FastMemory; +extern bool JIT_BranchOptimisations; +extern bool JIT_LiteralOptimisations; +extern bool JIT_FastMemory; #endif -extern int ExternalBIOSEnable; +extern bool ExternalBIOSEnable; -extern char BIOS9Path[1024]; -extern char BIOS7Path[1024]; -extern char FirmwarePath[1024]; +extern std::string BIOS9Path; +extern std::string BIOS7Path; +extern std::string FirmwarePath; -extern char DSiBIOS9Path[1024]; -extern char DSiBIOS7Path[1024]; -extern char DSiFirmwarePath[1024]; -extern char DSiNANDPath[1024]; +extern std::string DSiBIOS9Path; +extern std::string DSiBIOS7Path; +extern std::string DSiFirmwarePath; +extern std::string DSiNANDPath; -extern int DLDIEnable; -extern char DLDISDPath[1024]; +extern bool DLDIEnable; +extern std::string DLDISDPath; extern int DLDISize; -extern int DLDIReadOnly; -extern int DLDIFolderSync; -extern char DLDIFolderPath[1024]; +extern bool DLDIReadOnly; +extern bool DLDIFolderSync; +extern std::string DLDIFolderPath; -extern int DSiSDEnable; -extern char DSiSDPath[1024]; +extern bool DSiSDEnable; +extern std::string DSiSDPath; extern int DSiSDSize; -extern int DSiSDReadOnly; -extern int DSiSDFolderSync; -extern char DSiSDFolderPath[1024]; +extern bool DSiSDReadOnly; +extern bool DSiSDFolderSync; +extern std::string DSiSDFolderPath; -extern int FirmwareOverrideSettings; -extern char FirmwareUsername[64]; +extern bool FirmwareOverrideSettings; +extern std::string FirmwareUsername; extern int FirmwareLanguage; extern int FirmwareBirthdayMonth; extern int FirmwareBirthdayDay; extern int FirmwareFavouriteColour; -extern char FirmwareMessage[1024]; -extern char FirmwareMAC[18]; -extern int RandomizeMAC; +extern std::string FirmwareMessage; +extern std::string FirmwareMAC; +extern bool RandomizeMAC; -extern int SocketBindAnyAddr; -extern char LANDevice[128]; -extern int DirectLAN; +extern bool SocketBindAnyAddr; +extern std::string LANDevice; +extern bool DirectLAN; -extern int SavestateRelocSRAM; +extern bool SavestateRelocSRAM; extern int AudioInterp; extern int AudioBitrate; extern int AudioVolume; extern int MicInputType; -extern char MicWavPath[1024]; +extern std::string MicWavPath; -extern char LastROMFolder[1024]; +extern std::string LastROMFolder; -extern char RecentROMList[10][1024]; +extern std::string RecentROMList[10]; -extern int EnableCheats; +extern bool EnableCheats; -extern int MouseHide; +extern bool MouseHide; extern int MouseHideSeconds; -extern int PauseLostFocus; +extern bool PauseLostFocus; void Load(); diff --git a/src/frontend/qt_sdl/EmuSettingsDialog.cpp b/src/frontend/qt_sdl/EmuSettingsDialog.cpp index fd2ca85c..75118815 100644 --- a/src/frontend/qt_sdl/EmuSettingsDialog.cpp +++ b/src/frontend/qt_sdl/EmuSettingsDialog.cpp @@ -42,27 +42,27 @@ EmuSettingsDialog::EmuSettingsDialog(QWidget* parent) : QDialog(parent), ui(new ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); - ui->chkExternalBIOS->setChecked(Config::ExternalBIOSEnable != 0); - ui->txtBIOS9Path->setText(Config::BIOS9Path); - ui->txtBIOS7Path->setText(Config::BIOS7Path); - ui->txtFirmwarePath->setText(Config::FirmwarePath); + ui->chkExternalBIOS->setChecked(Config::ExternalBIOSEnable); + ui->txtBIOS9Path->setText(QString::fromStdString(Config::BIOS9Path)); + ui->txtBIOS7Path->setText(QString::fromStdString(Config::BIOS7Path)); + ui->txtFirmwarePath->setText(QString::fromStdString(Config::FirmwarePath)); - ui->txtDSiBIOS9Path->setText(Config::DSiBIOS9Path); - ui->txtDSiBIOS7Path->setText(Config::DSiBIOS7Path); - ui->txtDSiFirmwarePath->setText(Config::DSiFirmwarePath); - ui->txtDSiNANDPath->setText(Config::DSiNANDPath); + ui->txtDSiBIOS9Path->setText(QString::fromStdString(Config::DSiBIOS9Path)); + ui->txtDSiBIOS7Path->setText(QString::fromStdString(Config::DSiBIOS7Path)); + ui->txtDSiFirmwarePath->setText(QString::fromStdString(Config::DSiFirmwarePath)); + ui->txtDSiNANDPath->setText(QString::fromStdString(Config::DSiNANDPath)); ui->cbxConsoleType->addItem("DS"); ui->cbxConsoleType->addItem("DSi (experimental)"); ui->cbxConsoleType->setCurrentIndex(Config::ConsoleType); - ui->chkDirectBoot->setChecked(Config::DirectBoot != 0); + ui->chkDirectBoot->setChecked(Config::DirectBoot); #ifdef JIT_ENABLED - ui->chkEnableJIT->setChecked(Config::JIT_Enable != 0); - ui->chkJITBranchOptimisations->setChecked(Config::JIT_BranchOptimisations != 0); - ui->chkJITLiteralOptimisations->setChecked(Config::JIT_LiteralOptimisations != 0); - ui->chkJITFastMemory->setChecked(Config::JIT_FastMemory != 0); + ui->chkEnableJIT->setChecked(Config::JIT_Enable); + ui->chkJITBranchOptimisations->setChecked(Config::JIT_BranchOptimisations); + ui->chkJITLiteralOptimisations->setChecked(Config::JIT_LiteralOptimisations); + ui->chkJITFastMemory->setChecked(Config::JIT_FastMemory); #ifdef __APPLE__ ui->chkJITFastMemory->setDisabled(true); #endif @@ -101,20 +101,20 @@ EmuSettingsDialog::EmuSettingsDialog(QWidget* parent) : QDialog(parent), ui(new ui->cbxDSiSDSize->addItem(sizelbl); } - ui->cbDLDIEnable->setChecked(Config::DLDIEnable != 0); - ui->txtDLDISDPath->setText(Config::DLDISDPath); + ui->cbDLDIEnable->setChecked(Config::DLDIEnable); + ui->txtDLDISDPath->setText(QString::fromStdString(Config::DLDISDPath)); ui->cbxDLDISize->setCurrentIndex(Config::DLDISize); - ui->cbDLDIReadOnly->setChecked(Config::DLDIReadOnly != 0); - ui->cbDLDIFolder->setChecked(Config::DLDIFolderSync != 0); - ui->txtDLDIFolder->setText(Config::DLDIFolderPath); + ui->cbDLDIReadOnly->setChecked(Config::DLDIReadOnly); + ui->cbDLDIFolder->setChecked(Config::DLDIFolderSync); + ui->txtDLDIFolder->setText(QString::fromStdString(Config::DLDIFolderPath)); on_cbDLDIEnable_toggled(); - ui->cbDSiSDEnable->setChecked(Config::DSiSDEnable != 0); - ui->txtDSiSDPath->setText(Config::DSiSDPath); + ui->cbDSiSDEnable->setChecked(Config::DSiSDEnable); + ui->txtDSiSDPath->setText(QString::fromStdString(Config::DSiSDPath)); ui->cbxDSiSDSize->setCurrentIndex(Config::DSiSDSize); - ui->cbDSiSDReadOnly->setChecked(Config::DSiSDReadOnly != 0); - ui->cbDSiSDFolder->setChecked(Config::DSiSDFolderSync != 0); - ui->txtDSiSDFolder->setText(Config::DSiSDFolderPath); + ui->cbDSiSDReadOnly->setChecked(Config::DSiSDReadOnly); + ui->cbDSiSDFolder->setChecked(Config::DSiSDFolderSync); + ui->txtDSiSDFolder->setText(QString::fromStdString(Config::DSiSDFolderPath)); on_cbDSiSDEnable_toggled(); } @@ -140,8 +140,7 @@ void EmuSettingsDialog::verifyFirmware() // looked at has 0x180 bytes from the header repeated at 0x3FC80, but // bytes 0x0C-0x14 are different. - char filename[1024]; - strncpy(filename, ui->txtFirmwarePath->text().toStdString().c_str(), 1023); filename[1023] = '\0'; + std::string filename = ui->txtFirmwarePath->text().toStdString(); FILE* f = Platform::OpenLocalFile(filename, "rb"); if (!f) return; u8 chk1[0x180], chk2[0x180]; @@ -175,24 +174,24 @@ void EmuSettingsDialog::done(int r) verifyFirmware(); int consoleType = ui->cbxConsoleType->currentIndex(); - int directBoot = ui->chkDirectBoot->isChecked() ? 1:0; + bool directBoot = ui->chkDirectBoot->isChecked(); - int jitEnable = ui->chkEnableJIT->isChecked() ? 1:0; + bool jitEnable = ui->chkEnableJIT->isChecked(); int jitMaxBlockSize = ui->spnJITMaximumBlockSize->value(); - int jitBranchOptimisations = ui->chkJITBranchOptimisations->isChecked() ? 1:0; - int jitLiteralOptimisations = ui->chkJITLiteralOptimisations->isChecked() ? 1:0; - int jitFastMemory = ui->chkJITFastMemory->isChecked() ? 1:0; + bool jitBranchOptimisations = ui->chkJITBranchOptimisations->isChecked(); + bool jitLiteralOptimisations = ui->chkJITLiteralOptimisations->isChecked(); + bool jitFastMemory = ui->chkJITFastMemory->isChecked(); - int externalBiosEnable = ui->chkExternalBIOS->isChecked() ? 1:0; + bool externalBiosEnable = ui->chkExternalBIOS->isChecked(); std::string bios9Path = ui->txtBIOS9Path->text().toStdString(); std::string bios7Path = ui->txtBIOS7Path->text().toStdString(); std::string firmwarePath = ui->txtFirmwarePath->text().toStdString(); - int dldiEnable = ui->cbDLDIEnable->isChecked() ? 1:0; + bool dldiEnable = ui->cbDLDIEnable->isChecked(); std::string dldiSDPath = ui->txtDLDISDPath->text().toStdString(); int dldiSize = ui->cbxDLDISize->currentIndex(); - int dldiReadOnly = ui->cbDLDIReadOnly->isChecked() ? 1:0; - int dldiFolderSync = ui->cbDLDIFolder->isChecked() ? 1:0; + bool dldiReadOnly = ui->cbDLDIReadOnly->isChecked(); + bool dldiFolderSync = ui->cbDLDIFolder->isChecked(); std::string dldiFolderPath = ui->txtDLDIFolder->text().toStdString(); std::string dsiBios9Path = ui->txtDSiBIOS9Path->text().toStdString(); @@ -200,11 +199,11 @@ void EmuSettingsDialog::done(int r) std::string dsiFirmwarePath = ui->txtDSiFirmwarePath->text().toStdString(); std::string dsiNANDPath = ui->txtDSiNANDPath->text().toStdString(); - int dsiSDEnable = ui->cbDSiSDEnable->isChecked() ? 1:0; + bool dsiSDEnable = ui->cbDSiSDEnable->isChecked(); std::string dsiSDPath = ui->txtDSiSDPath->text().toStdString(); int dsiSDSize = ui->cbxDSiSDSize->currentIndex(); - int dsiSDReadOnly = ui->cbDSiSDReadOnly->isChecked() ? 1:0; - int dsiSDFolderSync = ui->cbDSiSDFolder->isChecked() ? 1:0; + bool dsiSDReadOnly = ui->cbDSiSDReadOnly->isChecked(); + bool dsiSDFolderSync = ui->cbDSiSDFolder->isChecked(); std::string dsiSDFolderPath = ui->txtDSiSDFolder->text().toStdString(); if (consoleType != Config::ConsoleType @@ -217,25 +216,25 @@ void EmuSettingsDialog::done(int r) || jitFastMemory != Config::JIT_FastMemory #endif || externalBiosEnable != Config::ExternalBIOSEnable - || strcmp(Config::BIOS9Path, bios9Path.c_str()) != 0 - || strcmp(Config::BIOS7Path, bios7Path.c_str()) != 0 - || strcmp(Config::FirmwarePath, firmwarePath.c_str()) != 0 + || bios9Path != Config::BIOS9Path + || bios7Path != Config::BIOS7Path + || firmwarePath != Config::FirmwarePath || dldiEnable != Config::DLDIEnable - || strcmp(Config::DLDISDPath, dldiSDPath.c_str()) != 0 + || dldiSDPath != Config::DLDISDPath || dldiSize != Config::DLDISize || dldiReadOnly != Config::DLDIReadOnly || dldiFolderSync != Config::DLDIFolderSync - || strcmp(Config::DLDIFolderPath, dldiFolderPath.c_str()) != 0 - || strcmp(Config::DSiBIOS9Path, dsiBios9Path.c_str()) != 0 - || strcmp(Config::DSiBIOS7Path, dsiBios7Path.c_str()) != 0 - || strcmp(Config::DSiFirmwarePath, dsiFirmwarePath.c_str()) != 0 - || strcmp(Config::DSiNANDPath, dsiNANDPath.c_str()) != 0 + || dldiFolderPath != Config::DLDIFolderPath + || dsiBios9Path != Config::DSiBIOS9Path + || dsiBios7Path != Config::DSiBIOS7Path + || dsiFirmwarePath != Config::DSiFirmwarePath + || dsiNANDPath != Config::DSiNANDPath || dsiSDEnable != Config::DSiSDEnable - || strcmp(Config::DSiSDPath, dsiSDPath.c_str()) != 0 + || dsiSDPath != Config::DSiSDPath || dsiSDSize != Config::DSiSDSize || dsiSDReadOnly != Config::DSiSDReadOnly || dsiSDFolderSync != Config::DSiSDFolderSync - || strcmp(Config::DSiSDFolderPath, dsiSDFolderPath.c_str()) != 0) + || dsiSDFolderPath != Config::DSiSDFolderPath) { if (RunningSomething && QMessageBox::warning(this, "Reset necessary to apply changes", @@ -244,28 +243,28 @@ void EmuSettingsDialog::done(int r) return; Config::ExternalBIOSEnable = externalBiosEnable; - strncpy(Config::BIOS9Path, bios9Path.c_str(), 1023); Config::BIOS9Path[1023] = '\0'; - strncpy(Config::BIOS7Path, bios7Path.c_str(), 1023); Config::BIOS7Path[1023] = '\0'; - strncpy(Config::FirmwarePath, firmwarePath.c_str(), 1023); Config::FirmwarePath[1023] = '\0'; + Config::BIOS9Path = bios9Path; + Config::BIOS7Path = bios7Path; + Config::FirmwarePath = firmwarePath; Config::DLDIEnable = dldiEnable; - strncpy(Config::DLDISDPath, dldiSDPath.c_str(), 1023); Config::DLDISDPath[1023] = '\0'; + Config::DLDISDPath = dldiSDPath; Config::DLDISize = dldiSize; Config::DLDIReadOnly = dldiReadOnly; Config::DLDIFolderSync = dldiFolderSync; - strncpy(Config::DLDIFolderPath, dldiFolderPath.c_str(), 1023); Config::DLDIFolderPath[1023] = '\0'; + Config::DLDIFolderPath = dldiFolderPath; - strncpy(Config::DSiBIOS9Path, dsiBios9Path.c_str(), 1023); Config::DSiBIOS9Path[1023] = '\0'; - strncpy(Config::DSiBIOS7Path, dsiBios7Path.c_str(), 1023); Config::DSiBIOS7Path[1023] = '\0'; - strncpy(Config::DSiFirmwarePath, dsiFirmwarePath.c_str(), 1023); Config::DSiFirmwarePath[1023] = '\0'; - strncpy(Config::DSiNANDPath, dsiNANDPath.c_str(), 1023); Config::DSiNANDPath[1023] = '\0'; + Config::DSiBIOS9Path = dsiBios9Path; + Config::DSiBIOS7Path = dsiBios7Path; + Config::DSiFirmwarePath = dsiFirmwarePath; + Config::DSiNANDPath = dsiNANDPath; Config::DSiSDEnable = dsiSDEnable; - strncpy(Config::DSiSDPath, dsiSDPath.c_str(), 1023); Config::DSiSDPath[1023] = '\0'; + Config::DSiSDPath = dsiSDPath; Config::DSiSDSize = dsiSDSize; Config::DSiSDReadOnly = dsiSDReadOnly; Config::DSiSDFolderSync = dsiSDFolderSync; - strncpy(Config::DSiSDFolderPath, dsiSDFolderPath.c_str(), 1023); Config::DSiSDFolderPath[1023] = '\0'; + Config::DSiSDFolderPath = dsiSDFolderPath; #ifdef JIT_ENABLED Config::JIT_Enable = jitEnable; diff --git a/src/frontend/qt_sdl/FirmwareSettingsDialog.cpp b/src/frontend/qt_sdl/FirmwareSettingsDialog.cpp index 0b2cad6c..976934f9 100644 --- a/src/frontend/qt_sdl/FirmwareSettingsDialog.cpp +++ b/src/frontend/qt_sdl/FirmwareSettingsDialog.cpp @@ -35,7 +35,7 @@ FirmwareSettingsDialog::FirmwareSettingsDialog(QWidget* parent) : QDialog(parent ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); - ui->usernameEdit->setText(Config::FirmwareUsername); + ui->usernameEdit->setText(QString::fromStdString(Config::FirmwareUsername)); ui->languageBox->addItems(languages); ui->languageBox->setCurrentIndex(Config::FirmwareLanguage); @@ -59,12 +59,12 @@ FirmwareSettingsDialog::FirmwareSettingsDialog(QWidget* parent) : QDialog(parent } ui->colorsEdit->setCurrentIndex(Config::FirmwareFavouriteColour); - ui->messageEdit->setText(Config::FirmwareMessage); + ui->messageEdit->setText(QString::fromStdString(Config::FirmwareMessage)); ui->overrideFirmwareBox->setChecked(Config::FirmwareOverrideSettings); - ui->txtMAC->setText(Config::FirmwareMAC); - ui->cbRandomizeMAC->setChecked(Config::RandomizeMAC != 0); + ui->txtMAC->setText(QString::fromStdString(Config::FirmwareMAC)); + ui->cbRandomizeMAC->setChecked(Config::RandomizeMAC); on_cbRandomizeMAC_toggled(); } @@ -123,7 +123,7 @@ void FirmwareSettingsDialog::done(int r) return; } - int newOverride = ui->overrideFirmwareBox->isChecked(); + bool newOverride = ui->overrideFirmwareBox->isChecked(); std::string newName = ui->usernameEdit->text().toStdString(); int newLanguage = ui->languageBox->currentIndex(); @@ -133,16 +133,16 @@ void FirmwareSettingsDialog::done(int r) std::string newMessage = ui->messageEdit->text().toStdString(); std::string newMAC = ui->txtMAC->text().toStdString(); - int newRandomizeMAC = ui->cbRandomizeMAC->isChecked() ? 1:0; + bool newRandomizeMAC = ui->cbRandomizeMAC->isChecked(); if ( newOverride != Config::FirmwareOverrideSettings - || strcmp(newName.c_str(), Config::FirmwareUsername) != 0 + || newName != Config::FirmwareUsername || newLanguage != Config::FirmwareLanguage || newFavColor != Config::FirmwareFavouriteColour || newBirthdayDay != Config::FirmwareBirthdayDay || newBirthdayMonth != Config::FirmwareBirthdayMonth - || strcmp(newMessage.c_str(), Config::FirmwareMessage) != 0 - || strcmp(newMAC.c_str(), Config::FirmwareMAC) != 0 + || newMessage != Config::FirmwareMessage + || newMAC != Config::FirmwareMAC || newRandomizeMAC != Config::RandomizeMAC) { if (RunningSomething @@ -153,14 +153,14 @@ void FirmwareSettingsDialog::done(int r) Config::FirmwareOverrideSettings = newOverride; - strncpy(Config::FirmwareUsername, newName.c_str(), 63); Config::FirmwareUsername[63] = '\0'; + Config::FirmwareUsername = newName; Config::FirmwareLanguage = newLanguage; Config::FirmwareFavouriteColour = newFavColor; Config::FirmwareBirthdayDay = newBirthdayDay; Config::FirmwareBirthdayMonth = newBirthdayMonth; - strncpy(Config::FirmwareMessage, newMessage.c_str(), 1023); Config::FirmwareMessage[1023] = '\0'; + Config::FirmwareMessage = newMessage; - strncpy(Config::FirmwareMAC, newMAC.c_str(), 17); Config::FirmwareMAC[17] = '\0'; + Config::FirmwareMAC = newMAC; Config::RandomizeMAC = newRandomizeMAC; Config::Save(); diff --git a/src/frontend/qt_sdl/LAN_PCap.cpp b/src/frontend/qt_sdl/LAN_PCap.cpp index ed3eee94..dcc23103 100644 --- a/src/frontend/qt_sdl/LAN_PCap.cpp +++ b/src/frontend/qt_sdl/LAN_PCap.cpp @@ -318,7 +318,7 @@ bool Init(bool open_adapter) PCapAdapterData = &Adapters[0]; for (int i = 0; i < NumAdapters; i++) { - if (!strncmp(Adapters[i].DeviceName, Config::LANDevice, 128)) + if (!strncmp(Adapters[i].DeviceName, Config::LANDevice.c_str(), 128)) PCapAdapterData = &Adapters[i]; } diff --git a/src/frontend/qt_sdl/Platform.cpp b/src/frontend/qt_sdl/Platform.cpp index 812c9532..de292d7f 100644 --- a/src/frontend/qt_sdl/Platform.cpp +++ b/src/frontend/qt_sdl/Platform.cpp @@ -207,7 +207,7 @@ bool GetConfigArray(ConfigEntry entry, void* data) { case Firm_MAC: { - char* mac_in = Config::FirmwareMAC; + std::string& mac_in = Config::FirmwareMAC; u8* mac_out = (u8*)data; int o = 0; diff --git a/src/frontend/qt_sdl/ROMInfoDialog.cpp b/src/frontend/qt_sdl/ROMInfoDialog.cpp index 9166efe8..66ccd96e 100644 --- a/src/frontend/qt_sdl/ROMInfoDialog.cpp +++ b/src/frontend/qt_sdl/ROMInfoDialog.cpp @@ -130,7 +130,7 @@ void ROMInfoDialog::on_saveIconButton_clicked() { QString filename = QFileDialog::getSaveFileName(this, "Save Icon", - Config::LastROMFolder, + QString::fromStdString(Config::LastROMFolder), "PNG Images (*.png)"); if (filename.isEmpty()) return; diff --git a/src/frontend/qt_sdl/WifiSettingsDialog.cpp b/src/frontend/qt_sdl/WifiSettingsDialog.cpp index d438179e..e584b6ac 100644 --- a/src/frontend/qt_sdl/WifiSettingsDialog.cpp +++ b/src/frontend/qt_sdl/WifiSettingsDialog.cpp @@ -55,7 +55,7 @@ WifiSettingsDialog::WifiSettingsDialog(QWidget* parent) : QDialog(parent), ui(ne ui->rbDirectMode->setText("Direct mode (requires " PCAP_NAME " and ethernet connection)"); - ui->cbBindAnyAddr->setChecked(Config::SocketBindAnyAddr != 0); + ui->cbBindAnyAddr->setChecked(Config::SocketBindAnyAddr); int sel = 0; for (int i = 0; i < LAN_PCap::NumAdapters; i++) @@ -64,13 +64,14 @@ WifiSettingsDialog::WifiSettingsDialog(QWidget* parent) : QDialog(parent), ui(ne ui->cbxDirectAdapter->addItem(QString(adapter->FriendlyName)); - if (!strncmp(adapter->DeviceName, Config::LANDevice, 128)) + if (!strncmp(adapter->DeviceName, Config::LANDevice.c_str(), 128)) sel = i; } ui->cbxDirectAdapter->setCurrentIndex(sel); - ui->rbDirectMode->setChecked(Config::DirectLAN != 0); - ui->rbIndirectMode->setChecked(Config::DirectLAN == 0); + // errrr??? + ui->rbDirectMode->setChecked(Config::DirectLAN); + ui->rbIndirectMode->setChecked(!Config::DirectLAN); if (!haspcap) ui->rbDirectMode->setEnabled(false); updateAdapterControls(); @@ -87,19 +88,18 @@ void WifiSettingsDialog::done(int r) if (r == QDialog::Accepted) { - Config::SocketBindAnyAddr = ui->cbBindAnyAddr->isChecked() ? 1:0; - Config::DirectLAN = ui->rbDirectMode->isChecked() ? 1:0; + Config::SocketBindAnyAddr = ui->cbBindAnyAddr->isChecked(); + Config::DirectLAN = ui->rbDirectMode->isChecked(); int sel = ui->cbxDirectAdapter->currentIndex(); if (sel < 0 || sel >= LAN_PCap::NumAdapters) sel = 0; if (LAN_PCap::NumAdapters < 1) { - Config::LANDevice[0] = '\0'; + Config::LANDevice = ""; } else { - strncpy(Config::LANDevice, LAN_PCap::Adapters[sel].DeviceName, 127); - Config::LANDevice[127] = '\0'; + Config::LANDevice = LAN_PCap::Adapters[sel].DeviceName; } Config::Save(); diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index d25da0d4..c17f382a 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -181,7 +181,7 @@ void micClose() micDevice = 0; } -void micLoadWav(const char* name) +void micLoadWav(std::string name) { SDL_AudioSpec format; memset(&format, 0, sizeof(SDL_AudioSpec)); @@ -192,7 +192,7 @@ void micLoadWav(const char* name) u8* buf; u32 len; - if (!SDL_LoadWAV(name, &format, &buf, &len)) + if (!SDL_LoadWAV(name.c_str(), &format, &buf, &len)) return; const u64 dstfreq = 44100; @@ -1274,7 +1274,7 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) oldW = Config::WindowWidth; oldH = Config::WindowHeight; - oldMax = Config::WindowMaximized!=0; + oldMax = Config::WindowMaximized; setWindowTitle("melonDS " MELONDS_VERSION); setAttribute(Qt::WA_DeleteOnClose); @@ -1295,9 +1295,9 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) recentMenu = menu->addMenu("Open recent"); for (int i = 0; i < 10; ++i) { - char* item = Config::RecentROMList[i]; - if (strlen(item) > 0) - recentFileList.push_back(item); + std::string item = Config::RecentROMList[i]; + if (!item.empty()) + recentFileList.push_back(QString::fromStdString(item)); } updateRecentFilesMenu(); @@ -1591,13 +1591,13 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) actFrameStep->setEnabled(false); actSetupCheats->setEnabled(false); - actTitleManager->setEnabled(strlen(Config::DSiNANDPath) > 0); + actTitleManager->setEnabled(!Config::DSiNANDPath.empty()); - actEnableCheats->setChecked(Config::EnableCheats != 0); + actEnableCheats->setChecked(Config::EnableCheats); actROMInfo->setEnabled(false); - actSavestateSRAMReloc->setChecked(Config::SavestateRelocSRAM != 0); + actSavestateSRAMReloc->setChecked(Config::SavestateRelocSRAM); actScreenRotation[Config::ScreenRotation]->setChecked(true); @@ -1612,18 +1612,18 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) actScreenLayout[Config::ScreenLayout]->setChecked(true); actScreenSizing[Config::ScreenSizing]->setChecked(true); - actIntegerScaling->setChecked(Config::IntegerScaling != 0); + actIntegerScaling->setChecked(Config::IntegerScaling); - actScreenSwap->setChecked(Config::ScreenSwap != 0); + actScreenSwap->setChecked(Config::ScreenSwap); actScreenAspectTop[Config::ScreenAspectTop]->setChecked(true); actScreenAspectBot[Config::ScreenAspectBot]->setChecked(true); - actScreenFiltering->setChecked(Config::ScreenFilter != 0); - actShowOSD->setChecked(Config::ShowOSD != 0); + actScreenFiltering->setChecked(Config::ScreenFilter); + actShowOSD->setChecked(Config::ShowOSD); - actLimitFramerate->setChecked(Config::LimitFPS != 0); - actAudioSync->setChecked(Config::AudioSync != 0); + actLimitFramerate->setChecked(Config::LimitFPS); + actAudioSync->setChecked(Config::AudioSync); } MainWindow::~MainWindow() @@ -1885,7 +1885,7 @@ void MainWindow::loadROM(QByteArray *romData, QString archiveFileName, QString r updateRecentFilesMenu(); // Strip entire archive name and get folder path - strncpy(Config::LastROMFolder, QFileInfo(archiveFileName).absolutePath().toStdString().c_str(), 1024); + Config::LastROMFolder = QFileInfo(archiveFileName).absolutePath().toStdString(); QString sramFileName = QFileInfo(archiveFileName).absolutePath() + QDir::separator() + QFileInfo(romFileName).completeBaseName() + ".sav"; @@ -1937,26 +1937,23 @@ void MainWindow::loadROM(QString filename) // * ensure the binary offsets are sane // * etc - // this shit is stupid - char file[1024]; - strncpy(file, filename.toStdString().c_str(), 1023); file[1023] = '\0'; - - int pos = strlen(file)-1; + std::string file = filename.toStdString(); + int pos = file.length() - 1; while (file[pos] != '/' && file[pos] != '\\' && pos > 0) pos--; - strncpy(Config::LastROMFolder, file, pos); - Config::LastROMFolder[pos] = '\0'; - char* ext = &file[strlen(file)-3]; + Config::LastROMFolder = file.substr(0, pos); + + std::string ext = file.substr(file.length() - 3); int slot; int res; - if (!strcasecmp(ext, "gba")) + if (ext == "gba") { slot = 1; - res = Frontend::LoadROM(file, Frontend::ROMSlot_GBA); + res = Frontend::LoadROM(file.c_str(), Frontend::ROMSlot_GBA); } else { slot = 0; - res = Frontend::LoadROM(file, Frontend::ROMSlot_NDS); + res = Frontend::LoadROM(file.c_str(), Frontend::ROMSlot_NDS); } if (res != Frontend::Load_OK) @@ -1983,7 +1980,7 @@ void MainWindow::onOpenFile() QString filename = QFileDialog::getOpenFileName(this, "Open ROM", - Config::LastROMFolder, + QString::fromStdString(Config::LastROMFolder), "DS ROMs (*.nds *.dsi *.srl);;GBA ROMs (*.gba *.zip);;Any file (*.*)"); if (filename.isEmpty()) { @@ -2000,7 +1997,7 @@ void MainWindow::onOpenFileArchive() QString archiveFileName = QFileDialog::getOpenFileName(this, "Open ROM Archive", - Config::LastROMFolder, + QString::fromStdString(Config::LastROMFolder), "Archived ROMs (*.zip *.7z *.rar *.tar *.tar.gz *.tar.xz *.tar.bz2);;Any file (*.*)"); if (archiveFileName.isEmpty()) { @@ -2073,7 +2070,8 @@ QString MainWindow::pickAndExtractFileFromArchive(QString archiveFileName, QByte void MainWindow::onClearRecentFiles() { recentFileList.clear(); - memset(Config::RecentROMList, 0, 10 * 1024); + for (int i = 0; i < 10; i++) + Config::RecentROMList[i] = ""; updateRecentFilesMenu(); } @@ -2109,8 +2107,8 @@ void MainWindow::updateRecentFilesMenu() actRecentFile_i->setData(item_full); connect(actRecentFile_i, &QAction::triggered, this, &MainWindow::onClickRecentFile); - if(i < 10) - strncpy(Config::RecentROMList[i], recentFileList.at(i).toStdString().c_str(), 1024); + if (i < 10) + Config::RecentROMList[i] = recentFileList.at(i).toStdString(); } recentMenu->addSeparator(); @@ -2177,17 +2175,17 @@ void MainWindow::onSaveState() emuThread->emuPause(); - char filename[1024]; + std::string filename; if (slot > 0) { - Frontend::GetSavestateName(slot, filename, 1024); + filename = Frontend::GetSavestateName(slot); } else { // TODO: specific 'last directory' for savestate files? QString qfilename = QFileDialog::getSaveFileName(this, "Save state", - Config::LastROMFolder, + QString::fromStdString(Config::LastROMFolder), "melonDS savestates (*.mln);;Any file (*.*)"); if (qfilename.isEmpty()) { @@ -2195,7 +2193,7 @@ void MainWindow::onSaveState() return; } - strncpy(filename, qfilename.toStdString().c_str(), 1023); filename[1023] = '\0'; + filename = qfilename.toStdString(); } if (Frontend::SaveState(filename)) @@ -2221,17 +2219,17 @@ void MainWindow::onLoadState() emuThread->emuPause(); - char filename[1024]; + std::string filename; if (slot > 0) { - Frontend::GetSavestateName(slot, filename, 1024); + filename = Frontend::GetSavestateName(slot); } else { // TODO: specific 'last directory' for savestate files? QString qfilename = QFileDialog::getOpenFileName(this, "Load state", - Config::LastROMFolder, + QString::fromStdString(Config::LastROMFolder), "melonDS savestates (*.ml*);;Any file (*.*)"); if (qfilename.isEmpty()) { @@ -2239,7 +2237,7 @@ void MainWindow::onLoadState() return; } - strncpy(filename, qfilename.toStdString().c_str(), 1023); filename[1023] = '\0'; + filename = qfilename.toStdString(); } if (!Platform::FileExists(filename)) @@ -2286,7 +2284,7 @@ void MainWindow::onImportSavefile() emuThread->emuPause(); QString path = QFileDialog::getOpenFileName(this, "Select savefile", - Config::LastROMFolder, + QString::fromStdString(Config::LastROMFolder), "Savefiles (*.sav *.bin *.dsv);;Any file (*.*)"); if (!path.isEmpty()) @@ -2424,7 +2422,7 @@ void MainWindow::onEmuSettingsDialogFinished(int res) onReset(); if (!RunningSomething) - actTitleManager->setEnabled(strlen(Config::DSiNANDPath) > 0); + actTitleManager->setEnabled(!Config::DSiNANDPath.empty()); } void MainWindow::onOpenInputConfig() @@ -2736,7 +2734,7 @@ void MainWindow::onEmuStop() actFrameStep->setEnabled(false); actSetupCheats->setEnabled(false); - actTitleManager->setEnabled(strlen(Config::DSiNANDPath) > 0); + actTitleManager->setEnabled(!Config::DSiNANDPath.empty()); actROMInfo->setEnabled(false); }