diff options
Diffstat (limited to 'src/Config.cpp')
-rw-r--r-- | src/Config.cpp | 108 |
1 files changed, 58 insertions, 50 deletions
diff --git a/src/Config.cpp b/src/Config.cpp index 660ff8c..4836cf5 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -1,5 +1,5 @@ /* - Copyright 2016-2017 StapleButter + Copyright 2016-2019 StapleButter This file is part of melonDS. @@ -20,18 +20,23 @@ #include <string.h> #include <stdlib.h> #include "Config.h" -#include <string> -#ifndef _WIN32 -#include <glib.h> -#endif +#include "melon_fopen.h" +bool LocalFileExists(const char* name); +extern char* EmuDirectory; + namespace Config { +const char* kConfigFile = "melonDS.ini"; + int KeyMapping[12]; int JoyMapping[12]; +int HKKeyMapping[HK_MAX]; +int HKJoyMapping[HK_MAX]; + int WindowWidth; int WindowHeight; @@ -47,6 +52,14 @@ int Threaded3D; int SocketBindAnyAddr; +int SavestateRelocSRAM; + +int AudioVolume; +int MicInputType; +char MicWavPath[512]; + +char LastROMFolder[512]; + typedef struct { char Name[16]; @@ -54,7 +67,7 @@ typedef struct void* Value; int DefaultInt; char* DefaultStr; - int StrLength; + int StrLength; // should be set to actual array length minus one } ConfigEntry; @@ -69,7 +82,7 @@ ConfigEntry ConfigFile[] = {"Key_Up", 0, &KeyMapping[6], 328, NULL, 0}, {"Key_Down", 0, &KeyMapping[7], 336, NULL, 0}, {"Key_R", 0, &KeyMapping[8], 54, NULL, 0}, - {"Key_L", 0, &KeyMapping[9], 42, NULL, 0}, + {"Key_L", 0, &KeyMapping[9], 86, NULL, 0}, {"Key_X", 0, &KeyMapping[10], 17, NULL, 0}, {"Key_Y", 0, &KeyMapping[11], 30, NULL, 0}, @@ -86,6 +99,12 @@ ConfigEntry ConfigFile[] = {"Joy_X", 0, &JoyMapping[10], -1, NULL, 0}, {"Joy_Y", 0, &JoyMapping[11], -1, NULL, 0}, + {"HKKey_Lid", 0, &HKKeyMapping[HK_Lid], 0x0E, NULL, 0}, + {"HKKey_Mic", 0, &HKKeyMapping[HK_Mic], 0x35, NULL, 0}, + + {"HKJoy_Lid", 0, &HKJoyMapping[HK_Lid], -1, NULL, 0}, + {"HKJoy_Mic", 0, &HKJoyMapping[HK_Mic], -1, NULL, 0}, + {"WindowWidth", 0, &WindowWidth, 256, NULL, 0}, {"WindowHeight", 0, &WindowHeight, 384, NULL, 0}, @@ -101,49 +120,17 @@ ConfigEntry ConfigFile[] = {"SockBindAnyAddr", 0, &SocketBindAnyAddr, 0, NULL, 0}, - {"", -1, NULL, 0, NULL, 0} -}; - -FILE* GetConfigFile(const char* fileName, const char* permissions) -{ - // Locations are application directory, and XDG_CONFIG_HOME/melonds or AppData/MelonDS on windows + {"SavStaRelocSRAM", 0, &SavestateRelocSRAM, 1, NULL, 0}, - FILE* f; - - // First check application directory - f = fopen(fileName, permissions); - if (f) return f; -#ifdef _WIN32 - // Now check AppData - PWSTR appDataPath = NULL; - SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, NULL, &appDataPath); - if (!appDataPath) - return NULL; - std::string path = std::string(appDataPath) + "\\melonds\\" + fileName; - f = fopen(path, permissions); - if (f) return f; -#else - // Now check XDG_CONFIG_HOME - std::string path = std::string(g_get_user_config_dir()) + "/melonds/" + fileName; - f = fopen(path.c_str(), permissions); - if (f) return f; -#endif - - return NULL; + {"AudioVolume", 0, &AudioVolume, 255, NULL, 0}, + {"MicInputType", 0, &MicInputType, 1, NULL, 0}, + {"MicWavPath", 1, MicWavPath, 0, "", 511}, + + {"LastROMFolder", 1, LastROMFolder, 0, "", 511}, -} + {"", -1, NULL, 0, NULL, 0} +}; -bool HasConfigFile(const char* fileName) -{ - FILE* f = GetConfigFile(fileName, "rb"); - if (f) - { - fclose(f); - return true; - } - else - return false; -} void Load() { @@ -155,12 +142,15 @@ void Load() 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 = Config::GetConfigFile("melonDS.ini", "r"); + FILE* f = melon_fopen_local(kConfigFile, "r"); if (!f) return; char linebuf[1024]; @@ -196,8 +186,26 @@ void Load() void Save() { - FILE* f = Config::GetConfigFile("melonDS.ini", "w"); - if (!f) return; + FILE* f; + if (LocalFileExists(kConfigFile)) + { + f = melon_fopen_local(kConfigFile, "w"); + if (!f) return; + } + else + { + int dirlen = strlen(EmuDirectory); + int filelen = strlen(kConfigFile); + char* path = new char[dirlen + 1 + filelen + 1]; + strncpy(&path[0], EmuDirectory, dirlen); + path[dirlen] = '/'; + strncpy(&path[dirlen+1], kConfigFile, filelen); + path[dirlen+1+filelen] = '\0'; + + f = melon_fopen(path, "w"); + delete[] path; + if (!f) return; + } ConfigEntry* entry = &ConfigFile[0]; for (;;) |