diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2016-07-19 04:07:38 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2016-07-19 04:07:38 +0300 |
commit | c721d79cbd2e11ef12da7c85147bd70848feae6d (patch) | |
tree | 0c5f216bc69aa0c503a68f04c28505ac3fd6a0b7 /src/Windows/Environment.hs | |
parent | refactoring (diff) | |
download | windows-env-c721d79cbd2e11ef12da7c85147bd70848feae6d.tar.gz windows-env-c721d79cbd2e11ef12da7c85147bd70848feae6d.zip |
refactoring
Diffstat (limited to '')
-rw-r--r-- | src/Windows/Environment.hs | 20 |
1 files changed, 15 insertions, 5 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 = ";" |