summaryrefslogtreecommitdiff
path: root/src/Network/Tox/Crypto
diff options
context:
space:
mode:
authorJames Crayne <jim.crayne@gmail.com>2017-11-04 04:45:20 +0000
committerJames Crayne <jim.crayne@gmail.com>2017-11-19 23:40:12 +0000
commit3834bef0fe30d6d640368da0d8ce9f8784d52c00 (patch)
tree1b9909b8fc31ba9f215bc32ec1d71b5677f9e376 /src/Network/Tox/Crypto
parent98c5eb996be5a3d015a46ed71c8db771deb53c0a (diff)
initialize svCacheDir and friends
Diffstat (limited to 'src/Network/Tox/Crypto')
-rw-r--r--src/Network/Tox/Crypto/Handlers.hs27
1 files changed, 24 insertions, 3 deletions
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
21import GHC.Conc (unsafeIOToSTM) 21import GHC.Conc (unsafeIOToSTM)
22import qualified Data.Set as Set 22import qualified Data.Set as Set
23import qualified Data.Array.Unboxed as A 23import qualified Data.Array.Unboxed as A
24import SensibleDir
25import System.FilePath
26import System.IO.Temp
27import System.Environment
28import System.Directory
24 29
25-- util, todo: move to another module 30-- util, todo: move to another module
26maybeToEither :: Maybe b -> Either String b 31maybeToEither :: Maybe b -> Either String b
@@ -38,6 +43,7 @@ type MsgTypeArray = A.UArray Word8 Word16
38 43
39-- | Information, that may be made visible in multiple sessions, as well 44-- | Information, that may be made visible in multiple sessions, as well
40-- as displayed in some way to the user via mutiple views. 45-- as displayed in some way to the user via mutiple views.
46--
41data SessionView = SessionView 47data SessionView = SessionView
42 { svNick :: TVar ByteString 48 { svNick :: TVar ByteString
43 , svStatus :: TVar UserStatus 49 , svStatus :: TVar UserStatus
@@ -45,8 +51,9 @@ data SessionView = SessionView
45 , svGroups :: TVar (Map.Map GroupChatId (Set.Set SockAddr)) 51 , svGroups :: TVar (Map.Map GroupChatId (Set.Set SockAddr))
46 , svCacheDir :: FilePath -- ^ directory path used if the session has to use the disk for cache 52 , svCacheDir :: FilePath -- ^ directory path used if the session has to use the disk for cache
47 -- clean up only if space is needed 53 -- clean up only if space is needed
48 , svTmpDir :: FilePath -- Once off storage goes here, should clean up quickly 54 , svTmpDir :: FilePath -- ^ Once off storage goes here, should clean up quickly
49 , svConfigDir :: FilePath -- profile related storage, etc, never clean up 55 , svConfigDir :: FilePath -- ^ profile related storage, etc, never clean up
56 , svDownloadDir :: TVar FilePath -- ^ where to put files the user downloads
50 } 57 }
51 58
52 59
@@ -88,11 +95,25 @@ newSessionsState crypto unrechook hooks = do
88 status <- atomically $ newTVar Online 95 status <- atomically $ newTVar Online
89 statusmsg <- atomically $ newTVar B.empty 96 statusmsg <- atomically $ newTVar B.empty
90 grps <- atomically $ newTVar Map.empty 97 grps <- atomically $ newTVar Map.empty
98 pname <- getProgName
99 cachedir <- sensibleCacheDirCreateIfMissing pname
100 tmpdir <- (</> pname) <$> getCanonicalTemporaryDirectory
101 configdir <- sensibleVarLib pname
102 homedir <- getHomeDirectory
103 svDownloadDir0 <- atomically $ newTVar (homedir </> "Downloads")
91 return NCSessions { netCryptoSessions = x 104 return NCSessions { netCryptoSessions = x
92 , transportCrypto = crypto 105 , transportCrypto = crypto
93 , defaultHooks = hooks 106 , defaultHooks = hooks
94 , defaultUnrecognizedHook = unrechook 107 , defaultUnrecognizedHook = unrechook
95 , sessionView = SessionView { svNick = nick, svStatus = status, svStatusMsg = statusmsg, svGroups = grps } 108 , sessionView = SessionView { svNick = nick
109 , svStatus = status
110 , svStatusMsg = statusmsg
111 , svGroups = grps
112 , svCacheDir = cachedir
113 , svTmpDir = tmpdir
114 , svConfigDir = configdir
115 , svDownloadDir = svDownloadDir0
116 }
96 , msgTypeArray = allMsgTypes -- todo make this a parameter 117 , msgTypeArray = allMsgTypes -- todo make this a parameter
97 } 118 }
98 119