1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
/* dllmain.c: DLL entry point for libgnomevfs on Win32
* copyright (C) 2005 Novell, Inc
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <windows.h>
#include <string.h>
#include <mbstring.h>
#include <glib.h>
const char *_gnome_vfs_datadir;
const char *_gnome_vfs_libdir;
const char *_gnome_vfs_prefix;
const char *_gnome_vfs_localedir;
const char *_gnome_vfs_sysconfdir;
BOOL WINAPI DllMain (HINSTANCE hinstDLL,
DWORD fdwReason,
LPVOID lpvReserved);
static char *
_gnome_vfs_replace_prefix (const char *configure_time_path)
{
if (strncmp (configure_time_path, GNOME_VFS_PREFIX "/", strlen (GNOME_VFS_PREFIX) + 1) == 0)
{
return g_strconcat (_gnome_vfs_prefix,
configure_time_path + strlen (GNOME_VFS_PREFIX),
NULL);
}
else
return g_strdup (configure_time_path);
}
/* DllMain function needed to fetch the DLL name and deduce the
* installation directory from that, and then form the pathnames for
* various directories relative to the installation directory.
*/
BOOL WINAPI
DllMain (HINSTANCE hinstDLL,
DWORD fdwReason,
LPVOID lpvReserved)
{
wchar_t wcbfr[1000];
char cpbfr[1000];
char *dll_name = NULL;
switch (fdwReason) {
case DLL_PROCESS_ATTACH:
/* GLib 2.6 uses UTF-8 file names */
if (GetVersion () < 0x80000000) {
/* NT-based Windows has wide char API */
if (GetModuleFileNameW ((HMODULE) hinstDLL,
wcbfr, G_N_ELEMENTS (wcbfr)))
dll_name = g_utf16_to_utf8 (wcbfr, -1,
NULL, NULL, NULL);
} else {
/* Win9x, yecch */
if (GetModuleFileNameA ((HMODULE) hinstDLL,
cpbfr, G_N_ELEMENTS (cpbfr)))
dll_name = g_locale_to_utf8 (cpbfr, -1,
NULL, NULL, NULL);
}
if (dll_name) {
gchar *p = strrchr (dll_name, '\\');
if (p != NULL)
*p = '\0';
p = strrchr (dll_name, '\\');
if (p && (g_ascii_strcasecmp (p + 1, "bin") == 0))
*p = '\0';
_gnome_vfs_prefix = dll_name;
} else {
_gnome_vfs_prefix = g_strdup ("");
}
_gnome_vfs_datadir = _gnome_vfs_replace_prefix (GNOME_VFS_DATADIR);
_gnome_vfs_libdir = _gnome_vfs_replace_prefix (GNOME_VFS_LIBDIR);
_gnome_vfs_localedir = _gnome_vfs_replace_prefix (GNOME_VFS_LOCALEDIR);
_gnome_vfs_sysconfdir = _gnome_vfs_replace_prefix (GNOME_VFS_SYSCONFDIR);
break;
}
return TRUE;
}
|