From 0730a34a5b8835467a820dc626c397ff3797fd65 Mon Sep 17 00:00:00 2001 From: Themaister Date: Wed, 24 Aug 2011 08:14:03 +0200 Subject: [PATCH] Reverting config path to system default if it doesn't find it. --- docs/ssnes.1 | 1 + file.c | 11 +++++++++++ file.h | 1 + ssnes.c | 5 +++++ 4 files changed, 18 insertions(+) diff --git a/docs/ssnes.1 b/docs/ssnes.1 index 0b1c02f9ba..098e8276fb 100644 --- a/docs/ssnes.1 +++ b/docs/ssnes.1 @@ -55,6 +55,7 @@ Should this not be defined, \fBssnes\fR will look in platform specific paths to /etc/ssnes.cfg (when installed), or ssnes.cfg in the source tarball serves as a skeleton configuration file. If PATH is a directory, SSNES will treat this as the config file directory, where the state file name will be inferred from the rom name (*.cfg). When loading a rom from stdin, the path must be a full path, however. +If a config cannot be found when using directory path, the default config path will be used instead. .IP Unix-like systems will look in $XDG_CONFIG_HOME/ssnes/ssnes.cfg first. Then it will try $HOME/.ssnes.cfg. Last, it will try /etc/ssnes.cfg. If no configuration is found, default settings will be assumed. A configuration file does not need to define every possible option, only those that should be overridden. diff --git a/file.c b/file.c index 5bcb320a0f..941c0a2c05 100644 --- a/file.c +++ b/file.c @@ -867,6 +867,17 @@ bool path_is_directory(const char *path) #endif } +bool path_file_exists(const char *path) +{ + FILE *dummy = fopen(path, "rb"); + if (dummy) + { + fclose(dummy); + return true; + } + return false; +} + void fill_pathname(char *out_path, const char *in_path, const char *replace, size_t size) { char tmp_path[strlen(in_path) + 1]; diff --git a/file.h b/file.h index b25a4e64df..c7948cd6ab 100644 --- a/file.h +++ b/file.h @@ -41,6 +41,7 @@ char** dir_list_new(const char *dir, const char *ext); void dir_list_free(char **dir_list); bool path_is_directory(const char *path); +bool path_file_exists(const char *path); // Path-name operations. // Replaces filename extension with replace. diff --git a/ssnes.c b/ssnes.c index 3fcd7ac4fd..60cd2188be 100644 --- a/ssnes.c +++ b/ssnes.c @@ -686,6 +686,11 @@ static void parse_input(int argc, char *argv[]) { fill_pathname_dir(g_extern.config_path, g_extern.basename, ".cfg", sizeof(g_extern.config_path)); SSNES_LOG("Redirecting config file to \"%s\".\n", g_extern.config_path); + if (!path_file_exists(g_extern.config_path)) + { + *g_extern.config_path = '\0'; + SSNES_LOG("Did not find config file. Using system default.\n"); + } } } else // Read ROM from stdin.