Skip to content

Commit

Permalink
Merge pull request #8 from DGP-Studio/feat/corrupted
Browse files Browse the repository at this point in the history
  • Loading branch information
Lightczx authored May 14, 2024
2 parents e31f23e + 2f6275e commit b81ef22
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Binary file modified src/Snap.Hutao.Deployment.Runtime/Snap.Hutao.Deployment.exe
Binary file not shown.
12 changes: 5 additions & 7 deletions src/Snap.Hutao.Deployment/Invocation.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -25,19 +23,19 @@ 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}
------------------------------------------------------------
""");

try
{
if (!File.Exists(path))
if (!Package.EnsurePackage(path))
{
Console.WriteLine("""
未找到包文件
Package file not found.
未找到包文件或包文件损坏
Package file not found or corrupted.
""");

if (isUpdateMode)
Expand All @@ -51,7 +49,7 @@ Package file not found.
开始下载包文件...
Start downloading package...
""");
await PackageDownload.DownloadPackageAsync(path).ConfigureAwait(false);
await Package.DownloadPackageAsync(path).ConfigureAwait(false);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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())
Expand Down

0 comments on commit b81ef22

Please sign in to comment.