-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathSimulateViewModel.cs
More file actions
76 lines (63 loc) · 3.26 KB
/
Copy pathSimulateViewModel.cs
File metadata and controls
76 lines (63 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using GeneralUpdate.Tools.Models;
using GeneralUpdate.Tools.Services;
namespace GeneralUpdate.Tools.ViewModels;
public partial class SimulateViewModel : ViewModelBase
{
private readonly LocalizationService _loc = LocalizationService.Instance;
public SimulateConfigModel Config { get; } = new();
[ObservableProperty] private bool _isRunning;
[ObservableProperty] private string _status;
[ObservableProperty] private ObservableCollection<string> _log = new();
public ObservableCollection<PlatformItem> Platforms { get; } = new()
{
new(1, "Windows"),
new(2, "Linux")
};
public ObservableCollection<AppTypeItem> AppTypes { get; } = new()
{
new(1, "ClientApp"),
new(2, "UpgradeApp")
};
public SimulateViewModel()
{
_status = _loc["Patch.Ready"];
}
async Task<string?> PickFolder(string title)
{
var tl = Avalonia.Controls.TopLevel.GetTopLevel(
(Avalonia.Application.Current?.ApplicationLifetime as Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime)?.MainWindow);
if (tl == null) return null;
var r = await tl.StorageProvider.OpenFolderPickerAsync(
new Avalonia.Platform.Storage.FolderPickerOpenOptions { Title = title, AllowMultiple = false });
return r.Count > 0 ? r[0].Path.LocalPath : null;
}
async Task<string?> PickFile(string title)
{
var tl = Avalonia.Controls.TopLevel.GetTopLevel(
(Avalonia.Application.Current?.ApplicationLifetime as Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime)?.MainWindow);
if (tl == null) return null;
var r = await tl.StorageProvider.OpenFilePickerAsync(
new Avalonia.Platform.Storage.FilePickerOpenOptions { Title = title, AllowMultiple = false });
return r.Count > 0 ? r[0].Path.LocalPath : null;
}
[RelayCommand] async Task SelectAppDir() { var p = await PickFolder("选择旧版本应用目录"); if (p != null) Config.AppDirectory = p; }
[RelayCommand] async Task SelectPatch() { var p = await PickFile("选择补丁包"); if (p != null) Config.PatchFilePath = p; }
[RelayCommand] async Task SelectOutputDir() { var p = await PickFolder("选择模拟输出目录"); if (p != null) Config.OutputDirectory = p; }
[RelayCommand]
async Task StartSimulation()
{
// Validation will be implemented in issue #4
if (string.IsNullOrWhiteSpace(Config.AppDirectory)) { Status = "请选择旧版本应用目录"; return; }
if (string.IsNullOrWhiteSpace(Config.PatchFilePath)) { Status = "请选择补丁包文件"; return; }
if (string.IsNullOrWhiteSpace(Config.OutputDirectory)) { Status = "请选择模拟输出目录"; return; }
Status = "模拟功能将在后续 issue 中实现";
}
void L(string msg) => Log.Add($"[{DateTime.Now:HH:mm:ss}] {msg}");
}
public record PlatformItem(int Value, string DisplayName) { public override string ToString() => DisplayName; }
public record AppTypeItem(int Value, string DisplayName) { public override string ToString() => DisplayName; }