Merge pull request #8 from DGP-Studio/feat/corrupted

This commit is contained in:
DismissedLight
2024-05-14 23:43:56 +08:00
committed by GitHub
4 changed files with 33 additions and 9 deletions

View File

@@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>Snap.Hutao.Deployment.Runtime</id>
<version>1.16.0</version>
<version>1.16.1</version>
<authors>DGP Studio</authors>
<developmentDependency>true</developmentDependency>
<requireLicenseAcceptance>false</requireLicenseAcceptance>

View File

@@ -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 @@ internal static partial class Invocation
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 @@ internal static partial class Invocation
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 @@ internal static partial class Invocation
...
Start downloading package...
""");
await PackageDownload.DownloadPackageAsync(path).ConfigureAwait(false);
await Package.DownloadPackageAsync(path).ConfigureAwait(false);
}
}

View File

@@ -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())