Search
lxdream.org :: lxdream/src/config.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/config.c
changeset 1038:f220d18c0615
prev1036:af7b0c5905dd
next1041:5fcc39857c5c
author nkeynes
date Thu Jun 25 01:15:25 2009 +0000 (10 years ago)
permissions -rw-r--r--
last change Move configuration to .lxdream/lxdreamrc on *nix, Library/Application Support/Lxdream on OS X
Create standard directories on first run
Add current quick state to config file
Refactor quick-state handling into dreamcast.c, and use the save directory
file annotate diff log raw
1.1 --- a/src/config.c Wed Jun 24 06:06:40 2009 +0000
1.2 +++ b/src/config.c Thu Jun 25 01:15:25 2009 +0000
1.3 @@ -25,6 +25,8 @@
1.4 #include <wordexp.h>
1.5 #include <glib/gmem.h>
1.6 #include <glib/gstrfuncs.h>
1.7 +#include <sys/types.h>
1.8 +#include <sys/stat.h>
1.9 #include "dream.h"
1.10 #include "config.h"
1.11 #include "maple/maple.h"
1.12 @@ -40,15 +42,16 @@
1.13 gboolean lxdream_save_config_stream( FILE *f );
1.14
1.15 static struct lxdream_config_entry global_config[] =
1.16 - {{ "bios", N_("Bios ROM"), CONFIG_TYPE_FILE, "dcboot.rom" },
1.17 - { "flash", N_("Flash ROM"), CONFIG_TYPE_FILE, "dcflash.rom" },
1.18 + {{ "bios", N_("Bios ROM"), CONFIG_TYPE_FILE, NULL },
1.19 + { "flash", N_("Flash ROM"), CONFIG_TYPE_FILE, NULL },
1.20 { "default path", N_("Default disc path"), CONFIG_TYPE_PATH, "." },
1.21 - { "save path", N_("Save-state path"), CONFIG_TYPE_PATH, "save" },
1.22 - { "vmu path", N_("VMU path"), CONFIG_TYPE_PATH, "vmu" },
1.23 - { "bootstrap", N_("Bootstrap IP.BIN"), CONFIG_TYPE_FILE, "IP.BIN" },
1.24 + { "save path", N_("Save-state path"), CONFIG_TYPE_PATH, NULL },
1.25 + { "vmu path", N_("VMU path"), CONFIG_TYPE_PATH, NULL },
1.26 + { "bootstrap", N_("Bootstrap IP.BIN"), CONFIG_TYPE_FILE, NULL },
1.27 { "gdrom", NULL, CONFIG_TYPE_FILE, NULL },
1.28 { "recent", NULL, CONFIG_TYPE_FILELIST, NULL },
1.29 { "vmu", NULL, CONFIG_TYPE_FILELIST, NULL },
1.30 + { "quick state", NULL, CONFIG_TYPE_INTEGER, "0" },
1.31 { NULL, CONFIG_TYPE_NONE }};
1.32
1.33 static struct lxdream_config_entry serial_config[] =
1.34 @@ -85,7 +88,15 @@
1.35 gboolean result = TRUE;
1.36 char *home = getenv("HOME");
1.37 if( lxdream_config_save_filename == NULL ) {
1.38 + /* For compatibility, look for the old ~/.lxdreamrc first. Use it if
1.39 + * found, otherwise use the new ~/.lxdream/lxdreamrc.
1.40 + */
1.41 lxdream_config_save_filename = g_strdup_printf("%s/.%s", home, DEFAULT_CONFIG_FILENAME);
1.42 + if( access(lxdream_config_save_filename, R_OK) != 0 ) {
1.43 + g_free(lxdream_config_save_filename);
1.44 + const char *user_path = get_user_data_path();
1.45 + lxdream_config_save_filename = g_strdup_printf("%s/%s", user_path, DEFAULT_CONFIG_FILENAME);
1.46 + }
1.47 }
1.48 if( lxdream_config_load_filename == NULL ) {
1.49 char *sysconfig = g_strdup_printf("%s/%s", get_sysconf_path(), DEFAULT_CONFIG_FILENAME);
1.50 @@ -94,9 +105,6 @@
1.51 g_free(sysconfig);
1.52 } else if( access( sysconfig, R_OK ) == 0 ) {
1.53 lxdream_config_load_filename = sysconfig;
1.54 - } else if( access( "./" DEFAULT_CONFIG_FILENAME, R_OK ) == 0 ) {
1.55 - lxdream_config_load_filename = g_strdup("./" DEFAULT_CONFIG_FILENAME);
1.56 - g_free(sysconfig);
1.57 } else {
1.58 lxdream_config_load_filename = g_strdup(lxdream_config_save_filename);
1.59 g_free(sysconfig);
1.60 @@ -120,6 +128,15 @@
1.61
1.62 void lxdream_set_default_config( )
1.63 {
1.64 + /* Construct platform dependent defaults */
1.65 + const gchar *user_path = get_user_data_path();
1.66 + global_config[CONFIG_BIOS_PATH].default_value = g_strdup_printf( "%s/dcboot.rom", user_path );
1.67 + global_config[CONFIG_FLASH_PATH].default_value = g_strdup_printf( "%s/dcflash.rom", user_path );
1.68 + global_config[CONFIG_SAVE_PATH].default_value = g_strdup_printf( "%s/save", user_path );
1.69 + global_config[CONFIG_VMU_PATH].default_value = g_strdup_printf( "%s/vmu", user_path );
1.70 + global_config[CONFIG_BOOTSTRAP].default_value = g_strdup_printf( "%s/IP.BIN", user_path );
1.71 +
1.72 + /* Copy defaults into main values */
1.73 struct lxdream_config_group *group = lxdream_config_root;
1.74 while( group->key != NULL ) {
1.75 struct lxdream_config_entry *param = group->params;
1.76 @@ -493,3 +510,28 @@
1.77 }
1.78 return TRUE;
1.79 }
1.80 +
1.81 +void lxdream_make_config_dir( )
1.82 +{
1.83 + const char *user_path = get_user_data_path();
1.84 + struct stat st;
1.85 +
1.86 + if( access( user_path, R_OK|X_OK ) == 0 && lstat( user_path, &st ) == 0 &&
1.87 + (st.st_mode & S_IFDIR) != 0 ) {
1.88 + /* All good */
1.89 + return;
1.90 + }
1.91 +
1.92 + if( mkdir( user_path, 0777 ) != 0 ) {
1.93 + ERROR( "Unable to create user configuration directory %s: %s", user_path, strerror(errno) );
1.94 + return;
1.95 + }
1.96 +
1.97 + char *vmupath = g_strdup_printf( "%s/vmu", user_path );
1.98 + mkdir( vmupath, 0777 );
1.99 + g_free( vmupath );
1.100 +
1.101 + char *savepath = g_strdup_printf( "%s/save", user_path );
1.102 + mkdir( savepath, 0777 );
1.103 + g_free( vmupath );
1.104 +}
.