桌面端打包优化
This commit is contained in:
@@ -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>
|
||||
/// 写入用户级 AppSettings(user.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("应用程序已启动");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user