From eefd35fa23b036c98cf5a8b970135b9d66172ffa Mon Sep 17 00:00:00 2001 From: shiqiqi Date: Fri, 28 Mar 2025 11:24:21 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=8D=E5=BA=93=E7=AE=A1=E7=90=86=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E8=AE=BE=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Common/YamlHelper.cs | 32 ++++++++++++ ViewModels/LexiconViewModel.cs | 25 +++++++++ Views/LexiconView.xaml | 92 ++++++++++++---------------------- 3 files changed, 88 insertions(+), 61 deletions(-) diff --git a/Common/YamlHelper.cs b/Common/YamlHelper.cs index 61269a5..67e4435 100644 --- a/Common/YamlHelper.cs +++ b/Common/YamlHelper.cs @@ -18,28 +18,55 @@ public static class YamlHelper _jsonserializer = new SerializerBuilder().JsonCompatible().Build(); } + /// + /// 从文件中反序列化 + /// + /// + /// + /// public static T DeserializeFromFile(string filePath) { var yaml = File.ReadAllText(filePath, Encoding.UTF8); return Deserizlize(yaml); } + /// + /// 反序列化 + /// + /// + /// + /// public static T Deserizlize(string yaml) { return _deserializer.Deserialize(yaml); } + /// + /// 序列化 + /// + /// + /// public static string Serialize(object target) { return _serializer.Serialize(target); } + /// + /// 序列化到文件 + /// + /// + /// public static void SerizlizerToFile(object target, string filePath) { var content = Serialize(target); File.WriteAllText(filePath, content, Encoding.UTF8); } + /// + /// 写入Yaml文件 + /// + /// + /// public static void WriteYaml(object target, string filePath) { StreamWriter yamlWriter = File.CreateText(filePath); @@ -61,6 +88,11 @@ public static class YamlHelper File.WriteAllLines(filePath, _list.ToArray(), encoding: Encoding.UTF8); } + /// + /// yaml转json + /// + /// + /// public static string YamlToJson(string yaml) { var yamlObject = _jsondeserializer.Deserialize(yaml); diff --git a/ViewModels/LexiconViewModel.cs b/ViewModels/LexiconViewModel.cs index 37900a0..fbc8f63 100644 --- a/ViewModels/LexiconViewModel.cs +++ b/ViewModels/LexiconViewModel.cs @@ -27,10 +27,35 @@ public partial class LexiconViewModel : ObservableObject CikuAllList = new List(); WeakReferenceMessenger.Default.Register(this, "ReLoadCikuData", ReLoadCikuData); + LoadCiKus(); LoadCikuData(); InitPageControl(); } + /// + /// 加载词库下载选项 + /// + public void LoadCiKus() + { + // 默认词库路径 + var default_ciku_path = GlobalValues.UserPath + @"\wubi.dict.yaml"; + // 扩展词库路径 + var extend_ciku_path = GlobalValues.UserPath + @"\wubi.extended.dict.yaml"; + + + if (!File.Exists(extend_ciku_path)) + { + this.ShowMessage($"找不到【wubi.extended.dict.yaml】扩展词库文件", DialogType.Error); + return; + } + + // # 读取词库名称列表 + var cikuNames = new List<(string, string)>(); + cikuNames.Add(("默认词库", default_ciku_path)); + cikuNames.Add(("扩展词库", extend_ciku_path)); + cikuNames.Add(("", "")); + } + private void InitPageControl() { try diff --git a/Views/LexiconView.xaml b/Views/LexiconView.xaml index 60fcae4..ed533b3 100644 --- a/Views/LexiconView.xaml +++ b/Views/LexiconView.xaml @@ -14,68 +14,38 @@ mc:Ignorable="d" DataContext="{Binding Source={StaticResource Locator}, Path=LexiconViewModel}"> - - - - -