equal
deleted
inserted
replaced
8 import System.Log.Logger |
8 import System.Log.Logger |
9 import Data.Maybe |
9 import Data.Maybe |
10 import Data.Unique |
10 import Data.Unique |
11 import Control.Monad |
11 import Control.Monad |
12 import Data.List |
12 import Data.List |
|
13 import qualified Data.ByteString as B |
|
14 import System.Directory |
13 --------------- |
15 --------------- |
14 import CoreTypes |
16 import CoreTypes |
15 import EngineInteraction |
17 import EngineInteraction |
16 |
18 |
17 |
19 |
27 (writeFile fileName (show replayInfo)) |
29 (writeFile fileName (show replayInfo)) |
28 (\(e :: IOException) -> warningM "REPLAYS" $ "Couldn't write to " ++ fileName ++ ": " ++ show e) |
30 (\(e :: IOException) -> warningM "REPLAYS" $ "Couldn't write to " ++ fileName ++ ": " ++ show e) |
29 |
31 |
30 |
32 |
31 loadReplay :: Int -> IO [B.ByteString] |
33 loadReplay :: Int -> IO [B.ByteString] |
32 loadReplay p = E.handle (\(e :: SomeException) -> warningM "REPLAYS" $ "Problems reading replay") $ do |
34 loadReplay p = E.handle (\(e :: SomeException) -> warningM "REPLAYS" "Problems reading replay" >> return []) $ do |
33 files <- liftM (isSuffixOf ('.' : show p)) getDirectoryContents |
35 files <- liftM (filter (isSuffixOf ('.' : show p))) $ getDirectoryContents "replays" |
34 if (not $ null files) then |
36 if (not $ null files) then |
35 loadFile $ head files |
37 loadFile $ head files |
36 else |
38 else |
37 return [] |
39 return [] |
38 where |
40 where |
39 loadFile fileName = E.handle (\(e :: SomeException) -> warningM "REPLAYS" $ "Problems reading " ++ fileName) $ do |
41 loadFile :: String -> IO [B.ByteString] |
|
42 loadFile fileName = E.handle (\(e :: SomeException) -> warningM "REPLAYS" ("Problems reading " ++ fileName) >> return []) $ do |
40 (teams, params1, params2, roundMsgs) <- liftM read $ readFile fileName |
43 (teams, params1, params2, roundMsgs) <- liftM read $ readFile fileName |
41 return $ replayToDemo teams (Map.fromList params1) (Map.fromList params2) roundMsgs |
44 return $ replayToDemo teams (Map.fromList params1) (Map.fromList params2) roundMsgs |