5 Commits
1.16.0 ... main

Author SHA1 Message Date
qhy040404
5947280fe3 1.16.3 2024-06-25 22:48:44 +08:00
qhy040404
4ca20b57e3 UseCookies = false 2024-06-25 22:43:49 +08:00
DismissedLight
b81ef222bd Merge pull request #8 from DGP-Studio/feat/corrupted 2024-05-14 23:43:56 +08:00
qhy040404
2f6275e165 using new 2024-05-14 23:17:14 +08:00
qhy040404
748f3e19e1 ensure package is valid 2024-05-14 23:08:27 +08:00
5 changed files with 68 additions and 41 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.3</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.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);
}
}

View 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}");
}
}
}

View File

@@ -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}");
}
}
}