mirror of
https://gitlab.gnome.org/GNOME/gimp
synced 2024-10-20 19:43:01 +00:00
app/config/Makefile.am app/config/gimpconfig-file.[ch] more new files,
2005-01-24 Sven Neumann <sven@gimp.org> * app/config/Makefile.am * app/config/gimpconfig-file.[ch] * app/config/gimprc-utils.[ch]: more new files, code factored out of gimpconfig-utils.[ch]. * app/config/gimpconfig-path.[ch] * app/config/gimpconfig-utils.[ch] * app/config/gimpcoreconfig.c * app/config/gimpguiconfig.c * app/config/gimppluginconfig.c * app/config/gimprc.c * app/core/gimp-units.c * app/dialogs/user-install-dialog.c * app/gui/session.c: changed accordingly.
This commit is contained in:
parent
edf1fc2d7b
commit
73c055bb52
17
ChangeLog
17
ChangeLog
|
@ -1,3 +1,20 @@
|
|||
2005-01-24 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* app/config/Makefile.am
|
||||
* app/config/gimpconfig-file.[ch]
|
||||
* app/config/gimprc-utils.[ch]: more new files, code factored out
|
||||
of gimpconfig-utils.[ch].
|
||||
|
||||
* app/config/gimpconfig-path.[ch]
|
||||
* app/config/gimpconfig-utils.[ch]
|
||||
* app/config/gimpcoreconfig.c
|
||||
* app/config/gimpguiconfig.c
|
||||
* app/config/gimppluginconfig.c
|
||||
* app/config/gimprc.c
|
||||
* app/core/gimp-units.c
|
||||
* app/dialogs/user-install-dialog.c
|
||||
* app/gui/session.c: changed accordingly.
|
||||
|
||||
2005-01-24 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* app/config/gimpconfig-deserialize.[ch]: removed an unused parameter.
|
||||
|
|
|
@ -16,6 +16,8 @@ libappconfig_a_SOURCES = \
|
|||
gimpconfig-dump.h \
|
||||
gimpconfig-error.c \
|
||||
gimpconfig-error.h \
|
||||
gimpconfig-file.c \
|
||||
gimpconfig-file.h \
|
||||
gimpconfig-params.h \
|
||||
gimpconfig-path.c \
|
||||
gimpconfig-path.h \
|
||||
|
@ -45,6 +47,8 @@ libappconfig_a_SOURCES = \
|
|||
gimprc-serialize.h \
|
||||
gimprc-unknown.c \
|
||||
gimprc-unknown.h \
|
||||
gimprc-utils.c \
|
||||
gimprc-utils.h \
|
||||
gimpscanner.c \
|
||||
gimpscanner.h \
|
||||
gimpxmlparser.c \
|
||||
|
|
140
app/config/gimpconfig-file.c
Normal file
140
app/config/gimpconfig-file.c
Normal file
|
@ -0,0 +1,140 @@
|
|||
/* The GIMP -- an image manipulation program
|
||||
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* File Utitility functions for GimpConfig.
|
||||
* Copyright (C) 2001-2003 Sven Neumann <sven@gimp.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "libgimpbase/gimpbase.h"
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
#include "libgimpbase/gimpwin32-io.h"
|
||||
#endif
|
||||
|
||||
#include "config-types.h"
|
||||
|
||||
#include "gimpconfig-file.h"
|
||||
|
||||
#include "gimp-intl.h"
|
||||
|
||||
|
||||
gboolean
|
||||
gimp_config_file_copy (const gchar *source,
|
||||
const gchar *dest,
|
||||
GError **error)
|
||||
{
|
||||
gchar buffer[8192];
|
||||
FILE *sfile;
|
||||
FILE *dfile;
|
||||
struct stat stat_buf;
|
||||
gint nbytes;
|
||||
|
||||
sfile = fopen (source, "rb");
|
||||
if (sfile == NULL)
|
||||
{
|
||||
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
|
||||
_("Could not open '%s' for reading: %s"),
|
||||
gimp_filename_to_utf8 (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),
|
||||
_("Could not open '%s' for writing: %s"),
|
||||
gimp_filename_to_utf8 (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"),
|
||||
gimp_filename_to_utf8 (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"),
|
||||
gimp_filename_to_utf8 (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"),
|
||||
gimp_filename_to_utf8 (dest), g_strerror (errno));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (stat (source, &stat_buf) == 0)
|
||||
{
|
||||
chmod (dest, stat_buf.st_mode);
|
||||
}
|
||||
|
||||
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. "
|
||||
"Default values will be used. A backup of your "
|
||||
"configuration has been created at '%s'."),
|
||||
name, gimp_filename_to_utf8 (backup));
|
||||
|
||||
g_free (backup);
|
||||
|
||||
return success;
|
||||
}
|
34
app/config/gimpconfig-file.h
Normal file
34
app/config/gimpconfig-file.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
/* The GIMP -- an image manipulation program
|
||||
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* File utitility functions for GimpConfig.
|
||||
* Copyright (C) 2001-2003 Sven Neumann <sven@gimp.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __GIMP_CONFIG_FILE_H__
|
||||
#define __GIMP_CONFIG_FILE_H__
|
||||
|
||||
|
||||
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_FILE_H__ */
|
|
@ -33,36 +33,40 @@
|
|||
#include "gimp-intl.h"
|
||||
|
||||
|
||||
#define SUBSTS_ALLOC 4
|
||||
|
||||
static gchar * gimp_config_path_expand_only (const gchar *path,
|
||||
GError **error);
|
||||
static inline gchar * extract_token (const gchar **str);
|
||||
|
||||
static inline gchar *
|
||||
extract_token (const gchar **str)
|
||||
|
||||
/*
|
||||
* GimpConfig path utilities
|
||||
*/
|
||||
|
||||
gchar *
|
||||
gimp_config_build_data_path (const gchar *name)
|
||||
{
|
||||
const gchar *p;
|
||||
gchar *token;
|
||||
|
||||
if (strncmp (*str, "${", 2))
|
||||
return NULL;
|
||||
|
||||
p = *str + 2;
|
||||
|
||||
while (*p && (*p != '}'))
|
||||
p = g_utf8_next_char (p);
|
||||
|
||||
if (!p)
|
||||
return NULL;
|
||||
|
||||
token = g_strndup (*str + 2, g_utf8_pointer_to_offset (*str + 2, p));
|
||||
|
||||
*str = p + 1; /* after the closing bracket */
|
||||
|
||||
return token;
|
||||
return g_strconcat ("${gimp_dir}", G_DIR_SEPARATOR_S, name,
|
||||
G_SEARCHPATH_SEPARATOR_S,
|
||||
"${gimp_data_dir}", G_DIR_SEPARATOR_S, name,
|
||||
NULL);
|
||||
}
|
||||
|
||||
gchar *
|
||||
gimp_config_build_writable_path (const gchar *name)
|
||||
{
|
||||
return g_strconcat ("${gimp_dir}", G_DIR_SEPARATOR_S, name, NULL);
|
||||
}
|
||||
|
||||
gchar *
|
||||
gimp_config_build_plug_in_path (const gchar *name)
|
||||
{
|
||||
return g_strconcat ("${gimp_dir}", G_DIR_SEPARATOR_S, name,
|
||||
G_SEARCHPATH_SEPARATOR_S,
|
||||
"${gimp_plug_in_dir}", G_DIR_SEPARATOR_S, name,
|
||||
NULL);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* gimp_config_path_expand:
|
||||
* @path: a %NUL-terminated string in UTF-8 encoding
|
||||
|
@ -105,6 +109,9 @@ gimp_config_path_expand (const gchar *path,
|
|||
return gimp_config_path_expand_only (path, error);
|
||||
}
|
||||
|
||||
|
||||
#define SUBSTS_ALLOC 4
|
||||
|
||||
static gchar *
|
||||
gimp_config_path_expand_only (const gchar *path,
|
||||
GError **error)
|
||||
|
@ -253,3 +260,27 @@ gimp_config_path_expand_only (const gchar *path,
|
|||
|
||||
return expanded;
|
||||
}
|
||||
|
||||
static inline gchar *
|
||||
extract_token (const gchar **str)
|
||||
{
|
||||
const gchar *p;
|
||||
gchar *token;
|
||||
|
||||
if (strncmp (*str, "${", 2))
|
||||
return NULL;
|
||||
|
||||
p = *str + 2;
|
||||
|
||||
while (*p && (*p != '}'))
|
||||
p = g_utf8_next_char (p);
|
||||
|
||||
if (!p)
|
||||
return NULL;
|
||||
|
||||
token = g_strndup (*str + 2, g_utf8_pointer_to_offset (*str + 2, p));
|
||||
|
||||
*str = p + 1; /* after the closing bracket */
|
||||
|
||||
return token;
|
||||
}
|
||||
|
|
|
@ -23,9 +23,9 @@
|
|||
#define __GIMP_CONFIG_PATH_H__
|
||||
|
||||
|
||||
gchar * gimp_config_path_expand (const gchar *path,
|
||||
gboolean recode,
|
||||
GError **error);
|
||||
gchar * gimp_config_path_expand (const gchar *path,
|
||||
gboolean recode,
|
||||
GError **error);
|
||||
|
||||
|
||||
#endif /* __GIMP_CONFIG_PATH_H__ */
|
||||
|
|
|
@ -21,28 +21,16 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "libgimpbase/gimpbase.h"
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
#include "libgimpbase/gimpwin32-io.h"
|
||||
#endif
|
||||
|
||||
#include "config-types.h"
|
||||
|
||||
#include "gimpconfig.h"
|
||||
#include "gimpconfig-params.h"
|
||||
#include "gimpconfig-utils.h"
|
||||
|
||||
#include "gimp-intl.h"
|
||||
|
||||
|
||||
static void
|
||||
gimp_config_connect_notify (GObject *src,
|
||||
|
@ -499,135 +487,3 @@ gimp_config_string_append_escaped (GString *string,
|
|||
g_string_append_len (string, "\"\"", 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* GimpConfig path utilities
|
||||
*/
|
||||
|
||||
gchar *
|
||||
gimp_config_build_data_path (const gchar *name)
|
||||
{
|
||||
return g_strconcat ("${gimp_dir}", G_DIR_SEPARATOR_S, name,
|
||||
G_SEARCHPATH_SEPARATOR_S,
|
||||
"${gimp_data_dir}", G_DIR_SEPARATOR_S, name,
|
||||
NULL);
|
||||
}
|
||||
|
||||
gchar *
|
||||
gimp_config_build_writable_path (const gchar *name)
|
||||
{
|
||||
return g_strconcat ("${gimp_dir}", G_DIR_SEPARATOR_S, name, NULL);
|
||||
}
|
||||
|
||||
gchar *
|
||||
gimp_config_build_plug_in_path (const gchar *name)
|
||||
{
|
||||
return g_strconcat ("${gimp_dir}", G_DIR_SEPARATOR_S, name,
|
||||
G_SEARCHPATH_SEPARATOR_S,
|
||||
"${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[8192];
|
||||
FILE *sfile;
|
||||
FILE *dfile;
|
||||
struct stat stat_buf;
|
||||
gint nbytes;
|
||||
|
||||
sfile = fopen (source, "rb");
|
||||
if (sfile == NULL)
|
||||
{
|
||||
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
|
||||
_("Could not open '%s' for reading: %s"),
|
||||
gimp_filename_to_utf8 (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),
|
||||
_("Could not open '%s' for writing: %s"),
|
||||
gimp_filename_to_utf8 (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"),
|
||||
gimp_filename_to_utf8 (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"),
|
||||
gimp_filename_to_utf8 (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"),
|
||||
gimp_filename_to_utf8 (dest), g_strerror (errno));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (stat (source, &stat_buf) == 0)
|
||||
{
|
||||
chmod (dest, stat_buf.st_mode);
|
||||
}
|
||||
|
||||
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. "
|
||||
"Default values will be used. A backup of your "
|
||||
"configuration has been created at '%s'."),
|
||||
name, gimp_filename_to_utf8 (backup));
|
||||
|
||||
g_free (backup);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
|
|
@ -41,15 +41,5 @@ void gimp_config_reset_properties (GimpConfig *config);
|
|||
void gimp_config_string_append_escaped (GString *string,
|
||||
const gchar *val);
|
||||
|
||||
gchar * gimp_config_build_data_path (const gchar *name);
|
||||
gchar * gimp_config_build_writable_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__ */
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "gimpconfig-utils.h"
|
||||
|
||||
#include "gimprc-blurbs.h"
|
||||
#include "gimprc-utils.h"
|
||||
#include "gimpcoreconfig.h"
|
||||
|
||||
#include "gimp-intl.h"
|
||||
|
|
|
@ -28,9 +28,9 @@
|
|||
#include "config-types.h"
|
||||
|
||||
#include "gimpconfig-params.h"
|
||||
#include "gimpconfig-utils.h"
|
||||
|
||||
#include "gimprc-blurbs.h"
|
||||
#include "gimprc-utils.h"
|
||||
#include "gimpguiconfig.h"
|
||||
|
||||
#include "gimp-intl.h"
|
||||
|
|
|
@ -28,9 +28,9 @@
|
|||
#include "config-types.h"
|
||||
|
||||
#include "gimpconfig-params.h"
|
||||
#include "gimpconfig-utils.h"
|
||||
|
||||
#include "gimprc-blurbs.h"
|
||||
#include "gimprc-utils.h"
|
||||
#include "gimppluginconfig.h"
|
||||
|
||||
|
||||
|
|
48
app/config/gimprc-utils.c
Normal file
48
app/config/gimprc-utils.c
Normal file
|
@ -0,0 +1,48 @@
|
|||
/* The GIMP -- an image manipulation program
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "gimprc-utils.h"
|
||||
|
||||
|
||||
gchar *
|
||||
gimp_rc_build_data_path (const gchar *name)
|
||||
{
|
||||
return g_strconcat ("${gimp_dir}", G_DIR_SEPARATOR_S, name,
|
||||
G_SEARCHPATH_SEPARATOR_S,
|
||||
"${gimp_data_dir}", G_DIR_SEPARATOR_S, name,
|
||||
NULL);
|
||||
}
|
||||
|
||||
gchar *
|
||||
gimp_rc_build_writable_path (const gchar *name)
|
||||
{
|
||||
return g_strconcat ("${gimp_dir}", G_DIR_SEPARATOR_S, name, NULL);
|
||||
}
|
||||
|
||||
gchar *
|
||||
gimp_rc_build_plug_in_path (const gchar *name)
|
||||
{
|
||||
return g_strconcat ("${gimp_dir}", G_DIR_SEPARATOR_S, name,
|
||||
G_SEARCHPATH_SEPARATOR_S,
|
||||
"${gimp_plug_in_dir}", G_DIR_SEPARATOR_S, name,
|
||||
NULL);
|
||||
}
|
31
app/config/gimprc-utils.h
Normal file
31
app/config/gimprc-utils.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
/* The GIMP -- an image manipulation program
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* gimpconfig-path.h
|
||||
* Copyright (C) 2001-2002 Sven Neumann <sven@gimp.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __GIMP_RC_UTILS_H__
|
||||
#define __GIMP_RC_UTILS_H__
|
||||
|
||||
|
||||
gchar * gimp_config_build_data_path (const gchar *name);
|
||||
gchar * gimp_config_build_writable_path (const gchar *name);
|
||||
gchar * gimp_config_build_plug_in_path (const gchar *name);
|
||||
|
||||
|
||||
#endif /* __GIMP_RC_UTILS_H__ */
|
|
@ -32,6 +32,7 @@
|
|||
#include "gimpconfig.h"
|
||||
#include "gimpconfig-deserialize.h"
|
||||
#include "gimpconfig-error.h"
|
||||
#include "gimpconfig-file.h"
|
||||
#include "gimpconfig-params.h"
|
||||
#include "gimpconfig-path.h"
|
||||
#include "gimpconfig-serialize.h"
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#include "gimpunit.h"
|
||||
|
||||
#include "config/gimpconfig-error.h"
|
||||
#include "config/gimpconfig-utils.h"
|
||||
#include "config/gimpconfig-file.h"
|
||||
#include "config/gimpconfigwriter.h"
|
||||
#include "config/gimpscanner.h"
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
|
||||
#include "dialogs-types.h"
|
||||
|
||||
#include "config/gimpconfig-utils.h"
|
||||
#include "config/gimpconfig-file.h"
|
||||
#include "config/gimprc.h"
|
||||
|
||||
#include "core/gimp-templates.h"
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
#include "gui-types.h"
|
||||
|
||||
#include "config/gimpconfig-error.h"
|
||||
#include "config/gimpconfig-utils.h"
|
||||
#include "config/gimpconfig-file.h"
|
||||
#include "config/gimpconfigwriter.h"
|
||||
#include "config/gimpguiconfig.h"
|
||||
#include "config/gimpscanner.h"
|
||||
|
|
|
@ -33,36 +33,40 @@
|
|||
#include "gimp-intl.h"
|
||||
|
||||
|
||||
#define SUBSTS_ALLOC 4
|
||||
|
||||
static gchar * gimp_config_path_expand_only (const gchar *path,
|
||||
GError **error);
|
||||
static inline gchar * extract_token (const gchar **str);
|
||||
|
||||
static inline gchar *
|
||||
extract_token (const gchar **str)
|
||||
|
||||
/*
|
||||
* GimpConfig path utilities
|
||||
*/
|
||||
|
||||
gchar *
|
||||
gimp_config_build_data_path (const gchar *name)
|
||||
{
|
||||
const gchar *p;
|
||||
gchar *token;
|
||||
|
||||
if (strncmp (*str, "${", 2))
|
||||
return NULL;
|
||||
|
||||
p = *str + 2;
|
||||
|
||||
while (*p && (*p != '}'))
|
||||
p = g_utf8_next_char (p);
|
||||
|
||||
if (!p)
|
||||
return NULL;
|
||||
|
||||
token = g_strndup (*str + 2, g_utf8_pointer_to_offset (*str + 2, p));
|
||||
|
||||
*str = p + 1; /* after the closing bracket */
|
||||
|
||||
return token;
|
||||
return g_strconcat ("${gimp_dir}", G_DIR_SEPARATOR_S, name,
|
||||
G_SEARCHPATH_SEPARATOR_S,
|
||||
"${gimp_data_dir}", G_DIR_SEPARATOR_S, name,
|
||||
NULL);
|
||||
}
|
||||
|
||||
gchar *
|
||||
gimp_config_build_writable_path (const gchar *name)
|
||||
{
|
||||
return g_strconcat ("${gimp_dir}", G_DIR_SEPARATOR_S, name, NULL);
|
||||
}
|
||||
|
||||
gchar *
|
||||
gimp_config_build_plug_in_path (const gchar *name)
|
||||
{
|
||||
return g_strconcat ("${gimp_dir}", G_DIR_SEPARATOR_S, name,
|
||||
G_SEARCHPATH_SEPARATOR_S,
|
||||
"${gimp_plug_in_dir}", G_DIR_SEPARATOR_S, name,
|
||||
NULL);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* gimp_config_path_expand:
|
||||
* @path: a %NUL-terminated string in UTF-8 encoding
|
||||
|
@ -105,6 +109,9 @@ gimp_config_path_expand (const gchar *path,
|
|||
return gimp_config_path_expand_only (path, error);
|
||||
}
|
||||
|
||||
|
||||
#define SUBSTS_ALLOC 4
|
||||
|
||||
static gchar *
|
||||
gimp_config_path_expand_only (const gchar *path,
|
||||
GError **error)
|
||||
|
@ -253,3 +260,27 @@ gimp_config_path_expand_only (const gchar *path,
|
|||
|
||||
return expanded;
|
||||
}
|
||||
|
||||
static inline gchar *
|
||||
extract_token (const gchar **str)
|
||||
{
|
||||
const gchar *p;
|
||||
gchar *token;
|
||||
|
||||
if (strncmp (*str, "${", 2))
|
||||
return NULL;
|
||||
|
||||
p = *str + 2;
|
||||
|
||||
while (*p && (*p != '}'))
|
||||
p = g_utf8_next_char (p);
|
||||
|
||||
if (!p)
|
||||
return NULL;
|
||||
|
||||
token = g_strndup (*str + 2, g_utf8_pointer_to_offset (*str + 2, p));
|
||||
|
||||
*str = p + 1; /* after the closing bracket */
|
||||
|
||||
return token;
|
||||
}
|
||||
|
|
|
@ -23,9 +23,9 @@
|
|||
#define __GIMP_CONFIG_PATH_H__
|
||||
|
||||
|
||||
gchar * gimp_config_path_expand (const gchar *path,
|
||||
gboolean recode,
|
||||
GError **error);
|
||||
gchar * gimp_config_path_expand (const gchar *path,
|
||||
gboolean recode,
|
||||
GError **error);
|
||||
|
||||
|
||||
#endif /* __GIMP_CONFIG_PATH_H__ */
|
||||
|
|
|
@ -21,28 +21,16 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "libgimpbase/gimpbase.h"
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
#include "libgimpbase/gimpwin32-io.h"
|
||||
#endif
|
||||
|
||||
#include "config-types.h"
|
||||
|
||||
#include "gimpconfig.h"
|
||||
#include "gimpconfig-params.h"
|
||||
#include "gimpconfig-utils.h"
|
||||
|
||||
#include "gimp-intl.h"
|
||||
|
||||
|
||||
static void
|
||||
gimp_config_connect_notify (GObject *src,
|
||||
|
@ -499,135 +487,3 @@ gimp_config_string_append_escaped (GString *string,
|
|||
g_string_append_len (string, "\"\"", 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* GimpConfig path utilities
|
||||
*/
|
||||
|
||||
gchar *
|
||||
gimp_config_build_data_path (const gchar *name)
|
||||
{
|
||||
return g_strconcat ("${gimp_dir}", G_DIR_SEPARATOR_S, name,
|
||||
G_SEARCHPATH_SEPARATOR_S,
|
||||
"${gimp_data_dir}", G_DIR_SEPARATOR_S, name,
|
||||
NULL);
|
||||
}
|
||||
|
||||
gchar *
|
||||
gimp_config_build_writable_path (const gchar *name)
|
||||
{
|
||||
return g_strconcat ("${gimp_dir}", G_DIR_SEPARATOR_S, name, NULL);
|
||||
}
|
||||
|
||||
gchar *
|
||||
gimp_config_build_plug_in_path (const gchar *name)
|
||||
{
|
||||
return g_strconcat ("${gimp_dir}", G_DIR_SEPARATOR_S, name,
|
||||
G_SEARCHPATH_SEPARATOR_S,
|
||||
"${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[8192];
|
||||
FILE *sfile;
|
||||
FILE *dfile;
|
||||
struct stat stat_buf;
|
||||
gint nbytes;
|
||||
|
||||
sfile = fopen (source, "rb");
|
||||
if (sfile == NULL)
|
||||
{
|
||||
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
|
||||
_("Could not open '%s' for reading: %s"),
|
||||
gimp_filename_to_utf8 (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),
|
||||
_("Could not open '%s' for writing: %s"),
|
||||
gimp_filename_to_utf8 (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"),
|
||||
gimp_filename_to_utf8 (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"),
|
||||
gimp_filename_to_utf8 (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"),
|
||||
gimp_filename_to_utf8 (dest), g_strerror (errno));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (stat (source, &stat_buf) == 0)
|
||||
{
|
||||
chmod (dest, stat_buf.st_mode);
|
||||
}
|
||||
|
||||
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. "
|
||||
"Default values will be used. A backup of your "
|
||||
"configuration has been created at '%s'."),
|
||||
name, gimp_filename_to_utf8 (backup));
|
||||
|
||||
g_free (backup);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
|
|
@ -41,15 +41,5 @@ void gimp_config_reset_properties (GimpConfig *config);
|
|||
void gimp_config_string_append_escaped (GString *string,
|
||||
const gchar *val);
|
||||
|
||||
gchar * gimp_config_build_data_path (const gchar *name);
|
||||
gchar * gimp_config_build_writable_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__ */
|
||||
|
|
|
@ -66,8 +66,8 @@ app/base/base-enums.c
|
|||
app/base/tile-swap.c
|
||||
|
||||
app/config/gimpconfig-deserialize.c
|
||||
app/config/gimpconfig-file.c
|
||||
app/config/gimpconfig-path.c
|
||||
app/config/gimpconfig-utils.c
|
||||
app/config/gimpconfig.c
|
||||
app/config/gimpconfigwriter.c
|
||||
app/config/gimprc.c
|
||||
|
|
Loading…
Reference in a new issue