Compare commits

..

3 Commits
v0.4 ... v0.7

Author SHA1 Message Date
Kei-Luna
12df57b273 UpdateService fix 2026-04-27 16:41:14 +09:00
Kei-Luna
c109c82a91 update test 2026-04-27 16:35:38 +09:00
Kei-Luna
d214778af1 Changed the repository 2026-04-27 16:32:14 +09:00
2 changed files with 19 additions and 15 deletions

View File

@@ -13,10 +13,13 @@ public static class UpdateService
private static readonly Logger Logger = new("Updater");
private static readonly bool UpdateEnabled = true;
private static readonly bool AskBeforeUpdate = true;
private static readonly string RepositoryOwner = "DevilProMT";
private static readonly string RepositoryOwner = "MikuLeaks";
private static readonly string RepositoryName = "MikuSB";
private static readonly string AssetName = "MikuSB-win-x64.zip";
private static readonly int TimeoutSeconds = 5;
private static readonly int ReleaseCheckTimeoutSeconds = 10;
private static readonly int PackageDownloadTimeoutSeconds = 300;
private static readonly int ResourceDownloadTimeoutSeconds = 300;
private static readonly int ChecksumDownloadTimeoutSeconds = 30;
private static readonly string ResourceArchiveUrl =
"https://github.com/Kei-Luna/MikuSB-Resource/archive/refs/heads/main.zip";
private static readonly string[] RequiredResourceFiles =
@@ -50,8 +53,9 @@ public static class UpdateService
Logger.Info($"Current build version: {BuildVersion.Current}");
using var client = CreateHttpClient();
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(Math.Max(1, TimeoutSeconds)));
var release = await GetLatestReleaseAsync(client, cts.Token);
using var releaseCts =
new CancellationTokenSource(TimeSpan.FromSeconds(Math.Max(1, ReleaseCheckTimeoutSeconds)));
var release = await GetLatestReleaseAsync(client, releaseCts.Token);
if (release == null)
return false;
@@ -78,18 +82,18 @@ public static class UpdateService
var packagePath = Path.Combine(tempRoot, asset.Name);
Logger.Info($"Downloading update {release.TagName}.");
await DownloadFileAsync(client, asset.DownloadUrl, packagePath, cts.Token);
await DownloadFileAsync(client, asset.DownloadUrl, packagePath, PackageDownloadTimeoutSeconds);
var resourcePackagePath = Path.Combine(tempRoot, "MikuSB-Resource-main.zip");
Logger.Info("Downloading resource package.");
await DownloadFileAsync(client, ResourceArchiveUrl, resourcePackagePath, cts.Token);
await DownloadFileAsync(client, ResourceArchiveUrl, resourcePackagePath, ResourceDownloadTimeoutSeconds);
var checksumAsset = release.Assets.FirstOrDefault(x =>
string.Equals(x.Name, AssetName + ".sha256", StringComparison.OrdinalIgnoreCase));
if (checksumAsset != null)
{
var checksumPath = Path.Combine(tempRoot, checksumAsset.Name);
await DownloadFileAsync(client, checksumAsset.DownloadUrl, checksumPath, cts.Token);
await DownloadFileAsync(client, checksumAsset.DownloadUrl, checksumPath, ChecksumDownloadTimeoutSeconds);
VerifySha256(packagePath, checksumPath);
}
@@ -166,12 +170,11 @@ public static class UpdateService
private static async Task DownloadAndInstallResourcesAsync()
{
using var client = CreateHttpClient();
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(Math.Max(1, TimeoutSeconds)));
var tempRoot = Path.Combine(Path.GetTempPath(), "MikuSB", "resources", Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(tempRoot);
var resourcePackagePath = Path.Combine(tempRoot, "MikuSB-Resource-main.zip");
await DownloadFileAsync(client, ResourceArchiveUrl, resourcePackagePath, cts.Token);
await DownloadFileAsync(client, ResourceArchiveUrl, resourcePackagePath, ResourceDownloadTimeoutSeconds);
InstallResourcesFromArchive(resourcePackagePath,
Path.Combine(AppContext.BaseDirectory, ConfigManager.Config.Path.ResourcePath));
}
@@ -214,7 +217,7 @@ public static class UpdateService
{
var client = new HttpClient
{
Timeout = TimeSpan.FromSeconds(Math.Max(1, TimeoutSeconds))
Timeout = Timeout.InfiniteTimeSpan
};
client.DefaultRequestHeaders.UserAgent.Add(
@@ -251,14 +254,15 @@ public static class UpdateService
HttpClient client,
string downloadUrl,
string destinationPath,
CancellationToken cancellationToken)
int timeoutSeconds)
{
using var response = await client.GetAsync(downloadUrl, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(Math.Max(1, timeoutSeconds)));
using var response = await client.GetAsync(downloadUrl, HttpCompletionOption.ResponseHeadersRead, cts.Token);
response.EnsureSuccessStatusCode();
await using var source = await response.Content.ReadAsStreamAsync(cancellationToken);
await using var source = await response.Content.ReadAsStreamAsync(cts.Token);
await using var destination = File.Create(destinationPath);
await source.CopyToAsync(destination, cancellationToken);
await source.CopyToAsync(destination, cts.Token);
}
private static void CopyDirectory(string sourceDirectory, string targetDirectory)

View File

@@ -1 +1 @@
v=0.4
v=0.7