Commit 39306937 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

base/base.c (base_init) moved the message about possible debug messages to

2003-10-21  Sven Neumann  <sven@gimp.org>

	* base/base.c (base_init)
	* app/errors.c (gimp_errors_init): moved the message about
	possible debug messages to gimp_errors_init() so that it appears
	before any startup debug output.

	* app/app_procs.c (app_init): register a log handler for the
	GimpConfig log domain.

	* app/widgets/gimpwidgets-utils.c (gimp_message_box)
	* app/core/gimp.c (gimp_message): added an extra newline when
	sending messages to stderr. Don't output the full progname for
	messages; use a simple "GIMP" like the GUI message handler does.

	* app/gui/user-install-dialog.c: removed function copy_file()...

	* app/config/gimpconfig-utils.[ch]: ... and added it here as
	gimp_config_file_copy(). Also added utility function
	gimp_config_file_backup_on_error().

	* app/config/gimprc.c (gimp_rc_load): if the user gimprc can't be
	parsed, create a backup and if that succeeds unlink the broken one
	to cure the problem.

	* app/gui/session.c: create a backup if sessionrc can't be parsed.

	* config/gimpconfig-deserialize.c (gimp_config_deserialize_properties):
	don't set an error when token is G_TOKEN_NONE; it should already
	be set then.
parent 42312eca
2003-10-21 Sven Neumann <sven@gimp.org>
* base/base.c (base_init)
* app/errors.c (gimp_errors_init): moved the message about
possible debug messages to gimp_errors_init() so that it appears
before any startup debug output.
* app/app_procs.c (app_init): register a log handler for the
GimpConfig log domain.
* app/widgets/gimpwidgets-utils.c (gimp_message_box)
* app/core/gimp.c (gimp_message): added an extra newline when
sending messages to stderr. Don't output the full progname for
messages; use a simple "GIMP" like the GUI message handler does.
* app/gui/user-install-dialog.c: removed function copy_file()...
* app/config/gimpconfig-utils.[ch]: ... and added it here as
gimp_config_file_copy(). Also added utility function
gimp_config_file_backup_on_error().
* app/config/gimprc.c (gimp_rc_load): if the user gimprc can't be
parsed, create a backup and if that succeeds unlink the broken one
to cure the problem.
* app/gui/session.c: create a backup if sessionrc can't be parsed.
* config/gimpconfig-deserialize.c (gimp_config_deserialize_properties):
don't set an error when token is G_TOKEN_NONE; it should already
be set then.
2003-10-21 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpdocked.[ch]: added new virtual function
......@@ -121,6 +121,10 @@ app_init (const gchar *full_prog_name,
G_LOG_LEVEL_MESSAGE,
gimp_message_log_func,
&the_gimp);
g_log_set_handler ("Gimp-Config",
G_LOG_LEVEL_MESSAGE,
gimp_message_log_func,
&the_gimp);
g_log_set_handler ("Gimp-Core",
G_LOG_LEVEL_MESSAGE,
gimp_message_log_func,
......
......@@ -33,7 +33,6 @@
#include <io.h> /* for _unlink() */
#endif
#include "libgimpbase/gimpversion.h"
#include "base-types.h"
#include "config/gimpbaseconfig.h"
......@@ -72,15 +71,6 @@ base_init (GimpBaseConfig *config,
base_config = config;
#if (GIMP_MINOR_VERSION % 2) == 1
g_printerr ("This is a development version of the GIMP\n"
"Debug messages may appear here.\n\n");
#ifdef G_OS_WIN32
g_printerr ("You can minimize this window, but don't close it.\n\n");
#endif
#endif /* odd minor version */
tile_cache_init (config->tile_cache_size);
g_signal_connect (config, "notify::tile-cache-size",
......
......@@ -199,6 +199,9 @@ gimp_config_deserialize_properties (GimpConfig *config,
g_object_thaw_notify (G_OBJECT (config));
if (token == G_TOKEN_NONE)
return FALSE;
/* If store_unknown_tokens is TRUE but the unknown token value couldn't
be parsed the default error message is rather confusing.
We try to produce something more meaningful here ... */
......
......@@ -22,6 +22,8 @@
#include "config.h"
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <glib-object.h>
......@@ -33,6 +35,8 @@
#include "gimpconfig-params.h"
#include "gimpconfig-utils.h"
#include "gimp-intl.h"
static void
gimp_config_connect_notify (GObject *src,
......@@ -416,3 +420,98 @@ gimp_config_build_plug_in_path (const gchar *name)
"${gimp_plug_in_dir}", G_DIR_SEPARATOR_S, name,
NULL);
}
/*
* GimpConfig file utilities
*/
gboolean
gimp_config_file_copy (const gchar *source,
const gchar *dest,
GError **error)
{
gchar buffer[4096];
FILE *sfile, *dfile;
gint nbytes;
sfile = fopen (source, "rb");
if (sfile == NULL)
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Cannot open '%s' for reading: %s"),
source, g_strerror (errno));
return FALSE;
}
dfile = fopen (dest, "wb");
if (dfile == NULL)
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Cannot open '%s' for writing: %s"),
dest, g_strerror (errno));
fclose (sfile);
return FALSE;
}
while ((nbytes = fread (buffer, 1, sizeof (buffer), sfile)) > 0)
{
if (fwrite (buffer, 1, nbytes, dfile) < nbytes)
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Error while writing '%s': %s"),
dest, g_strerror (errno));
fclose (sfile);
fclose (dfile);
return FALSE;
}
}
if (ferror (sfile))
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Error while reading '%s': %s"),
source, g_strerror (errno));
fclose (sfile);
fclose (dfile);
return FALSE;
}
fclose (sfile);
if (fclose (dfile) == EOF)
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Error while writing '%s': %s"),
dest, g_strerror (errno));
return FALSE;
}
return TRUE;
}
gboolean
gimp_config_file_backup_on_error (const gchar *filename,
const gchar *name,
GError **error)
{
gchar *backup;
gboolean success;
g_return_val_if_fail (filename != NULL, FALSE);
g_return_val_if_fail (name != NULL, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
backup = g_strconcat (filename, "~", NULL);
success = gimp_config_file_copy (filename, backup, error);
if (success)
g_message (_("There was an error parsing your %s file.\n"
"Default values will be used. A backup of your configuration has been\n"
"created at '%s'."), name, backup);
g_free (backup);
return success;
}
......@@ -43,5 +43,11 @@ void gimp_config_string_append_escaped (GString *string,
gchar * gimp_config_build_data_path (const gchar *name);
gchar * gimp_config_build_plug_in_path (const gchar *name);
gboolean gimp_config_file_copy (const gchar *source,
const gchar *dest,
GError **error);
gboolean gimp_config_file_backup_on_error (const gchar *filename,
const gchar *name,
GError **error);
#endif /* __GIMP_CONFIG_UTILS_H__ */
......@@ -356,7 +356,13 @@ gimp_rc_load (GimpRc *rc)
rc->user_gimprc, NULL, &error))
{
if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT)
g_message (error->message);
{
g_message (error->message);
if (gimp_config_file_backup_on_error (rc->user_gimprc,
"gimprc", NULL))
unlink (rc->user_gimprc);
}
g_clear_error (&error);
}
......
......@@ -691,10 +691,12 @@ gimp_real_exit (Gimp *gimp,
plug_ins_exit (gimp);
gimp_modules_unload (gimp);
gimp_data_factory_data_save (gimp->brush_factory);
gimp_data_factory_data_save (gimp->pattern_factory);
gimp_data_factory_data_save (gimp->gradient_factory);
gimp_data_factory_data_save (gimp->palette_factory);
gimp_fonts_reset (gimp);
gimp_documents_save (gimp);
gimp_templates_save (gimp);
......@@ -1029,7 +1031,7 @@ gimp_message (Gimp *gimp,
}
}
g_printerr ("%s: %s\n", domain ? domain : GIMP_OBJECT (gimp)->name, message);
g_printerr ("%s: %s\n\n", domain ? domain : _("GIMP"), message);
}
void
......
......@@ -20,7 +20,6 @@
#include "config.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
......@@ -41,6 +40,7 @@
#include "gui-types.h"
#include "config/gimpconfig-utils.h"
#include "config/gimprc.h"
#include "widgets/gimppropwidgets.h"
......@@ -980,70 +980,6 @@ user_install_dialog_run (const gchar *alternate_system_gimprc,
/*********************/
/* Local functions */
static gboolean
copy_file (gchar *source,
gchar *dest,
GError **error)
{
gchar buffer[4096];
FILE *sfile, *dfile;
gint nbytes;
sfile = fopen (source, "rb");
if (sfile == NULL)
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Cannot open '%s' for reading: %s"),
source, g_strerror (errno));
return FALSE;
}
dfile = fopen (dest, "wb");
if (dfile == NULL)
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Cannot open '%s' for writing: %s"),
dest, g_strerror (errno));
fclose (sfile);
return FALSE;
}
while ((nbytes = fread (buffer, 1, sizeof (buffer), sfile)) > 0)
{
if (fwrite (buffer, 1, nbytes, dfile) < nbytes)
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Error while writing '%s': %s"),
dest, g_strerror (errno));
fclose (sfile);
fclose (dfile);
return FALSE;
}
}
if (ferror (sfile))
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Error while reading '%s': %s"),
source, g_strerror (errno));
fclose (sfile);
fclose (dfile);
return FALSE;
}
fclose (sfile);
if (fclose (dfile) == EOF)
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Error while writing '%s': %s"),
dest, g_strerror (errno));
return FALSE;
}
return TRUE;
}
static void
print_log (GtkWidget *view,
GtkTextBuffer *buffer,
......@@ -1187,7 +1123,7 @@ user_install_run (void)
while (gtk_events_pending ())
gtk_main_iteration ();
if (! copy_file (source, dest, &error))
if (! gimp_config_file_copy (source, dest, &error))
goto break_out_of_loop;
break;
......
......@@ -28,6 +28,8 @@
#include <glib-object.h>
#include "libgimpbase/gimpversion.h"
#include "core/core-types.h"
#include "core/gimp.h"
......@@ -62,6 +64,15 @@ gimp_errors_init (const gchar *_full_prog_name,
{
g_return_if_fail (_full_prog_name != NULL);
#if (GIMP_MINOR_VERSION % 2) == 1
g_printerr ("This is a development version of the GIMP\n"
"Debug messages may appear here.\n\n");
#ifdef G_OS_WIN32
g_printerr ("You can minimize this window, but don't close it.\n\n");
#endif
#endif /* odd minor version */
use_debug_handler = _use_debug_handler ? TRUE : FALSE;
stack_trace_mode = _stack_trace_mode;
full_prog_name = g_strdup (_full_prog_name);
......@@ -81,7 +92,7 @@ gimp_message_log_func (const gchar *log_domain,
return;
}
g_printerr ("%s: %s\n", full_prog_name, message);
g_printerr ("%s: %s\n\n", full_prog_name, message);
}
void
......
......@@ -30,13 +30,13 @@
#include "gui-types.h"
#include "config/gimpconfig-utils.h"
#include "config/gimpconfigwriter.h"
#include "config/gimpguiconfig.h"
#include "config/gimpscanner.h"
#include "core/gimp.h"
#include "config/gimpconfigwriter.h"
#include "config/gimpscanner.h"
#include "widgets/gimpdialogfactory.h"
#include "widgets/gimpsessioninfo.h"
......@@ -68,14 +68,10 @@ session_init (Gimp *gimp)
filename = gimp_personal_rc_file ("sessionrc");
scanner = gimp_scanner_new_file (filename, &error);
g_free (filename);
if (! scanner)
{
/* always show L&C&P, Tool Options and Brushes on first invocation */
/* TODO */
g_free (filename);
return;
}
......@@ -155,9 +151,12 @@ session_init (Gimp *gimp)
{
g_message (error->message);
g_clear_error (&error);
gimp_config_file_backup_on_error (filename, "sessionrc", NULL);
}
gimp_scanner_destroy (scanner);
g_free (filename);
}
void
......
......@@ -20,7 +20,6 @@
#include "config.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
......@@ -41,6 +40,7 @@
#include "gui-types.h"
#include "config/gimpconfig-utils.h"
#include "config/gimprc.h"
#include "widgets/gimppropwidgets.h"
......@@ -980,70 +980,6 @@ user_install_dialog_run (const gchar *alternate_system_gimprc,
/*********************/
/* Local functions */
static gboolean
copy_file (gchar *source,
gchar *dest,
GError **error)
{
gchar buffer[4096];
FILE *sfile, *dfile;
gint nbytes;
sfile = fopen (source, "rb");
if (sfile == NULL)
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Cannot open '%s' for reading: %s"),
source, g_strerror (errno));
return FALSE;
}
dfile = fopen (dest, "wb");
if (dfile == NULL)
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Cannot open '%s' for writing: %s"),
dest, g_strerror (errno));
fclose (sfile);
return FALSE;
}
while ((nbytes = fread (buffer, 1, sizeof (buffer), sfile)) > 0)
{
if (fwrite (buffer, 1, nbytes, dfile) < nbytes)
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Error while writing '%s': %s"),
dest, g_strerror (errno));
fclose (sfile);
fclose (dfile);
return FALSE;
}
}
if (ferror (sfile))
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Error while reading '%s': %s"),
source, g_strerror (errno));
fclose (sfile);
fclose (dfile);
return FALSE;
}
fclose (sfile);
if (fclose (dfile) == EOF)
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Error while writing '%s': %s"),
dest, g_strerror (errno));
return FALSE;
}
return TRUE;
}
static void
print_log (GtkWidget *view,
GtkTextBuffer *buffer,
......@@ -1187,7 +1123,7 @@ user_install_run (void)
while (gtk_events_pending ())
gtk_main_iteration ();
if (! copy_file (source, dest, &error))
if (! gimp_config_file_copy (source, dest, &error))
goto break_out_of_loop;
break;
......
......@@ -90,7 +90,7 @@ gimp_message_box (const gchar *stock_id,
if (g_list_length (message_boxes) > MESSAGE_BOX_MAXIMUM)
{
g_printerr ("%s: %s\n", domain, message);
g_printerr ("%s: %s\n\n", domain, message);
return;
}
......@@ -140,7 +140,7 @@ gimp_message_box (const gchar *stock_id,
if (g_list_length (message_boxes) == MESSAGE_BOX_MAXIMUM)
{
g_printerr ("%s: %s\n", domain, message);
g_printerr ("%s: %s\n\n", domain, message);
message = _("WARNING:\n"
"Too many open message dialogs.\n"
"Messages are redirected to stderr.");
......
......@@ -199,6 +199,9 @@ gimp_config_deserialize_properties (GimpConfig *config,
g_object_thaw_notify (G_OBJECT (config));
if (token == G_TOKEN_NONE)
return FALSE;
/* If store_unknown_tokens is TRUE but the unknown token value couldn't
be parsed the default error message is rather confusing.
We try to produce something more meaningful here ... */
......
......@@ -22,6 +22,8 @@
#include "config.h"
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <glib-object.h>
......@@ -33,6 +35,8 @@
#include "gimpconfig-params.h"
#include "gimpconfig-utils.h"
#include "gimp-intl.h"
static void
gimp_config_connect_notify (GObject *src,
......@@ -416,3 +420,98 @@ gimp_config_build_plug_in_path (const gchar *name)
"${gimp_plug_in_dir}", G_DIR_SEPARATOR_S, name,
NULL);
}
/*
* GimpConfig file utilities
*/
gboolean
gimp_config_file_copy (const gchar *source,
const gchar *dest,
GError **error)
{
gchar buffer[4096];
FILE *sfile, *dfile;
gint nbytes;
sfile = fopen (source, "rb");
if (sfile == NULL)
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Cannot open '%s' for reading: %s"),
source, g_strerror (errno));
return FALSE;
}
dfile = fopen (dest, "wb");
if (dfile == NULL)
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Cannot open '%s' for writing: %s"),
dest, g_strerror (errno));
fclose (sfile);
return FALSE;
}
while ((nbytes = fread (buffer, 1, sizeof (buffer), sfile)) > 0)
{
if (fwrite (buffer, 1, nbytes, dfile) < nbytes)
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Error while writing '%s': %s"),
dest, g_strerror (errno));
fclose (sfile);
fclose (dfile);
return FALSE;
}
}
if (ferror (sfile))
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Error while reading '%s': %s"),
source, g_strerror (errno));
fclose (sfile);
fclose (dfile);
return FALSE;
}
fclose (sfile);
if (fclose (dfile) == EOF)
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Error while writing '%s': %s"),
dest, g_strerror (errno));
return FALSE;
}
return TRUE;
}
gboolean
gimp_config_file_backup_on_error (const gchar *filename,
const gchar *name,
GError **error)
{
gchar *backup;
gboolean success;
g_return_val_if_fail (filename != NULL, FALSE);
g_return_val_if_fail (name != NULL, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
backup = g_strconcat (filename, "~", NULL);
success = gimp_config_file_copy (filename, backup, error);
if (success)
g_message (_("There was an error parsing your %s file.\n"
"Default values will be used. A backup of your configuration has been\n"
"created at '%s'."), name, backup);
g_free (backup);
return success;
}
......@@ -43,5 +43,11 @@ void gimp_config_string_append_escaped (GString *string,
gchar * gimp_config_build_data_path (const gchar *name);
gchar * gimp_config_build_plug_in_path (const gchar *name);
gboolean gimp_config_file_copy (const gchar *source,
const gchar *dest,
GError **error);
gboolean gimp_config_file_backup_on_error (const gchar *filename,
const gchar *name,
GError **error);
#endif /* __GIMP_CONFIG_UTILS_H__ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment