1999-03-07 20:56:03 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
2003-11-23 23:35:27 +08:00
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
2000-11-19 23:14:21 +08:00
|
|
|
*
|
|
|
|
* gimpenv.c
|
2003-11-23 23:35:27 +08:00
|
|
|
* Copyright (C) 1999 Tor Lillqvist <tml@iki.fi>
|
1999-03-07 20:56:03 +08:00
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This library is free software: you can redistribute it and/or
|
2003-11-23 23:35:27 +08:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2009-01-18 06:28:01 +08:00
|
|
|
* version 3 of the License, or (at your option) any later version.
|
1999-03-07 20:56:03 +08:00
|
|
|
*
|
2003-11-23 23:35:27 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
1999-03-07 20:56:03 +08:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2003-11-23 23:35:27 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
1999-03-07 20:56:03 +08:00
|
|
|
*
|
2003-11-23 23:35:27 +08:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2009-01-18 06:28:01 +08:00
|
|
|
* License along with this library. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
1999-03-07 20:56:03 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
1999-05-29 05:56:04 +08:00
|
|
|
#include <string.h>
|
2000-02-22 01:15:30 +08:00
|
|
|
#include <sys/types.h>
|
2002-02-18 22:34:50 +08:00
|
|
|
|
2000-02-22 01:15:30 +08:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2012-05-12 20:39:44 +08:00
|
|
|
#ifdef PLATFORM_OSX
|
|
|
|
#include <AppKit/AppKit.h>
|
|
|
|
#endif
|
|
|
|
|
2007-05-14 00:31:14 +08:00
|
|
|
#include <glib-object.h>
|
2005-02-07 09:10:50 +08:00
|
|
|
#include <glib/gstdio.h>
|
|
|
|
|
2007-10-31 21:09:46 +08:00
|
|
|
#undef GIMP_DISABLE_DEPRECATED
|
2007-05-14 00:31:14 +08:00
|
|
|
#include "gimpbasetypes.h"
|
|
|
|
|
2011-12-04 12:55:27 +08:00
|
|
|
#define __GIMP_ENV_C__
|
1999-03-07 20:56:03 +08:00
|
|
|
#include "gimpenv.h"
|
2002-03-30 07:10:18 +08:00
|
|
|
#include "gimpversion.h"
|
2005-11-06 09:06:41 +08:00
|
|
|
#include "gimpreloc.h"
|
1999-03-07 20:56:03 +08:00
|
|
|
|
1999-10-05 03:26:07 +08:00
|
|
|
#ifdef G_OS_WIN32
|
1999-03-07 20:56:03 +08:00
|
|
|
#define STRICT
|
2007-05-14 07:12:52 +08:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <windows.h>
|
2000-03-09 02:32:31 +08:00
|
|
|
#include <io.h>
|
|
|
|
#ifndef S_IWUSR
|
|
|
|
# define S_IWUSR _S_IWRITE
|
|
|
|
#endif
|
2000-02-24 06:03:37 +08:00
|
|
|
#ifndef S_IWGRP
|
|
|
|
#define S_IWGRP (_S_IWRITE>>3)
|
|
|
|
#define S_IWOTH (_S_IWRITE>>6)
|
|
|
|
#endif
|
2000-03-09 02:32:31 +08:00
|
|
|
#ifndef S_ISDIR
|
2005-11-17 02:07:44 +08:00
|
|
|
# define __S_ISTYPE(mode, mask) (((mode) & _S_IFMT) == (mask))
|
|
|
|
# define S_ISDIR(mode) __S_ISTYPE((mode), _S_IFDIR)
|
2000-03-09 02:32:31 +08:00
|
|
|
#endif
|
2000-02-24 06:03:37 +08:00
|
|
|
#define uid_t gint
|
|
|
|
#define gid_t gint
|
|
|
|
#define geteuid() 0
|
|
|
|
#define getegid() 0
|
2012-11-11 19:20:14 +08:00
|
|
|
|
|
|
|
/* This is a hack for Windows known directory support.
|
|
|
|
* DATADIR (autotools-generated constant) is a type defined in objidl.h
|
|
|
|
* so we must #undef it before including shlobj.h in order to avoid a
|
|
|
|
* name clash. */
|
|
|
|
static const char* datadir = DATADIR;
|
|
|
|
#undef DATADIR
|
|
|
|
#include <shlobj.h>
|
|
|
|
#define DATADIR datadir
|
|
|
|
/* Constant available since Shell32.dll 4.72 */
|
|
|
|
#ifndef CSIDL_APPDATA
|
|
|
|
#define CSIDL_APPDATA 0x001a
|
|
|
|
#endif
|
|
|
|
|
1999-03-07 20:56:03 +08:00
|
|
|
#endif
|
|
|
|
|
2006-11-28 19:57:05 +08:00
|
|
|
|
2010-06-30 01:13:40 +08:00
|
|
|
/**
|
|
|
|
* SECTION: gimpenv
|
|
|
|
* @title: gimpenv
|
|
|
|
* @short_description: Functions to access the GIMP environment.
|
|
|
|
*
|
|
|
|
* A set of functions to find the locations of GIMP's data directories
|
|
|
|
* and configuration files.
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
2012-11-11 19:20:14 +08:00
|
|
|
static gchar * gimp_env_get_dir (const gchar *gimp_env_name,
|
2013-01-28 05:26:29 +08:00
|
|
|
const gchar *compile_time_dir,
|
|
|
|
const gchar *relative_subdir);
|
2012-11-11 19:20:14 +08:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
static gchar * get_special_folder (gint csidl);
|
|
|
|
#endif
|
2001-12-11 04:43:51 +08:00
|
|
|
|
2004-01-09 22:18:43 +08:00
|
|
|
|
2006-11-28 19:57:05 +08:00
|
|
|
const guint gimp_major_version = GIMP_MAJOR_VERSION;
|
|
|
|
const guint gimp_minor_version = GIMP_MINOR_VERSION;
|
|
|
|
const guint gimp_micro_version = GIMP_MICRO_VERSION;
|
|
|
|
|
|
|
|
|
2005-11-06 09:06:41 +08:00
|
|
|
/**
|
|
|
|
* gimp_env_init:
|
|
|
|
* @plug_in: must be %TRUE if this function is called from a plug-in
|
|
|
|
*
|
|
|
|
* You don't need to care about this function. It is being called for
|
|
|
|
* you automatically (by means of the MAIN() macro that every plug-in
|
|
|
|
* runs). Calling it again will cause a fatal error.
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gimp_env_init (gboolean plug_in)
|
|
|
|
{
|
|
|
|
static gboolean gimp_env_initialized = FALSE;
|
|
|
|
|
|
|
|
if (gimp_env_initialized)
|
|
|
|
g_error ("gimp_env_init() must only be called once!");
|
|
|
|
|
|
|
|
gimp_env_initialized = TRUE;
|
|
|
|
|
|
|
|
#ifndef G_OS_WIN32
|
|
|
|
if (plug_in)
|
|
|
|
{
|
|
|
|
_gimp_reloc_init_lib (NULL);
|
|
|
|
}
|
|
|
|
else if (_gimp_reloc_init (NULL))
|
|
|
|
{
|
|
|
|
/* Set $LD_LIBRARY_PATH to ensure that plugins can be loaded. */
|
|
|
|
|
|
|
|
const gchar *ldpath = g_getenv ("LD_LIBRARY_PATH");
|
2013-01-28 05:26:29 +08:00
|
|
|
gchar *libdir = g_build_filename (gimp_installation_directory (),
|
|
|
|
"lib",
|
|
|
|
NULL);
|
2005-11-06 09:06:41 +08:00
|
|
|
|
|
|
|
if (ldpath && *ldpath)
|
|
|
|
{
|
|
|
|
gchar *tmp = g_strconcat (libdir, ":", ldpath, NULL);
|
|
|
|
|
2005-11-17 02:07:44 +08:00
|
|
|
g_setenv ("LD_LIBRARY_PATH", tmp, TRUE);
|
2005-11-06 09:06:41 +08:00
|
|
|
|
|
|
|
g_free (tmp);
|
2005-11-17 02:07:44 +08:00
|
|
|
}
|
2005-11-06 09:06:41 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
g_setenv ("LD_LIBRARY_PATH", libdir, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (libdir);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2000-02-07 07:16:24 +08:00
|
|
|
/**
|
|
|
|
* gimp_directory:
|
|
|
|
*
|
2001-02-14 22:57:14 +08:00
|
|
|
* Returns the user-specific GIMP settings directory. If the
|
2003-08-18 23:10:30 +08:00
|
|
|
* environment variable GIMP2_DIRECTORY exists, it is used. If it is
|
|
|
|
* an absolute path, it is used as is. If it is a relative path, it
|
|
|
|
* is taken to be a subdirectory of the home directory. If it is a
|
2001-02-14 22:57:14 +08:00
|
|
|
* relative path, and no home directory can be determined, it is taken
|
|
|
|
* to be a subdirectory of gimp_data_directory().
|
2000-02-07 07:16:24 +08:00
|
|
|
*
|
2003-08-18 23:10:30 +08:00
|
|
|
* The usual case is that no GIMP2_DIRECTORY environment variable
|
2012-11-11 19:20:14 +08:00
|
|
|
* exists, and then we use the GIMPDIR subdirectory of the local
|
|
|
|
* configuration directory:
|
|
|
|
*
|
|
|
|
* - UNIX: $XDG_CONFIG_HOME (defaults to $HOME/.config/)
|
|
|
|
*
|
|
|
|
* - Windows: CSIDL_APPDATA
|
|
|
|
*
|
|
|
|
* - OSX (UNIX exception): the Application Support Directory.
|
|
|
|
*
|
|
|
|
* If neither the configuration nor home directory exist,
|
|
|
|
* g_get_user_config_dir() will return {tmp}/{user_name}/.config/ where
|
|
|
|
* the temporary directory {tmp} and the {user_name} are determined
|
|
|
|
* according to platform rules.
|
|
|
|
*
|
|
|
|
* In any case, we always return some non-empty string, whether it
|
|
|
|
* corresponds to an existing directory or not.
|
2000-02-07 07:16:24 +08:00
|
|
|
*
|
2005-04-05 03:23:46 +08:00
|
|
|
* The returned string is owned by GIMP and must not be modified or
|
|
|
|
* freed. The returned string is in the encoding used for filenames by
|
2012-11-11 19:20:14 +08:00
|
|
|
* GLib, which isn't necessarily UTF-8 (on Windows it is always
|
2007-08-28 20:27:59 +08:00
|
|
|
* UTF-8.)
|
2000-02-07 07:16:24 +08:00
|
|
|
*
|
|
|
|
* Returns: The user-specific GIMP settings directory.
|
2000-11-19 23:14:21 +08:00
|
|
|
**/
|
2001-02-14 22:57:14 +08:00
|
|
|
const gchar *
|
2000-02-07 07:16:24 +08:00
|
|
|
gimp_directory (void)
|
1999-03-07 20:56:03 +08:00
|
|
|
{
|
2010-01-30 00:47:30 +08:00
|
|
|
static gchar *gimp_dir = NULL;
|
|
|
|
static gchar *last_env_gimp_dir = NULL;
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-25 05:27:11 +08:00
|
|
|
|
|
|
|
const gchar *env_gimp_dir;
|
1999-03-07 20:56:03 +08:00
|
|
|
|
2010-01-30 00:47:30 +08:00
|
|
|
env_gimp_dir = g_getenv ("GIMP2_DIRECTORY");
|
|
|
|
|
2001-12-11 04:43:51 +08:00
|
|
|
if (gimp_dir)
|
2010-01-30 00:47:30 +08:00
|
|
|
{
|
|
|
|
gboolean gimp2_directory_changed = FALSE;
|
|
|
|
|
|
|
|
/* We have constructed the gimp_dir already. We can return
|
|
|
|
* gimp_dir unless some parameter gimp_dir depends on has
|
|
|
|
* changed. For now we just check for changes to GIMP2_DIRECTORY
|
|
|
|
*/
|
|
|
|
gimp2_directory_changed =
|
|
|
|
(env_gimp_dir == NULL &&
|
|
|
|
last_env_gimp_dir != NULL) ||
|
|
|
|
(env_gimp_dir != NULL &&
|
|
|
|
last_env_gimp_dir == NULL) ||
|
|
|
|
(env_gimp_dir != NULL &&
|
|
|
|
last_env_gimp_dir != NULL &&
|
|
|
|
strcmp (env_gimp_dir, last_env_gimp_dir) != 0);
|
|
|
|
|
|
|
|
if (! gimp2_directory_changed)
|
|
|
|
{
|
|
|
|
return gimp_dir;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Free the old gimp_dir and go on to update it */
|
|
|
|
g_free (gimp_dir);
|
|
|
|
gimp_dir = NULL;
|
|
|
|
}
|
|
|
|
}
|
1999-03-07 20:56:03 +08:00
|
|
|
|
2010-01-30 00:47:30 +08:00
|
|
|
/* Remember the GIMP2_DIRECTORY to next invocation so we can check
|
|
|
|
* if it changes
|
|
|
|
*/
|
|
|
|
g_free (last_env_gimp_dir);
|
|
|
|
last_env_gimp_dir = g_strdup (env_gimp_dir);
|
|
|
|
|
2001-10-24 23:56:33 +08:00
|
|
|
if (env_gimp_dir)
|
1999-03-07 20:56:03 +08:00
|
|
|
{
|
|
|
|
if (g_path_is_absolute (env_gimp_dir))
|
2001-10-24 23:56:33 +08:00
|
|
|
{
|
|
|
|
gimp_dir = g_strdup (env_gimp_dir);
|
|
|
|
}
|
1999-03-07 20:56:03 +08:00
|
|
|
else
|
2005-11-17 02:07:44 +08:00
|
|
|
{
|
2012-11-11 19:20:14 +08:00
|
|
|
const gchar *home_dir = g_get_home_dir ();
|
|
|
|
|
2005-11-17 02:07:44 +08:00
|
|
|
if (home_dir)
|
2012-11-11 19:20:14 +08:00
|
|
|
gimp_dir = g_build_filename (home_dir, env_gimp_dir, NULL);
|
2005-11-17 02:07:44 +08:00
|
|
|
else
|
2012-11-11 19:20:14 +08:00
|
|
|
gimp_dir = g_build_filename (gimp_data_directory (), env_gimp_dir, NULL);
|
2005-11-17 02:07:44 +08:00
|
|
|
}
|
1999-03-07 20:56:03 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-05-12 20:39:44 +08:00
|
|
|
#ifdef PLATFORM_OSX
|
|
|
|
|
|
|
|
NSAutoreleasePool *pool;
|
|
|
|
NSArray *path;
|
|
|
|
NSString *library_dir;
|
|
|
|
|
|
|
|
pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
|
2012-10-09 05:20:54 +08:00
|
|
|
path = NSSearchPathForDirectoriesInDomains (NSApplicationSupportDirectory,
|
2012-05-12 20:39:44 +08:00
|
|
|
NSUserDomainMask, YES);
|
|
|
|
library_dir = [path objectAtIndex:0];
|
|
|
|
|
2012-05-12 22:48:05 +08:00
|
|
|
gimp_dir = g_build_filename ([library_dir UTF8String],
|
2012-11-11 19:20:14 +08:00
|
|
|
GIMPDIR, GIMP_USER_VERSION, NULL);
|
2012-05-12 20:39:44 +08:00
|
|
|
|
|
|
|
[pool drain];
|
|
|
|
|
2012-11-11 19:20:14 +08:00
|
|
|
#elif defined G_OS_WIN32
|
2012-05-12 20:39:44 +08:00
|
|
|
|
2012-11-11 19:20:14 +08:00
|
|
|
gchar *conf_dir = get_special_folder (CSIDL_APPDATA);
|
2002-03-30 07:10:18 +08:00
|
|
|
|
2012-11-11 19:20:14 +08:00
|
|
|
gimp_dir = g_build_filename (conf_dir,
|
|
|
|
GIMPDIR, GIMP_USER_VERSION, NULL);
|
|
|
|
g_free(conf_dir);
|
2002-03-30 07:10:18 +08:00
|
|
|
|
2012-11-11 19:20:14 +08:00
|
|
|
#else /* UNIX */
|
|
|
|
|
|
|
|
/* g_get_user_config_dir () always returns a path as a non-null
|
|
|
|
* and non-empty string
|
|
|
|
*/
|
|
|
|
gimp_dir = g_build_filename (g_get_user_config_dir (),
|
|
|
|
GIMPDIR, GIMP_USER_VERSION, NULL);
|
2012-05-12 20:39:44 +08:00
|
|
|
|
|
|
|
#endif /* PLATFORM_OSX */
|
1999-03-07 20:56:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return gimp_dir;
|
|
|
|
}
|
|
|
|
|
2007-12-12 17:41:13 +08:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
|
2013-01-23 14:38:21 +08:00
|
|
|
/* Taken from glib 2.35 code. */
|
2012-11-11 19:20:14 +08:00
|
|
|
static gchar *
|
|
|
|
get_special_folder (int csidl)
|
|
|
|
{
|
|
|
|
wchar_t path[MAX_PATH+1];
|
|
|
|
HRESULT hr;
|
|
|
|
LPITEMIDLIST pidl = NULL;
|
|
|
|
BOOL b;
|
|
|
|
gchar *retval = NULL;
|
|
|
|
|
2013-01-23 14:38:21 +08:00
|
|
|
hr = SHGetSpecialFolderLocation (NULL, csidl, &pidl);
|
2012-11-11 19:20:14 +08:00
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
b = SHGetPathFromIDListW (pidl, path);
|
|
|
|
if (b)
|
|
|
|
retval = g_utf16_to_utf8 (path, -1, NULL, NULL, NULL);
|
|
|
|
CoTaskMemFree (pidl);
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2007-12-12 17:41:13 +08:00
|
|
|
static HMODULE libgimpbase_dll = NULL;
|
|
|
|
|
|
|
|
/* Minimal DllMain that just stores the handle to this DLL */
|
|
|
|
|
2013-01-28 05:38:35 +08:00
|
|
|
BOOL WINAPI /* Avoid silly "no previous prototype" gcc warning */
|
2007-12-12 17:41:13 +08:00
|
|
|
DllMain (HINSTANCE hinstDLL,
|
|
|
|
DWORD fdwReason,
|
|
|
|
LPVOID lpvReserved);
|
|
|
|
|
|
|
|
BOOL WINAPI
|
|
|
|
DllMain (HINSTANCE hinstDLL,
|
|
|
|
DWORD fdwReason,
|
|
|
|
LPVOID lpvReserved)
|
|
|
|
{
|
|
|
|
switch (fdwReason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
libgimpbase_dll = hinstDLL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2012-05-23 17:49:07 +08:00
|
|
|
/**
|
|
|
|
* gimp_installation_directory:
|
|
|
|
*
|
|
|
|
* Returns the top installation directory of GIMP. On Unix the
|
|
|
|
* compile-time defined installation prefix is used. On Windows, the
|
|
|
|
* installation directory as deduced from the executable's full
|
|
|
|
* filename is used. On OSX we ask [NSBundle mainBundle] for the
|
|
|
|
* resource path to check if GIMP is part of a relocatable bundle.
|
|
|
|
*
|
|
|
|
* The returned string is owned by GIMP and must not be modified or
|
|
|
|
* freed. The returned string is in the encoding used for filenames by
|
|
|
|
* GLib, which isn't necessarily UTF-8. (On Windows it always is
|
|
|
|
* UTF-8.)
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.8
|
|
|
|
*
|
|
|
|
* Returns: The toplevel installation directory of GIMP.
|
|
|
|
**/
|
|
|
|
const gchar *
|
|
|
|
gimp_installation_directory (void)
|
2002-03-30 07:10:18 +08:00
|
|
|
{
|
|
|
|
static gchar *toplevel = NULL;
|
2003-12-05 23:55:15 +08:00
|
|
|
|
2004-01-09 22:18:43 +08:00
|
|
|
if (toplevel)
|
2002-03-30 07:10:18 +08:00
|
|
|
return toplevel;
|
2003-12-05 23:55:15 +08:00
|
|
|
|
2005-11-17 02:07:44 +08:00
|
|
|
#ifdef G_OS_WIN32
|
2012-05-13 02:56:30 +08:00
|
|
|
|
2013-01-28 05:38:35 +08:00
|
|
|
toplevel = g_win32_get_package_installation_directory_of_module (libgimpbase_dll);
|
|
|
|
if (! toplevel)
|
|
|
|
g_error ("g_win32_get_package_installation_directory_of_module() failed");
|
2012-05-13 02:56:30 +08:00
|
|
|
|
|
|
|
#elif PLATFORM_OSX
|
|
|
|
|
|
|
|
{
|
|
|
|
NSAutoreleasePool *pool;
|
|
|
|
NSString *resource_path;
|
|
|
|
gchar *basename;
|
|
|
|
gchar *dirname;
|
|
|
|
|
|
|
|
pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
|
|
|
|
resource_path = [[NSBundle mainBundle] resourcePath];
|
|
|
|
|
|
|
|
basename = g_path_get_basename ([resource_path UTF8String]);
|
|
|
|
dirname = g_path_get_dirname ([resource_path UTF8String]);
|
|
|
|
|
|
|
|
if (! strcmp (basename, ".libs"))
|
|
|
|
{
|
|
|
|
/* we are running from the source dir, do normal unix things */
|
|
|
|
|
|
|
|
toplevel = _gimp_reloc_find_prefix (PREFIX);
|
|
|
|
}
|
|
|
|
else if (! strcmp (basename, "bin"))
|
|
|
|
{
|
|
|
|
/* we are running the main app, but not from a bundle, the resource
|
|
|
|
* path is the directory which contains the executable
|
|
|
|
*/
|
|
|
|
|
|
|
|
toplevel = g_strdup (dirname);
|
|
|
|
}
|
|
|
|
else if (! strcmp (basename, "plug-ins"))
|
|
|
|
{
|
|
|
|
/* same for plug-ins, go three levels up from prefix/lib/gimp/x.y */
|
|
|
|
|
|
|
|
gchar *tmp = g_path_get_dirname (dirname);
|
|
|
|
gchar *tmp2 = g_path_get_dirname (tmp);
|
|
|
|
|
|
|
|
toplevel = g_path_get_dirname (tmp2);
|
|
|
|
|
|
|
|
g_free (tmp);
|
|
|
|
g_free (tmp2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* if none of the above match, we assume that we are really in a bundle */
|
|
|
|
|
|
|
|
toplevel = g_strdup ([resource_path UTF8String]);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (basename);
|
|
|
|
g_free (dirname);
|
|
|
|
|
|
|
|
[pool drain];
|
|
|
|
}
|
|
|
|
|
2005-11-06 09:06:41 +08:00
|
|
|
#else
|
2012-05-13 02:56:30 +08:00
|
|
|
|
2005-11-17 02:07:44 +08:00
|
|
|
toplevel = _gimp_reloc_find_prefix (PREFIX);
|
2012-05-13 02:56:30 +08:00
|
|
|
|
2002-03-30 07:10:18 +08:00
|
|
|
#endif
|
2005-11-17 02:07:44 +08:00
|
|
|
|
|
|
|
return toplevel;
|
2005-11-06 09:06:41 +08:00
|
|
|
}
|
2002-03-30 07:10:18 +08:00
|
|
|
|
2000-02-07 07:16:24 +08:00
|
|
|
/**
|
|
|
|
* gimp_data_directory:
|
|
|
|
*
|
2003-08-18 23:10:30 +08:00
|
|
|
* Returns the top directory for GIMP data. If the environment
|
|
|
|
* variable GIMP2_DATADIR exists, that is used. It should be an
|
|
|
|
* absolute pathname. Otherwise, on Unix the compile-time defined
|
2007-08-28 20:27:59 +08:00
|
|
|
* directory is used. On Windows, the installation directory as deduced
|
|
|
|
* from the executable's full filename is used.
|
2000-02-07 07:16:24 +08:00
|
|
|
*
|
2005-04-05 03:23:46 +08:00
|
|
|
* The returned string is owned by GIMP and must not be modified or
|
|
|
|
* freed. The returned string is in the encoding used for filenames by
|
2007-08-28 20:27:59 +08:00
|
|
|
* GLib, which isn't necessarily UTF-8. (On Windows it always is
|
|
|
|
* UTF-8.)
|
2000-02-07 07:16:24 +08:00
|
|
|
*
|
|
|
|
* Returns: The top directory for GIMP data.
|
2000-11-19 23:14:21 +08:00
|
|
|
**/
|
2001-02-14 22:57:14 +08:00
|
|
|
const gchar *
|
2000-02-07 07:16:24 +08:00
|
|
|
gimp_data_directory (void)
|
1999-03-07 20:56:03 +08:00
|
|
|
{
|
2000-02-07 07:16:24 +08:00
|
|
|
static gchar *gimp_data_dir = NULL;
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-25 05:27:11 +08:00
|
|
|
|
2004-01-09 22:18:43 +08:00
|
|
|
if (! gimp_data_dir)
|
2005-11-06 09:06:41 +08:00
|
|
|
{
|
2013-01-28 05:26:29 +08:00
|
|
|
gchar *tmp = g_build_filename ("share",
|
|
|
|
GIMP_PACKAGE,
|
|
|
|
GIMP_DATA_VERSION,
|
|
|
|
NULL);
|
2005-11-06 09:06:41 +08:00
|
|
|
|
2013-01-28 05:26:29 +08:00
|
|
|
gimp_data_dir = gimp_env_get_dir ("GIMP2_DATADIR", DATADIR, tmp);
|
2005-11-06 09:06:41 +08:00
|
|
|
g_free (tmp);
|
|
|
|
}
|
1999-03-07 20:56:03 +08:00
|
|
|
|
|
|
|
return gimp_data_dir;
|
|
|
|
}
|
|
|
|
|
2002-05-11 07:30:09 +08:00
|
|
|
/**
|
|
|
|
* gimp_locale_directory:
|
|
|
|
*
|
|
|
|
* Returns the top directory for GIMP locale files. If the environment
|
2003-08-18 23:10:30 +08:00
|
|
|
* variable GIMP2_LOCALEDIR exists, that is used. It should be an
|
2002-05-11 07:30:09 +08:00
|
|
|
* absolute pathname. Otherwise, on Unix the compile-time defined
|
2007-08-28 20:27:59 +08:00
|
|
|
* directory is used. On Windows, the installation directory as deduced
|
|
|
|
* from the executable's full filename is used.
|
2002-05-11 07:30:09 +08:00
|
|
|
*
|
2005-04-05 03:23:46 +08:00
|
|
|
* The returned string is owned by GIMP and must not be modified or
|
|
|
|
* freed. The returned string is in the encoding used for filenames by
|
2007-10-27 06:02:13 +08:00
|
|
|
* the C library, which isn't necessarily UTF-8. (On Windows, unlike
|
|
|
|
* the other similar functions here, the return value from this
|
|
|
|
* function is in the system codepage, never in UTF-8. It can thus be
|
|
|
|
* passed directly to the bindtextdomain() function from libintl which
|
|
|
|
* does not handle UTF-8.)
|
2002-05-11 07:30:09 +08:00
|
|
|
*
|
|
|
|
* Returns: The top directory for GIMP locale files.
|
|
|
|
*/
|
|
|
|
const gchar *
|
|
|
|
gimp_locale_directory (void)
|
|
|
|
{
|
|
|
|
static gchar *gimp_locale_dir = NULL;
|
|
|
|
|
2004-01-09 22:18:43 +08:00
|
|
|
if (! gimp_locale_dir)
|
2005-11-06 09:06:41 +08:00
|
|
|
{
|
2013-01-28 05:26:29 +08:00
|
|
|
gchar *tmp = g_build_filename ("share",
|
|
|
|
"locale",
|
|
|
|
NULL);
|
2005-11-06 09:06:41 +08:00
|
|
|
|
2013-01-28 05:26:29 +08:00
|
|
|
gimp_locale_dir = gimp_env_get_dir ("GIMP2_LOCALEDIR", LOCALEDIR, tmp);
|
2005-11-06 09:06:41 +08:00
|
|
|
g_free (tmp);
|
2013-01-28 05:26:29 +08:00
|
|
|
|
2007-10-27 06:02:13 +08:00
|
|
|
#ifdef G_OS_WIN32
|
2007-12-13 07:35:00 +08:00
|
|
|
tmp = g_win32_locale_filename_from_utf8 (gimp_locale_dir);
|
2007-10-27 06:02:13 +08:00
|
|
|
g_free (gimp_locale_dir);
|
|
|
|
gimp_locale_dir = tmp;
|
|
|
|
#endif
|
2005-11-06 09:06:41 +08:00
|
|
|
}
|
2002-05-11 07:30:09 +08:00
|
|
|
|
|
|
|
return gimp_locale_dir;
|
|
|
|
}
|
|
|
|
|
2000-10-15 06:15:11 +08:00
|
|
|
/**
|
|
|
|
* gimp_sysconf_directory:
|
|
|
|
*
|
|
|
|
* Returns the top directory for GIMP config files. If the environment
|
2003-08-18 23:10:30 +08:00
|
|
|
* variable GIMP2_SYSCONFDIR exists, that is used. It should be an
|
2000-10-15 06:15:11 +08:00
|
|
|
* absolute pathname. Otherwise, on Unix the compile-time defined
|
2007-08-28 20:27:59 +08:00
|
|
|
* directory is used. On Windows, the installation directory as deduced
|
|
|
|
* from the executable's full filename is used.
|
2000-10-15 06:15:11 +08:00
|
|
|
*
|
2005-04-05 03:23:46 +08:00
|
|
|
* The returned string is owned by GIMP and must not be modified or
|
|
|
|
* freed. The returned string is in the encoding used for filenames by
|
2007-08-28 20:27:59 +08:00
|
|
|
* GLib, which isn't necessarily UTF-8. (On Windows it always is
|
|
|
|
* UTF-8.).
|
2000-10-15 06:15:11 +08:00
|
|
|
*
|
2000-11-19 23:14:21 +08:00
|
|
|
* Returns: The top directory for GIMP config files.
|
|
|
|
**/
|
2001-02-14 22:57:14 +08:00
|
|
|
const gchar *
|
2000-10-15 06:15:11 +08:00
|
|
|
gimp_sysconf_directory (void)
|
|
|
|
{
|
|
|
|
static gchar *gimp_sysconf_dir = NULL;
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-25 05:27:11 +08:00
|
|
|
|
2004-01-09 22:18:43 +08:00
|
|
|
if (! gimp_sysconf_dir)
|
2005-11-06 09:06:41 +08:00
|
|
|
{
|
2013-01-28 05:26:29 +08:00
|
|
|
gchar *tmp = g_build_filename ("etc",
|
|
|
|
GIMP_PACKAGE,
|
|
|
|
GIMP_SYSCONF_VERSION,
|
|
|
|
NULL);
|
2005-11-06 09:06:41 +08:00
|
|
|
|
2013-01-28 05:26:29 +08:00
|
|
|
gimp_sysconf_dir = gimp_env_get_dir ("GIMP2_SYSCONFDIR", SYSCONFDIR, tmp);
|
2005-11-06 09:06:41 +08:00
|
|
|
g_free (tmp);
|
|
|
|
}
|
2000-10-15 06:15:11 +08:00
|
|
|
|
2001-12-11 04:43:51 +08:00
|
|
|
return gimp_sysconf_dir;
|
|
|
|
}
|
2000-10-15 06:15:11 +08:00
|
|
|
|
2007-05-14 00:31:14 +08:00
|
|
|
/**
|
|
|
|
* gimp_user_directory:
|
|
|
|
* @type: the type of user directory to retrieve
|
|
|
|
*
|
2008-01-11 01:14:06 +08:00
|
|
|
* This procedure is deprecated! Use g_get_user_special_dir() instead.
|
2007-05-14 00:31:14 +08:00
|
|
|
*
|
2007-08-12 01:15:52 +08:00
|
|
|
* Returns: The path to the specified user directory, or %NULL if the
|
|
|
|
* logical ID was not found.
|
2007-05-14 00:31:14 +08:00
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
**/
|
2007-08-12 01:15:52 +08:00
|
|
|
const gchar *
|
2007-05-14 00:31:14 +08:00
|
|
|
gimp_user_directory (GimpUserDirectory type)
|
|
|
|
{
|
2007-10-31 21:09:46 +08:00
|
|
|
return g_get_user_special_dir (type);
|
2007-05-14 00:31:14 +08:00
|
|
|
}
|
|
|
|
|
2001-12-11 04:43:51 +08:00
|
|
|
/**
|
|
|
|
* gimp_plug_in_directory:
|
|
|
|
*
|
2003-12-05 23:55:15 +08:00
|
|
|
* Returns the top directory for GIMP plug_ins and modules. If the
|
|
|
|
* environment variable GIMP2_PLUGINDIR exists, that is used. It
|
|
|
|
* should be an absolute pathname. Otherwise, on Unix the compile-time
|
2007-08-28 20:27:59 +08:00
|
|
|
* defined directory is used. On Windows, the installation directory as
|
|
|
|
* deduced from the executable's full filename is used.
|
2001-12-11 04:43:51 +08:00
|
|
|
*
|
2005-04-05 03:23:46 +08:00
|
|
|
* The returned string is owned by GIMP and must not be modified or
|
|
|
|
* freed. The returned string is in the encoding used for filenames by
|
2007-08-28 20:27:59 +08:00
|
|
|
* GLib, which isn't necessarily UTF-8. (On Windows it always is
|
|
|
|
* UTF-8.)
|
2001-12-11 04:43:51 +08:00
|
|
|
*
|
|
|
|
* Returns: The top directory for GIMP plug_ins and modules.
|
|
|
|
**/
|
|
|
|
const gchar *
|
|
|
|
gimp_plug_in_directory (void)
|
|
|
|
{
|
|
|
|
static gchar *gimp_plug_in_dir = NULL;
|
2000-10-15 06:15:11 +08:00
|
|
|
|
2004-01-09 22:18:43 +08:00
|
|
|
if (! gimp_plug_in_dir)
|
2005-11-06 09:06:41 +08:00
|
|
|
{
|
2013-01-28 05:26:29 +08:00
|
|
|
gchar *tmp = g_build_filename ("lib",
|
|
|
|
GIMP_PACKAGE,
|
|
|
|
GIMP_PLUGIN_VERSION,
|
|
|
|
NULL);
|
2005-11-06 09:06:41 +08:00
|
|
|
|
2013-01-28 05:26:29 +08:00
|
|
|
gimp_plug_in_dir = gimp_env_get_dir ("GIMP2_PLUGINDIR", PLUGINDIR, tmp);
|
2005-11-06 09:06:41 +08:00
|
|
|
g_free (tmp);
|
|
|
|
}
|
2000-10-15 06:15:11 +08:00
|
|
|
|
2001-12-11 04:43:51 +08:00
|
|
|
return gimp_plug_in_dir;
|
2000-10-15 06:15:11 +08:00
|
|
|
}
|
|
|
|
|
2007-05-14 00:31:14 +08:00
|
|
|
/**
|
|
|
|
* gimp_personal_rc_file:
|
|
|
|
* @basename: The basename of a rc_file.
|
|
|
|
*
|
|
|
|
* Returns the name of a file in the user-specific GIMP settings directory.
|
|
|
|
*
|
|
|
|
* The returned string is allocated dynamically and *SHOULD* be freed
|
2007-08-28 20:27:59 +08:00
|
|
|
* with g_free() after use. The returned string is in the encoding
|
|
|
|
* used for filenames by GLib, which isn't necessarily
|
|
|
|
* UTF-8. (On Windows it always is UTF-8.)
|
2007-05-14 00:31:14 +08:00
|
|
|
*
|
|
|
|
* Returns: The name of a file in the user-specific GIMP settings directory.
|
|
|
|
**/
|
|
|
|
gchar *
|
|
|
|
gimp_personal_rc_file (const gchar *basename)
|
|
|
|
{
|
|
|
|
return g_build_filename (gimp_directory (), basename, NULL);
|
|
|
|
}
|
|
|
|
|
2000-02-07 07:16:24 +08:00
|
|
|
/**
|
|
|
|
* gimp_gtkrc:
|
|
|
|
*
|
2007-06-06 16:44:52 +08:00
|
|
|
* Returns the name of GIMP's application-specific gtkrc file.
|
1999-03-07 20:56:03 +08:00
|
|
|
*
|
2005-04-05 03:23:46 +08:00
|
|
|
* The returned string is owned by GIMP and must not be modified or
|
|
|
|
* freed. The returned string is in the encoding used for filenames by
|
2007-08-28 20:27:59 +08:00
|
|
|
* GLib, which isn't necessarily UTF-8. (On Windows it always is
|
|
|
|
* UTF-8.)
|
2000-02-07 07:16:24 +08:00
|
|
|
*
|
2007-06-06 16:44:52 +08:00
|
|
|
* Returns: The name of GIMP's application-specific gtkrc file.
|
2003-12-05 23:55:15 +08:00
|
|
|
**/
|
2001-02-14 22:57:14 +08:00
|
|
|
const gchar *
|
2000-02-07 07:16:24 +08:00
|
|
|
gimp_gtkrc (void)
|
1999-03-07 20:56:03 +08:00
|
|
|
{
|
2000-02-07 07:16:24 +08:00
|
|
|
static gchar *gimp_gtkrc_filename = NULL;
|
1999-03-07 20:56:03 +08:00
|
|
|
|
2001-10-24 23:56:33 +08:00
|
|
|
if (! gimp_gtkrc_filename)
|
2004-01-09 22:18:43 +08:00
|
|
|
gimp_gtkrc_filename = g_build_filename (gimp_data_directory (),
|
|
|
|
"themes", "Default", "gtkrc",
|
|
|
|
NULL);
|
2001-08-06 04:34:10 +08:00
|
|
|
|
1999-03-07 20:56:03 +08:00
|
|
|
return gimp_gtkrc_filename;
|
|
|
|
}
|
2000-02-07 07:16:24 +08:00
|
|
|
|
2002-03-30 07:10:18 +08:00
|
|
|
/**
|
|
|
|
* gimp_path_runtime_fix:
|
2002-05-30 10:13:11 +08:00
|
|
|
* @path: A pointer to a string (allocated with g_malloc) that is
|
|
|
|
* (or could be) a pathname.
|
2002-03-30 07:10:18 +08:00
|
|
|
*
|
|
|
|
* On Windows, this function checks if the string pointed to by @path
|
|
|
|
* starts with the compile-time prefix, and in that case, replaces the
|
|
|
|
* prefix with the run-time one. @path should be a pointer to a
|
|
|
|
* dynamically allocated (with g_malloc, g_strconcat, etc) string. If
|
|
|
|
* the replacement takes place, the original string is deallocated,
|
|
|
|
* and *@path is replaced with a pointer to a new string with the
|
|
|
|
* run-time prefix spliced in.
|
|
|
|
*
|
2005-11-06 09:06:41 +08:00
|
|
|
* On Linux, it does the same thing, but only if BinReloc support is enabled.
|
|
|
|
* On other Unices, it does nothing because those platforms don't have a
|
|
|
|
* way to find out where our binary is.
|
2002-03-30 07:10:18 +08:00
|
|
|
*/
|
2002-05-30 10:13:11 +08:00
|
|
|
static void
|
2002-03-30 07:10:18 +08:00
|
|
|
gimp_path_runtime_fix (gchar **path)
|
|
|
|
{
|
|
|
|
#if defined (G_OS_WIN32) && defined (PREFIX)
|
|
|
|
gchar *p;
|
|
|
|
|
|
|
|
/* Yes, I do mean forward slashes below */
|
|
|
|
if (strncmp (*path, PREFIX "/", strlen (PREFIX "/")) == 0)
|
|
|
|
{
|
|
|
|
/* This is a compile-time entry. Replace the path with the
|
|
|
|
* real one on this machine.
|
|
|
|
*/
|
|
|
|
p = *path;
|
2012-05-23 17:49:07 +08:00
|
|
|
*path = g_strconcat (gimp_installation_directory (),
|
2005-11-17 02:07:44 +08:00
|
|
|
"\\",
|
|
|
|
*path + strlen (PREFIX "/"),
|
|
|
|
NULL);
|
2002-03-30 07:10:18 +08:00
|
|
|
g_free (p);
|
|
|
|
}
|
|
|
|
/* Replace forward slashes with backslashes, just for
|
|
|
|
* completeness */
|
|
|
|
p = *path;
|
|
|
|
while ((p = strchr (p, '/')) != NULL)
|
|
|
|
{
|
|
|
|
*p = '\\';
|
|
|
|
p++;
|
|
|
|
}
|
2002-05-11 07:30:09 +08:00
|
|
|
#elif defined (G_OS_WIN32)
|
|
|
|
/* without defineing PREFIX do something useful too */
|
|
|
|
gchar *p = *path;
|
|
|
|
if (!g_path_is_absolute (p))
|
|
|
|
{
|
2012-05-23 17:49:07 +08:00
|
|
|
*path = g_build_filename (gimp_installation_directory (), *path, NULL);
|
2002-05-11 07:30:09 +08:00
|
|
|
g_free (p);
|
|
|
|
}
|
2005-11-06 09:06:41 +08:00
|
|
|
#else
|
|
|
|
gchar *p;
|
|
|
|
|
2005-11-17 02:07:44 +08:00
|
|
|
if (strncmp (*path, PREFIX G_DIR_SEPARATOR_S,
|
|
|
|
strlen (PREFIX G_DIR_SEPARATOR_S)) == 0)
|
2005-11-06 09:06:41 +08:00
|
|
|
{
|
|
|
|
/* This is a compile-time entry. Replace the path with the
|
|
|
|
* real one on this machine.
|
|
|
|
*/
|
|
|
|
p = *path;
|
2012-05-23 17:49:07 +08:00
|
|
|
*path = g_build_filename (gimp_installation_directory (),
|
2005-11-17 02:07:44 +08:00
|
|
|
*path + strlen (PREFIX G_DIR_SEPARATOR_S),
|
|
|
|
NULL);
|
2005-11-06 09:06:41 +08:00
|
|
|
g_free (p);
|
|
|
|
}
|
2002-03-30 07:10:18 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2000-02-22 01:15:30 +08:00
|
|
|
/**
|
|
|
|
* gimp_path_parse:
|
2001-10-24 23:56:33 +08:00
|
|
|
* @path: A list of directories separated by #G_SEARCHPATH_SEPARATOR.
|
|
|
|
* @max_paths: The maximum number of directories to return.
|
2003-02-07 05:17:12 +08:00
|
|
|
* @check: %TRUE if you want the directories to be checked.
|
2000-02-23 23:52:33 +08:00
|
|
|
* @check_failed: Returns a #GList of path elements for which the
|
2001-10-24 23:56:33 +08:00
|
|
|
* check failed.
|
2000-02-22 01:15:30 +08:00
|
|
|
*
|
2001-10-24 23:56:33 +08:00
|
|
|
* Returns: A #GList of all directories in @path.
|
2000-11-19 23:14:21 +08:00
|
|
|
**/
|
2000-02-22 01:15:30 +08:00
|
|
|
GList *
|
2001-02-14 22:57:14 +08:00
|
|
|
gimp_path_parse (const gchar *path,
|
2005-11-17 02:07:44 +08:00
|
|
|
gint max_paths,
|
|
|
|
gboolean check,
|
|
|
|
GList **check_failed)
|
2000-02-22 01:15:30 +08:00
|
|
|
{
|
2012-11-11 20:22:17 +08:00
|
|
|
gchar **patharray;
|
|
|
|
GList *list = NULL;
|
|
|
|
GList *fail_list = NULL;
|
|
|
|
gint i;
|
|
|
|
gboolean exists = TRUE;
|
2000-02-22 01:15:30 +08:00
|
|
|
|
|
|
|
if (!path || !*path || max_paths < 1 || max_paths > 256)
|
|
|
|
return NULL;
|
2000-02-07 07:16:24 +08:00
|
|
|
|
2000-02-22 01:15:30 +08:00
|
|
|
patharray = g_strsplit (path, G_SEARCHPATH_SEPARATOR_S, max_paths);
|
|
|
|
|
|
|
|
for (i = 0; i < max_paths; i++)
|
|
|
|
{
|
|
|
|
GString *dir;
|
2000-02-07 07:16:24 +08:00
|
|
|
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-25 05:27:11 +08:00
|
|
|
if (! patharray[i])
|
2005-11-17 02:07:44 +08:00
|
|
|
break;
|
2000-02-22 01:15:30 +08:00
|
|
|
|
2000-05-16 06:47:36 +08:00
|
|
|
#ifndef G_OS_WIN32
|
2000-02-22 01:15:30 +08:00
|
|
|
if (*patharray[i] == '~')
|
2005-11-17 02:07:44 +08:00
|
|
|
{
|
2012-11-11 20:22:17 +08:00
|
|
|
dir = g_string_new (g_get_home_dir ());
|
2005-11-17 02:07:44 +08:00
|
|
|
g_string_append (dir, patharray[i] + 1);
|
|
|
|
}
|
2000-02-22 01:15:30 +08:00
|
|
|
else
|
2000-05-16 06:47:36 +08:00
|
|
|
#endif
|
2005-11-17 02:07:44 +08:00
|
|
|
{
|
|
|
|
gimp_path_runtime_fix (&patharray[i]);
|
|
|
|
dir = g_string_new (patharray[i]);
|
|
|
|
}
|
2000-02-22 01:15:30 +08:00
|
|
|
|
|
|
|
if (check)
|
2002-02-18 22:34:50 +08:00
|
|
|
exists = g_file_test (dir->str, G_FILE_TEST_IS_DIR);
|
2000-02-22 01:15:30 +08:00
|
|
|
|
2002-02-18 22:34:50 +08:00
|
|
|
if (exists)
|
2005-11-17 02:07:44 +08:00
|
|
|
list = g_list_prepend (list, g_strdup (dir->str));
|
2000-02-22 01:15:30 +08:00
|
|
|
else if (check_failed)
|
2005-11-17 02:07:44 +08:00
|
|
|
fail_list = g_list_prepend (fail_list, g_strdup (dir->str));
|
2000-02-22 01:15:30 +08:00
|
|
|
|
2000-02-24 09:52:31 +08:00
|
|
|
g_string_free (dir, TRUE);
|
2000-02-22 01:15:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
g_strfreev (patharray);
|
|
|
|
|
|
|
|
list = g_list_reverse (list);
|
|
|
|
|
|
|
|
if (check && check_failed)
|
|
|
|
{
|
|
|
|
fail_list = g_list_reverse (fail_list);
|
|
|
|
*check_failed = fail_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_path_to_str:
|
|
|
|
* @path: A list of directories as returned by gimp_path_parse().
|
|
|
|
*
|
|
|
|
* Returns: A searchpath string separated by #G_SEARCHPATH_SEPARATOR.
|
2000-11-19 23:14:21 +08:00
|
|
|
**/
|
2000-02-22 01:15:30 +08:00
|
|
|
gchar *
|
|
|
|
gimp_path_to_str (GList *path)
|
|
|
|
{
|
2005-02-07 08:49:36 +08:00
|
|
|
GString *str = NULL;
|
2000-02-22 01:15:30 +08:00
|
|
|
GList *list;
|
|
|
|
gchar *retval = NULL;
|
|
|
|
|
|
|
|
for (list = path; list; list = g_list_next (list))
|
|
|
|
{
|
2005-02-07 08:49:36 +08:00
|
|
|
gchar *dir = list->data;
|
2004-01-09 22:18:43 +08:00
|
|
|
|
2000-02-22 01:15:30 +08:00
|
|
|
if (str)
|
2005-11-17 02:07:44 +08:00
|
|
|
{
|
|
|
|
g_string_append_c (str, G_SEARCHPATH_SEPARATOR);
|
|
|
|
g_string_append (str, dir);
|
|
|
|
}
|
2000-02-22 01:15:30 +08:00
|
|
|
else
|
2005-11-17 02:07:44 +08:00
|
|
|
{
|
|
|
|
str = g_string_new (dir);
|
|
|
|
}
|
2000-02-22 01:15:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (str)
|
2004-01-09 22:18:43 +08:00
|
|
|
retval = g_string_free (str, FALSE);
|
2000-02-22 01:15:30 +08:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_path_free:
|
|
|
|
* @path: A list of directories as returned by gimp_path_parse().
|
|
|
|
*
|
2004-01-09 22:18:43 +08:00
|
|
|
* This function frees the memory allocated for the list and the strings
|
|
|
|
* it contains.
|
2000-11-19 23:14:21 +08:00
|
|
|
**/
|
2000-02-22 01:15:30 +08:00
|
|
|
void
|
|
|
|
gimp_path_free (GList *path)
|
|
|
|
{
|
2011-03-08 00:10:18 +08:00
|
|
|
g_list_free_full (path, (GDestroyNotify) g_free);
|
2000-02-22 01:15:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_path_get_user_writable_dir:
|
|
|
|
* @path: A list of directories as returned by gimp_path_parse().
|
|
|
|
*
|
2000-02-24 19:39:26 +08:00
|
|
|
* Note that you have to g_free() the returned string.
|
|
|
|
*
|
2000-02-22 01:15:30 +08:00
|
|
|
* Returns: The first directory in @path where the user has write permission.
|
2000-11-19 23:14:21 +08:00
|
|
|
**/
|
2000-02-22 01:15:30 +08:00
|
|
|
gchar *
|
|
|
|
gimp_path_get_user_writable_dir (GList *path)
|
|
|
|
{
|
2004-01-09 22:18:43 +08:00
|
|
|
GList *list;
|
|
|
|
uid_t euid;
|
|
|
|
gid_t egid;
|
|
|
|
struct stat filestat;
|
|
|
|
gint err;
|
2000-02-22 01:15:30 +08:00
|
|
|
|
2001-10-24 23:56:33 +08:00
|
|
|
g_return_val_if_fail (path != NULL, NULL);
|
|
|
|
|
2000-02-22 01:15:30 +08:00
|
|
|
euid = geteuid ();
|
|
|
|
egid = getegid ();
|
|
|
|
|
|
|
|
for (list = path; list; list = g_list_next (list))
|
|
|
|
{
|
2005-02-07 08:49:36 +08:00
|
|
|
gchar *dir = list->data;
|
2000-04-12 02:39:31 +08:00
|
|
|
|
2001-10-24 23:56:33 +08:00
|
|
|
/* check if directory exists */
|
2005-02-07 08:49:36 +08:00
|
|
|
err = g_stat (dir, &filestat);
|
2000-02-22 01:15:30 +08:00
|
|
|
|
|
|
|
/* this is tricky:
|
|
|
|
* if a file is e.g. owned by the current user but not user-writable,
|
|
|
|
* the user has no permission to write to the file regardless
|
|
|
|
* of his group's or other's write permissions
|
|
|
|
*/
|
|
|
|
if (!err && S_ISDIR (filestat.st_mode) &&
|
|
|
|
|
2005-11-17 02:07:44 +08:00
|
|
|
((filestat.st_mode & S_IWUSR) ||
|
2000-02-22 01:15:30 +08:00
|
|
|
|
2005-11-17 02:07:44 +08:00
|
|
|
((filestat.st_mode & S_IWGRP) &&
|
|
|
|
(euid != filestat.st_uid)) ||
|
2000-02-22 01:15:30 +08:00
|
|
|
|
2005-11-17 02:07:44 +08:00
|
|
|
((filestat.st_mode & S_IWOTH) &&
|
|
|
|
(euid != filestat.st_uid) &&
|
|
|
|
(egid != filestat.st_gid))))
|
|
|
|
{
|
|
|
|
return g_strdup (dir);
|
|
|
|
}
|
2000-02-22 01:15:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-12-11 04:43:51 +08:00
|
|
|
|
|
|
|
static gchar *
|
|
|
|
gimp_env_get_dir (const gchar *gimp_env_name,
|
2013-01-28 05:26:29 +08:00
|
|
|
const gchar *compile_time_dir,
|
|
|
|
const gchar *relative_subdir)
|
2001-12-11 04:43:51 +08:00
|
|
|
{
|
2005-02-07 08:49:36 +08:00
|
|
|
const gchar *env = g_getenv (gimp_env_name);
|
2001-12-11 04:43:51 +08:00
|
|
|
|
|
|
|
if (env)
|
|
|
|
{
|
|
|
|
if (! g_path_is_absolute (env))
|
2005-11-17 02:07:44 +08:00
|
|
|
g_error ("%s environment variable should be an absolute path.",
|
2001-12-11 04:43:51 +08:00
|
|
|
gimp_env_name);
|
2004-01-12 05:25:24 +08:00
|
|
|
|
2001-12-11 04:43:51 +08:00
|
|
|
return g_strdup (env);
|
|
|
|
}
|
2013-01-28 05:26:29 +08:00
|
|
|
else if (compile_time_dir)
|
2001-12-11 04:43:51 +08:00
|
|
|
{
|
2013-01-28 05:26:29 +08:00
|
|
|
gchar *retval = g_strdup (compile_time_dir);
|
2005-02-07 08:49:36 +08:00
|
|
|
|
2002-03-30 07:10:18 +08:00
|
|
|
gimp_path_runtime_fix (&retval);
|
2005-02-07 08:49:36 +08:00
|
|
|
|
2002-03-30 07:10:18 +08:00
|
|
|
return retval;
|
2001-12-11 04:43:51 +08:00
|
|
|
}
|
2013-01-28 05:26:29 +08:00
|
|
|
|
|
|
|
return g_build_filename (gimp_installation_directory (),
|
|
|
|
relative_subdir,
|
|
|
|
NULL);
|
2001-12-11 04:43:51 +08:00
|
|
|
}
|