mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.Deployment.git
synced 2025-11-19 21:08:45 +08:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5947280fe3 | ||
|
|
4ca20b57e3 | ||
|
|
b81ef222bd | ||
|
|
2f6275e165 | ||
|
|
748f3e19e1 |
@@ -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.3</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.3]
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
62
src/Snap.Hutao.Deployment/Package.cs
Normal file
62
src/Snap.Hutao.Deployment/Package.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Snap.Hutao.Deployment;
|
||||
|
||||
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 (HttpClientHandler handler = new() { UseCookies = false })
|
||||
{
|
||||
using (HttpClient httpClient = new(handler))
|
||||
{
|
||||
HttpShardCopyWorkerOptions<DownloadStatus> options = new()
|
||||
{
|
||||
HttpClient = httpClient,
|
||||
SourceUrl = "https://api.snapgenshin.com/patch/hutao/download",
|
||||
DestinationFilePath = packagePath,
|
||||
StatusFactory = (bytesRead, totalBytes) => new DownloadStatus(bytesRead, totalBytes),
|
||||
};
|
||||
|
||||
using (HttpShardCopyWorker<DownloadStatus> worker = await HttpShardCopyWorker<DownloadStatus>.CreateAsync(options).ConfigureAwait(false))
|
||||
{
|
||||
Progress<DownloadStatus> progress = new(ConsoleWriteProgress);
|
||||
await worker.CopyAsync(progress).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void ConsoleWriteProgress(DownloadStatus status)
|
||||
{
|
||||
Console.Write($"\r{status.ProgressDescription}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Snap.Hutao.Deployment;
|
||||
|
||||
internal static class PackageDownload
|
||||
{
|
||||
public static async Task DownloadPackageAsync(string packagePath)
|
||||
{
|
||||
using (HttpClient httpClient = new())
|
||||
{
|
||||
HttpShardCopyWorkerOptions<DownloadStatus> options = new()
|
||||
{
|
||||
HttpClient = httpClient,
|
||||
SourceUrl = "https://api.snapgenshin.com/patch/hutao/download",
|
||||
DestinationFilePath = packagePath,
|
||||
StatusFactory = (bytesRead, totalBytes) => new DownloadStatus(bytesRead, totalBytes),
|
||||
};
|
||||
|
||||
using (HttpShardCopyWorker<DownloadStatus> worker = await HttpShardCopyWorker<DownloadStatus>.CreateAsync(options).ConfigureAwait(false))
|
||||
{
|
||||
Progress<DownloadStatus> progress = new(ConsoleWriteProgress);
|
||||
await worker.CopyAsync(progress).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
static void ConsoleWriteProgress(DownloadStatus status)
|
||||
{
|
||||
Console.Write($"\r{status.ProgressDescription}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user