桌面端打包优化

This commit is contained in:
geht
2026-05-18 17:31:18 +08:00
parent c11f3104cb
commit 2ed796c1a1
8 changed files with 639 additions and 9 deletions

View File

@@ -3,6 +3,7 @@ using FluentValidation;
using Mapster;
using Microsoft.Extensions.Configuration;
using NewLife;
using System.Configuration;
using System.IO;
using System.Text;
using System.Windows;
@@ -73,6 +74,46 @@ namespace YY.Admin
}
}
/// <summary>
/// 写入用户级 AppSettingsuser.config。若文件损坏如缺少 configSections删除后重试一次。
/// </summary>
private static void PersistSkinTypeUserSettingSafe()
{
for (var attempt = 0; attempt < 2; attempt++)
{
try
{
AppSettings.Default.SkinType = AppSettingsViewModel.GetSkinType().ToInt();
AppSettings.Default.Save();
return;
}
catch (ConfigurationErrorsException ex)
{
if (attempt == 0)
{
var path = ex.Filename;
if (string.IsNullOrWhiteSpace(path) && ex.InnerException is ConfigurationErrorsException inner)
path = inner.Filename;
try
{
if (!string.IsNullOrWhiteSpace(path) && File.Exists(path))
File.Delete(path);
AppSettings.Default.Reload();
}
catch
{
// 删除/Reload 失败则向上抛出原异常
}
continue;
}
throw;
}
}
}
protected override Window CreateShell()
{
return Container.Resolve<LoginWindow>();
@@ -178,9 +219,8 @@ namespace YY.Admin
_logger = Container.Resolve<ILoggerService>();
// 初始化全局异常处理(通过解析触发构造函数注册)
Container.Resolve<GlobalExceptionHandler>();
// 保存默认主题
AppSettings.Default.SkinType = AppSettingsViewModel.GetSkinType().ToInt();
AppSettings.Default.Save();
// 保存默认主题(用户级 user.config损坏时自动删文件并重载
PersistSkinTypeUserSettingSafe();
_logger.Information("应用程序已启动");