mirror of
https://github.com/real-zony/ZonyLrcToolsX.git
synced 2026-11-24 03:37:47 +08:00
feat(desktop): 保存配置时不再重写整个 config.yaml
桌面端从共享的 DI 容器拿配置对象,再用 YamlDotNet 的序列化器整份写回。这样 一轮往返会把文件重写一遍:仓库里那 60 行、注释众多的 config.yaml 会变成 40 行机器生成的块,注释全没了,多行值的引号风格也变了。只要在设置页动一个开关, 注释就丢了。 SettingsStore 不再重新序列化整个文档,只补丁 UI 真正拥有的那几个键: - PatchText 按行扫描 YAML,用缩进栈跟踪每个受管键的路径 (networkOptions.isEnable、provider.lyric.plugin[NetEase].priority …), 只替换那个标量,其余每一个字节 —— 注释、空行、列对齐 —— 保持原样。带 引号的值保持原引号风格(QuotedScalarEventEmitter 沿用原文样式)。 - 补丁后的文本会被重新解析,并逐字段与预期值比对,通过才落盘。往返不一致 就拒绝写入,磁盘上的文件保持不动。另有重新生成整份文件的兜底路径,用于 原文件已被替换成补丁器无法跟随的内容时。 同一提交里还有: - AppPaths:可执行文件所在目录可写时配置就放那里(便携安装),否则回退到 %AppData%/ZonyLrcTools。写入走临时文件 + File.Move,崩溃不会留下半份配置。 - NetEaseSessionStore / KugouDatabaseStore:两个小 JSON,分别存网易云登录 cookie 和用户手动指定的 KGMusicV3.db 路径。刻意与 config.yaml 分开 —— 它们是机器状态而不是用户偏好,也不该出现在设置的 diff 里。 - ConfigurationServiceCollectionExtensions:构造与 CLI 相同的 GlobalOptions, 但基于上面解析出的路径,而不是固定的 AppContext.BaseDirectory。 Common 为此一行未改:CLI 照旧从自己所在目录读 config.yaml。
This commit is contained in:
1 parent
4ec67b9ee0
commit
9cda87dbfe
7 files changed
+972
No files matched your search
+29
@@ -0,0 +1,29 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ZonyLrcTools.Common.Configuration;
|
||||
using ZonyLrcTools.Common.Infrastructure.DependencyInject;
|
||||
|
||||
namespace ZonyLrcTools.Desktop.Infrastructure.Configuration;
|
||||
|
||||
public static class ConfigurationServiceCollectionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Bind <see cref="GlobalOptions"/> from the writable settings file resolved by
|
||||
/// <see cref="AppPaths"/>, instead of the read-only folder next to the executable that
|
||||
/// <see cref="ServiceCollectionExtensions.ConfigureConfiguration"/> uses.
|
||||
/// </summary>
|
||||
public static IServiceCollection ConfigureDesktopConfiguration(this IServiceCollection services)
|
||||
{
|
||||
AppPaths.EnsureConfigFile();
|
||||
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.SetBasePath(AppPaths.ConfigDirectory)
|
||||
.AddYamlFile(Path.GetFileName(AppPaths.ConfigFilePath), optional: true, reloadOnChange: false)
|
||||
.Build();
|
||||
|
||||
services.Configure<GlobalOptions>(configuration);
|
||||
services.AddSingleton<ISettingsStore, SettingsStore>();
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user