From: James Antill Date: Fri, 7 Feb 2003 19:14:16 +0000 (+0000) Subject: If blocks config. entry doesn't exist in theme error out, instead of X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=fb59545ffe1c3e1686e7bd427b4b3205b1e2928c;p=gtetrinet If blocks config. entry doesn't exist in theme error out, instead of 2003-02-07 James Antill * src/config.c (config_loadtheme): If blocks config. entry doesn't exist in theme error out, instead of crashing. (config_getthemeinfo): Use empty values, if author and/or description doesn't exist. (config_loadconfig): Don't crash if current_theme or midicmd don't exist. (config_loadconfig): Change currenttheme to a GString to fix overflow truncate problems. --- diff --git a/ChangeLog b/ChangeLog index 4329db8..8a3f796 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2003-02-07 James Antill + + * src/config.c (config_loadtheme): If blocks config. entry doesn't + exist in theme error out, instead of crashing. + (config_getthemeinfo): Use empty values, if author and/or + description doesn't exist. + (config_loadconfig): Don't crash if current_theme or midicmd don't + exist. + (config_loadconfig): Change currenttheme to a GString to fix overflow + truncate problems. + 2003-02-06 Jordi Mallach * src/config.c (config_loadconfig): remove unused variable. diff --git a/src/config.c b/src/config.c index a4e11be..2d270c3 100644 --- a/src/config.c +++ b/src/config.c @@ -40,7 +40,7 @@ char blocksfile[1024]; int bsize; -char currenttheme[1024]; +GString *currenttheme = NULL; extern GConfClient *gconf_client; @@ -83,32 +83,28 @@ void config_loadtheme (const gchar *themedir) gnome_config_push_prefix (buf); p = gnome_config_get_string ("Theme/Name"); - if (p == 0) { - GtkWidget *mb; - mb = gtk_message_dialog_new (NULL, - 0, - GTK_MESSAGE_WARNING, - GTK_BUTTONS_OK, - _("Warning: theme does not have a name")); - gtk_dialog_run (GTK_DIALOG (mb)); - gtk_widget_destroy (mb); - } - else g_free (p); + if (!p) + goto bad_theme; + g_free (p); - p = gnome_config_get_string ("Graphics/Blocks=blocks.png"); + p = gnome_config_get_string ("Graphics/Blocks=blocks.png") + if (!p) + goto bad_theme; + GTET_O_STRCPY(blocksfile, themedir); GTET_O_STRCAT(blocksfile, p); g_free (p); bsize = gnome_config_get_int ("Graphics/BlockSize=16"); p = gnome_config_get_string ("Sounds/MidiFile"); - if (p) { + if (!p) + midifile[0] = 0; + else + { GTET_O_STRCPY(midifile, themedir); GTET_O_STRCAT(midifile, p); g_free (p); } - else - midifile[0] = 0; for (i = 0; i < S_NUM; i ++) { p = gnome_config_get_string (soundkeys[i]); @@ -124,12 +120,27 @@ void config_loadtheme (const gchar *themedir) sound_cache (); gnome_config_pop_prefix (); + + return; + + bad_theme: + { + GtkWidget *mb; + mb = gtk_message_dialog_new (NULL, + 0, + GTK_MESSAGE_WARNING, + GTK_BUTTONS_OK, + _("Warning: theme does not have a name")); + gtk_dialog_run (GTK_DIALOG (mb)); + gtk_widget_destroy (mb); + } } /* Arrggh... all these params are sizeof() == 1024 ... this needs a real fix */ int config_getthemeinfo (char *themedir, char *name, char *author, char *desc) { - char buf[1024], *p; + char buf[1024]; + const char *p = NULL; GTET_O_STRCPY (buf, "="); GTET_O_STRCAT (buf, themedir); @@ -146,13 +157,11 @@ int config_getthemeinfo (char *themedir, char *name, char *author, char *desc) if (name) GTET_STRCPY(name, p, 1024); g_free (p); } - if (author) { - p = gnome_config_get_string ("Theme/Author="); + if (author && (p = gnome_config_get_string ("Theme/Author="))) { GTET_STRCPY(author, p, 1024); g_free (p); } - if (desc) { - p = gnome_config_get_string ("Theme/Description="); + if (desc && (p = gnome_config_get_string ("Theme/Description="))) { GTET_STRCPY(desc, p, 1024); g_free (p); } @@ -166,29 +175,34 @@ void config_loadconfig (void) { int l; gchar *p; + + currenttheme = g_string_sized_new(100); /* get the current theme */ p = gconf_client_get_string (gconf_client, "/apps/gtetrinet/themes/theme_dir", NULL); /* if there is no theme configured, then we fallback to DEFAULTTHEME */ - if (strlen (p) == 0) + if (!p || !p[0]) { g_free (p); - p = g_strdup (DEFAULTTHEME); - gconf_client_set_string (gconf_client, "/apps/gtetrinet/themes/theme_dir", p, NULL); + g_string_assign(currenttheme, DEFAULTTHEME); + gconf_client_set_string (gconf_client, "/apps/gtetrinet/themes/theme_dir", currenttheme->str, NULL); } - GTET_O_STRCPY(currenttheme, p); + else + g_string_assign(currenttheme, p); g_free (p); + /* add trailing slash if none exists */ - l = strlen(currenttheme); - if (currenttheme[l-1] != '/') { - GTET_O_STRCAT(currenttheme, "/"); - } + if (currenttheme->str[currenttheme->len - 1] != '/') + g_string_append_c(currenttheme, '/'); /* get the midi player */ p = gconf_client_get_string (gconf_client, "/apps/gtetrinet/sound/midi_player", NULL); - GTET_O_STRCPY(midicmd, p); - g_free (p); - + if (p) + { + GTET_O_STRCPY(midicmd, p); + g_free (p); + } + /* get the other sound options */ soundenable = gconf_client_get_bool (gconf_client, "/apps/gtetrinet/sound/enable_sound", NULL); midienable = gconf_client_get_bool (gconf_client, "/apps/gtetrinet/sound/enable_midi", NULL); @@ -287,13 +301,13 @@ void config_loadconfig (void) else keys[K_GAMEMSG] = defaultkeys[K_GAMEMSG]; - config_loadtheme (currenttheme); + config_loadtheme (currenttheme->str); } void load_theme (const gchar *theme_dir) { /* load the theme */ - GTET_O_STRCPY (currenttheme, theme_dir); + g_string_assign(currenttheme, theme_dir); config_loadtheme (theme_dir); /* update the fields */ diff --git a/src/config.h b/src/config.h index 5fae705..f8a23f6 100644 --- a/src/config.h +++ b/src/config.h @@ -2,7 +2,7 @@ extern char blocksfile[1024]; extern int bsize; -extern gchar currenttheme[1024]; +extern GString *currenttheme; extern guint keys[]; extern guint defaultkeys[]; diff --git a/src/dialogs.c b/src/dialogs.c index 68c3193..4caeae3 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -757,7 +757,7 @@ void prefdialog_themelist () text[1] = 0; gtk_list_store_append (theme_store, &iter); gtk_list_store_set (theme_store, &iter, 0, themes[i].name, 1, i, -1); - if (strcmp (themes[i].dir, currenttheme) == 0) + if (strcmp (themes[i].dir, currenttheme->str) == 0) { iter_selected = iter; theme_select = i;