aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/Environment.hs
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-07-13 03:28:51 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-07-13 03:28:51 +0300
commit54db9a94963826141c79ffe30df0453f85a117c8 (patch)
tree22190418728ed381c1c0c45c2d58c5acfda06423 /src/Environment.hs
parentreorder imports (diff)
downloadwindows-env-54db9a94963826141c79ffe30df0453f85a117c8.tar.gz
windows-env-54db9a94963826141c79ffe30df0453f85a117c8.zip
bugfix + refactoring
Diffstat (limited to '')
-rw-r--r--src/Environment.hs15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/Environment.hs b/src/Environment.hs
index c0dd723..eef1948 100644
--- a/src/Environment.hs
+++ b/src/Environment.hs
@@ -19,6 +19,7 @@ module Environment
import Control.Monad (when)
import Data.List (intercalate)
import Data.List.Split (splitOn)
+import Data.Maybe (fromJust, isJust)
import System.IO.Error (catchIOError, isDoesNotExistError)
import qualified Graphics.Win32.Window as WinAPI
@@ -64,12 +65,12 @@ notifyEnvUpdate =
allWindows = WinAPI.castUINTPtrToPtr 0xffff
-query :: RegistryLocation -> Registry.ValueName -> IO Registry.ValueData
+query :: RegistryLocation -> Registry.ValueName -> IO (Maybe Registry.ValueData)
query env name = do
keyHandle <- openRegistryKey env
- catchIOError (Registry.getString keyHandle name) emptyIfDoesNotExist
+ catchIOError (Registry.getString keyHandle name >>= return . Just) emptyIfDoesNotExist
where
- emptyIfDoesNotExist e = if isDoesNotExistError e then return "" else ioError e
+ emptyIfDoesNotExist e = if isDoesNotExistError e then return Nothing else ioError e
engrave :: RegistryLocation -> Registry.ValueName -> Registry.ValueData -> IO ()
engrave env name value = do
@@ -81,8 +82,12 @@ engraveWithPrompt :: RegistryLocation -> Registry.ValueName -> Registry.ValueDat
engraveWithPrompt env name value = do
putStrLn $ "Saving variable '" ++ name ++ "' to '" ++ registryKeyPath env ++ "'..."
oldValue <- query env name
- putStrLn $ "\tOld value: " ++ oldValue
- putStrLn $ "\tNew value: " ++ value
+ if (isJust oldValue)
+ then do
+ putStrLn $ "\tOld value: " ++ fromJust oldValue
+ putStrLn $ "\tNew value: " ++ value
+ else do
+ putStrLn $ "\tValue: " ++ value
agreed <- Utils.promptToContinue
when agreed $ engrave env name value