Remaining bugs in Cabal under Windows

Krasimir Angelov ka2_mail at yahoo.com
Tue Aug 17 08:44:19 EDT 2004


--- Graham Klyne <GK at ninebynine.org> wrote:

> At 10:20 17/08/04 +0100, Simon Marlow wrote:
> > >    - The package uses (getEnv "HOME") to get the
> path
> > > to home directory. The variable isn't present in
> plain
> > > Command prompt under Windows.
> >
> >Agreed.  I need to know the equivalent of $HOME for
> GHC too, so that GHC
> >can keep a per-user package database.
> 
> On my Windows XP system, its:
> 
> HOMEDRIVE=C:
> HOMEPATH=\Documents and Settings\Graham

I also have these variables but their values aren't
correct. I have

HOMEDRIVE=C:
HOMEPATH=\

These variables aren't present in Windows 98/Milenium.
I use there functions:

-------------------------------------------------
{-# OPTIONS -cpp #-}
#ifdef mingw32_TARGET_OS
{-# OPTIONS -#include "shlobj.h" #-}
#endif

#ifdef mingw32_TARGET_OS
import Foreign
import Foreign.C
#else
import System.Environment
#endif

getHomeDirectory :: IO FilePath
getHomeDirectory =
#ifdef mingw32_TARGET_OS
  allocaBytes 1024 $ \pPath -> do
     r <- c_SHGetFolderPath nullPtr 0x28 nullPtr 0
pPath
     if (r < 0)
       then c_SHGetFolderPath nullPtr 0x05 nullPtr 0
pPath
       else return 0
     peekCString pPath
#else
  getEnv "HOME"
#endif

getAppUserDataDirectory :: String -> IO FilePath
getAppUserDataDirectory appName = do
#ifdef mingw32_TARGET_OS
  allocaBytes 1024    $ \pPath -> do
     r <- c_SHGetFolderPath nullPtr 0x1A nullPtr 0
pPath
     s <- peekCString pPath
     return (s++'\\':appName)
#else
  path <- getEnv "HOME"
  return (path++'/':'.':appName)
#endif

#ifdef mingw32_TARGET_OS
foreign import stdcall "SHGetFolderPath" 
            c_SHGetFolderPath :: Ptr () 
                              -> CInt 
                              -> Ptr () 
                              -> CInt 
                              -> CString 
                              -> IO CInt
#endif

main = do
  getHomeDirectory >>= putStrLn
  getAppUserDataDirectory "appName" >>= putStrLn
-------------------------------------------------

The returned values are:

+-----+--------------------------------+
| OS  |getHomeDirectory                |
+-----+--------------------------------+
|Win98|C:\My Documents                 |
|WinNT|C:\Documents and Settings\<user>|
|Posix|/home/<user>                    |
+-----+--------------------------------+

+-----+-----------------------------------+
| OS  |getAppUserDataDirectory "appName"  |
+-----+-----------------------------------+
|Win98|C:\WINDOWS\Application Data\appName|
|WinNT|C:\Documents and Settings\<user>\  |
|     |         Application Data\appName  |
|Posix|/home/<user>/.appName              |
+-----+-----------------------------------+

Cheers,
  Krasimir



		
__________________________________
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail


More information about the Libraries mailing list