Skip to content

Commit 8d22196

Browse files
committed
fix: 修复更新包解压位置错误
1 parent 034c26a commit 8d22196

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

SRAFrontend/App.axaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ private static void ConfigureServices(IServiceCollection services)
7979
var announcementService = provider.GetRequiredService<AnnouncementService>();
8080
var settingsService = provider.GetRequiredService<SettingsService>();
8181
var updateService = provider.GetRequiredService<UpdateService>();
82-
return new MainWindowViewModel(pages, toastManager, announcementService, settingsService, updateService);
82+
var logger = provider.GetRequiredService<ILogger<MainWindowViewModel>>();
83+
return new MainWindowViewModel(pages, toastManager, announcementService, settingsService, updateService, logger);
8384
});
8485
services.AddTransient<HomePageViewModel>();
8586
services.AddTransient<TaskPageViewModel>();

SRAFrontend/Services/UpdateService.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ public string GetErrorMessage(int code)
6363
return await response.Content.ReadFromJsonAsync<VersionResponse>();
6464
}
6565

66+
/// <summary>
67+
/// 异步下载更新包
68+
/// </summary>
69+
/// <param name="versionResponse">版本响应模型</param>
70+
/// <param name="downloadChannel">下载渠道</param>
71+
/// <param name="statusProgress">下载状态回调</param>
72+
/// <param name="proxies">代理列表</param>
73+
/// <param name="cancellationToken">取消下载Token</param>
74+
/// <returns>更新文件的路径</returns>
75+
/// <exception cref="InvalidOperationException">下载地址无效或下载失败</exception>
76+
/// <exception cref="Exception"></exception>
6677
public async Task<string> DownloadUpdateAsync(
6778
VersionResponse versionResponse,
6879
int downloadChannel,

SRAFrontend/ViewModels/MainWindowViewModel.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.IO;
43
using System.Threading.Tasks;
54
using Avalonia.Collections;
65
using Avalonia.Controls;
76
using CommunityToolkit.Mvvm.ComponentModel;
87
using CommunityToolkit.Mvvm.Input;
98
using Markdown.Avalonia;
9+
using Microsoft.Extensions.Logging;
1010
using SRAFrontend.Controls;
11-
using SRAFrontend.Localization;
1211
using SRAFrontend.Models;
1312
using SRAFrontend.Services;
1413
using SRAFrontend.utilities;
@@ -25,27 +24,27 @@ public partial class MainWindowViewModel : ViewModelBase
2524
private readonly AnnouncementService _announcementService;
2625
private readonly SettingsService _settingsService;
2726
private readonly UpdateService _updateService;
27+
private readonly ILogger _logger;
2828

2929
[ObservableProperty] private string _lightModeText =
3030
SukiTheme.GetInstance().ActiveBaseTheme.ToString() == "Light" ? "\uE472" : "\uE330";
3131

3232
[ObservableProperty] private bool _titleBarVisible = true;
3333

3434
public MainWindowViewModel(IEnumerable<PageViewModel> pages, ISukiToastManager toastManager,
35-
AnnouncementService announcementService, SettingsService settingsService, UpdateService updateService)
35+
AnnouncementService announcementService, SettingsService settingsService, UpdateService updateService, ILogger<MainWindowViewModel> logger)
3636
{
3737
_announcementService = announcementService;
3838
Pages = new AvaloniaList<PageViewModel>(pages);
3939
ToastManager = toastManager;
4040
_settingsService = settingsService;
4141
_updateService = updateService;
42+
_logger = logger;
4243
_ = CheckForUpdates();
4344
}
4445

4546
public ISukiToastManager ToastManager { get; init; }
4647

47-
public string Greeting { get; } = Resources.GreetingText;
48-
4948
public IAvaloniaReadOnlyList<PageViewModel> Pages { get; }
5049

5150
public void SwitchLightMode()
@@ -154,18 +153,25 @@ private async Task DownloadUpdateAsync(VersionResponse versionResponse)
154153
}
155154
catch (Exception e)
156155
{
157-
Console.WriteLine(e);
156+
_logger.LogError(e, "Error downloading update");
157+
ToastManager.Dismiss(toast);
158+
ToastManager.CreateToast()
159+
.WithTitle("Update Failed")
160+
.WithContent($"Failed to download update: {e.Message}")
161+
.Dismiss().After(TimeSpan.FromSeconds(5))
162+
.Dismiss().ByClicking()
163+
.Queue();
158164
return;
159165
}
160166

161167
ToastManager.Dismiss(toast);
162168
ToastManager.CreateToast()
163169
.WithTitle("Download Complete")
164-
.WithContent("Update package will be unzip within 3 seconds.")
170+
.WithContent($"Update package will be unzip to {Environment.CurrentDirectory} within 3 seconds.")
165171
.Dismiss().After(TimeSpan.FromSeconds(3))
166172
.Dismiss().ByClicking()
167173
.Queue();
168174
await Task.Delay(3000);
169-
UnzipUtil.Unzip(result, Path.GetDirectoryName(Environment.CurrentDirectory)!);
175+
UnzipUtil.Unzip(result, Environment.CurrentDirectory);
170176
}
171177
}

0 commit comments

Comments
 (0)