diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2016-12-12 20:43:42 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2016-12-12 20:43:42 +0300 |
commit | f1a4c2b98f1707c09e17ddd07cb25d6e1cfe4022 (patch) | |
tree | 55877ee2e87e89b552b194966292f6f46eb0982f /src/Windows/Environment.hs | |
parent | fix export lists (diff) | |
download | windows-env-f1a4c2b98f1707c09e17ddd07cb25d6e1cfe4022.tar.gz windows-env-f1a4c2b98f1707c09e17ddd07cb25d6e1cfe4022.zip |
use monad transformers
Diffstat (limited to 'src/Windows/Environment.hs')
-rw-r--r-- | src/Windows/Environment.hs | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/src/Windows/Environment.hs b/src/Windows/Environment.hs index 8597d42..0399d5b 100644 --- a/src/Windows/Environment.hs +++ b/src/Windows/Environment.hs @@ -20,9 +20,10 @@ module Windows.Environment , pathSplit ) where -import Control.Exception (finally) -import Data.List (intercalate) -import Data.List.Split (splitOn) +import Control.Monad.Trans.Class (lift) +import Control.Monad.Trans.Except (ExceptT(..)) +import Data.List (intercalate) +import Data.List.Split (splitOn) import qualified Windows.Registry as Registry import Windows.Utils (notifyEnvironmentUpdate) @@ -44,18 +45,20 @@ profileKeyPath AllUsers = Registry.KeyPath Registry.LocalMachine type VarName = String type VarValue = String -query :: Profile -> VarName -> IO (Either IOError VarValue) +query :: Profile -> VarName -> ExceptT IOError IO VarValue query profile name = Registry.getExpandedString (profileKeyPath profile) name -engrave :: Profile -> VarName -> VarValue -> IO (Either IOError ()) -engrave profile name value = finally doEngrave notifyEnvironmentUpdate - where - doEngrave = Registry.setStringPreserveType (profileKeyPath profile) name value +engrave :: Profile -> VarName -> VarValue -> ExceptT IOError IO () +engrave profile name value = do + ret <- Registry.setStringPreserveType (profileKeyPath profile) name value + lift notifyEnvironmentUpdate + return ret -wipe :: Profile -> VarName -> IO (Either IOError ()) -wipe profile name = finally doWipe notifyEnvironmentUpdate - where - doWipe = Registry.deleteValue (profileKeyPath profile) name +wipe :: Profile -> VarName -> ExceptT IOError IO () +wipe profile name = do + ret <- Registry.deleteValue (profileKeyPath profile) name + lift notifyEnvironmentUpdate + return ret pathSep :: VarValue pathSep = ";" |