Skip to content

Commit

Permalink
Disable FileOptions.Asynchronous across the app
Browse files Browse the repository at this point in the history
  • Loading branch information
neon-nyan committed Oct 31, 2024
1 parent ef33544 commit 8e5b7ed
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 88 deletions.
48 changes: 23 additions & 25 deletions CollapseLauncher/Classes/Helper/Image/ImageLoaderHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -490,38 +490,36 @@ public static async ValueTask TryDownloadToCompleteness(string url, FileInfo fil

Logger.LogWriteLine($"Start downloading resource from: {url}", LogType.Default, true);

if (fileInfo.Exists)
fileInfo.Delete();

// Try to get the remote stream and download the file
await using Stream netStream = await FallbackCDNUtil.GetHttpStreamFromResponse(url, token);
await using (Stream outStream = fileInfoTemp.Open(new FileStreamOptions()
await using (Stream netStream = await FallbackCDNUtil.GetHttpStreamFromResponse(url, token))
{
Access = FileAccess.Write,
Mode = FileMode.Create,
Share = FileShare.ReadWrite,
Options = FileOptions.Asynchronous
}))
{
// Get the file length
fileLength = netStream.Length;

// Create the prop file for download completeness checking
string outputParentPath = Path.GetDirectoryName(fileInfoTemp.FullName);
string outputFilename = Path.GetFileName(fileInfoTemp.FullName);
if (outputParentPath != null)
await using (Stream outStream = fileInfoTemp.Create())
{
string propFilePath = Path.Combine(outputParentPath, $"{outputFilename}#{netStream.Length}");
await File.Create(propFilePath).DisposeAsync();
// Get the file length
fileLength = netStream.Length;

// Create the prop file for download completeness checking
string outputParentPath = Path.GetDirectoryName(fileInfoTemp.FullName);
string outputFilename = Path.GetFileName(fileInfoTemp.FullName);
if (outputParentPath != null)
{
string propFilePath = Path.Combine(outputParentPath, $"{outputFilename}#{netStream.Length}");
await File.Create(propFilePath).DisposeAsync();
}

// Copy (and download) the remote streams to local
int read;
while ((read = await netStream.ReadAsync(buffer, token)) > 0)
await outStream.WriteAsync(buffer, 0, read, token);
}

// Copy (and download) the remote streams to local
int read;
while ((read = await netStream.ReadAsync(buffer, token)) > 0)
await outStream.WriteAsync(buffer, 0, read, token);
}

// If the file has already been downloaded, then move to its original filename
if (fileInfoTemp.Exists)
fileInfoTemp.MoveTo(fileInfo.FullName, true);
// Move to its original filename
fileInfoTemp.Refresh();
fileInfoTemp.MoveTo(fileInfo.FullName, true);

Logger.LogWriteLine($"Resource download from: {url} has been completed and stored locally into:"
+ $"\"{fileInfo.FullName}\" with size: {ConverterTool.SummarizeSizeSimple(fileLength)} ({fileLength} bytes)", LogType.Default, true);
Expand Down
12 changes: 3 additions & 9 deletions CollapseLauncher/Classes/Helper/StreamUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,21 @@ internal static class StreamUtility
{
Mode = FileMode.Open,
Access = FileAccess.Read,
Share = FileShare.Read,
BufferSize = DefaultBufferSize,
Options = FileOptions.Asynchronous | FileOptions.RandomAccess
Share = FileShare.Read
};

internal static readonly FileStreamOptions FileStreamCreateWriteOpt = new FileStreamOptions
{
Mode = FileMode.Create,
Access = FileAccess.Write,
Share = FileShare.Write,
BufferSize = DefaultBufferSize,
Options = FileOptions.Asynchronous | FileOptions.RandomAccess
Share = FileShare.Write
};

internal static readonly FileStreamOptions FileStreamCreateReadWriteOpt = new FileStreamOptions
{
Mode = FileMode.Create,
Access = FileAccess.ReadWrite,
Share = FileShare.ReadWrite,
BufferSize = DefaultBufferSize,
Options = FileOptions.Asynchronous | FileOptions.RandomAccess
Share = FileShare.ReadWrite
};

/*
Expand Down
3 changes: 1 addition & 2 deletions CollapseLauncher/Classes/ShortcutCreator/SteamShortcut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ private static async ValueTask DownloadImage(FileInfo fileInfo, string url, Canc
{
Access = FileAccess.Write,
Mode = FileMode.Create,
Share = FileShare.ReadWrite,
Options = FileOptions.Asynchronous
Share = FileShare.ReadWrite
});

// Get the file length
Expand Down
20 changes: 0 additions & 20 deletions Hi3Helper.CommunityToolkit/ImageCropper/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@
"Microsoft.WindowsAppSDK": "1.5.240311000"
}
},
"Microsoft.DotNet.ILCompiler": {
"type": "Direct",
"requested": "[9.0.0-rc.2.24473.5, )",
"resolved": "9.0.0-rc.2.24473.5",
"contentHash": "+4KH+fbuWXX+I1nM+iP84N0nnorwxY3N8SrNLDNdWdblCPcWXSZnnst/IS+NEHTavnoTErwFNwk7IP8rPrNAQA=="
},
"Microsoft.Graphics.Win2D": {
"type": "Direct",
"requested": "[1.3.0, )",
Expand Down Expand Up @@ -92,15 +86,6 @@
}
},
"net9.0-windows10.0.22621/win-x64": {
"Microsoft.DotNet.ILCompiler": {
"type": "Direct",
"requested": "[9.0.0-rc.2.24473.5, )",
"resolved": "9.0.0-rc.2.24473.5",
"contentHash": "+4KH+fbuWXX+I1nM+iP84N0nnorwxY3N8SrNLDNdWdblCPcWXSZnnst/IS+NEHTavnoTErwFNwk7IP8rPrNAQA==",
"dependencies": {
"runtime.win-x64.Microsoft.DotNet.ILCompiler": "9.0.0-rc.2.24473.5"
}
},
"Microsoft.Graphics.Win2D": {
"type": "Direct",
"requested": "[1.3.0, )",
Expand All @@ -125,11 +110,6 @@
"Microsoft.Web.WebView2": "1.0.2651.64",
"Microsoft.Windows.SDK.BuildTools": "10.0.22621.756"
}
},
"runtime.win-x64.Microsoft.DotNet.ILCompiler": {
"type": "Transitive",
"resolved": "9.0.0-rc.2.24473.5",
"contentHash": "gtZORh0O2hlNn8D+ezseJs1SEAI83Ca+LC8vmAIqaYUbiAn5+6iqD+ytuztGo4Thjr/2qWXKn3l7GGQEQiCJMg=="
}
}
}
Expand Down
20 changes: 0 additions & 20 deletions Hi3Helper.CommunityToolkit/SettingsControls/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@
"Microsoft.WindowsAppSDK": "1.5.240311000"
}
},
"Microsoft.DotNet.ILCompiler": {
"type": "Direct",
"requested": "[9.0.0-rc.2.24473.5, )",
"resolved": "9.0.0-rc.2.24473.5",
"contentHash": "+4KH+fbuWXX+I1nM+iP84N0nnorwxY3N8SrNLDNdWdblCPcWXSZnnst/IS+NEHTavnoTErwFNwk7IP8rPrNAQA=="
},
"Microsoft.NET.ILLink.Tasks": {
"type": "Direct",
"requested": "[9.0.0-rc.2.24473.5, )",
Expand Down Expand Up @@ -80,15 +74,6 @@
}
},
"net9.0-windows10.0.22621/win-x64": {
"Microsoft.DotNet.ILCompiler": {
"type": "Direct",
"requested": "[9.0.0-rc.2.24473.5, )",
"resolved": "9.0.0-rc.2.24473.5",
"contentHash": "+4KH+fbuWXX+I1nM+iP84N0nnorwxY3N8SrNLDNdWdblCPcWXSZnnst/IS+NEHTavnoTErwFNwk7IP8rPrNAQA==",
"dependencies": {
"runtime.win-x64.Microsoft.DotNet.ILCompiler": "9.0.0-rc.2.24473.5"
}
},
"Microsoft.Web.WebView2": {
"type": "Direct",
"requested": "[1.0.2895-prerelease, )",
Expand All @@ -104,11 +89,6 @@
"Microsoft.Web.WebView2": "1.0.2651.64",
"Microsoft.Windows.SDK.BuildTools": "10.0.22621.756"
}
},
"runtime.win-x64.Microsoft.DotNet.ILCompiler": {
"type": "Transitive",
"resolved": "9.0.0-rc.2.24473.5",
"contentHash": "gtZORh0O2hlNn8D+ezseJs1SEAI83Ca+LC8vmAIqaYUbiAn5+6iqD+ytuztGo4Thjr/2qWXKn3l7GGQEQiCJMg=="
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions Hi3Helper.Core/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
"version": 1,
"dependencies": {
"net9.0-windows10.0.22621": {
"Microsoft.DotNet.ILCompiler": {
"type": "Direct",
"requested": "[9.0.0-rc.2.24473.5, )",
"resolved": "9.0.0-rc.2.24473.5",
"contentHash": "+4KH+fbuWXX+I1nM+iP84N0nnorwxY3N8SrNLDNdWdblCPcWXSZnnst/IS+NEHTavnoTErwFNwk7IP8rPrNAQA=="
},
"Microsoft.NET.ILLink.Tasks": {
"type": "Direct",
"requested": "[9.0.0-rc.2.24473.5, )",
Expand Down
6 changes: 0 additions & 6 deletions InnoSetupHelper/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
"version": 1,
"dependencies": {
"net9.0": {
"Microsoft.DotNet.ILCompiler": {
"type": "Direct",
"requested": "[9.0.0-rc.2.24473.5, )",
"resolved": "9.0.0-rc.2.24473.5",
"contentHash": "+4KH+fbuWXX+I1nM+iP84N0nnorwxY3N8SrNLDNdWdblCPcWXSZnnst/IS+NEHTavnoTErwFNwk7IP8rPrNAQA=="
},
"Microsoft.NET.ILLink.Tasks": {
"type": "Direct",
"requested": "[9.0.0-rc.2.24473.5, )",
Expand Down

0 comments on commit 8e5b7ed

Please sign in to comment.