Made xdgmime work on win32
This commit is contained in:
parent
6f88ef4845
commit
2783146fe2
@ -7,6 +7,9 @@ AC_DEFUN_ONCE([MOO_AC_FUNCS],[
|
||||
AC_CHECK_HEADERS(execinfo.h)
|
||||
AC_CHECK_FUNCS(backtrace)
|
||||
|
||||
# for xdgmime
|
||||
AC_CHECK_HEADERS(fnmatch.h netinet/in.h)
|
||||
|
||||
# for pcre
|
||||
AC_CHECK_FUNCS(memmove bcopy strerror)
|
||||
|
||||
|
@ -3,11 +3,7 @@
|
||||
# does nothing, just defines MOO_USE_XDGMIME on unix
|
||||
#
|
||||
AC_DEFUN_ONCE([MOO_AC_XDGMIME],[
|
||||
AC_REQUIRE([MOO_AC_CHECK_OS])
|
||||
MOO_USE_XDGMIME=no
|
||||
if test x$MOO_OS_UNIX = "xyes"; then
|
||||
MOO_USE_XDGMIME=yes
|
||||
MOO_USE_XDGMIME=true
|
||||
AC_DEFINE(MOO_USE_XDGMIME, 1, [use xdgmime])
|
||||
fi
|
||||
AM_CONDITIONAL(MOO_USE_XDGMIME, test x$MOO_OS_UNIX = "xyes")
|
||||
AM_CONDITIONAL(MOO_USE_XDGMIME, true)
|
||||
])
|
||||
|
4
makewin
4
makewin
@ -13,7 +13,7 @@ dir = os.getcwd()
|
||||
builddir = dir
|
||||
thisscript = os.path.abspath(sys.argv[0])
|
||||
moo_windir = "/usr/local/win/medit"
|
||||
strip = "i586-mingw32msvc-strip"
|
||||
strip = "i586-mingw32msvc-strip --strip-unneeded"
|
||||
do_strip = True
|
||||
do_zip = False
|
||||
pida = False
|
||||
@ -119,7 +119,7 @@ def copy_files():
|
||||
|
||||
if do_strip:
|
||||
if not bin_only and not no_python:
|
||||
if not pida:
|
||||
if pida:
|
||||
do_cmd("%s %s/lib/site-packages/*.dll" % (strip, moo_windir))
|
||||
else:
|
||||
do_cmd("%s %s/lib/moo/plugins/*/*.dll" % (strip, moo_windir))
|
||||
|
@ -88,10 +88,8 @@ guint8 _moo_file_get_icon_type (MooFile *file,
|
||||
const char *dirname);
|
||||
void _moo_file_stat (MooFile *file,
|
||||
const char *dirname);
|
||||
#ifndef __WIN32__
|
||||
void _moo_file_find_mime_type (MooFile *file,
|
||||
const char *path);
|
||||
#endif
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "mooutils/mooutils-fs.h"
|
||||
#include "mooutils/mooutils-misc.h"
|
||||
#include "mooutils/moomarshals.h"
|
||||
#include "mooutils/xdgmime/xdgmime.h"
|
||||
#include <glib/gstdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
@ -45,10 +46,6 @@
|
||||
#include <gtk/gtkiconfactory.h>
|
||||
#include <gtk/gtkstock.h>
|
||||
|
||||
#ifndef __WIN32__
|
||||
#include "mooutils/xdgmime/xdgmime.h"
|
||||
#endif
|
||||
|
||||
#ifdef MOO_US_XDGMIME
|
||||
#define MIME_TYPE_UNKNOWN xdg_mime_type_unknown
|
||||
#else
|
||||
@ -83,7 +80,6 @@ static GdkPixbuf *render_icon_for_path (const char *path,
|
||||
#define MAKE_PATH(dirname,file) g_build_filename (dirname, file->name, NULL)
|
||||
|
||||
|
||||
#ifndef __WIN32__
|
||||
void
|
||||
_moo_file_find_mime_type (MooFile *file,
|
||||
const char *path)
|
||||
@ -103,7 +99,6 @@ _moo_file_find_mime_type (MooFile *file,
|
||||
|
||||
file->flags |= MOO_FILE_HAS_MIME_TYPE;
|
||||
}
|
||||
#endif /* !__WIN32__ */
|
||||
|
||||
|
||||
/********************************************************************/
|
||||
|
@ -35,10 +35,6 @@
|
||||
#include <gtk/gtkiconfactory.h>
|
||||
#include <gtk/gtkstock.h>
|
||||
|
||||
#ifndef __WIN32__
|
||||
#include "mooutils/xdgmime/xdgmime.h"
|
||||
#endif
|
||||
|
||||
#define NORMAL_PRIORITY G_PRIORITY_DEFAULT_IDLE
|
||||
#define NORMAL_TIMEOUT 0.04
|
||||
#define BACKGROUND_PRIORITY G_PRIORITY_LOW
|
||||
@ -1031,7 +1027,6 @@ _moo_folder_get_file_info (MooFolder *folder,
|
||||
|
||||
_moo_file_stat (file, folder->impl->path);
|
||||
|
||||
#ifndef __WIN32__
|
||||
if (file->info & MOO_FILE_INFO_EXISTS &&
|
||||
!(file->flags & MOO_FILE_HAS_MIME_TYPE))
|
||||
{
|
||||
@ -1043,7 +1038,6 @@ _moo_folder_get_file_info (MooFolder *folder,
|
||||
file->icon = _moo_file_get_icon_type (file, folder->impl->path);
|
||||
g_free (path);
|
||||
}
|
||||
#endif
|
||||
|
||||
array = g_ptr_array_new ();
|
||||
|
||||
|
@ -17,4 +17,6 @@ mooxdgmime_sources = \
|
||||
noinst_LTLIBRARIES = libxdgmime.la
|
||||
libxdgmime_la_SOURCES = $(mooxdgmime_sources)
|
||||
AM_CFLAGS = \
|
||||
$(MOO_CFLAGS)
|
||||
$(MOO_CFLAGS) \
|
||||
$(MOO_DEBUG_CFLAGS) \
|
||||
-Wno-sign-compare
|
||||
|
@ -43,6 +43,12 @@
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef __WIN32__
|
||||
#include <mooutils/mooutils-win32.h>
|
||||
#include <mooutils/mooutils-misc.h>
|
||||
#endif
|
||||
|
||||
typedef struct XdgDirTimeList XdgDirTimeList;
|
||||
typedef struct XdgCallbackList XdgCallbackList;
|
||||
@ -148,9 +154,9 @@ xdg_mime_init_from_directory (const char *directory)
|
||||
|
||||
assert (directory != NULL);
|
||||
|
||||
#ifdef HAVE_MMAP
|
||||
file_name = malloc (strlen (directory) + strlen ("/mime/mime.cache") + 1);
|
||||
strcpy (file_name, directory); strcat (file_name, "/mime/mime.cache");
|
||||
#ifdef XDG_MIME_USE_CACHE
|
||||
file_name = g_build_filename (directory, "mime", "mime.cache", NULL);
|
||||
errno = 0;
|
||||
if (stat (file_name, &st) == 0)
|
||||
{
|
||||
XdgMimeCache *cache = _xdg_mime_cache_new_from_file (file_name);
|
||||
@ -171,11 +177,12 @@ xdg_mime_init_from_directory (const char *directory)
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
free (file_name);
|
||||
#endif /* HAVE_MMAP */
|
||||
g_free (file_name);
|
||||
#endif /* XDG_MIME_USE_CACHE */
|
||||
|
||||
file_name = malloc (strlen (directory) + strlen ("/mime/globs") + 1);
|
||||
strcpy (file_name, directory); strcat (file_name, "/mime/globs");
|
||||
errno = 0;
|
||||
if (stat (file_name, &st) == 0)
|
||||
{
|
||||
_xdg_mime_glob_read_from_file (global_hash, file_name);
|
||||
@ -193,6 +200,7 @@ xdg_mime_init_from_directory (const char *directory)
|
||||
|
||||
file_name = malloc (strlen (directory) + strlen ("/mime/magic") + 1);
|
||||
strcpy (file_name, directory); strcat (file_name, "/mime/magic");
|
||||
errno = 0;
|
||||
if (stat (file_name, &st) == 0)
|
||||
{
|
||||
_xdg_mime_magic_read_from_file (global_magic, file_name);
|
||||
@ -221,6 +229,26 @@ xdg_mime_init_from_directory (const char *directory)
|
||||
return FALSE; /* Keep processing */
|
||||
}
|
||||
|
||||
#ifdef __WIN32__
|
||||
/* Runs a command on all the directories in the search path */
|
||||
static void
|
||||
xdg_run_command_on_dirs (XdgDirectoryFunc func,
|
||||
void *user_data)
|
||||
{
|
||||
char **dirs, **p;
|
||||
|
||||
dirs = moo_get_data_dirs (MOO_DATA_SHARE, NULL);
|
||||
|
||||
for (p = dirs; p && *p; ++p)
|
||||
{
|
||||
if (func (*p, user_data))
|
||||
goto out;
|
||||
}
|
||||
|
||||
out:
|
||||
g_strfreev (dirs);
|
||||
}
|
||||
#else
|
||||
/* Runs a command on all the directories in the search path */
|
||||
static void
|
||||
xdg_run_command_on_dirs (XdgDirectoryFunc func,
|
||||
@ -296,6 +324,7 @@ xdg_run_command_on_dirs (XdgDirectoryFunc func,
|
||||
ptr = end_ptr;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Checks file_path to make sure it has the same mtime as last time it was
|
||||
* checked. If it has a different mtime, or if the file doesn't exist, it
|
||||
@ -310,6 +339,7 @@ xdg_check_file (const char *file_path,
|
||||
struct stat st;
|
||||
|
||||
/* If the file exists */
|
||||
errno = 0;
|
||||
if (stat (file_path, &st) == 0)
|
||||
{
|
||||
XdgDirTimeList *list;
|
||||
@ -348,7 +378,7 @@ xdg_check_dir (const char *directory,
|
||||
|
||||
assert (directory != NULL);
|
||||
|
||||
#ifdef HAVE_MMAP
|
||||
#ifdef XDG_MIME_USE_CACHE
|
||||
/* Check the mime.cache file */
|
||||
file_name = malloc (strlen (directory) + strlen ("/mime/mime.cache") + 1);
|
||||
strcpy (file_name, directory); strcat (file_name, "/mime/mime.cache");
|
||||
@ -361,7 +391,7 @@ xdg_check_dir (const char *directory,
|
||||
}
|
||||
else if (exists)
|
||||
return FALSE;
|
||||
#endif
|
||||
#endif /* XDG_MIME_USE_CACHE */
|
||||
|
||||
/* Check the globs file */
|
||||
file_name = malloc (strlen (directory) + strlen ("/mime/globs") + 1);
|
||||
@ -515,6 +545,8 @@ xdg_mime_get_mime_type_for_file (const char *file_name,
|
||||
|
||||
if (!statbuf)
|
||||
{
|
||||
errno = 0;
|
||||
|
||||
if (stat (file_name, &buf) != 0)
|
||||
return XDG_MIME_TYPE_UNKNOWN;
|
||||
|
||||
|
@ -35,7 +35,6 @@
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <fnmatch.h>
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE (0)
|
||||
|
@ -34,10 +34,20 @@
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <fnmatch.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef HAVE_FNMATCH_H
|
||||
#include <fnmatch.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h> /* for ntohl/ntohs */
|
||||
#endif
|
||||
#ifdef __WIN32__
|
||||
#include <winsock2.h>
|
||||
#include <mooutils/mooutils-win32.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_MMAP
|
||||
#include <sys/mman.h>
|
||||
@ -79,6 +89,10 @@ struct _XdgMimeCache
|
||||
|
||||
size_t size;
|
||||
char *buffer;
|
||||
|
||||
#ifndef HAVE_MMAP
|
||||
GMappedFile *mf;
|
||||
#endif
|
||||
};
|
||||
|
||||
#define GET_UINT16(cache,offset) (ntohs(*(xdg_uint16_t*)((cache) + (offset))))
|
||||
@ -100,6 +114,8 @@ _xdg_mime_cache_unref (XdgMimeCache *cache)
|
||||
{
|
||||
#ifdef HAVE_MMAP
|
||||
munmap (cache->buffer, cache->size);
|
||||
#else
|
||||
g_mapped_file_free (cache->mf);
|
||||
#endif
|
||||
g_free (cache->filename);
|
||||
free (cache);
|
||||
@ -149,6 +165,36 @@ _xdg_mime_cache_new_from_file (const char *file_name)
|
||||
if (fd != -1)
|
||||
close (fd);
|
||||
|
||||
#else
|
||||
|
||||
GMappedFile *mf;
|
||||
char *buffer;
|
||||
size_t length;
|
||||
|
||||
mf = g_mapped_file_new (file_name, FALSE, NULL);
|
||||
|
||||
if (!mf)
|
||||
return NULL;
|
||||
|
||||
buffer = g_mapped_file_get_contents (mf);
|
||||
length = g_mapped_file_get_length (mf);
|
||||
|
||||
/* Verify version */
|
||||
if (length < 2 ||
|
||||
GET_UINT16 (buffer, 0) != MAJOR_VERSION ||
|
||||
GET_UINT16 (buffer, 2) != MINOR_VERSION)
|
||||
{
|
||||
g_mapped_file_free (mf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cache = (XdgMimeCache *) malloc (sizeof (XdgMimeCache));
|
||||
cache->ref_count = 1;
|
||||
cache->buffer = buffer;
|
||||
cache->size = length;
|
||||
cache->filename = g_strdup (file_name);
|
||||
cache->mf = mf;
|
||||
|
||||
#endif /* HAVE_MMAP */
|
||||
|
||||
return cache;
|
||||
@ -701,6 +747,8 @@ _xdg_mime_cache_get_mime_type_for_file (const char *file_name,
|
||||
|
||||
if (!statbuf)
|
||||
{
|
||||
errno = 0;
|
||||
|
||||
if (stat (file_name, &buf) != 0)
|
||||
return XDG_MIME_TYPE_UNKNOWN;
|
||||
|
||||
|
@ -29,6 +29,8 @@
|
||||
|
||||
#include "xdgmime.h"
|
||||
|
||||
#define XDG_MIME_USE_CACHE 1
|
||||
|
||||
typedef struct _XdgMimeCache XdgMimeCache;
|
||||
|
||||
#ifdef XDG_PREFIX
|
||||
|
@ -35,7 +35,7 @@
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <fnmatch.h>
|
||||
#include <mooutils/mooutils-win32.h>
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE (0)
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <mooutils/mooutils-win32.h>
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE (0)
|
||||
@ -480,24 +481,6 @@ _xdg_mime_magic_parse_magic_line (FILE *magic_file,
|
||||
_xdg_mime_magic_matchlet_free (matchlet);
|
||||
return XDG_MIME_MAGIC_ERROR;
|
||||
}
|
||||
/* FIXME: need to get this defined in a <config.h> style file */
|
||||
#if LITTLE_ENDIAN
|
||||
for (i = 0; i < matchlet->value_length; i = i + matchlet->word_size)
|
||||
{
|
||||
if (matchlet->word_size == 2)
|
||||
*((xdg_uint16_t *) matchlet->value + i) = SWAP_BE16_TO_LE16 (*((xdg_uint16_t *) (matchlet->value + i)));
|
||||
else if (matchlet->word_size == 4)
|
||||
*((xdg_uint32_t *) matchlet->value + i) = SWAP_BE32_TO_LE32 (*((xdg_uint32_t *) (matchlet->value + i)));
|
||||
if (matchlet->mask)
|
||||
{
|
||||
if (matchlet->word_size == 2)
|
||||
*((xdg_uint16_t *) matchlet->mask + i) = SWAP_BE16_TO_LE16 (*((xdg_uint16_t *) (matchlet->mask + i)));
|
||||
else if (matchlet->word_size == 4)
|
||||
*((xdg_uint32_t *) matchlet->mask + i) = SWAP_BE32_TO_LE32 (*((xdg_uint32_t *) (matchlet->mask + i)));
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
matchlet->next = match->matchlet;
|
||||
|
@ -35,7 +35,6 @@
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <fnmatch.h>
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE (0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user