From 3834bef0fe30d6d640368da0d8ce9f8784d52c00 Mon Sep 17 00:00:00 2001 From: James Crayne Date: Sat, 4 Nov 2017 04:45:20 +0000 Subject: initialize svCacheDir and friends --- src/Network/Tox/Crypto/Handlers.hs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'src/Network/Tox/Crypto') diff --git a/src/Network/Tox/Crypto/Handlers.hs b/src/Network/Tox/Crypto/Handlers.hs index d6f2de7e..7cfbdd4e 100644 --- a/src/Network/Tox/Crypto/Handlers.hs +++ b/src/Network/Tox/Crypto/Handlers.hs @@ -21,6 +21,11 @@ import Data.Word import GHC.Conc (unsafeIOToSTM) import qualified Data.Set as Set import qualified Data.Array.Unboxed as A +import SensibleDir +import System.FilePath +import System.IO.Temp +import System.Environment +import System.Directory -- util, todo: move to another module maybeToEither :: Maybe b -> Either String b @@ -38,6 +43,7 @@ type MsgTypeArray = A.UArray Word8 Word16 -- | Information, that may be made visible in multiple sessions, as well -- as displayed in some way to the user via mutiple views. +-- data SessionView = SessionView { svNick :: TVar ByteString , svStatus :: TVar UserStatus @@ -45,8 +51,9 @@ data SessionView = SessionView , svGroups :: TVar (Map.Map GroupChatId (Set.Set SockAddr)) , svCacheDir :: FilePath -- ^ directory path used if the session has to use the disk for cache -- clean up only if space is needed - , svTmpDir :: FilePath -- Once off storage goes here, should clean up quickly - , svConfigDir :: FilePath -- profile related storage, etc, never clean up + , svTmpDir :: FilePath -- ^ Once off storage goes here, should clean up quickly + , svConfigDir :: FilePath -- ^ profile related storage, etc, never clean up + , svDownloadDir :: TVar FilePath -- ^ where to put files the user downloads } @@ -88,11 +95,25 @@ newSessionsState crypto unrechook hooks = do status <- atomically $ newTVar Online statusmsg <- atomically $ newTVar B.empty grps <- atomically $ newTVar Map.empty + pname <- getProgName + cachedir <- sensibleCacheDirCreateIfMissing pname + tmpdir <- ( pname) <$> getCanonicalTemporaryDirectory + configdir <- sensibleVarLib pname + homedir <- getHomeDirectory + svDownloadDir0 <- atomically $ newTVar (homedir "Downloads") return NCSessions { netCryptoSessions = x , transportCrypto = crypto , defaultHooks = hooks , defaultUnrecognizedHook = unrechook - , sessionView = SessionView { svNick = nick, svStatus = status, svStatusMsg = statusmsg, svGroups = grps } + , sessionView = SessionView { svNick = nick + , svStatus = status + , svStatusMsg = statusmsg + , svGroups = grps + , svCacheDir = cachedir + , svTmpDir = tmpdir + , svConfigDir = configdir + , svDownloadDir = svDownloadDir0 + } , msgTypeArray = allMsgTypes -- todo make this a parameter } -- cgit v1.2.3