aboutsummaryrefslogtreecommitdiff
path: root/src/Config.cpp
diff options
context:
space:
mode:
authorStapleButter <thetotalworm@gmail.com>2017-03-23 17:27:33 +0100
committerStapleButter <thetotalworm@gmail.com>2017-03-23 17:27:33 +0100
commitf237afeb66d45220ae0061c1dd8a35eb0335e8b0 (patch)
tree866662d613c66cc7cbd81d92496e7bd542182f54 /src/Config.cpp
parent8c059c99535690033397dcbb0ae1de1019d0740c (diff)
aqezsfrdgthfyjgu
Diffstat (limited to 'src/Config.cpp')
-rw-r--r--src/Config.cpp132
1 files changed, 132 insertions, 0 deletions
diff --git a/src/Config.cpp b/src/Config.cpp
new file mode 100644
index 0000000..9cf6a50
--- /dev/null
+++ b/src/Config.cpp
@@ -0,0 +1,132 @@
+/*
+ Copyright 2016-2017 StapleButter
+
+ This file is part of melonDS.
+
+ melonDS is free software: you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation, either version 3 of the License, or (at your option)
+ any later version.
+
+ melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with melonDS. If not, see http://www.gnu.org/licenses/.
+*/
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include "Config.h"
+
+
+namespace Config
+{
+
+int KeyMapping[12];
+int JoyMapping[12];
+
+typedef struct
+{
+ char Name[16];
+ int Type;
+ void* Value;
+ int DefaultInt;
+ char* DefaultStr;
+ int StrLength;
+
+} ConfigEntry;
+
+ConfigEntry ConfigFile[] =
+{
+ {"Key_A", 0, &KeyMapping[0], 15, NULL, 0},
+ {"Key_B", 0, &KeyMapping[1], 54, NULL, 0},
+ {"Key_Select", 0, &KeyMapping[2], 44, NULL, 0},
+ {"Key_Start", 0, &KeyMapping[3], 40, NULL, 0},
+ {"Key_Right", 0, &KeyMapping[4], 22, NULL, 0},
+ {"Key_Left", 0, &KeyMapping[5], 4, NULL, 0},
+ {"Key_Up", 0, &KeyMapping[6], 26, NULL, 0},
+ {"Key_Down", 0, &KeyMapping[7], 29, NULL, 0},
+ {"Key_R", 0, &KeyMapping[8], 19, NULL, 0},
+ {"Key_L", 0, &KeyMapping[9], 20, NULL, 0},
+ {"Key_X", 0, &KeyMapping[10], 18, NULL, 0},
+ {"Key_Y", 0, &KeyMapping[11], 14, NULL, 0},
+
+ {"", -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);
+
+ entry++;
+ }
+
+ FILE* f = fopen("melonDS.ini", "r");
+ if (!f) return;
+
+ char linebuf[1024];
+ char entryname[16];
+ char entryval[1024];
+ while (!feof(f))
+ {
+ fgets(linebuf, 1024, f);
+ int ret = sscanf(linebuf, "%15[A-Za-z_0-9]=%[^\t\n]", entryname, entryval);
+ if (ret < 2) continue;
+
+ ConfigEntry* entry = &ConfigFile[0];
+ for (;;)
+ {
+ if (!entry->Value) break;
+
+ if (!strncmp(entry->Name, entryname, 15))
+ {
+ 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 = fopen("melonDS.ini", "w");
+ if (!f) return;
+
+ ConfigEntry* entry = &ConfigFile[0];
+ for (;;)
+ {
+ if (!entry->Value) break;
+
+ if (entry->Type == 0)
+ fprintf(f, "%s=%d\n", entry->Name, *(int*)entry->Value);
+ else
+ fprintf(f, "%s=%s\n", entry->Name, entry->Value);
+
+ entry++;
+ }
+
+ fclose(f);
+}
+
+
+}