Reverting config path to system default if it doesn't find it.

This commit is contained in:
Themaister 2011-08-24 08:14:03 +02:00
parent f827bb4cbd
commit 0730a34a5b
4 changed files with 18 additions and 0 deletions

View File

@ -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.

11
file.c
View File

@ -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];

1
file.h
View File

@ -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.

View File

@ -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.