2003-11-23 23:35:27 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
1997-11-25 06:05:25 +08:00
|
|
|
*
|
|
|
|
* Datafiles module copyight (C) 1996 Federico Mena Quintero
|
|
|
|
* federico@nuclecu.unam.mx
|
|
|
|
*
|
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.
|
1997-11-25 06:05:25 +08:00
|
|
|
*
|
2003-11-23 23:35:27 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
1997-11-25 06:05:25 +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.
|
1997-11-25 06:05:25 +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/>.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2000-12-29 23:22:01 +08:00
|
|
|
|
1999-02-21 07:20:54 +08:00
|
|
|
#include "config.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
#include <string.h>
|
2005-02-07 09:10:50 +08:00
|
|
|
|
2013-07-12 21:18:38 +08:00
|
|
|
#include <gio/gio.h>
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
#include "gimpbasetypes.h"
|
2000-12-29 23:22:01 +08:00
|
|
|
|
2001-07-10 03:48:30 +08:00
|
|
|
#include "gimpdatafiles.h"
|
2002-10-23 22:55:07 +08:00
|
|
|
#include "gimpenv.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-14 11:55:56 +08:00
|
|
|
|
2010-06-30 01:13:40 +08:00
|
|
|
/**
|
|
|
|
* SECTION: gimpdatafiles
|
|
|
|
* @title: gimpdatafiles
|
|
|
|
* @short_description: Functions to handle GIMP data files.
|
|
|
|
*
|
|
|
|
* Functions to handle GIMP data files.
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
2007-09-14 23:39:28 +08:00
|
|
|
static inline gboolean is_script (const gchar *filename);
|
removed the gimp_busy boolean, check whether user_installation is needed
2001-07-10 Michael Natterer <mitch@gimp.org>
* app/app_procs.[ch]: removed the gimp_busy boolean, check whether
user_installation is needed here, not in user_install.c, parse
gtkrc an friends only if(!no_interface), create the Gimp object
before parsing gimp's rc files an pas it to the parse functions,
many other cleanups.
* app/appenums.h: added MessageHandlerType and StackTraceMode.
* app/appenv.h: removed MessageHandlerType, declare all global
variables from main.c (no more hidden global stuff please).
* app/errors.[ch]: added the fatal message func here (from main.c),
removed the StackTraceMode enum.
* app/gimprc.[ch]: renamed functions to gimprc_*(), pass a Gimp
pointer to some functions.
* app/gimpunit.c
* app/unitrc.h: ok, this is ugly: renamed all functions to
_gimp_unit_*() and made them public. The unit list is part
of the Gimp object now, so pass a Gimp* to all functions.
* app/libgimp_glue.[ch]: added EEKy wrappers for all gimp_unit_*()
functions which are used by widgets.
* app/main.c: cleaned up the global variables, removed the fatal
message handler, call app_init() directly, not via the
user_install stuff, misc. cleanups.
* app/user_install.[ch]: removed the check if user_installation is
needed (done by app_procs.c now).
* app/core/gimp.[ch]: added the user_unit list and the "busy"
boolean. Moved gimp_[set|unset]_busy() here. Added
gimp_initialize() which is called after unitrc and gimprc are
parsed.
* app/batch.c
* app/colormaps.c
* app/devices.c
* app/disp_callbacks.c
* app/gdisplay_ops.c
* app/gimphelp.c
* app/module_db.c
* app/nav_window.c
* app/plug_in.c
* app/core/gimpcontext.c
* app/core/gimpdatafiles.c
* app/core/gimpimage-convert.c
* app/core/gimpimage-duplicate.c
* app/core/gimpimage.c
* app/core/gimpparasite.c
* app/core/gimpparasitelist.h
* app/gui/file-open-dialog.c
* app/gui/gui.[ch]
* app/gui/info-dialog.c
* app/gui/info-window.c
* app/gui/preferences-dialog.c
* app/gui/session.c
* app/gui/tips-dialog.c
* app/gui/toolbox.c
* app/tools/gimpblendtool.c
* app/tools/gimpbucketfilltool.c
* app/tools/gimpcolorpickertool.c
* app/tools/gimpfuzzyselecttool.c
* app/tools/gimptransformtool.c
* app/tools/tool_manager.c
* app/widgets/gimpcolorpanel.c
* app/widgets/gimpcursor.c
* app/xcf/xcf-load.c
* app/xcf/xcf-save.c
* app/xcf/xcf.c
* tools/pdbgen/Makefile.am
* tools/pdbgen/app.pl
* tools/pdbgen/enums.pl
* tools/pdbgen/pdb/image.pdb
* tools/pdbgen/pdb/message.pdb
* tools/pdbgen/pdb/unit.pdb
* app/pdb/image_cmds.c
* app/pdb/message_cmds.c
* app/pdb/unit_cmds.c: changed accordingly, minor cleanups.
2001-07-11 03:16:16 +08:00
|
|
|
|
libgimp/gimp.def libgimp/gimpui.def libgimp/makefile.{cygwin,msc}
2000-02-15 Tor Lillqvist <tml@iki.fi>
* libgimp/gimp.def
* libgimp/gimpui.def
* libgimp/makefile.{cygwin,msc}
* app/makefile.{cygwin,msc}
* plug-ins/makefile.{cygwin,msc}: Updates.
* app/datafiles.c (is_script): New Win32-only function, which
tests if a file's extension matches one of the extensions in the
PATHEXT environment variable (which the cmd.exe command
interpreter also uses). This is to avoid starting applications
associated with any random data file the user might have dropped
in the plug-ins folder, while still supporting plug-ins written in
scripting languages.
* app/gimpparasite.c (gimp_parasiterc_save): (Win32:) Cannot
rename to an existing file.
* plug-ins/Lighting/lighting_image.c
* plug-ins/Lighting/lighting_share.c
* plug-ins/MapObject/mapobject_preview.c
* plug-ins/MapObject/mapobject_shade.c: Use G_PI.
* plug-ins/common/gz.c: #ifdef G_OS_WIN32 was used before its
potential definition via glib.h.
* plug-ins/common/jpeg.c: Also recognize Exif files, which are
typically produced by digital cameras. The usually have a .jpg
file name extension, and would thus already match this plug-in,
but add the magic string just in case. They are loaded just fine
by libjpeg even if they don't have the JFIF signature.
* plug-ins/common/tiff.c: Set TIFF warning and error handler, so
we get to pass libtiff's messages through the normal channels.
2000-02-15 06:44:06 +08:00
|
|
|
|
2007-09-14 23:39:28 +08:00
|
|
|
/* public functions */
|
libgimp/gimp.def libgimp/gimpui.def libgimp/makefile.{cygwin,msc}
2000-02-15 Tor Lillqvist <tml@iki.fi>
* libgimp/gimp.def
* libgimp/gimpui.def
* libgimp/makefile.{cygwin,msc}
* app/makefile.{cygwin,msc}
* plug-ins/makefile.{cygwin,msc}: Updates.
* app/datafiles.c (is_script): New Win32-only function, which
tests if a file's extension matches one of the extensions in the
PATHEXT environment variable (which the cmd.exe command
interpreter also uses). This is to avoid starting applications
associated with any random data file the user might have dropped
in the plug-ins folder, while still supporting plug-ins written in
scripting languages.
* app/gimpparasite.c (gimp_parasiterc_save): (Win32:) Cannot
rename to an existing file.
* plug-ins/Lighting/lighting_image.c
* plug-ins/Lighting/lighting_share.c
* plug-ins/MapObject/mapobject_preview.c
* plug-ins/MapObject/mapobject_shade.c: Use G_PI.
* plug-ins/common/gz.c: #ifdef G_OS_WIN32 was used before its
potential definition via glib.h.
* plug-ins/common/jpeg.c: Also recognize Exif files, which are
typically produced by digital cameras. The usually have a .jpg
file name extension, and would thus already match this plug-in,
but add the magic string just in case. They are loaded just fine
by libjpeg even if they don't have the JFIF signature.
* plug-ins/common/tiff.c: Set TIFF warning and error handler, so
we get to pass libtiff's messages through the normal channels.
2000-02-15 06:44:06 +08:00
|
|
|
|
2001-02-12 00:14:25 +08:00
|
|
|
gboolean
|
2001-05-10 06:34:59 +08:00
|
|
|
gimp_datafiles_check_extension (const gchar *filename,
|
2006-04-12 18:53:28 +08:00
|
|
|
const gchar *extension)
|
2001-02-12 00:14:25 +08:00
|
|
|
{
|
|
|
|
gint name_len;
|
|
|
|
gint ext_len;
|
|
|
|
|
|
|
|
g_return_val_if_fail (filename != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (extension != NULL, FALSE);
|
|
|
|
|
|
|
|
name_len = strlen (filename);
|
|
|
|
ext_len = strlen (extension);
|
|
|
|
|
|
|
|
if (! (name_len && ext_len && (name_len > ext_len)))
|
|
|
|
return FALSE;
|
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
return (g_ascii_strcasecmp (&filename[name_len - ext_len], extension) == 0);
|
2001-02-12 00:14:25 +08:00
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
void
|
2001-05-10 06:34:59 +08:00
|
|
|
gimp_datafiles_read_directories (const gchar *path_str,
|
2006-04-12 18:53:28 +08:00
|
|
|
GFileTest flags,
|
|
|
|
GimpDatafileLoaderFunc loader_func,
|
|
|
|
gpointer user_data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2007-08-28 20:31:29 +08:00
|
|
|
gchar *local_path;
|
|
|
|
GList *path;
|
|
|
|
GList *list;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-02-12 00:14:25 +08:00
|
|
|
g_return_if_fail (path_str != NULL);
|
|
|
|
g_return_if_fail (loader_func != NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
local_path = g_strdup (path_str);
|
2000-02-22 01:15:30 +08:00
|
|
|
|
2012-09-27 05:29:51 +08:00
|
|
|
path = gimp_path_parse (local_path, 256, TRUE, NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-02-22 01:15:30 +08:00
|
|
|
for (list = path; list; list = g_list_next (list))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2005-02-07 08:49:36 +08:00
|
|
|
const gchar *dirname = list->data;
|
2007-08-28 20:31:29 +08:00
|
|
|
GDir *dir;
|
2005-02-07 08:49:36 +08:00
|
|
|
|
|
|
|
dir = g_dir_open (dirname, 0, NULL);
|
2000-02-22 01:15:30 +08:00
|
|
|
|
2003-02-06 06:15:39 +08:00
|
|
|
if (dir)
|
2006-04-12 18:53:28 +08:00
|
|
|
{
|
2007-08-28 20:31:29 +08:00
|
|
|
const gchar *dir_ent;
|
|
|
|
|
2006-04-12 18:53:28 +08:00
|
|
|
while ((dir_ent = g_dir_read_name (dir)))
|
|
|
|
{
|
2013-07-12 21:18:38 +08:00
|
|
|
gchar *filename;
|
|
|
|
GFile *file;
|
|
|
|
GFileInfo *info;
|
2007-09-14 23:39:28 +08:00
|
|
|
|
2006-04-12 18:53:28 +08:00
|
|
|
filename = g_build_filename (dirname, dir_ent, NULL);
|
2013-07-12 21:18:38 +08:00
|
|
|
file = g_file_new_for_path (filename);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2013-07-12 21:18:38 +08:00
|
|
|
info = g_file_query_info (file,
|
2015-12-07 08:07:30 +08:00
|
|
|
G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN ","
|
2013-07-12 21:18:38 +08:00
|
|
|
G_FILE_ATTRIBUTE_STANDARD_TYPE ","
|
|
|
|
G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE ","
|
|
|
|
"time::*",
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
if (info)
|
2007-09-14 23:39:28 +08:00
|
|
|
{
|
|
|
|
GimpDatafileData file_data;
|
2013-07-12 21:18:38 +08:00
|
|
|
GFileType file_type;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2007-09-14 23:39:28 +08:00
|
|
|
file_data.filename = filename;
|
|
|
|
file_data.dirname = dirname;
|
|
|
|
file_data.basename = dir_ent;
|
2013-07-12 21:18:38 +08:00
|
|
|
|
|
|
|
file_data.atime =
|
|
|
|
g_file_info_get_attribute_uint64 (info,
|
|
|
|
G_FILE_ATTRIBUTE_TIME_ACCESS);
|
|
|
|
|
|
|
|
file_data.mtime =
|
|
|
|
g_file_info_get_attribute_uint64 (info,
|
|
|
|
G_FILE_ATTRIBUTE_TIME_MODIFIED);
|
|
|
|
|
|
|
|
file_data.ctime =
|
|
|
|
g_file_info_get_attribute_uint64 (info,
|
|
|
|
G_FILE_ATTRIBUTE_TIME_CREATED);
|
|
|
|
|
2015-12-07 08:07:30 +08:00
|
|
|
file_type = g_file_info_get_file_type (info);
|
2002-10-23 22:55:07 +08:00
|
|
|
|
2015-12-07 08:07:30 +08:00
|
|
|
if (g_file_info_get_is_hidden (info))
|
|
|
|
{
|
|
|
|
/* do nothing */
|
|
|
|
}
|
|
|
|
else if (flags & G_FILE_TEST_EXISTS)
|
2002-10-23 22:55:07 +08:00
|
|
|
{
|
2003-07-03 01:11:00 +08:00
|
|
|
(* loader_func) (&file_data, user_data);
|
2002-10-23 22:55:07 +08:00
|
|
|
}
|
|
|
|
else if ((flags & G_FILE_TEST_IS_REGULAR) &&
|
2013-07-12 21:18:38 +08:00
|
|
|
(file_type == G_FILE_TYPE_REGULAR))
|
2002-10-23 22:55:07 +08:00
|
|
|
{
|
2003-07-03 01:11:00 +08:00
|
|
|
(* loader_func) (&file_data, user_data);
|
2002-10-23 22:55:07 +08:00
|
|
|
}
|
2006-04-12 18:53:28 +08:00
|
|
|
else if ((flags & G_FILE_TEST_IS_DIR) &&
|
2013-07-12 21:18:38 +08:00
|
|
|
(file_type == G_FILE_TYPE_DIRECTORY))
|
2006-04-12 18:53:28 +08:00
|
|
|
{
|
|
|
|
(* loader_func) (&file_data, user_data);
|
|
|
|
}
|
|
|
|
else if ((flags & G_FILE_TEST_IS_SYMLINK) &&
|
2013-07-12 21:18:38 +08:00
|
|
|
(file_type == G_FILE_TYPE_SYMBOLIC_LINK))
|
2006-04-12 18:53:28 +08:00
|
|
|
{
|
|
|
|
(* loader_func) (&file_data, user_data);
|
|
|
|
}
|
|
|
|
else if ((flags & G_FILE_TEST_IS_EXECUTABLE) &&
|
2013-07-12 21:18:38 +08:00
|
|
|
(g_file_info_get_attribute_boolean (info,
|
|
|
|
G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE) ||
|
|
|
|
((file_type == G_FILE_TYPE_REGULAR) &&
|
2002-10-23 22:55:07 +08:00
|
|
|
is_script (filename))))
|
2006-04-12 18:53:28 +08:00
|
|
|
{
|
|
|
|
(* loader_func) (&file_data, user_data);
|
|
|
|
}
|
2013-07-12 21:18:38 +08:00
|
|
|
|
|
|
|
g_object_unref (info);
|
2006-04-12 18:53:28 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2013-07-12 21:18:38 +08:00
|
|
|
g_object_unref (file);
|
2006-04-12 18:53:28 +08:00
|
|
|
g_free (filename);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-04-12 18:53:28 +08:00
|
|
|
g_dir_close (dir);
|
|
|
|
}
|
2000-02-22 01:15:30 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-02-22 01:15:30 +08:00
|
|
|
gimp_path_free (path);
|
2000-02-24 09:52:31 +08:00
|
|
|
g_free (local_path);
|
2000-02-22 01:15:30 +08:00
|
|
|
}
|
2007-09-14 23:39:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static inline gboolean
|
|
|
|
is_script (const gchar *filename)
|
|
|
|
{
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
/* On Windows there is no concept like the Unix executable flag.
|
|
|
|
* There is a weak emulation provided by the MS C Runtime using file
|
|
|
|
* extensions (com, exe, cmd, bat). This needs to be extended to treat
|
|
|
|
* scripts (Python, Perl, ...) as executables, too. We use the PATHEXT
|
|
|
|
* variable, which is also used by cmd.exe.
|
|
|
|
*/
|
|
|
|
static gchar **exts = NULL;
|
|
|
|
|
|
|
|
const gchar *ext = strrchr (filename, '.');
|
|
|
|
gchar *pathext;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
if (exts == NULL)
|
|
|
|
{
|
2018-01-27 05:14:11 +08:00
|
|
|
pathext = (gchar *) g_getenv ("PATHEXT");
|
2007-09-14 23:39:28 +08:00
|
|
|
if (pathext != NULL)
|
|
|
|
{
|
|
|
|
exts = g_strsplit (pathext, G_SEARCHPATH_SEPARATOR_S, 100);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
exts = g_new (gchar *, 1);
|
|
|
|
exts[0] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (exts[i] != NULL)
|
|
|
|
{
|
|
|
|
if (g_ascii_strcasecmp (ext, exts[i]) == 0)
|
|
|
|
return TRUE;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
#endif /* G_OS_WIN32 */
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|