comparison src/xs_config.c @ 913:f8aa81ac2528

Improve configuration sanity checking.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 10 Nov 2012 13:29:51 +0200
parents 5d26b869a48e
children 3fdb0af448c7
comparison
equal deleted inserted replaced
912:4c6c5247de7d 913:f8aa81ac2528
54 #include <stdio.h> 54 #include <stdio.h>
55 #include <ctype.h> 55 #include <ctype.h>
56 #include "xs_glade.h" 56 #include "xs_glade.h"
57 #include "xs_interface.h" 57 #include "xs_interface.h"
58 #include "xs_support.h" 58 #include "xs_support.h"
59 59 #include "xs_backend.h"
60 60
61 /* 61 /*
62 * Global widgets 62 * Global widgets
63 */ 63 */
64 static GtkWidget *xs_configwin = NULL, 64 static GtkWidget *xs_configwin = NULL,
67 *xs_hvsc_selector = NULL, 67 *xs_hvsc_selector = NULL,
68 *xs_rom_selector = NULL, 68 *xs_rom_selector = NULL,
69 *xs_filt_importselector = NULL, 69 *xs_filt_importselector = NULL,
70 *xs_filt_exportselector = NULL; 70 *xs_filt_exportselector = NULL;
71 71
72
72 #define LUW(x) lookup_widget(xs_configwin, x) 73 #define LUW(x) lookup_widget(xs_configwin, x)
74
75 void xs_messagebox_const(const gchar *title, const gchar *msg);
76 void xs_messagebox(const gchar *title, const gchar *fmt, ...);
77
73 78
74 /* Samplerates 79 /* Samplerates
75 */ 80 */
76 static const gchar *xs_samplerates_table[] = 81 static const gchar *xs_samplerates_table[] =
77 { 82 {
207 { WTYPE_BUTTON, CTYPE_BOOL, "cfg_subauto_min_only", &xs_cfg.subAutoMinOnly, 0 }, 212 { WTYPE_BUTTON, CTYPE_BOOL, "cfg_subauto_min_only", &xs_cfg.subAutoMinOnly, 0 },
208 { WTYPE_SPIN, CTYPE_INT, "cfg_subauto_mintime", &xs_cfg.subAutoMinTime, 0 }, 213 { WTYPE_SPIN, CTYPE_INT, "cfg_subauto_mintime", &xs_cfg.subAutoMinTime, 0 },
209 }; 214 };
210 215
211 static const gint xs_nwidtable = sizeof(xs_cfgitems) / sizeof(xs_cfgitems[0]); 216 static const gint xs_nwidtable = sizeof(xs_cfgitems) / sizeof(xs_cfgitems[0]);
217
218
219 /* Check configuration
220 */
221 gboolean xs_check_configuration(void)
222 {
223 // Check for plain errors
224 switch (xs_cfg.playerEngine)
225 {
226 case XS_ENG_SIDPLAYFP:
227 {
228 if (xs_cfg.romPath == NULL || xs_cfg.romPath[0] == 0)
229 {
230 xs_messagebox("Error",
231 "You have selected libSIDPlayFP backend, but not set the C64 ROM images directory.");
232 return FALSE;
233 }
234
235 if (!xs_is_dir_path(xs_cfg.romPath))
236 {
237 xs_messagebox("Error",
238 "The C64 ROM images directory path '%s' is not a directory.\n",
239 xs_cfg.romPath);
240 return FALSE;
241 }
242
243 gint i;
244 gchar *result = NULL;
245 for (i = 0; i < XS_C64_ROM_IMAGES; i++)
246 {
247 guint8 *buf = NULL;
248 if (!xs_load_rom_image(i, &buf))
249 {
250 const XSROMImageData *rom = &xs_rom_images[i];
251 gchar *tmp = g_strdup_printf("%s%s file '%s'",
252 result != NULL ? ", " : "",
253 rom->name, rom->filename);
254
255 xs_pstrcat(&result, tmp);
256 g_free(tmp);
257 }
258 g_free(buf);
259 }
260
261 if (result != NULL)
262 {
263 xs_messagebox("Error",
264 "Could not load the required C64 ROM image files from '%s'.\n"
265 "\n"
266 "Following files could not be found: %s.",
267 xs_cfg.romPath, result);
268 g_free(result);
269 return FALSE;
270 }
271 }
272 break;
273 }
274
275 // Automatic adjustments
276 switch (xs_cfg.sid2Builder)
277 {
278 #if !defined(HAVE_RESID_BUILDER) && defined(HAVE_RESID_FP_BUILDER)
279 case XS_BLD_RESID: xs_cfg.sid2Builder = XS_BLD_RESID_FP; break;
280 #endif
281 #if defined(HAVE_RESID_BUILDER) && !defined(HAVE_RESID_FP_BUILDER)
282 case XS_BLD_RESID_FP: xs_cfg.sid2Builder = XS_BLD_RESID; break;
283 #endif
284 #if !defined(HAVE_HARDSID_BUILDER)
285 case XS_BLD_HARDSID:
286 #if defined(HAVE_RESID_FP_BUILDER)
287 xs_cfg.sid2Builder = XS_BLD_RESID_FP; break;
288 #elif defined(HAVE_RESID_BUILDER)
289 xs_cfg.sid2Builder = XS_BLD_RESID; break;
290 #endif
291 #endif
292 }
293
294 return TRUE;
295 }
212 296
213 297
214 /* Reset/initialize the configuration 298 /* Reset/initialize the configuration
215 */ 299 */
216 void xs_init_configuration(void) 300 void xs_init_configuration(void)
932 xs_pstrcpy((gchar **) xs_cfgitems[i].itemData, 1016 xs_pstrcpy((gchar **) xs_cfgitems[i].itemData,
933 gtk_entry_get_text(GTK_ENTRY(LUW(xs_cfgitems[i].widName)))); 1017 gtk_entry_get_text(GTK_ENTRY(LUW(xs_cfgitems[i].widName))));
934 break; 1018 break;
935 } 1019 }
936 1020
1021 // Check the settings
1022 if (!xs_check_configuration())
1023 goto error;
1024
937 /* Get filter settings */ 1025 /* Get filter settings */
938 /* 1026 /*
939 if (!xs_curve_get_points(XS_CURVE(LUW("")), &xs_cfg.sid2Filter.points, &xs_cfg.sid2Filter.npoints)) { 1027 if (!xs_curve_get_points(XS_CURVE(LUW("")), &xs_cfg.sid2Filter.points, &xs_cfg.sid2Filter.npoints)) {
940 xs_error("Warning: Could not get filter curve widget points!\n"); 1028 xs_error("Warning: Could not get filter curve widget points!\n");
941 } 1029 }
951 /* Write settings */ 1039 /* Write settings */
952 xs_write_configuration(); 1040 xs_write_configuration();
953 1041
954 /* Re-initialize */ 1042 /* Re-initialize */
955 xs_reinit(); 1043 xs_reinit();
1044 return;
1045
1046 error:
1047 /* Release lock */
1048 XS_MUTEX_UNLOCK(xs_cfg);
956 } 1049 }
957 1050
958 1051
959 void xs_messagebox_ok(GtkButton *button, gpointer user_data) 1052 void xs_messagebox_ok(GtkButton *button, gpointer user_data)
960 { 1053 {