aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/Environment.hs
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-07-11 19:11:23 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-07-11 19:11:23 +0300
commit7b3fd9218596a2d7a14a92625a4d62c9a7b7b0f6 (patch)
tree8195393c18d0cdd3d9ebcdadb014d75285bfaf7e /src/Environment.hs
parentbecome a proper stack project (diff)
downloadwindows-env-7b3fd9218596a2d7a14a92625a4d62c9a7b7b0f6.tar.gz
windows-env-7b3fd9218596a2d7a14a92625a4d62c9a7b7b0f6.zip
rename modules + fix compiler warnings
Diffstat (limited to '')
-rw-r--r--src/Environment.hs (renamed from src/EnvUtils.hs)32
1 files changed, 17 insertions, 15 deletions
diff --git a/src/EnvUtils.hs b/src/Environment.hs
index 7e9bc96..0690278 100644
--- a/src/EnvUtils.hs
+++ b/src/Environment.hs
@@ -4,15 +4,15 @@
- See LICENSE.txt for details.
-}
-module EnvUtils ( saveToRegistry
- , saveToRegistryWithPrompt
- , queryFromRegistry
- , wipeFromRegistry
- , wipeFromRegistryWithPrompt
- , getEnv
- , splitPaths
- , joinPaths
- , RegistryBasedEnvironment ( CurrentUserEnvironment, AllUsersEnvironment ) ) where
+module Environment ( saveToRegistry
+ , saveToRegistryWithPrompt
+ , queryFromRegistry
+ , wipeFromRegistry
+ , wipeFromRegistryWithPrompt
+ , getEnv
+ , splitPaths
+ , joinPaths
+ , RegistryBasedEnvironment(..) ) where
import Control.Monad ( liftM, when )
import Data.List ( intercalate )
@@ -21,7 +21,7 @@ import Data.Maybe ( fromMaybe )
import qualified System.Environment ( lookupEnv )
import System.IO.Error ( catchIOError, isDoesNotExistError )
-import qualified RegUtils
+import qualified Registry
import qualified Utils ( promptToContinue )
data RegistryBasedEnvironment = CurrentUserEnvironment
@@ -32,15 +32,16 @@ registrySubKeyPath :: RegistryBasedEnvironment -> String
registrySubKeyPath CurrentUserEnvironment = "Environment"
registrySubKeyPath AllUsersEnvironment = "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"
-registryKey CurrentUserEnvironment = RegUtils.hkcu
-registryKey AllUsersEnvironment = RegUtils.hklm
+registryKey :: RegistryBasedEnvironment -> Registry.KeyHandle
+registryKey CurrentUserEnvironment = Registry.hkcu
+registryKey AllUsersEnvironment = Registry.hklm
registryKeyPath :: RegistryBasedEnvironment -> String
registryKeyPath CurrentUserEnvironment = "HKCU\\" ++ registrySubKeyPath CurrentUserEnvironment
registryKeyPath AllUsersEnvironment = "HKLM\\" ++ registrySubKeyPath AllUsersEnvironment
saveToRegistry :: RegistryBasedEnvironment -> String -> String -> IO ()
-saveToRegistry env = RegUtils.setString (registryKey env) (registrySubKeyPath env)
+saveToRegistry env = Registry.setString (registryKey env) (registrySubKeyPath env)
saveToRegistryWithPrompt :: RegistryBasedEnvironment -> String -> String -> IO ()
saveToRegistryWithPrompt env name value = do
@@ -52,13 +53,13 @@ saveToRegistryWithPrompt env name value = do
when agreed $ saveToRegistry env name value
queryFromRegistry :: RegistryBasedEnvironment -> String -> IO String
-queryFromRegistry env name = catchIOError (RegUtils.getString (registryKey env) (registrySubKeyPath env) name) emptyIfDoesNotExist
+queryFromRegistry env name = catchIOError (Registry.getString (registryKey env) (registrySubKeyPath env) name) emptyIfDoesNotExist
where
emptyIfDoesNotExist :: IOError -> IO String
emptyIfDoesNotExist e = if isDoesNotExistError e then return "" else ioError e
wipeFromRegistry :: RegistryBasedEnvironment -> String -> IO ()
-wipeFromRegistry env name = catchIOError (RegUtils.delValue (registryKey env) (registrySubKeyPath env) name) ignoreIfDoesNotExist
+wipeFromRegistry env name = catchIOError (Registry.delValue (registryKey env) (registrySubKeyPath env) name) ignoreIfDoesNotExist
where
ignoreIfDoesNotExist :: IOError -> IO ()
ignoreIfDoesNotExist e = if isDoesNotExistError e then return () else ioError e
@@ -72,6 +73,7 @@ wipeFromRegistryWithPrompt env name = do
getEnv :: String -> IO String
getEnv = liftM (fromMaybe "") . System.Environment.lookupEnv
+pathSep :: String
pathSep = ";"
splitPaths :: String -> [String]