mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.Deployment.git
synced 2025-11-19 21:08:45 +08:00
Merge pull request #8 from DGP-Studio/feat/corrupted
This commit is contained in:
@@ -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>
|
||||
|
||||
Binary file not shown.
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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())
|
||||
Reference in New Issue
Block a user