From 9f5df2a6f2cc5fe0e7bdf478d7882e11c8dc8faa Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sun, 9 Nov 2014 23:27:43 -0800 Subject: [PATCH] GBA Config: Move config file to ~/.config/mgba/config.ini --- src/gba/gba-config.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/gba/gba-config.c b/src/gba/gba-config.c index 6fbc96ac3..5ebb99d71 100644 --- a/src/gba/gba-config.c +++ b/src/gba/gba-config.c @@ -2,6 +2,8 @@ #include "platform/commandline.h" +#include + #define SECTION_NAME_MAX 128 static const char* _lookupValue(const struct GBAConfig* config, const char* key) { @@ -93,11 +95,22 @@ void GBAConfigDeinit(struct GBAConfig* config) { } bool GBAConfigLoad(struct GBAConfig* config) { - return ConfigurationRead(&config->configTable, BINARY_NAME ".ini"); + char path[PATH_MAX]; + char* home = getenv("HOME"); + snprintf(path, PATH_MAX, "%s/.config/%s/config.ini", home, BINARY_NAME); + return ConfigurationRead(&config->configTable, path); } bool GBAConfigSave(const struct GBAConfig* config) { - return ConfigurationWrite(&config->configTable, BINARY_NAME ".ini"); + // TODO: Support Windows; move to common code + char path[PATH_MAX]; + char* home = getenv("HOME"); + snprintf(path, PATH_MAX, "%s/.config", home); + mkdir(path, 0755); + snprintf(path, PATH_MAX, "%s/.config/%s", home, BINARY_NAME); + mkdir(path, 0755); + snprintf(path, PATH_MAX, "%s/.config/%s/config.ini", home, BINARY_NAME); + return ConfigurationWrite(&config->configTable, path); } const char* GBAConfigGetValue(const struct GBAConfig* config, const char* key) {