From 121fde8c86186a5d7f36ab81033e0c2a5b39e960 Mon Sep 17 00:00:00 2001 From: diamondminerita Date: Mon, 19 Aug 2019 23:13:25 +0200 Subject: [PATCH] Fix StorageController.LoadAsync Fix StorageController.Storage check. Fix cache reading from UTF-8 to UTF-16. Stop StorageController from loading its storage on instantiation as it isn't awaitable, rendering it useless on first access and requiring to call it externally, essentially calling it twice. --- Parse/Internal/Storage/Controller/StorageController.cs | 6 +++--- Parse/Internal/Utilities/StorageManager.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Parse/Internal/Storage/Controller/StorageController.cs b/Parse/Internal/Storage/Controller/StorageController.cs index f5619882..bc6632e9 100644 --- a/Parse/Internal/Storage/Controller/StorageController.cs +++ b/Parse/Internal/Storage/Controller/StorageController.cs @@ -142,9 +142,9 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() TaskQueue Queue { get; } = new TaskQueue { }; /// - /// Creates a Parse storage controller and attempts to extract a previously created settings storage file from the persistent storage location. + /// Creates a Parse storage controller with the default file wrapper. /// - public StorageController() => Storage = new StorageDictionary(File = StorageManager.PersistentStorageFileWrapper); + public StorageController() => File = StorageManager.PersistentStorageFileWrapper; /// /// Creates a Parse storage controller with the provided wrapper. @@ -156,7 +156,7 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() /// Loads a settings dictionary from the file wrapped by . /// /// A storage dictionary containing the deserialized content of the storage file targeted by the instance - public Task> LoadAsync() => Queue.Enqueue(toAwait => toAwait.ContinueWith(_ => Task.FromResult((IStorageDictionary) Storage) ?? (Storage = new StorageDictionary(File)).LoadAsync().OnSuccess(__ => Storage as IStorageDictionary)).Unwrap(), CancellationToken.None); + public Task> LoadAsync() => Queue.Enqueue(toAwait => toAwait.ContinueWith(_ => (Storage != null) ? Task.FromResult((IStorageDictionary) Storage) : (Storage = new StorageDictionary(File)).LoadAsync().OnSuccess(__ => Storage as IStorageDictionary)).Unwrap(), CancellationToken.None); /// /// diff --git a/Parse/Internal/Utilities/StorageManager.cs b/Parse/Internal/Utilities/StorageManager.cs index 4843057e..cac0cc6f 100644 --- a/Parse/Internal/Utilities/StorageManager.cs +++ b/Parse/Internal/Utilities/StorageManager.cs @@ -41,7 +41,7 @@ public static async Task WriteToAsync(this FileInfo file, string content) /// A task that should contain the little-endian 16-bit character string (UTF-16) extracted from the if the read completes successfully public static async Task ReadAllTextAsync(this FileInfo file) { - using (StreamReader reader = file.OpenText()) + using (var reader = new StreamReader(file.FullName, Encoding.Unicode)) return await reader.ReadToEndAsync(); }