From 4cac1b533e133fdc8b3def90a0f998820f51907a Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期三, 26 三月 2025 17:57:59 +0800
Subject: [PATCH] 优化UI,新增日志自动删除;

---
 WPFProject/App.xaml.cs |   30 ++++++++++++++++++++++++++++--
 1 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/WPFProject/App.xaml.cs b/WPFProject/App.xaml.cs
index cfb8c29..214e876 100644
--- a/WPFProject/App.xaml.cs
+++ b/WPFProject/App.xaml.cs
@@ -4,6 +4,8 @@
 using log4net;
 using Panuon.WPF.UI;
 using System;
+using System.IO;
+using System.Reflection;
 using System.Threading;
 using System.Windows;
 using WPFProject.Utils;
@@ -16,6 +18,7 @@
     public partial class App : Application
     {
         private ILog log;
+        private LogCleanner logCleanner;
         public App()
         {
             log = LogManager.GetLogger("APP");
@@ -26,7 +29,7 @@
         {
             var ex = e.ExceptionObject as Exception;
             log.Error("UnhandledException.", ex);
-            MsgBoxHelper.ErrorMessage(Current.MainWindow, this.lang("App.AppUnhandledException",ex.Message),
+            MsgBoxHelper.ErrorMessage(Current.MainWindow, this.lang("App.AppUnhandledException", ex.Message),
                     this.lang("App.Error"), MessageBoxButton.OK,
                     MessageBoxIcon.Error, DefaultButton.YesOK, 5);
         }
@@ -34,9 +37,12 @@
         private static Mutex mutex;
         private void Application_Startup(object sender, StartupEventArgs e)
         {
-            mutex = new System.Threading.Mutex(true, "TestPlatform_OnlyRun_CRNS");
+            mutex = new Mutex(true, "TestPlatform_OnlyRun_CRNS");
             if (mutex.WaitOne(0, false))
             {
+                logCleanner = new LogCleanner();
+                AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
+                LoggerHelper.Register(new CommonLogger());
                 LangUtil.Load();
                 SystemSetting.SystemSettingChanged += SystemSetting_SystemSettingChanged;
                 ToastHelper.Register(new MainToastHandler());
@@ -51,6 +57,26 @@
             }
         }
 
+        private Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
+        {
+            // 鑾峰彇璇锋眰鍔犺浇鐨勭▼搴忛泦鍚嶇О
+            string assemblyName = new AssemblyName(args.Name).Name;
+
+            string[] dirs = new string[] { "3rds", "Libs" };
+
+            foreach (string dir in dirs)
+            {
+                string dllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, dir, $"{assemblyName}.dll");
+                if (File.Exists(dllPath))
+                {
+                    // 濡傛灉渚濊禆 DLL 瀛樺湪锛屽垯鍔犺浇骞惰繑鍥炲畠
+                    return Assembly.LoadFrom(dllPath);
+                }
+            }
+            // 鍚﹀垯杩斿洖 null
+            return null;
+        }
+
         private void SystemSetting_SystemSettingChanged(object sender, SystemSetting e)
         {
             LangUtil.LoadLang();

--
Gitblit v1.9.1