diff --git a/app/Main.hs b/app/Main.hs index dc3b322..a75a659 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -24,9 +24,12 @@ module Main where import Control.Monad (mapM_) import Control.Monad.Trans.State as S -import Data.Maybe (maybe) -import System.Console.HCL (Request, reqFail, reqIO, runRequest) -import System.Environment (lookupEnv) +import System.Console.HCL (Request, reqIO, runRequest) +import System.EasyFile + ( createDirectoryIfMissing + , getAppUserDataDirectory + , () + ) import System.Random (getStdGen) import Types @@ -45,24 +48,9 @@ setup = do return $ Status g pw p db getDBPath :: Request FilePath -getDBPath = reqIO (lookupEnv "HOME") >>= maybe - (do - reqIO $ putStrLn "ERROR: can't find home directory" - reqFail) - (\home -> case pathDelim home of - Nothing -> do - reqIO $ putStrLn "ERROR: unsupported home path" - reqFail - Just delim -> return $ home ++ - (if last home == delim then "" else [delim]) ++ - ".passman.json") - -pathDelim :: FilePath -> Maybe Char -pathDelim = foldr - (\x a -> case x of - '/' -> Just '/' - '\\' -> Just '\\' - _ -> a) - Nothing +getDBPath = reqIO $ do + path <- getAppUserDataDirectory "passman" + createDirectoryIfMissing True path + return $ path "database.json" --jl