Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:hiberis:mingw:win32
mingw32-glib2
0001-Add-data-based-content-type-guessing-for-w...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0001-Add-data-based-content-type-guessing-for-win32.patch of Package mingw32-glib2
From 77384085712dbf6f0addcbdad9390810c55c7f14 Mon Sep 17 00:00:00 2001 From: Hib Eris <hib@hiberis.nl> Date: Tue, 30 Oct 2012 08:18:31 +0100 Subject: [PATCH] Add data based content type guessing for win32 http://bugzilla.gnome.org/show_bug.cgi?id=664043 --- gio/gcontenttype-win32.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/gio/gcontenttype-win32.c b/gio/gcontenttype-win32.c index e7e9785..0d77ddf 100644 --- a/gio/gcontenttype-win32.c +++ b/gio/gcontenttype-win32.c @@ -33,6 +33,52 @@ #include "glibintl.h" #include <windows.h> +#include <shlwapi.h> + +static HMODULE +_g_win32_load_system_library_W (LPCWSTR library) +{ + WCHAR path[MAX_PATH]; + UINT l; + + l = GetSystemDirectoryW (path, MAX_PATH); + if (G_UNLIKELY (l == 0 || l >= MAX_PATH)) + return NULL; + + if (G_UNLIKELY (!PathAppendW (path, library))) + return NULL; + + return LoadLibraryW (path); +} + +typedef HRESULT (WINAPI *t_FindMimeFromData) (LPBC pBC, + LPCWSTR pwzUrl, + LPVOID pBuffer, + DWORD cbSize, + LPCWSTR pwzMimeProposed, + DWORD dwMimeFlags, + LPWSTR *ppwzMimeOut, + DWORD dwReserved); + +static gpointer +find_FindMimeFromData (gpointer unused) +{ + HMODULE urlmon = _g_win32_load_system_library_W (L"urlmon.dll"); + if (!urlmon) + return NULL; + + return (gpointer) GetProcAddress (urlmon, "FindMimeFromData"); +} + +static t_FindMimeFromData +get_FindMimeFromData (void) +{ + static GOnce my_once = G_ONCE_INIT; + + g_once (&my_once, find_FindMimeFromData, NULL); + + return (t_FindMimeFromData) my_once.retval; +} static char * get_registry_classes_key (const char *subdir, @@ -340,6 +386,48 @@ g_content_type_guess (const gchar *filename, if (type) return type; + if (data) + { + t_FindMimeFromData p_FindMimeFromData = get_FindMimeFromData (); + + if (p_FindMimeFromData) + { + DWORD cbSize; + LPVOID pBuffer; + HRESULT hr; + LPWSTR pwzMimeOut; + + cbSize = data_size < 256 ? data_size : 256; + pBuffer = (LPVOID) g_malloc (cbSize); + memcpy (pBuffer, data, cbSize); + hr = (p_FindMimeFromData)( + NULL, /* LPBC pBC, */ + NULL, /* LPCWSTR pwzUrl, */ + pBuffer, /* LPVOID pBuffer, */ + cbSize, /* DWORD cbSize, */ + NULL, /* LPCWSTR pwzMimeProposed, */ + FMFD_DEFAULT, /* DWORD dwMimeFlags, */ + &pwzMimeOut, /* LPWSTR *ppwzMimeOut, */ + 0 /* DWORD dwReserved */ + ); + g_free (pBuffer); + + if (hr == S_OK) + { + gchar *mime_type; + + mime_type = g_utf16_to_utf8 (pwzMimeOut, -1, NULL, NULL, NULL); + type = g_content_type_from_mime_type (mime_type); + + g_free (mime_type); + CoTaskMemFree(pwzMimeOut); + + if (type) + return type; + } + } + } + if (data && looks_like_text (data, data_size)) return g_strdup (".txt"); -- 1.7.10.4
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor