diff --git a/src/LipNETWrapper/Class/LipPackage.cs b/src/LipNETWrapper/Class/LipPackage.cs index 5aad7ad..b35f99b 100644 --- a/src/LipNETWrapper/Class/LipPackage.cs +++ b/src/LipNETWrapper/Class/LipPackage.cs @@ -1,46 +1,64 @@ -using Newtonsoft.Json; -using System; +#nullable disable +using System.Collections.Generic; +using Newtonsoft.Json; -namespace LipNETWrapper.Class +namespace LipNETWrapper.Class; + +public partial class LipPackage { - // { - // "author": "Mojang", - // "description": "Bedrock Dedicated Servers allow Minecraft players on Windows and Linux computers to set up their own server at home, or host their server using a cloud-based service.", - // "files": [], - // "homepage": "https://www.minecraft.net", - // "license": "", - // "name": "Minecraft Bedrock Dedicated Server", - // "tooth": "github.com/tooth-hub/bds", - // "version": "1.19.61", - // "versions": [ - // "1.19.61", - // "1.7.0", - // "1.6.1" - // ] - //} - [Serializable] - public class LipPackageVersions - { - [JsonProperty("versions")] public string[]? Versions { get; set; } - } - [Serializable] - public class LipPackage: LipPackageVersions - { - [JsonProperty("author")] public string Author { get; set; } = string.Empty; - [JsonProperty("description")] public string Description { get; set; } = string.Empty; - [JsonProperty("files")] public LipFile[] Files { get; set; } = Array.Empty(); - [JsonProperty("homepage")] public string Homepage { get; set; } = string.Empty; - [JsonProperty("license")] public string License { get; set; } = string.Empty; - [JsonProperty("name")] public string Name { get; set; } = string.Empty; - [JsonProperty("tooth")] public string Tooth { get; set; } = string.Empty; - [JsonProperty("version")] public string Version { get; set; } = string.Empty; - } - [Serializable] - public class LipFile//todo 这玩意长啥样 - { - //[JsonProperty("name")] public string Name { get; set; } - //[JsonProperty("sha256")] public string Sha256 { get; set; } - //[JsonProperty("size")] public long Size { get; set; } - //[JsonProperty("url")] public string Url { get; set; } - } + [JsonProperty("format_version")] + public long FormatVersion { get; set; } + + [JsonProperty("tooth")] + public string Tooth { get; set; } + + [JsonProperty("version")] + public string Version { get; set; } + + [JsonProperty("info")] + public Info Info { get; set; } + + [JsonProperty("commands")] + public Commands Commands { get; set; } + + [JsonProperty("dependencies")] + public Dictionary Dependencies { get; set; } + + [JsonProperty("files")] + public Files Files { get; set; } } + +public partial class Commands +{ + [JsonProperty("post_install")] + public string[] PostInstall { get; set; } +} +public partial class Files +{ + [JsonProperty("place")] + public Place[] Place { get; set; } + + [JsonProperty("remove")] + public string[] Remove { get; set; } +} + +public partial class Place +{ + [JsonProperty("src")] + public string Src { get; set; } + + [JsonProperty("dest")] + public string Dest { get; set; } +} + +public partial class Info +{ + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("description")] + public string Description { get; set; } + + [JsonProperty("author")] + public string Author { get; set; } +} \ No newline at end of file diff --git a/src/LipNETWrapper/Class/LipPackageItem.cs b/src/LipNETWrapper/Class/LipPackageItem.cs new file mode 100644 index 0000000..c0f06b8 --- /dev/null +++ b/src/LipNETWrapper/Class/LipPackageItem.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; +#nullable disable +namespace LipNETWrapper.Class; + +public class LipPackageItem +{ + [JsonProperty("available_versions")] public LipPackageVersions AvailableVersions { get; set; } + [JsonProperty("metadata")] public LipPackage Package { get; set; } +} + +public class LipPackageVersions : List +{ + +} \ No newline at end of file diff --git a/src/LipNETWrapper/Class/LipPackageSimple.cs b/src/LipNETWrapper/Class/LipPackageSimple.cs deleted file mode 100644 index 6af3d71..0000000 --- a/src/LipNETWrapper/Class/LipPackageSimple.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Newtonsoft.Json; - -namespace LipNETWrapper.Class -{ - /*[ - { - "tooth": "github.com/tooth-hub/bds", - "version": "1.19.61" - }, - { - "tooth": "github.com/tooth-hub/bdsdownloader", - "version": "0.1.0" - }, - { - "tooth": "github.com/tooth-hub/liteloaderbds", - "version": "2.10.0" - }, - { - "tooth": "github.com/tooth-hub/llessentials", - "version": "2.10.0" - } - ]*/ - [Serializable] - public class LipPackageSimple - { - [JsonProperty("tooth")] public string Tooth { get; set; } = string.Empty; - [JsonProperty("version")] public string Version { get; set; } = string.Empty; - [JsonProperty("information")] public LipPackageSimpleInformation Information { get; set; } = new(); - public class LipPackageSimpleInformation - { - //"information": { - // "author": "Igor Pavlov.", - // "description": "7-Zip for Lip", - // "homepage": "https://www.7-zip.org/", - // "license": "LGPL-2.1", - // "name": "7-Zip Lip Tool" - //} - [JsonProperty("author")] public string Author { get; set; } = string.Empty; - [JsonProperty("description")] public string Description { get; set; } = string.Empty; - [JsonProperty("homepage")] public string Homepage { get; set; } = string.Empty; - [JsonProperty("license")] public string License { get; set; } = string.Empty; - [JsonProperty("name")] public string Name { get; set; } = string.Empty; - } - } -} diff --git a/src/LipNETWrapper/Class/Tooth/ToothJson.cs b/src/LipNETWrapper/Class/Tooth/ToothJson.cs index 658bc1b..38e4c12 100644 --- a/src/LipNETWrapper/Class/Tooth/ToothJson.cs +++ b/src/LipNETWrapper/Class/Tooth/ToothJson.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Collections.ObjectModel; using Newtonsoft.Json; @@ -46,4 +46,4 @@ public class Confirmation [JsonProperty("GOOS")] public string GOOS { get; set; } = ""; [JsonProperty("GOARCH")] public string GOARCH { get; set; } = ""; -} +} \ No newline at end of file diff --git a/src/LipNETWrapper/ILipWrapper.cs b/src/LipNETWrapper/ILipWrapper.cs index 5d0ceff..8bc7941 100644 --- a/src/LipNETWrapper/ILipWrapper.cs +++ b/src/LipNETWrapper/ILipWrapper.cs @@ -9,7 +9,7 @@ public interface ILipWrapper string ExecutablePath { get; set; } string? WorkingPath { get; set; } Task GetLipVersion(CancellationToken tk = default); - Task<(LipPackageSimple[] packages, string message)> GetAllPackagesAsync(CancellationToken tk = default); + Task<(LipPackage[] packages, string message)> GetAllPackagesAsync(CancellationToken tk = default); Task<(bool success, LipPackageVersions? package, string message)> GetPackageInfoAsync(string packageId, CancellationToken tk = default, Action? onOutput = null); Task<(bool success, LipPackage? package, string message)> GetLocalPackageInfoAsync(string packageId, @@ -19,6 +19,5 @@ Task InstallPackageAsync(string packageId, bool upgrade = false, bool skipD Task UninstallPackageAsync(string packageId, CancellationToken tk = default, Action? onOutput = null); Task GetLipRegistryAsync(string registry, CancellationToken tk = default); - Task CachePurge(); } diff --git a/src/LipNETWrapper/LipConsoleLoader.cs b/src/LipNETWrapper/LipConsoleLoader.cs index 95b7a4b..21c33a3 100644 --- a/src/LipNETWrapper/LipConsoleLoader.cs +++ b/src/LipNETWrapper/LipConsoleLoader.cs @@ -22,7 +22,8 @@ public static LipCommand Create(string cmd, bool quiet = false) var instance = new LipCommand(); if (quiet) { - instance.Add("-q"); + //todo ? + //instance.Add("-q"); } return instance.Add(cmd); } diff --git a/src/LipNETWrapper/LipConsoleWrapper.cs b/src/LipNETWrapper/LipConsoleWrapper.cs index a607771..52388fa 100644 --- a/src/LipNETWrapper/LipConsoleWrapper.cs +++ b/src/LipNETWrapper/LipConsoleWrapper.cs @@ -1,98 +1,93 @@ #nullable enable using System; -using System.Collections.Generic; using System.Diagnostics; -using System.Linq; -using System.Net; using System.Text; +using System.Net; using System.Threading; using System.Threading.Tasks; using LipNETWrapper.Class; using Newtonsoft.Json; -namespace LipNETWrapper +namespace LipNETWrapper; + +public class LipConsoleWrapper : ILipWrapper { - public class LipConsoleWrapper : ILipWrapper + public LipConsoleWrapper(string executablePath = "lip.exe", string? workingDir = null) { - public LipConsoleWrapper(string executablePath = "lip.exe", string? workingDir = null) - { - ExecutablePath = executablePath; - WorkingPath = workingDir; - } - public string ExecutablePath { get; set; } - public string? WorkingPath { get; set; } - public async Task GetLipVersion(CancellationToken tk = default) - { - return (await new LipConsoleLoader(ExecutablePath, WorkingPath) - .RunString(LipCommand.Create("-V"), tk: tk)).Trim(); - } - public async Task<(LipPackageSimple[] packages, string message)> GetAllPackagesAsync(CancellationToken tk = default) - { - async Task<(LipPackageSimple[] packages, string message)> GetInternal() - { - var text = await new LipConsoleLoader(ExecutablePath, WorkingPath) - .RunString(LipCommand.Create("list", true).WithJson(), tk: tk); - Debug.WriteLine(text); - var json = text.Split('\n').First(x => x.StartsWith("[")).Trim(); - var arr = JsonConvert.DeserializeObject(json); - return (arr ?? Array.Empty(), text); - } - try - { - return await GetInternal(); - } - catch - { //retry once - return await GetInternal(); - } - } - public async Task<(bool success, LipPackageVersions? package, string message)> GetPackageInfoAsync(string packageId, CancellationToken tk = default, Action? onOutput = null) + ExecutablePath = executablePath; + WorkingPath = workingDir; + } + public string ExecutablePath { get; set; } + public string? WorkingPath { get; set; } + public async Task GetLipVersion(CancellationToken tk = default) + { + return (await new LipConsoleLoader(ExecutablePath, WorkingPath) + .RunString(LipCommand.Create("-V"), tk: tk)).Trim(); + } + public async Task<(LipPackage[] packages, string message)> GetAllPackagesAsync(CancellationToken tk = default) + { + async Task<(LipPackage[] packages, string message)> GetInternal() { - var text = await new LipConsoleLoader(ExecutablePath, WorkingPath) - .RunString(LipCommand.Create("show", onOutput is null).WithJson() + "--available" + packageId, onOutput, tk); - var json = text.Split('\n').FirstOrDefault(x => x.StartsWith("{"))?.Trim(); - var obj = json is null ? null : JsonConvert.DeserializeObject(json); - return (obj is not null, obj, text); + var json = await new LipConsoleLoader(ExecutablePath, WorkingPath) + .RunString(LipCommand.Create("list", true).WithJson(), tk: tk); + Debug.WriteLine(json); + var arr = JsonConvert.DeserializeObject(json); + return (arr ?? Array.Empty(), json); } - public async Task<(bool success, LipPackage? package, string message)> GetLocalPackageInfoAsync(string packageId, CancellationToken tk = default) + try { - var text = await new LipConsoleLoader(ExecutablePath, WorkingPath) - .RunString(LipCommand.Create("show", true).WithJson() + packageId, tk: tk); - var json = text.Split('\n').FirstOrDefault(x => x.StartsWith("{"))?.Trim(); - var obj = json is null ? null : JsonConvert.DeserializeObject(json); - return (obj is not null, obj, text); + return await GetInternal(); } - public Task InstallPackageAsync(string packageId, bool upgrade = false, bool skipDependency = false, CancellationToken tk = default, Action>? onOutput = null) - { - var cmd = LipCommand.Create("install") + "-y" + "--numeric-progress"; - if (upgrade) - cmd += "--upgrade"; - if (skipDependency) - cmd += "--no-dependencies"; - //todo 强制重装 - //if (forceReinstall) - // cmd += "--force-reinstall"; - return new LipConsoleLoader(ExecutablePath, WorkingPath) - .RunWithInput(cmd + packageId, onOutput, tk); + catch + { //retry once + return await GetInternal(); } + } + public async Task<(bool success, LipPackageVersions? package, string message)> GetPackageInfoAsync(string packageId, CancellationToken tk = default, Action? onOutput = null) + { + var json = await new LipConsoleLoader(ExecutablePath, WorkingPath) + .RunString(LipCommand.Create("show", onOutput is null).WithJson() + "--available" + packageId, onOutput, tk); + var obj = JsonConvert.DeserializeObject(json)?.AvailableVersions; + return (obj is not null, obj, json); + } + public async Task<(bool success, LipPackage? package, string message)> GetLocalPackageInfoAsync(string packageId, CancellationToken tk = default) + { + var json = await new LipConsoleLoader(ExecutablePath, WorkingPath) + .RunString(LipCommand.Create("show", true).WithJson() + packageId, tk: tk); + var obj = JsonConvert.DeserializeObject(json)?.Package; + return (obj is not null, obj, json); + } + public Task InstallPackageAsync(string packageId, bool upgrade = false, bool skipDependency = false, CancellationToken tk = default, Action>? onOutput = null) + { + var cmd = LipCommand.Create("install")/* + "-y"*/ /*+ "--numeric-progress"*/; + if (upgrade) + cmd += "--upgrade"; + if (skipDependency) + cmd += "--no-dependencies"; + //todo 强制重装 + //if (forceReinstall) + // cmd += "--force-reinstall"; + return new LipConsoleLoader(ExecutablePath, WorkingPath) + .RunWithInput(cmd + packageId, onOutput, tk); + } - public Task UninstallPackageAsync(string packageId, CancellationToken tk = default, Action? onOutput = null) - { - return new LipConsoleLoader(ExecutablePath, WorkingPath) - .Run(LipCommand.Create("uninstall") + packageId, onOutput, tk); - } - public async Task GetLipRegistryAsync(string registry, CancellationToken tk = default) - { + public Task UninstallPackageAsync(string packageId, CancellationToken tk = default, Action? onOutput = null) + { + return new LipConsoleLoader(ExecutablePath, WorkingPath) + .Run(LipCommand.Create("uninstall") + "-y" + packageId, onOutput, tk); + } + public async Task GetLipRegistryAsync(string registry, CancellationToken tk = default) + { #if NET7_0 || NETCOREAPP - var client = new System.Net.Http.HttpClient() { }; - var response = await client.GetAsync(registry, tk); + var client = new System.Net.Http.HttpClient() { }; + var response = await client.GetAsync(registry, tk); - if (!response.IsSuccessStatusCode) - { - throw new Exception("Failed to get registry: " + response.StatusCode); - } - var content = await response.Content.ReadAsStringAsync(tk); - return JsonConvert.DeserializeObject(content)!; + if (!response.IsSuccessStatusCode) + { + throw new Exception("Failed to get registry: " + response.StatusCode); + } + var content = await response.Content.ReadAsStringAsync(tk); + return JsonConvert.DeserializeObject(content)!; #else using var client = new WebClient() { Encoding = Encoding.UTF8 }; var text = await client.DownloadStringTaskAsync(registry); @@ -102,11 +97,10 @@ public async Task GetLipRegistryAsync(string registry, Cancellation } return JsonConvert.DeserializeObject(text)!; #endif - } - public Task CachePurge() - { - return new LipConsoleLoader(ExecutablePath, WorkingPath) - .Run(LipCommand.Create("cache") + "purge", null, CancellationToken.None); - } } -} + public Task CachePurge() + { + return new LipConsoleLoader(ExecutablePath, WorkingPath) + .Run(LipCommand.Create("cache") + "purge", null, CancellationToken.None); + } +} \ No newline at end of file diff --git a/src/LipNETWrapperTest/UnitTest.cs b/src/LipNETWrapperTest/UnitTest.cs index 99ac627..3d92e01 100644 --- a/src/LipNETWrapperTest/UnitTest.cs +++ b/src/LipNETWrapperTest/UnitTest.cs @@ -36,7 +36,7 @@ public void Setup() //} foreach (var workingDir in new[] { - "A:\\Documents\\GitHub\\BDS\\Latest\\", + "A:\\Documents\\GitHub\\LipUI\\src\\LipUI\\bin\\Debug\\net462", //put your path here }) { @@ -76,17 +76,15 @@ public async Task TestGetAllPackages() public async Task TestGetPackageInfo() { //github.com/tooth-hub/liteloaderbds - var (success, package, message) = await Loader.GetPackageInfoAsync("github.com/tooth-hub/liteloaderbds"); + var (success, versions, message) = await Loader.GetPackageInfoAsync("github.com/tooth-hub/liteloaderbds"); OutPut(success.ToString()); if (success) { - if (package!.Versions is not null) - { - foreach (var v in package!.Versions) + if (versions is not null) + foreach (var v in versions) { OutPut(v); } - } } OutPut("----------"); OutPut(message); @@ -98,7 +96,7 @@ public async Task TestGetLocalPackageInfo() //github.com/tooth-hub/liteloaderbds var (success, package, message) = await Loader.GetLocalPackageInfoAsync("github.com/tooth-hub/liteloaderbds"); OutPut(success.ToString()); - OutPut(package?.Name); + OutPut(package?.Info.Name); OutPut(package?.Version); OutPut("----------"); OutPut(message); diff --git a/src/LipUI.sln.DotSettings b/src/LipUI.sln.DotSettings new file mode 100644 index 0000000..06b71d5 --- /dev/null +++ b/src/LipUI.sln.DotSettings @@ -0,0 +1,2 @@ + + False \ No newline at end of file diff --git a/src/LipUI/Global.cs b/src/LipUI/Global.cs index 3786cef..f8d23ef 100644 --- a/src/LipUI/Global.cs +++ b/src/LipUI/Global.cs @@ -534,7 +534,10 @@ await DispatcherInvokeAsync(async () => void Hide() { successAndHide = true; + DispatcherInvoke(() => + { dialog.Hide(); + }); } RoutedEventHandler onDialogOnButtonLeftClick = (_, e) => Hide(); RoutedEventHandler onDialogOnButtonRightClick = (_, e) => Hide(); diff --git a/src/LipUI/Language/Files/en.lang b/src/LipUI/Language/Files/en.lang index 9c75000..248d4b6 100644 --- a/src/LipUI/Language/Files/en.lang +++ b/src/LipUI/Language/Files/en.lang @@ -130,3 +130,9 @@ LipInstallerInvalidOperationTip=Please select 'Global' or 'Portable' to download WorkingPathSelectorInitDialog=A valid working directory needs to be specified WorkingPathSelectorInitDialogComplete=Complete WorkingPathSelectorInitErr=Please select a valid job working directory +SettingsClearCache=Cache Purge for Lip +SettingsClearCacheTitle=Cache Purge +SettingsClearCacheContent=Confirm to clear cache for lip +SettingsClearCacheConfirm=Confirm +SettingsClearCacheCancel=Cancel +SettingsClearCacheCompleted=Cache purge completed diff --git a/src/LipUI/Language/Model.cs b/src/LipUI/Language/Model.cs index 7989882..ea1fcdd 100644 --- a/src/LipUI/Language/Model.cs +++ b/src/LipUI/Language/Model.cs @@ -149,4 +149,10 @@ public class Model : ObservableObject public string WorkingPathSelectorInitDialog { get; set; } = "需要指定有效的工作路径"; public string WorkingPathSelectorInitDialogComplete { get; set; } = "完成"; public string WorkingPathSelectorInitErr { get; set; } = "请选择有效的工作路径"; + public string SettingsClearCache { get; set; } = "清除Lip的缓存"; + public string SettingsClearCacheTitle { get; set; } = "清除Lip的缓存"; + public string SettingsClearCacheContent { get; set; } = "确认清除缓存"; + public string SettingsClearCacheConfirm { get; set; } = "确定"; + public string SettingsClearCacheCancel { get; set; } = "取消"; + public string SettingsClearCacheCompleted { get; set; } = "清除缓存执行完成"; } \ No newline at end of file diff --git a/src/LipUI/LipUI.csproj b/src/LipUI/LipUI.csproj index f85a183..731948f 100644 --- a/src/LipUI/LipUI.csproj +++ b/src/LipUI/LipUI.csproj @@ -2,7 +2,7 @@ WinExe - 0.2.6 + 0.2.7 enable 11.0 true diff --git a/src/LipUI/ViewModels/DashboardViewModel.cs b/src/LipUI/ViewModels/DashboardViewModel.cs index 48fd947..764c26c 100644 --- a/src/LipUI/ViewModels/DashboardViewModel.cs +++ b/src/LipUI/ViewModels/DashboardViewModel.cs @@ -1,8 +1,6 @@ using CommunityToolkit.Mvvm.ComponentModel; -using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; -using System.Threading.Tasks; using Wpf.Ui.Common.Interfaces; namespace LipUI.ViewModels; @@ -23,7 +21,6 @@ void OnConfigOnPropertyChanged(object s, PropertyChangedEventArgs e) LocalRef.OnNavigatedTo(); } } - public void OnNavigatedFrom() { Global.Config.PropertyChanged -= OnConfigOnPropertyChanged; diff --git a/src/LipUI/ViewModels/InstallPageViewModel.cs b/src/LipUI/ViewModels/InstallPageViewModel.cs index ead3f38..0b6c6d1 100644 --- a/src/LipUI/ViewModels/InstallPageViewModel.cs +++ b/src/LipUI/ViewModels/InstallPageViewModel.cs @@ -52,7 +52,7 @@ public async Task Install() { if (!string.IsNullOrWhiteSpace(x)) { - if (x.EndsWith("(y/n)", true, CultureInfo.InvariantCulture))//条款 + if (x.EndsWith("[y/N]", true, CultureInfo.InvariantCulture))//条款 { Task.Delay(1000).ContinueWith(async _ => { @@ -61,7 +61,7 @@ public async Task Install() OutPut.Last() .Replace("(http", Environment.NewLine + "http"); //.Replace("http", Environment.NewLine + "http"); - if (fullEula.EndsWith("(y/n)", true, CultureInfo.InvariantCulture)) + if (fullEula.EndsWith("[y/N]", true, CultureInfo.InvariantCulture)) { //remove fullEula = fullEula[..^5].Trim(); @@ -147,6 +147,11 @@ public async Task Install() //去除匹配并去除"[==> ] " Percentage = Regex.Replace(str, @"\[(=|>|\s)+?\]", ""); } + // 79% |███████████████████████████████ | (101/126 kB, 151 kB/s) [0s:0s] + else if (Regex.Match(x, @"(\d+%)") is { Success: true }) + { + Percentage = Regex.Replace(x, @"\|(█|\s)+\|", "").Trim(); + } else if (x.Trim().EndsWith("|")) Percentage = x.Replace("|", "").Trim(); else @@ -184,7 +189,7 @@ public async Task FetchInfo() Ctk = new CancellationTokenSource(); try { - var (success, package, message) = await Global.Lip.GetPackageInfoAsync(ToothName, Ctk?.Token ?? default, x => + var (success, versions, message) = await Global.Lip.GetPackageInfoAsync(ToothName, Ctk?.Token ?? default, x => { if (!x.StartsWith("{")) { @@ -195,15 +200,15 @@ public async Task FetchInfo() { if (ToothInfoPanel?.Tooth != ToothName) { - ToothInfoPanel = new ToothInfoPanelViewModel(package!) + ToothInfoPanel = new ToothInfoPanelViewModel(versions!) { Tooth = ToothName }; } else { - ToothInfoPanel.RefreshVersion(package!); - if (package?.Versions?.FirstOrDefault() is not null and var v) + ToothInfoPanel.RefreshVersion(versions!); + if (versions?.FirstOrDefault() is not null and var v) { SelectedVersion = v; } diff --git a/src/LipUI/ViewModels/SettingsViewModel.cs b/src/LipUI/ViewModels/SettingsViewModel.cs index 6834a5c..018bfe5 100644 --- a/src/LipUI/ViewModels/SettingsViewModel.cs +++ b/src/LipUI/ViewModels/SettingsViewModel.cs @@ -47,7 +47,7 @@ partial void OnLipPathChanged(string value) } else { - Global.PopupSnackbarWarn(Global.I18N.SettingsFailedTitle,value); + Global.PopupSnackbarWarn(Global.I18N.SettingsFailedTitle, value); } } [ObservableProperty] @@ -118,12 +118,29 @@ private void OnChangeTheme(string parameter) [RelayCommand] private async Task ExitDeveloperMode() { - await Global.ShowDialog(Global.I18N.DeveloperTitle, Global.I18N.DeveloperDialogExit , (Global.I18N.DeveloperDialogCancel, hide => hide()), (Global.I18N.DeveloperDialogConfirm, hide => - { - Global.Config.DeveloperMode = false; - Global.PopupSnackbar(Global.I18N.DeveloperSnackbarTitle, Global.I18N.DeveloperDialogExited); - hide(); - } + await Global.ShowDialog(Global.I18N.DeveloperTitle, Global.I18N.DeveloperDialogExit, + (Global.I18N.DeveloperDialogCancel, hide => hide()), (Global.I18N.DeveloperDialogConfirm, hide => + { + Global.Config.DeveloperMode = false; + Global.PopupSnackbar(Global.I18N.DeveloperSnackbarTitle, Global.I18N.DeveloperDialogExited); + hide(); + } + )); + } + + [RelayCommand] + private async Task ClearCache() + { + await Global.ShowDialog(Global.I18N.SettingsClearCacheTitle, Global.I18N.SettingsClearCacheContent, + (Global.I18N.SettingsClearCacheCancel, hide => hide()), (Global.I18N.SettingsClearCacheConfirm, hide => + { + hide(); + Global.Lip.CachePurge().ContinueWith(_ => + { + Global.PopupSnackbar(Global.I18N.SettingsClearCacheTitle, + Global.I18N.SettingsClearCacheCompleted); + }); + } )); } } diff --git a/src/LipUI/ViewModels/ToothInfoPanelViewModel.cs b/src/LipUI/ViewModels/ToothInfoPanelViewModel.cs index 7ad0ea6..4267711 100644 --- a/src/LipUI/ViewModels/ToothInfoPanelViewModel.cs +++ b/src/LipUI/ViewModels/ToothInfoPanelViewModel.cs @@ -9,16 +9,19 @@ namespace LipUI.ViewModels { public partial class ToothInfoPanelViewModel : ObservableObject { - private readonly LipPackage? _info; - private readonly LipRegistry.LipRegistryItem? _registryItem; - private LipPackageVersions _ver; - public ToothInfoPanelViewModel(LipPackage info) : this((LipPackageVersions)info) + private LipPackageVersions? _ver; + public ToothInfoPanelViewModel(LipPackage info) { Tooth = info.Tooth; + Author = info.Info.Author; + Description = info.Info.Description; + Homepage = "undefined"; + Name = info.Info.Name; + License = ""; + Version = info.Version; } public ToothInfoPanelViewModel(LipPackageVersions info, LipRegistry.LipRegistryItem item) : this(info) { - _registryItem = item; Tooth = item.Tooth; Author = item.Author; Description = item.Description; @@ -31,16 +34,6 @@ public ToothInfoPanelViewModel(LipPackageVersions info, LipRegistry.LipRegistryI public ToothInfoPanelViewModel(LipPackageVersions ver) { _ver = ver; - if (ver is LipPackage info) - { - _info = info; - Author = info.Author; - Description = info.Description; - Homepage = info.Homepage; - Name = info.Name; - License = info.License; - Version = info.Version; - } if (Versions?.FirstOrDefault() is not null and var v) { SelectedVersion = v; @@ -54,8 +47,7 @@ public ToothInfoPanelViewModel(LipPackageVersions ver) [ObservableProperty] string _version = string.Empty; [ObservableProperty] string _tooth = string.Empty; [ObservableProperty] string[] _tags = Array.Empty(); - public string[]? Versions => _ver.Versions; - + public string[]? Versions => _ver?.ToArray(); public void RefreshVersion(LipPackageVersions ver) { _ver = ver; diff --git a/src/LipUI/ViewModels/ToothItemViewModel.cs b/src/LipUI/ViewModels/ToothItemViewModel.cs index 34979a2..36eb215 100644 --- a/src/LipUI/ViewModels/ToothItemViewModel.cs +++ b/src/LipUI/ViewModels/ToothItemViewModel.cs @@ -10,13 +10,13 @@ public partial class ToothItemViewModel : ObservableObject { [ObservableProperty] bool _actived = true;//等待移除,用于淡出动画 private Func _showInfo; - public ToothItemViewModel(Func showInfo, LipPackageSimple package) + public ToothItemViewModel(Func showInfo, LipPackage package) { _showInfo = showInfo; Version = package.Version; Tooth = package.Tooth; - Information = package.Information; - Author.Tag = Information.Author; + Information = package; + Author.Tag = Information.Info.Author; } public ToothItemViewModel( Func showInfo, LipRegistry.LipRegistryItem item) @@ -34,7 +34,7 @@ public ToothItemViewModel( #region Detailed [ObservableProperty] bool _detailed;//是否有具体细节 [ObservableProperty] LipRegistry.LipRegistryItem? _registryItem; - [ObservableProperty] LipPackageSimple.LipPackageSimpleInformation? _Information; + [ObservableProperty] LipPackage? _information; #endregion [RelayCommand(CanExecute = nameof(ExecutingShowInfo))] async Task ShowInfo() => await _showInfo(this); diff --git a/src/LipUI/ViewModels/ToothLocalModel.cs b/src/LipUI/ViewModels/ToothLocalModel.cs index 103fb86..f63caa7 100644 --- a/src/LipUI/ViewModels/ToothLocalModel.cs +++ b/src/LipUI/ViewModels/ToothLocalModel.cs @@ -1,5 +1,6 @@ using System; using System.Collections.ObjectModel; +using System.Diagnostics; using System.Threading.Tasks; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; @@ -36,7 +37,8 @@ protected async Task LoadAllPackages() try { await Global.DispatcherInvokeAsync(() => ToothItems.Clear()); - var (packages, message) = await Global.Lip.GetAllPackagesAsync(); + var (packages, _) = await Global.Lip.GetAllPackagesAsync(); + //Debug.WriteLine(message); foreach (var package in packages) { await Global.DispatcherInvokeAsync(() => ToothItems.Add(new ToothItemViewModel(ShowInfo, package))); diff --git a/src/LipUI/Views/Controls/ToothItem.xaml b/src/LipUI/Views/Controls/ToothItem.xaml index f9157c1..c9eed05 100644 --- a/src/LipUI/Views/Controls/ToothItem.xaml +++ b/src/LipUI/Views/Controls/ToothItem.xaml @@ -132,20 +132,20 @@ - - + - + - - + --> - + + @@ -75,10 +79,10 @@