aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/Windows
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2017-06-13 15:26:47 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2017-06-13 15:26:47 +0300
commitcd890acc6fbb2b228f0903f0cea313fde02c026f (patch)
tree3c77877df3ccff9e88eb8306009e6cc4bbf6a309 /src/Windows
parentbump version (diff)
downloadwindows-env-cd890acc6fbb2b228f0903f0cea313fde02c026f.tar.gz
windows-env-cd890acc6fbb2b228f0903f0cea313fde02c026f.zip
refactoring
Diffstat (limited to '')
-rw-r--r--src/WindowsEnv/Environment.hs4
-rw-r--r--src/WindowsEnv/Registry.hs12
2 files changed, 6 insertions, 10 deletions
diff --git a/src/WindowsEnv/Environment.hs b/src/WindowsEnv/Environment.hs
index aa05017..6784d43 100644
--- a/src/WindowsEnv/Environment.hs
+++ b/src/WindowsEnv/Environment.hs
@@ -34,7 +34,7 @@ import Data.List (intercalate)
import Data.List.Split (splitOn)
import Foreign.Marshal.Alloc (allocaBytes)
import Foreign.Storable (sizeOf)
-import System.IO.Error (catchIOError, isDoesNotExistError)
+import System.IO.Error (isDoesNotExistError, tryIOError)
import qualified System.Win32.Types as WinAPI
import qualified WindowsEnv.Registry as Registry
@@ -108,7 +108,7 @@ foreign import WINDOWS_ENV_CCALL unsafe "Windows.h ExpandEnvironmentStringsW"
c_ExpandEnvironmentStrings :: WinAPI.LPCTSTR -> WinAPI.LPTSTR -> WinAPI.DWORD -> IO WinAPI.ErrCode
expand :: String -> ExceptT IOError IO String
-expand value = ExceptT $ catchIOError (Right <$> doExpand) (return . Left)
+expand value = ExceptT $ tryIOError doExpand
where
doExpandIn valuePtr bufferPtr bufferLength = do
newBufferLength <- WinAPI.failIfZero "ExpandEnvironmentStringsW" $
diff --git a/src/WindowsEnv/Registry.hs b/src/WindowsEnv/Registry.hs
index 73606d9..3121d9d 100644
--- a/src/WindowsEnv/Registry.hs
+++ b/src/WindowsEnv/Registry.hs
@@ -50,7 +50,7 @@ import Foreign.ForeignPtr (withForeignPtr)
import Foreign.Marshal.Alloc (alloca, allocaBytes)
import Foreign.Marshal.Array (peekArray, pokeArray)
import Foreign.Storable (peek, poke)
-import System.IO.Error (catchIOError)
+import System.IO.Error (tryIOError)
import qualified System.Win32.Types as WinAPI
import qualified System.Win32.Registry as WinAPI
@@ -63,16 +63,12 @@ closeKey :: Handle -> IO ()
closeKey = WinAPI.regCloseKey
openKey :: IsKeyPath a => a -> IO (Either IOError Handle)
-openKey keyPath = catchIOError doOpenKey wrapError
- where
- doOpenKey = Right <$> openKeyUnsafe keyPath
- wrapError = return . Left
+openKey keyPath = tryIOError $ openKeyUnsafe keyPath
withHandle :: IsKeyPath a => a -> (Handle -> IO b) -> ExceptT IOError IO b
-withHandle keyPath f = ExceptT $ catchIOError doWithHandle wrapError
+withHandle keyPath f = ExceptT $ tryIOError doWithHandle
where
- doWithHandle = Right <$> bracket (openKeyUnsafe keyPath) closeKey f
- wrapError = return . Left
+ doWithHandle = bracket (openKeyUnsafe keyPath) closeKey f
data RootKey = CurrentUser
| LocalMachine