Skip to content

Commit

Permalink
BugFix ASFFreeGamesOptionsLoader #110
Browse files Browse the repository at this point in the history
  • Loading branch information
maxisoft committed Dec 3, 2024
1 parent 3aa01e5 commit ca6c407
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions ASFFreeGames/Configurations/ASFFreeGamesOptionsLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<byte> buffer = MemoryPool<byte>.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;
Expand All @@ -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<byte>) buffer)[..read], cancellationToken).ConfigureAwait(false);
fs.SetLength(read);

throw;
Expand Down

0 comments on commit ca6c407

Please sign in to comment.