# HG changeset patch # User Matti Hamalainen # Date 1352546991 -7200 # Node ID f8aa81ac25283288f7593d1ae3dcc9f7c7fb7de0 # Parent 4c6c5247de7d096aff3cccf124c2331b9a863707 Improve configuration sanity checking. diff -r 4c6c5247de7d -r f8aa81ac2528 src/xs_config.c --- a/src/xs_config.c Sat Nov 10 13:29:42 2012 +0200 +++ b/src/xs_config.c Sat Nov 10 13:29:51 2012 +0200 @@ -56,7 +56,7 @@ #include "xs_glade.h" #include "xs_interface.h" #include "xs_support.h" - +#include "xs_backend.h" /* * Global widgets @@ -69,8 +69,13 @@ *xs_filt_importselector = NULL, *xs_filt_exportselector = NULL; + #define LUW(x) lookup_widget(xs_configwin, x) +void xs_messagebox_const(const gchar *title, const gchar *msg); +void xs_messagebox(const gchar *title, const gchar *fmt, ...); + + /* Samplerates */ static const gchar *xs_samplerates_table[] = @@ -211,6 +216,85 @@ static const gint xs_nwidtable = sizeof(xs_cfgitems) / sizeof(xs_cfgitems[0]); +/* Check configuration + */ +gboolean xs_check_configuration(void) +{ + // Check for plain errors + switch (xs_cfg.playerEngine) + { + case XS_ENG_SIDPLAYFP: + { + if (xs_cfg.romPath == NULL || xs_cfg.romPath[0] == 0) + { + xs_messagebox("Error", + "You have selected libSIDPlayFP backend, but not set the C64 ROM images directory."); + return FALSE; + } + + if (!xs_is_dir_path(xs_cfg.romPath)) + { + xs_messagebox("Error", + "The C64 ROM images directory path '%s' is not a directory.\n", + xs_cfg.romPath); + return FALSE; + } + + gint i; + gchar *result = NULL; + for (i = 0; i < XS_C64_ROM_IMAGES; i++) + { + guint8 *buf = NULL; + if (!xs_load_rom_image(i, &buf)) + { + const XSROMImageData *rom = &xs_rom_images[i]; + gchar *tmp = g_strdup_printf("%s%s file '%s'", + result != NULL ? ", " : "", + rom->name, rom->filename); + + xs_pstrcat(&result, tmp); + g_free(tmp); + } + g_free(buf); + } + + if (result != NULL) + { + xs_messagebox("Error", + "Could not load the required C64 ROM image files from '%s'.\n" + "\n" + "Following files could not be found: %s.", + xs_cfg.romPath, result); + g_free(result); + return FALSE; + } + } + break; + } + + // Automatic adjustments + switch (xs_cfg.sid2Builder) + { +#if !defined(HAVE_RESID_BUILDER) && defined(HAVE_RESID_FP_BUILDER) + case XS_BLD_RESID: xs_cfg.sid2Builder = XS_BLD_RESID_FP; break; +#endif +#if defined(HAVE_RESID_BUILDER) && !defined(HAVE_RESID_FP_BUILDER) + case XS_BLD_RESID_FP: xs_cfg.sid2Builder = XS_BLD_RESID; break; +#endif +#if !defined(HAVE_HARDSID_BUILDER) + case XS_BLD_HARDSID: +#if defined(HAVE_RESID_FP_BUILDER) + xs_cfg.sid2Builder = XS_BLD_RESID_FP; break; +#elif defined(HAVE_RESID_BUILDER) + xs_cfg.sid2Builder = XS_BLD_RESID; break; +#endif +#endif + } + + return TRUE; +} + + /* Reset/initialize the configuration */ void xs_init_configuration(void) @@ -934,6 +1018,10 @@ break; } + // Check the settings + if (!xs_check_configuration()) + goto error; + /* Get filter settings */ /* if (!xs_curve_get_points(XS_CURVE(LUW("")), &xs_cfg.sid2Filter.points, &xs_cfg.sid2Filter.npoints)) { @@ -953,6 +1041,11 @@ /* Re-initialize */ xs_reinit(); + return; + +error: + /* Release lock */ + XS_MUTEX_UNLOCK(xs_cfg); }