diff --git a/src/Snap.Hutao.Deployment.Runtime/Snap.Hutao.Deployment.Runtime.nuspec b/src/Snap.Hutao.Deployment.Runtime/Snap.Hutao.Deployment.Runtime.nuspec index d1b96d3..7376b98 100644 --- a/src/Snap.Hutao.Deployment.Runtime/Snap.Hutao.Deployment.Runtime.nuspec +++ b/src/Snap.Hutao.Deployment.Runtime/Snap.Hutao.Deployment.Runtime.nuspec @@ -2,7 +2,7 @@ Snap.Hutao.Deployment.Runtime - 1.16.0 + 1.16.1 DGP Studio true false diff --git a/src/Snap.Hutao.Deployment.Runtime/Snap.Hutao.Deployment.exe b/src/Snap.Hutao.Deployment.Runtime/Snap.Hutao.Deployment.exe index a2519fc..d7f4d01 100644 Binary files a/src/Snap.Hutao.Deployment.Runtime/Snap.Hutao.Deployment.exe and b/src/Snap.Hutao.Deployment.Runtime/Snap.Hutao.Deployment.exe differ diff --git a/src/Snap.Hutao.Deployment/Invocation.cs b/src/Snap.Hutao.Deployment/Invocation.cs index 059dbdd..c40caa9 100644 --- a/src/Snap.Hutao.Deployment/Invocation.cs +++ b/src/Snap.Hutao.Deployment/Invocation.cs @@ -1,8 +1,6 @@ using System; using System.CommandLine.Invocation; using System.Diagnostics; -using System.IO; -using System.Runtime.ExceptionServices; using System.Runtime.InteropServices; using System.Threading.Tasks; using Windows.Management.Deployment; @@ -25,7 +23,7 @@ public static async Task RunDeploymentAsync(InvocationContext context) ArgumentException.ThrowIfNullOrEmpty(path); Console.WriteLine($""" - Snap Hutao Deployment Tool [1.16.0] + Snap Hutao Deployment Tool [1.16.1] PackagePath: {path} FamilyName: {name} ------------------------------------------------------------ @@ -33,11 +31,11 @@ Snap Hutao Deployment Tool [1.16.0] try { - if (!File.Exists(path)) + if (!Package.EnsurePackage(path)) { Console.WriteLine(""" - 未找到包文件。 - Package file not found. + 未找到包文件或包文件损坏。 + Package file not found or corrupted. """); if (isUpdateMode) @@ -51,7 +49,7 @@ Package file not found. 开始下载包文件... Start downloading package... """); - await PackageDownload.DownloadPackageAsync(path).ConfigureAwait(false); + await Package.DownloadPackageAsync(path).ConfigureAwait(false); } } diff --git a/src/Snap.Hutao.Deployment/PackageDownload.cs b/src/Snap.Hutao.Deployment/Package.cs similarity index 63% rename from src/Snap.Hutao.Deployment/PackageDownload.cs rename to src/Snap.Hutao.Deployment/Package.cs index 7a43ba3..b1eda56 100644 --- a/src/Snap.Hutao.Deployment/PackageDownload.cs +++ b/src/Snap.Hutao.Deployment/Package.cs @@ -1,11 +1,37 @@ using System; +using System.IO; +using System.IO.Compression; using System.Net.Http; using System.Threading.Tasks; namespace Snap.Hutao.Deployment; -internal static class PackageDownload +internal static class Package { + public static bool EnsurePackage(string packagePath) + { + if (!File.Exists(packagePath)) + { + return false; + } + + try + { + using (FileStream packageStream = File.OpenRead(packagePath)) + { + using (new ZipArchive(packageStream, ZipArchiveMode.Read)) + { + return true; + } + } + } + catch (InvalidDataException) + { + File.Delete(packagePath); + return false; + } + } + public static async Task DownloadPackageAsync(string packagePath) { using (HttpClient httpClient = new())