aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-07-19 04:07:38 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-07-19 04:07:38 +0300
commitc721d79cbd2e11ef12da7c85147bd70848feae6d (patch)
tree0c5f216bc69aa0c503a68f04c28505ac3fd6a0b7
parentrefactoring (diff)
downloadwindows-env-c721d79cbd2e11ef12da7c85147bd70848feae6d.tar.gz
windows-env-c721d79cbd2e11ef12da7c85147bd70848feae6d.zip
refactoring
-rw-r--r--src/Windows/Environment.hs20
-rw-r--r--src/Windows/Registry.hs3
2 files changed, 17 insertions, 6 deletions
diff --git a/src/Windows/Environment.hs b/src/Windows/Environment.hs
index 2bea481..5c26eea 100644
--- a/src/Windows/Environment.hs
+++ b/src/Windows/Environment.hs
@@ -52,7 +52,10 @@ openRootProfileKey :: Profile -> Registry.KeyHandle
openRootProfileKey = Registry.openRootKey . profileRootKey
openProfileKey :: Profile -> IO Registry.KeyHandle
-openProfileKey profile = Registry.openSubKey (openRootProfileKey profile) (profileSubKeyPath profile)
+openProfileKey profile = Registry.openSubKey rootKey subKeyPath
+ where
+ rootKey = openRootProfileKey profile
+ subKeyPath = profileSubKeyPath profile
type VarName = Registry.ValueName
type VarValue = Registry.ValueData
@@ -60,9 +63,14 @@ type VarValue = Registry.ValueData
query :: Profile -> VarName -> IO (Maybe VarValue)
query profile name = do
keyHandle <- openProfileKey profile
- catchIOError (Registry.getString keyHandle name >>= return . Just) emptyIfDoesNotExist
+ catchIOError (tryQuery keyHandle) ignoreMissing
where
- emptyIfDoesNotExist e = if isDoesNotExistError e then return Nothing else ioError e
+ tryQuery keyHandle = do
+ value <- Registry.getString keyHandle name
+ return $ Just value
+ ignoreMissing e
+ | isDoesNotExistError e = return Nothing
+ | otherwise = ioError e
engrave :: Profile -> VarName -> VarValue -> IO ()
engrave profile name value = do
@@ -73,10 +81,12 @@ engrave profile name value = do
wipe :: Profile -> VarName -> IO ()
wipe profile name = do
keyHandle <- openProfileKey profile
- catchIOError (Registry.delValue keyHandle name) ignoreIfDoesNotExist
+ catchIOError (Registry.delValue keyHandle name) ignoreMissing
notifyEnvironmentUpdate
where
- ignoreIfDoesNotExist e = if isDoesNotExistError e then return () else ioError e
+ ignoreMissing e
+ | isDoesNotExistError e = return ()
+ | otherwise = ioError e
pathSep :: VarValue
pathSep = ";"
diff --git a/src/Windows/Registry.hs b/src/Windows/Registry.hs
index 528027f..a8504d6 100644
--- a/src/Windows/Registry.hs
+++ b/src/Windows/Registry.hs
@@ -31,7 +31,8 @@ import Foreign.ForeignPtr (withForeignPtr)
import Foreign.Marshal.Alloc (alloca, allocaBytes)
import Foreign.Ptr (castPtr, plusPtr)
import Foreign.Storable (peek, poke, sizeOf)
-import System.IO.Error (catchIOError, doesNotExistErrorType, mkIOError, isDoesNotExistError)
+import System.IO.Error
+ (catchIOError, doesNotExistErrorType, mkIOError, isDoesNotExistError)
import qualified System.Win32.Registry as WinAPI
import qualified System.Win32.Types as WinAPI