From ca6c40766016880b890763acbc8038b3aa683081 Mon Sep 17 00:00:00 2001 From: maxisoft Date: Tue, 3 Dec 2024 19:02:28 +0100 Subject: [PATCH] BugFix ASFFreeGamesOptionsLoader #110 --- .../Configurations/ASFFreeGamesOptionsLoader.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ASFFreeGames/Configurations/ASFFreeGamesOptionsLoader.cs b/ASFFreeGames/Configurations/ASFFreeGamesOptionsLoader.cs index 93e8835..805bebc 100644 --- a/ASFFreeGames/Configurations/ASFFreeGamesOptionsLoader.cs +++ b/ASFFreeGames/Configurations/ASFFreeGamesOptionsLoader.cs @@ -59,13 +59,12 @@ public static async Task Save(ASFFreeGamesOptions options, CancellationToken can try { #pragma warning disable CAC001 #pragma warning disable CA2007 - - // Use FileOptions.Asynchronous when creating a file stream for async operations - await using FileStream fs = new(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite, 4096, FileOptions.Asynchronous); + await using FileStream fs = new(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite); #pragma warning restore CA2007 #pragma warning restore CAC001 - using IMemoryOwner buffer = MemoryPool.Shared.Rent(checked(fs.Length > 0 ? (int) fs.Length + 1 : 1 << 15)); - int read = await fs.ReadAsync(buffer.Memory, cancellationToken).ConfigureAwait(false); + byte[] buffer = new byte[fs.Length > 0 ? (int) fs.Length + 1 : 1 << 15]; + + int read = await fs.ReadAsync(buffer, cancellationToken).ConfigureAwait(false); try { fs.Position = 0; @@ -76,7 +75,8 @@ public static async Task Save(ASFFreeGamesOptions options, CancellationToken can catch (Exception) { fs.Position = 0; - await fs.WriteAsync(buffer.Memory[..read], cancellationToken).ConfigureAwait(false); + + await fs.WriteAsync(((ReadOnlyMemory) buffer)[..read], cancellationToken).ConfigureAwait(false); fs.SetLength(read); throw;