Rewrite getExecDir to use GetModuleFileName on Windows (thanks, sof),
and switch unDosifyPath's definitions between Windows and Unix so that
it actually does something on Windows.
#if !defined(mingw32_TARGET_OS)
import qualified Posix
#else
#if !defined(mingw32_TARGET_OS)
import qualified Posix
#else
import List ( isPrefixOf )
#endif
import List ( isPrefixOf )
#endif
#if defined(mingw32_TARGET_OS)
--------------------- Windows version ------------------
#if defined(mingw32_TARGET_OS)
--------------------- Windows version ------------------
dosifyPaths xs = map dosifyPath xs
dosifyPaths xs = map dosifyPath xs
+unDosifyPath xs = subst '\\' '/' xs
+
pgmPath dir pgm = dosifyPath dir ++ '\\' : pgm
dosifyPath stuff
pgmPath dir pgm = dosifyPath dir ++ '\\' : pgm
dosifyPath stuff
--------------------- Unix version ---------------------
dosifyPaths ps = ps
--------------------- Unix version ---------------------
dosifyPaths ps = ps
-unDosifyPath xs = subst '\\' '/' xs
pgmPath dir pgm = dir ++ '/' : pgm
--------------------------------------------------------
#endif
pgmPath dir pgm = dir ++ '/' : pgm
--------------------------------------------------------
#endif
#if defined(mingw32_TARGET_OS)
getExecDir :: IO (Maybe String)
#if defined(mingw32_TARGET_OS)
getExecDir :: IO (Maybe String)
-getExecDir = do hKey <- regOpenKey hKEY_LOCAL_MACHINE "SOFTWARE\\University of Glasgow\\Glasgow Haskell Compiler\\ghc-5.01"
- s <- regQueryValue hKey (Just "InstallDir")
- if s == "" then return Nothing else return (Just s)
+getExecDir = do h <- getModuleHandle Nothing
+ n <- getModuleFileName h
+ return (Just (reverse (tail (dropWhile (not .isSlash) (reverse (unDosifyPath n))))))
#else
getExecDir :: IO (Maybe String) = do return Nothing
#endif
#else
getExecDir :: IO (Maybe String) = do return Nothing
#endif