Permalink
Browse files

config file now always has to specify savegame and highscore paths

Previously, the current directory was chosen if no paths were given,
now it's only when the ~/.LambadaHack directory does not exist.
  • Loading branch information...
1 parent 208fc62 commit a9cc93d532004f73d80b6af53cf73a6e407fa212 @Mikolaj Mikolaj committed Mar 2, 2011
Showing with 13 additions and 10 deletions.
  1. +11 −8 src/Config.hs
  2. +1 −1 src/HighScores.hs
  3. +1 −1 src/Save.hs
View
@@ -82,17 +82,20 @@ get (CP config) s o =
then forceEither $ CF.get config s o
else error $ "unknown config option: " ++ s ++ "." ++ o
--- | Looks up a file path in the config file, faling back to the default path.
--- The path from the config file is taken relative to the home directory
--- and the default is taken relative to the current directory. In any case,
--- the returned path is absolute.
-getFile :: CP -> FilePath -> CF.SectionSpec -> CF.OptionSpec -> IO FilePath
-getFile config dflt s o =
+-- | Looks up a file path in the config file and makes it absolute.
+-- If the LambdaHack configuration directory exists,
+-- the path is appended to it; otherwise, it's appended
+-- to the current directory.
+getFile :: CP -> CF.SectionSpec -> CF.OptionSpec -> IO FilePath
+getFile config s o =
do
current <- getCurrentDirectory
appData <- getAppUserDataDirectory "LambdaHack"
- let path = getOption config s o
- return $ maybe (combine current dflt) (combine appData) path
+ let path = get config s o
+ appPath = combine appData path
+ curPath = combine current path
+ b <- doesDirectoryExist appData
+ return $ if b then appPath else curPath
dump :: FilePath -> CP -> IO ()
dump fn (CP config) =
View
@@ -95,7 +95,7 @@ empty = []
-- | Name of the high scores file.
file :: Config.CP -> IO String
-file config = Config.getFile config "LambdaHack.scores" "files" "highScores"
+file config = Config.getFile config "files" "highScores"
-- | We save a simple serialized version of the high scores table.
-- The 'False' is used only as an EOF marker.
View
@@ -10,7 +10,7 @@ import qualified Config
-- | Name of the save game.
file :: Config.CP -> IO String
-file config = Config.getFile config "LambdaHack.save" "files" "saveGame"
+file config = Config.getFile config "files" "saveGame"
-- | We save a simple serialized version of the current level and
-- the current state. The 'False' is used only as an EOF marker.

0 comments on commit a9cc93d

Please sign in to comment.