diff --git a/Cursed.Base/Actors/CacheActor.fs b/Cursed.Base/Actors/CacheActor.fs index 24da643..ee3a5b1 100644 --- a/Cursed.Base/Actors/CacheActor.fs +++ b/Cursed.Base/Actors/CacheActor.fs @@ -1,7 +1,27 @@ namespace Cursed.Base module CacheActor = - open System + open Common + open System.IO + open System.Text + open System.Collections.Generic + open Newtonsoft.Json + + let private cacheFileLocation = HomePath @@ "cache.txt" + + let private ensureDirectory directoryPath = + let directory = new DirectoryInfo(directoryPath) + if not directory.Exists then + directory.Create() + + let private ensureFile fileName = + let file = new FileInfo(fileName) + + ensureDirectory <| file.DirectoryName + + if not file.Exists then + let newFile = file.Create() + newFile.Close() let FileLoop = let inboxHandler (inbox: MailboxProcessor) = @@ -46,12 +66,20 @@ module CacheActor = p ) + File.WriteAllText(cacheFileLocation, JsonConvert.SerializeObject(newState), Encoding.UTF8) return! messageLoop newState | GetCache reply -> reply.Reply oldState return! messageLoop oldState - | Load projects -> - return! messageLoop projects + | Load -> + ensureFile cacheFileLocation + let cache = File.ReadAllText(cacheFileLocation, Encoding.UTF8) + let projects = JsonConvert.DeserializeObject>(cache) + + if isNull projects then + return! messageLoop [] + else + return! messageLoop (projects |> List.ofSeq) | FileReplyMessage.Restart -> return! messageLoop [] diff --git a/Cursed.Base/Cursed.Base.fsproj b/Cursed.Base/Cursed.Base.fsproj index 10f7348..afb39d5 100644 --- a/Cursed.Base/Cursed.Base.fsproj +++ b/Cursed.Base/Cursed.Base.fsproj @@ -57,7 +57,6 @@ - @@ -109,14 +108,14 @@ + + True + ..\packages\FSharp.Data\lib\net40\FSharp.Data.dll True True - - True - diff --git a/Cursed.Base/DataAccess.fs b/Cursed.Base/DataAccess.fs deleted file mode 100644 index 9b0cc33..0000000 --- a/Cursed.Base/DataAccess.fs +++ /dev/null @@ -1,37 +0,0 @@ -namespace Cursed.Base - -module DataAccess = - open Common - open System.IO - open System.Text - open System.Collections.Generic - open Newtonsoft.Json - - let private cacheFileLocation = HomePath @@ "cache.txt" - - let private ensureDirectory directoryPath = - let directory = new DirectoryInfo(directoryPath) - if not directory.Exists then - directory.Create() - - let private ensureFile fileName = - let file = new FileInfo(fileName) - - ensureDirectory <| file.DirectoryName - - if not file.Exists then - let newFile = file.Create() - newFile.Close() - - let Save cache = - File.WriteAllText(cacheFileLocation, JsonConvert.SerializeObject(cache), Encoding.UTF8) - - let LoadCache () = - ensureFile cacheFileLocation - let cache = File.ReadAllText(cacheFileLocation, Encoding.UTF8) - let projects = JsonConvert.DeserializeObject>(cache) - - if isNull projects then - CacheActor.FileLoop.Post <| Load [] - else - CacheActor.FileLoop.Post <| Load (projects |> List.ofSeq) diff --git a/Cursed.Base/MainForm.fs b/Cursed.Base/MainForm.fs index 3f2ca35..e23a759 100644 --- a/Cursed.Base/MainForm.fs +++ b/Cursed.Base/MainForm.fs @@ -126,7 +126,7 @@ type MainForm(app: Application) = layout do - DataAccess.LoadCache () + CacheActor.FileLoop.Post Load let dynamicLayout = let layout = new DynamicLayout() @@ -159,11 +159,17 @@ type MainForm(app: Application) = base.DataContext <- modpack async { - let! isLatest = Startup.IsLatest - - if not isLatest then + try + let! isLatest = Startup.IsLatest + + if not isLatest then + app.Invoke (fun () -> + app.MainForm.Title <- sprintf "Cursed - Update Available" + ) + with + | :? Exception -> app.Invoke (fun () -> - app.MainForm.Title <- sprintf "Cursed - Update Available" + app.MainForm.Title <- sprintf "Cursed - Update check failed" ) } |> Async.Start diff --git a/Cursed.Base/Modpack.fs b/Cursed.Base/Modpack.fs index 03e2f86..cf15c6b 100644 --- a/Cursed.Base/Modpack.fs +++ b/Cursed.Base/Modpack.fs @@ -13,7 +13,6 @@ open HttpFs.Client open Eto.Forms open Common open ModpackController -open DataAccess type ModpackBase() = let propertyChanged = new Event<_, _>() @@ -94,8 +93,6 @@ type Modpack(app: Application) as this = let saveToCache projectId modName fileId fileName = CacheActor.FileLoop.Post <| SaveProject { Id = projectId; Name = modName; Files = [] } CacheActor.FileLoop.Post <| SaveMod (projectId, { Id = fileId; FileName = fileName }) - let cache = CacheActor.FileLoop.PostAndReply GetCache - Save cache let cachedModName = let cache = CacheActor.FileLoop.PostAndReply GetCache diff --git a/Cursed.Base/State.fs b/Cursed.Base/State.fs index 73a9494..479342c 100644 --- a/Cursed.Base/State.fs +++ b/Cursed.Base/State.fs @@ -43,5 +43,5 @@ type FileReplyMessage = | SaveProject of Project | SaveMod of projectId: int * ModFile | GetCache of AsyncReplyChannel -| Load of Project list +| Load | Restart \ No newline at end of file diff --git a/Cursed/Cursed.fsproj b/Cursed/Cursed.fsproj index 36634f1..2e35dbd 100644 --- a/Cursed/Cursed.fsproj +++ b/Cursed/Cursed.fsproj @@ -177,14 +177,14 @@ + + True + ..\packages\FSharp.Data\lib\net40\FSharp.Data.dll True True - - True - diff --git a/paket.dependencies b/paket.dependencies index b806f68..4ae12ba 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -9,7 +9,7 @@ nuget Eto.Platform.Gtk3 #nuget Eto.Platform.Mac.Template nuget Eto.Platform.Wpf nuget FSharp.Data -nuget FSharp.Core redirects: force +nuget FSharp.Core redirects: force nuget Http.fs nuget Newtonsoft.Json nuget SharpZipLib diff --git a/release-notes.md b/release-notes.md index 1f4394c..a93fdec 100644 --- a/release-notes.md +++ b/release-notes.md @@ -1,3 +1,6 @@ +## New in 1.2.3 (Release 2017/01/30) +* Fix concurrency issues with cache saving + ## New in 1.2.2 (Release 2017/01/07) * Fix handling of Zip files in Linux systems