Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ZIP streaming decompression #1037

Open
wants to merge 59 commits into
base: dev/exp
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
238d5a1
Added support for ZIP compressed package streaming download
iamscottxu Aug 15, 2024
038243a
Merge branch 'main' of https://github.com/Scighost/Starward
iamscottxu Aug 15, 2024
248af32
Fixed Chinese translation error for streaming download options
iamscottxu Aug 15, 2024
60e59c1
Adjusted the conditions for automatic deletion of ZIP central directo…
iamscottxu Aug 15, 2024
7eb4b97
Fixed Chinese translation error for streaming `Default Game Installat…
iamscottxu Aug 16, 2024
ad36ad1
remove an unnecessary judgment `if(FileInfo.Exists)FileInfo.Delete;`
iamscottxu Aug 16, 2024
ddceb6b
fixed a bug where the ZipStreamDownload resource file could not be found
iamscottxu Aug 16, 2024
ab656c8
HttpClientHandler has been deprecated and replaced SocketsHttpHandler
iamscottxu Aug 16, 2024
ccf9d53
Merge branch 'SocketsHttpHandler' into streamdownload
iamscottxu Aug 16, 2024
eff47d8
fixed a bug where streaming download tasks could run in parallel and …
iamscottxu Aug 17, 2024
6f97c05
fixed a bug that could cause a download task to end prematurely when …
iamscottxu Aug 17, 2024
be2caed
fixed a bug where exceptions might not be caught when streaming downl…
iamscottxu Aug 17, 2024
ec1257d
fixed a bug where exceptions during streaming downloads would be inco…
iamscottxu Aug 17, 2024
d161ba2
fixed a bug where an error occurred when an HttpServerNotSupportedPar…
iamscottxu Aug 18, 2024
cbc0e68
HTTP LastModified is no longer required to be present when streaming …
iamscottxu Aug 18, 2024
28b8c7d
resolve domain names in advance before streaming downloads
iamscottxu Aug 18, 2024
5fb6513
fixed a bug in ContentType validation when ZIP streaming download
iamscottxu Aug 19, 2024
7fadea2
fixed a bug where cancel exceptions were not caught when streaming do…
iamscottxu Aug 20, 2024
cb7be67
added Canceling status because streaming downloads take too long to c…
iamscottxu Aug 20, 2024
81770d3
disk space pre-allocation and read/write cache optimization for strea…
iamscottxu Aug 21, 2024
cb8247a
optimized the thread scheduling logic of streaming download mode, and…
iamscottxu Aug 22, 2024
50ea759
fixed a bug where central directory files were not closed after task …
iamscottxu Aug 22, 2024
4784d5e
optimized the code for streaming download
iamscottxu Aug 22, 2024
d97bc30
removed redundant code for streaming downloads
iamscottxu Aug 22, 2024
e1cc38a
adjusted the code format
iamscottxu Aug 22, 2024
d2d7196
optimized the code of streaming download speed limiter
iamscottxu Aug 22, 2024
1def457
Merge branch 'main' into streamdownload
iamscottxu Aug 25, 2024
daa4bbd
added "Cancelling" message
iamscottxu Aug 25, 2024
f33702f
globally limit the maximum number of connections per server and optim…
iamscottxu Aug 25, 2024
101e7b1
Merge branch 'main' into streamdownload
iamscottxu Aug 27, 2024
352d4c1
added missing `ConfigureAwait`
iamscottxu Aug 29, 2024
e2f0e4f
Merge branch 'main' into streamdownload
iamscottxu Aug 29, 2024
a4db541
streaming download: optimized the retry speed when network errors occur
iamscottxu Aug 29, 2024
aa03f15
submit missing file
iamscottxu Aug 29, 2024
61eeaa0
removed redundant code
iamscottxu Aug 29, 2024
23aa9fd
optimized the code of stream download
iamscottxu Aug 31, 2024
81c3f1d
Merge branch 'streamdownload' into streamdownload_optimization
iamscottxu Aug 31, 2024
cf4ce68
Merge branch 'main' into streamdownload
iamscottxu Sep 1, 2024
3e6b2e6
Merge branch 'streamdownload' into streamdownload_optimization
iamscottxu Sep 1, 2024
d7bce53
optimized the speed of DNS resolution during streaming downloads.
iamscottxu Sep 3, 2024
6a7d922
optimized the number of threads that need to be started when there ar…
iamscottxu Sep 5, 2024
dc09431
Merge branch 'main' into streamdownload
iamscottxu Sep 7, 2024
57da19b
fixed the bug that method `CurrentTaskFinished` was executed multiple…
iamscottxu Sep 8, 2024
e64c24c
handling exception, deleted voice code
iamscottxu Sep 8, 2024
640f41e
Merge branch 'bug_fix' into streamdownload
iamscottxu Sep 8, 2024
631be21
fixed typo of variable name
iamscottxu Sep 8, 2024
cc0a99d
fixed typo in variable name
iamscottxu Sep 8, 2024
b9f2ebd
Merge branch 'bug_fix' into streamdownload
iamscottxu Sep 8, 2024
9ad0944
fixed a bug where only the first step of the task could be run if the…
iamscottxu Sep 8, 2024
671d245
Merge branch 'bug_fix' into streamdownload
iamscottxu Sep 8, 2024
a5b1980
Merge branch 'main' into streamdownload
iamscottxu Sep 8, 2024
7b8df5c
fixed bug where task would not continue after streaming download comp…
iamscottxu Sep 9, 2024
2ea68fe
Merge branch 'main' into streamdownload
iamscottxu Sep 17, 2024
b72c87c
Added judgment to skip relevant code when streaming download without …
iamscottxu Sep 17, 2024
1656da6
because the "pausing" state was added, some codes were restored
iamscottxu Sep 17, 2024
0674c97
fixed a bug where speed limiting didn't work when streaming downloads
iamscottxu Sep 17, 2024
533129e
Merge branch 'dev/exp' into streamdownload
iamscottxu Oct 17, 2024
e698cb1
Optimized the update logic during streaming download. First download …
iamscottxu Oct 18, 2024
875520d
removed redundant dependencies
iamscottxu Oct 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Starward.sln
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Starward.Launcher", "src\St
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Starward.Language", "src\Starward.Language\Starward.Language.csproj", "{5FC2380B-F424-4EAE-BDEE-C0D4D4B1C7CF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Starward.Core.ZipStreamDownload", "src\Starward.Core.ZipStreamDownload\Starward.Core.ZipStreamDownload.csproj", "{AAD0ECEC-1814-4CCE-AF0D-EF1C9EB627DA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -92,6 +94,22 @@ Global
{5FC2380B-F424-4EAE-BDEE-C0D4D4B1C7CF}.Release|x64.Build.0 = Release|Any CPU
{5FC2380B-F424-4EAE-BDEE-C0D4D4B1C7CF}.Release|x86.ActiveCfg = Release|Any CPU
{5FC2380B-F424-4EAE-BDEE-C0D4D4B1C7CF}.Release|x86.Build.0 = Release|Any CPU
{AAD0ECEC-1814-4CCE-AF0D-EF1C9EB627DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AAD0ECEC-1814-4CCE-AF0D-EF1C9EB627DA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AAD0ECEC-1814-4CCE-AF0D-EF1C9EB627DA}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{AAD0ECEC-1814-4CCE-AF0D-EF1C9EB627DA}.Debug|ARM64.Build.0 = Debug|Any CPU
{AAD0ECEC-1814-4CCE-AF0D-EF1C9EB627DA}.Debug|x64.ActiveCfg = Debug|Any CPU
{AAD0ECEC-1814-4CCE-AF0D-EF1C9EB627DA}.Debug|x64.Build.0 = Debug|Any CPU
{AAD0ECEC-1814-4CCE-AF0D-EF1C9EB627DA}.Debug|x86.ActiveCfg = Debug|Any CPU
{AAD0ECEC-1814-4CCE-AF0D-EF1C9EB627DA}.Debug|x86.Build.0 = Debug|Any CPU
{AAD0ECEC-1814-4CCE-AF0D-EF1C9EB627DA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AAD0ECEC-1814-4CCE-AF0D-EF1C9EB627DA}.Release|Any CPU.Build.0 = Release|Any CPU
{AAD0ECEC-1814-4CCE-AF0D-EF1C9EB627DA}.Release|ARM64.ActiveCfg = Release|Any CPU
{AAD0ECEC-1814-4CCE-AF0D-EF1C9EB627DA}.Release|ARM64.Build.0 = Release|Any CPU
{AAD0ECEC-1814-4CCE-AF0D-EF1C9EB627DA}.Release|x64.ActiveCfg = Release|Any CPU
{AAD0ECEC-1814-4CCE-AF0D-EF1C9EB627DA}.Release|x64.Build.0 = Release|Any CPU
{AAD0ECEC-1814-4CCE-AF0D-EF1C9EB627DA}.Release|x86.ActiveCfg = Release|Any CPU
{AAD0ECEC-1814-4CCE-AF0D-EF1C9EB627DA}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.Diagnostics.CodeAnalysis;
using Starward.Core.ZipStreamDownload.Resources;

namespace Starward.Core.ZipStreamDownload.Exceptions;

/// <summary>
/// 当CRC校验失败时引发的异常
/// </summary>
public class CrcVerificationFailedException : ZipStreamDownloadException
{
/// <summary>
/// 创建一个当CRC校验失败时引发的异常的实例。
/// </summary>
/// <param name="message">异常消息</param>
public CrcVerificationFailedException(string? message) : base(message)
{
}

/// <summary>
/// 创建一个当CRC校验失败时引发的异常的实例。
/// </summary>
/// <param name="message">异常消息</param>
/// <param name="innerException">引发该异常的异常</param>
public CrcVerificationFailedException(string? message, Exception? innerException) : base(message, innerException)
{
}

/// <summary>
/// 使用ZipEntry的名称引发CRC校验失败时引发的异常。
/// </summary>
/// <param name="zipEntryName">ZipEntry的名称</param>
/// <exception cref="InvalidZipEntryNameException">当CRC校验失败时引发此异常。</exception>
[DoesNotReturn]
internal static void ThrowByZipEntryName(string zipEntryName)
{
throw new InvalidZipEntryNameException(
string.Format(ExceptionMessages.CrcVerificationFailedExceptionMessage, zipEntryName));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.Diagnostics.CodeAnalysis;
using Starward.Core.ZipStreamDownload.Resources;

namespace Starward.Core.ZipStreamDownload.Exceptions;

/// <summary>
/// 当解压ZIP文件所需的功能不受支持时引发的异常。
/// </summary>
public class FeatureNotSupportedException : ZipStreamDownloadException
{
/// <summary>
/// 创建一个当解压ZIP文件所需的功能不受支持时引发的异常的实例。
/// </summary>
/// <param name="message">异常消息</param>
public FeatureNotSupportedException(string? message) : base(message)
{
}

/// <summary>
/// 创建一个当解压ZIP文件所需的功能不受支持时引发的异常的实例。
/// </summary>
/// <param name="message">异常消息</param>
/// <param name="innerException">引发该异常的异常</param>
public FeatureNotSupportedException(string? message, Exception? innerException) : base(message, innerException)
{
}

/// <summary>
/// 使用原因引发解压ZIP文件所需的功能不受支持的异常。
/// </summary>
/// <param name="reason">引发该异常的原因</param>
/// <exception cref="InvalidZipEntryNameException">当解压ZIP文件所需的功能不受支持时引发此异常。</exception>
[DoesNotReturn]
internal static void ThrowByReason(string reason)
{
throw new InvalidZipEntryNameException(
string.Format(ExceptionMessages.FeatureNotSupportedExceptionMessage, reason));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.Diagnostics.CodeAnalysis;
using Starward.Core.ZipStreamDownload.Resources;

namespace Starward.Core.ZipStreamDownload.Exceptions;

/// <summary>
/// 当ZIP实体的名称无效时引发的异常。
/// </summary>
public class InvalidZipEntryNameException : ZipStreamDownloadException
{
/// <summary>
/// 创建一个当ZIP实体的名称无效时引发的异常的实例。
/// </summary>
/// <param name="message">异常消息</param>
public InvalidZipEntryNameException(string? message) : base(message)
{
}

/// <summary>
/// 创建一个当ZIP实体的名称无效时引发的异常的实例。
/// </summary>
/// <param name="message">异常消息</param>
/// <param name="innerException">引发该异常的异常</param>
public InvalidZipEntryNameException(string? message, Exception? innerException) : base(message, innerException)
{
}

/// <summary>
/// 使用ZIP实体名称引发ZIP实体的名称无效的异常。
/// </summary>
/// <param name="zipEntryName">ZIP实体名称</param>
/// <exception cref="InvalidZipEntryNameException">当ZIP实体的名称无效时引发此异常。</exception>
[DoesNotReturn]
internal static void ThrowByZipEntryName(string zipEntryName)
{
throw new InvalidZipEntryNameException(
string.Format(ExceptionMessages.ZipEntryFileNameNotFoundExceptionMessage, zipEntryName));
}
}
36 changes: 36 additions & 0 deletions src/Starward.Core.ZipStreamDownload/Exceptions/ThrowException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Runtime.CompilerServices;
using ICSharpCode.SharpZipLib.Zip;
using Starward.Core.ZipStreamDownload.Resources;

namespace Starward.Core.ZipStreamDownload.Exceptions;

/// <summary>
/// 异常帮助类(当满足特定条件时抛出特定异常)
/// </summary>
internal static class ThrowException
{
/// <summary>
/// 如果给定的目录不存在则引发找不到路径的异常。
/// </summary>
/// <param name="directoryInfo">要进行检查的目录信息</param>
/// <exception cref="DirectoryNotFoundException">当给定的路径不存在时引发此异常</exception>
public static void ThrowDirectoryNotFoundExceptionIfDirectoryNotExists(DirectoryInfo directoryInfo)
{
if (!directoryInfo.Exists)
throw new DirectoryNotFoundException(
string.Format(ExceptionMessages.DirectoryNotFoundExceptionMessage, directoryInfo.FullName));
}

/// <summary>
/// 如ZipEntry不为文件时引发异常。
/// </summary>
/// <param name="zipEntry"><see cref="ZipEntry"/>的实例</param>
/// <param name="paramName">参数名称</param>
/// <exception cref="ArgumentException">当参数错误时引发的异常</exception>
public static void ThrowArgumentExceptionIfZipEntryNotIsFile(ZipEntry zipEntry,
[CallerArgumentExpression(nameof(zipEntry))] string? paramName = null)
{
if (!zipEntry.IsFile)
throw new ArgumentException(ExceptionMessages.ZipEntryNotIsFileArgumentExceptionMessage, paramName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Diagnostics.CodeAnalysis;
using Starward.Core.ZipStreamDownload.Resources;

namespace Starward.Core.ZipStreamDownload.Exceptions;

/// <summary>
/// 当ZIP文件测试失败时引发的异常。
/// </summary>
public class ZipFileTestFailedException : ZipStreamDownloadException
{
/// <summary>
/// 创建一个当ZIP文件测试失败时引发的异常的实例。
/// </summary>
/// <param name="message">异常消息</param>
public ZipFileTestFailedException(string? message) : base(message)
{
}

/// <summary>
/// 创建一个当ZIP文件测试失败时引发的异常的实例。
/// </summary>
/// <param name="message">异常消息</param>
/// <param name="innerException">引发该异常的异常</param>
public ZipFileTestFailedException(string? message, Exception? innerException) : base(message, innerException)
{
}

/// <summary>
/// 根据ZIP实体名称和异常原因引发ZIP文件测试失败的异常。
/// </summary>
/// <param name="zipEntryName">ZIP实体名称</param>
/// <param name="reason">异常原因</param>
/// <exception cref="InvalidZipEntryNameException">当ZIP文件测试失败时引发此异常。</exception>
[DoesNotReturn]
internal static void ThrowByZipEntryNameAndReason(string zipEntryName, string reason)
{
throw new InvalidZipEntryNameException(
string.Format(ExceptionMessages.ZipFileTestFailedExceptionMessage, zipEntryName, reason));
}

/// <summary>
/// 根据中心文件下载时的异常原因引发ZIP文件测试失败的异常。
/// </summary>
/// <param name="reason">异常原因</param>
/// <exception cref="InvalidZipEntryNameException">当ZIP文件测试失败时引发此异常。</exception>
[DoesNotReturn]
internal static void ThrowByReasonCentralDirectory(string reason)
{
throw new InvalidZipEntryNameException(
string.Format(ExceptionMessages.ZipFileTestFailedExceptionCentralDirectoryMessage, reason));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace Starward.Core.ZipStreamDownload.Exceptions;

/// <summary>
/// 当ZIP流式下载时出现错误引发的异常。
/// </summary>
public class ZipStreamDownloadException : Exception
{
/// <summary>
/// 创建一个当ZIP流式下载时出现错误引发的异常的实例。
/// </summary>
/// <param name="message">异常消息</param>
public ZipStreamDownloadException(string? message) : base(message)
{
}

/// <summary>
/// 创建一个当ZIP流式下载时出现错误引发的异常的实例。
/// </summary>
/// <param name="message">异常消息</param>
/// <param name="innerException">引发该异常的异常</param>
public ZipStreamDownloadException(string? message, Exception? innerException) : base(message, innerException)
{
}
}
Loading
Loading