From 7ffe2d8843bee42e9a26103c1e7d7019caba1f78 Mon Sep 17 00:00:00 2001 From: sof Date: Fri, 15 Apr 2005 21:51:28 +0000 Subject: [PATCH] [project @ 2005-04-15 21:51:28 by sof] back out Directory.hs:1.14 and directory.c:1.7; neither meant for HEAD --- ghc/lib/compat/Compat/Directory.hs | 2 +- ghc/lib/compat/cbits/directory.c | 146 ++++++++++++++++++++++++------------ 2 files changed, 97 insertions(+), 51 deletions(-) diff --git a/ghc/lib/compat/Compat/Directory.hs b/ghc/lib/compat/Compat/Directory.hs index bce1da6..e6e4cd4 100644 --- a/ghc/lib/compat/Compat/Directory.hs +++ b/ghc/lib/compat/Compat/Directory.hs @@ -55,7 +55,7 @@ getAppUserDataDirectory appName = do #endif #if __GLASGOW_HASKELL__ && defined(mingw32_HOST_OS) -foreign import stdcall unsafe "SHGetFolderPathA" +foreign import ccall unsafe "directory.h __hscore_getFolderPath" c_SHGetFolderPath :: Ptr () -> CInt -> Ptr () diff --git a/ghc/lib/compat/cbits/directory.c b/ghc/lib/compat/cbits/directory.c index af09655..79d6cd4 100644 --- a/ghc/lib/compat/cbits/directory.c +++ b/ghc/lib/compat/cbits/directory.c @@ -1,50 +1,96 @@ -#include "../../../includes/ghcconfig.h" - -#include "HsFFI.h" - -#if HAVE_LIMITS_H -#include -#endif -#if HAVE_WINDOWS_H -#include -#endif - -#define INLINE /* nothing */ - -/* - * Following code copied from libraries/base/includes/HsBase.h - */ - -#ifdef PATH_MAX -/* A size that will contain many path names, but not necessarily all - * (PATH_MAX is not defined on systems with unlimited path length, - * e.g. the Hurd). - */ -INLINE HsInt __compat_long_path_size() { return PATH_MAX; } -#else -INLINE HsInt __compat_long_path_size() { return 4096; } -#endif - -#if defined(mingw32_HOST_OS) - -/* Make sure we've got the reqd CSIDL_ constants in scope; - * w32api header files are lagging a bit in defining the full set. - */ -#if !defined(CSIDL_APPDATA) -#define CSIDL_APPDATA 0x001a -#endif -#if !defined(CSIDL_PERSONAL) -#define CSIDL_PERSONAL 0x0005 -#endif -#if !defined(CSIDL_PROFILE) -#define CSIDL_PROFILE 0x0028 -#endif -#if !defined(CSIDL_WINDOWS) -#define CSIDL_WINDOWS 0x0024 -#endif - -INLINE int __hscore_CSIDL_PROFILE() { return CSIDL_PROFILE; } -INLINE int __hscore_CSIDL_APPDATA() { return CSIDL_APPDATA; } -INLINE int __hscore_CSIDL_WINDOWS() { return CSIDL_WINDOWS; } -INLINE int __hscore_CSIDL_PERSONAL() { return CSIDL_PERSONAL; } -#endif +#include "HsFFI.h" + +#include "../../../includes/ghcconfig.h" + +#if HAVE_LIMITS_H +#include +#endif +#if HAVE_WINDOWS_H +#include +#endif +#include "directory.h" + +#define INLINE /* nothing */ + +/* + * Following code copied from libraries/base/includes/HsBase.h + */ + +#ifdef PATH_MAX +/* A size that will contain many path names, but not necessarily all + * (PATH_MAX is not defined on systems with unlimited path length, + * e.g. the Hurd). + */ +INLINE HsInt __compat_long_path_size() { return PATH_MAX; } +#else +INLINE HsInt __compat_long_path_size() { return 4096; } +#endif + +#if defined(mingw32_HOST_OS) + +/* Make sure we've got the reqd CSIDL_ constants in scope; + * w32api header files are lagging a bit in defining the full set. + */ +#if !defined(CSIDL_APPDATA) +#define CSIDL_APPDATA 0x001a +#endif +#if !defined(CSIDL_PERSONAL) +#define CSIDL_PERSONAL 0x0005 +#endif +#if !defined(CSIDL_PROFILE) +#define CSIDL_PROFILE 0x0028 +#endif +#if !defined(CSIDL_WINDOWS) +#define CSIDL_WINDOWS 0x0024 +#endif + +INLINE int __hscore_CSIDL_PROFILE() { return CSIDL_PROFILE; } +INLINE int __hscore_CSIDL_APPDATA() { return CSIDL_APPDATA; } +INLINE int __hscore_CSIDL_WINDOWS() { return CSIDL_WINDOWS; } +INLINE int __hscore_CSIDL_PERSONAL() { return CSIDL_PERSONAL; } + +#if __GLASGOW_HASKELL__ < 604 +/* + * Function: __hscore_getFolderPath() + * + * Late-bound version of SHGetFolderPath(), coping with OS versions + * that have shell32's lacking that particular API. + * + */ +typedef HRESULT (*HSCORE_GETAPPFOLDERFUNTY)(HWND,int,HANDLE,DWORD,char*); +int +__hscore_getFolderPath(HWND hwndOwner, + int nFolder, + HANDLE hToken, + DWORD dwFlags, + char* pszPath) +{ + static int loaded_dll = 0; + static HMODULE hMod = (HMODULE)NULL; + static HSCORE_GETAPPFOLDERFUNTY funcPtr = NULL; + /* The DLLs to try loading entry point from */ + char* dlls[] = { "shell32.dll", "shfolder.dll" }; + + if (loaded_dll < 0) { + return (-1); + } else if (loaded_dll == 0) { + int i; + for(i=0;i < sizeof(dlls); i++) { + hMod = LoadLibrary(dlls[i]); + if ( hMod != NULL && + (funcPtr = (HSCORE_GETAPPFOLDERFUNTY)GetProcAddress(hMod, "SHGetFolderPathA")) ) { + loaded_dll = 1; + break; + } + } + if (loaded_dll == 0) { + loaded_dll = (-1); + return (-1); + } + } + /* OK, if we got this far the function has been bound */ + return (int)funcPtr(hwndOwner,nFolder,hToken,dwFlags,pszPath); + /* ToDo: unload the DLL on shutdown? */ +} +#endif /* __GLASGOW_HASKELL__ < 604 */ +#endif -- 1.7.10.4