Skip to content
This repository has been archived by the owner on Mar 15, 2024. It is now read-only.

Commit

Permalink
Revert asynchronous file IO in .NET 8
Browse files Browse the repository at this point in the history
  • Loading branch information
SadPencil committed Feb 20, 2024
1 parent 76e59b5 commit 9ae5ee6
Showing 1 changed file with 12 additions and 77 deletions.
89 changes: 12 additions & 77 deletions ClientUpdater/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,12 @@ private static void ReadLegacyUpdaterConfig(List<UpdateMirror> updateMirrors)
}
}

private static FileStream NewFileStream(string filename)
{
var fileStream = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.None, 4096, FileOptions.Asynchronous);
return fileStream;
}

/// <summary>
/// Performs a version file check on update server.
/// </summary>
Expand Down Expand Up @@ -615,31 +621,13 @@ private static async Task DoVersionCheckAsync()
{
Logger.Log("Updater: Trying to connect to update mirror " + updateMirrors[currentUpdateMirrorIndex].URL);

#if NETFRAMEWORK
var fileStream = new FileStream(downloadFile.FullName, FileMode.Create, FileAccess.Write, FileShare.None, 4096, FileOptions.Asynchronous);
#else
var fileStream = new FileStream(downloadFile.FullName, new FileStreamOptions
{
Access = FileAccess.Write,
Mode = FileMode.Create,
Options = FileOptions.Asynchronous,
Share = FileShare.None
});
#endif
FileStream fileStream = NewFileStream(downloadFile.FullName);

#if NETFRAMEWORK
using (fileStream)
#else
await using (fileStream.ConfigureAwait(false))
#endif
{
Stream stream = await SharedHttpClient.GetStreamAsync(updateMirrors[currentUpdateMirrorIndex].URL + VERSION_FILE).ConfigureAwait(false);

#if NETFRAMEWORK
using (stream)
#else
await using (stream.ConfigureAwait(false))
#endif
{
await stream.CopyToAsync(fileStream).ConfigureAwait(false);
}
Expand Down Expand Up @@ -791,31 +779,14 @@ private static async ValueTask ExecuteAfterUpdateScriptAsync()
try
{
string downloadFile = SafePath.CombineFilePath(GamePath, "updateexec");
#if NETFRAMEWORK
var fileStream = new FileStream(downloadFile, FileMode.Create, FileAccess.Write, FileShare.None, 4096, FileOptions.Asynchronous);
#else
var fileStream = new FileStream(downloadFile, new FileStreamOptions
{
Access = FileAccess.Write,
Mode = FileMode.Create,
Options = FileOptions.Asynchronous,
Share = FileShare.None
});
#endif

FileStream fileStream = NewFileStream(downloadFile);

#if NETFRAMEWORK
using (fileStream)
#else
await using (fileStream.ConfigureAwait(false))
#endif
{
Stream stream = await SharedHttpClient.GetStreamAsync(updateMirrors[currentUpdateMirrorIndex].URL + "updateexec").ConfigureAwait(false);

#if NETFRAMEWORK
using (stream)
#else
await using (stream.ConfigureAwait(false))
#endif
{
await stream.CopyToAsync(fileStream).ConfigureAwait(false);
}
Expand All @@ -840,31 +811,14 @@ private static async ValueTask<bool> ExecutePreUpdateScriptAsync()
try
{
string downloadFile = SafePath.CombineFilePath(GamePath, "preupdateexec");
#if NETFRAMEWORK
var fileStream = new FileStream(downloadFile, FileMode.Create, FileAccess.Write, FileShare.None, 4096, FileOptions.Asynchronous);
#else
var fileStream = new FileStream(downloadFile, new FileStreamOptions
{
Access = FileAccess.Write,
Mode = FileMode.Create,
Options = FileOptions.Asynchronous,
Share = FileShare.None
});
#endif

FileStream fileStream = NewFileStream(downloadFile);

#if NETFRAMEWORK
using (fileStream)
#else
await using (fileStream.ConfigureAwait(false))
#endif
{
Stream stream = await SharedHttpClient.GetStreamAsync(updateMirrors[currentUpdateMirrorIndex].URL + "preupdateexec").ConfigureAwait(false);

#if NETFRAMEWORK
using (stream)
#else
await using (stream.ConfigureAwait(false))
#endif
{
await stream.CopyToAsync(fileStream).ConfigureAwait(false);
}
Expand Down Expand Up @@ -1474,31 +1428,12 @@ private static async ValueTask<string> DownloadFileAsync(UpdaterFileInfo fileInf
else
{
Logger.Log("Updater: Downloading file " + filename + extraExtension);
#if NETFRAMEWORK
var fileStream = new FileStream(downloadFile.FullName, FileMode.Create, FileAccess.Write, FileShare.None, 4096, FileOptions.Asynchronous);
#else
var fileStream = new FileStream(downloadFile.FullName, new FileStreamOptions
{
Access = FileAccess.Write,
Mode = FileMode.Create,
Options = FileOptions.Asynchronous,
Share = FileShare.None
});
#endif

#if NETFRAMEWORK
FileStream fileStream = NewFileStream(downloadFile.FullName);
using (fileStream)
#else
await using (fileStream.ConfigureAwait(false))
#endif
{
Stream stream = await SharedHttpClient.GetStreamAsync(new Uri(uriString)).ConfigureAwait(false);

#if NETFRAMEWORK
using (stream)
#else
await using (stream.ConfigureAwait(false))
#endif
{
await stream.CopyToAsync(fileStream).ConfigureAwait(false);
}
Expand Down

0 comments on commit 9ae5ee6

Please sign in to comment.