all repos — mgba @ 5c0c966a74d1913092b3ce706ad228443838d90b

mGBA Game Boy Advance Emulator

GBA Config: Windows support
Jeffrey Pfau jeffrey@endrift.com
Tue, 11 Nov 2014 00:46:30 -0800
commit

5c0c966a74d1913092b3ce706ad228443838d90b

parent

a64259f12c108b7d8cdccf2496ae59e6870d382b

1 files changed, 15 insertions(+), 2 deletions(-)

jump to
M src/gba/gba-config.csrc/gba/gba-config.c

@@ -4,6 +4,12 @@ #include "platform/commandline.h"

#include <sys/stat.h> +#ifdef _WIN32 +#include <windows.h> +#include <shlobj.h> +#include <strsafe.h> +#endif + #define SECTION_NAME_MAX 128 static const char* _lookupValue(const struct GBAConfig* config, const char* key) {

@@ -85,7 +91,7 @@ void GBAConfigInit(struct GBAConfig* config, const char* port) {

ConfigurationInit(&config->configTable); ConfigurationInit(&config->defaultsTable); config->port = malloc(strlen("ports.") + strlen(port) + 1); - sprintf(config->port, "ports.%s", port); + snprintf(config->port, strlen("ports.") + strlen(port) + 1, "ports.%s", port); } void GBAConfigDeinit(struct GBAConfig* config) {

@@ -102,14 +108,21 @@ return ConfigurationRead(&config->configTable, path);

} bool GBAConfigSave(const struct GBAConfig* config) { - // TODO: Support Windows; move to common code char path[PATH_MAX]; +#ifndef _WIN32 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); +#else + char home[MAX_PATH]; + SHGetFolderPath(0, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, home); + snprintf(path, PATH_MAX, "%s/%s", home, PROJECT_NAME); + CreateDirectoryA(path, NULL); + snprintf(path, PATH_MAX, "%s/%s/config.ini", home, PROJECT_NAME); +#endif return ConfigurationWrite(&config->configTable, path); }