module Yi.Paths(
getEvaluatorContextFilename
,getConfigFilename
,getConfigModules
,getArticleDbFilename
,getPersistentStateFilename
,getConfigDir
,getConfigPath
,getDataPath
) where
import System.Directory(getAppUserDataDirectory,
doesDirectoryExist,
createDirectoryIfMissing)
import System.FilePath((</>))
import Control.Monad.Trans(liftIO, MonadIO)
import qualified System.Environment.XDG.BaseDir as XDG
appUserDataCond ::(MonadIO m) => ([Char] -> IO FilePath) -> m FilePath
appUserDataCond dirQuery = liftIO $
do oldDir <- getAppUserDataDirectory "yi"
newDir <- dirQuery "yi"
oldDirExists <- doesDirectoryExist oldDir
newDirExists <- doesDirectoryExist newDir
if newDirExists
then return newDir
else if oldDirExists
then return oldDir
else do createDirectoryIfMissing True newDir
return newDir
getConfigDir ::(MonadIO m) => m FilePath
getConfigDir = appUserDataCond XDG.getUserConfigDir
getDataDir ::(MonadIO m) => m FilePath
getDataDir = appUserDataCond XDG.getUserDataDir
getDataPath :: (MonadIO m) => FilePath -> m FilePath
getDataPath fp = getDataDir >>= (return . (</> fp))
getConfigPath :: (MonadIO m) => FilePath -> m FilePath
getConfigPath fp = getConfigDir >>= (return . (</> fp))
getEvaluatorContextFilename, getConfigFilename, getConfigModules,
getArticleDbFilename, getPersistentStateFilename :: (MonadIO m) => m FilePath
getConfigFilename = getConfigPath "yi.hs"
getConfigModules = getConfigPath "modules"
getArticleDbFilename = getConfigPath "articles.db"
getPersistentStateFilename = getDataPath "history"
getEvaluatorContextFilename = getConfigPath $ "local" </> "Env.hs"