From ca92c51f51722acd13e870009b18393ecc6bbc7f Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Thu, 28 Dec 2017 21:46:59 +0200 Subject: [PATCH] Save user configuration --- SDL/main.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/SDL/main.c b/SDL/main.c index 79271a91..0641544c 100755 --- a/SDL/main.c +++ b/SDL/main.c @@ -399,6 +399,17 @@ restart: } } +static char prefs_path[1024] = {0, }; + +static void save_configuration(void) +{ + FILE *prefs_file = fopen(prefs_path, "wb"); + if (prefs_file) { + fwrite(&configuration, 1, sizeof(configuration), prefs_file); + fclose(prefs_file); + } +} + int main(int argc, char **argv) { #define str(x) #x @@ -469,6 +480,18 @@ usage: SDL_EventState(SDL_DROPFILE, SDL_ENABLE); + char *prefs_dir = SDL_GetPrefPath("", "SameBoy"); + snprintf(prefs_path, sizeof(prefs_path) - 1, "%sprefs.bin", prefs_dir); + SDL_free(prefs_dir); + + FILE *prefs_file = fopen(prefs_path, "rb"); + if (prefs_file) { + fread(&configuration, 1, sizeof(configuration), prefs_file); + fclose(prefs_file); + } + + atexit(save_configuration); + if (!init_shader_with_name(&shader, configuration.filter)) { init_shader_with_name(&shader, "NearestNeighbor"); }