From dedcf4174c8540ee3a912daad2ff13e014e495b1 Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期五, 28 三月 2025 16:28:30 +0800
Subject: [PATCH] 优化UI组件;

---
 WPFProject/App.xaml.cs |   62 +++++++++++++++++++++++++++----
 1 files changed, 54 insertions(+), 8 deletions(-)

diff --git a/WPFProject/App.xaml.cs b/WPFProject/App.xaml.cs
index 882f867..214e876 100644
--- a/WPFProject/App.xaml.cs
+++ b/WPFProject/App.xaml.cs
@@ -1,8 +1,14 @@
-锘縰sing HMI.UI.Util;
+锘縰sing HMI.Core.Setting;
+using HMI.Core.Util;
+using HMI.UI.Util;
 using log4net;
 using Panuon.WPF.UI;
 using System;
+using System.IO;
+using System.Reflection;
+using System.Threading;
 using System.Windows;
+using WPFProject.Utils;
 
 namespace WPFProject
 {
@@ -12,6 +18,7 @@
     public partial class App : Application
     {
         private ILog log;
+        private LogCleanner logCleanner;
         public App()
         {
             log = LogManager.GetLogger("APP");
@@ -22,18 +29,57 @@
         {
             var ex = e.ExceptionObject as Exception;
             log.Error("UnhandledException.", ex);
-            Dispatcher.Invoke(() =>
-            {
-                MsgBoxHelper.ErrorMessage(Current.MainWindow, $"鍙戠敓鏈煡寮傚父锛佺▼搴忓嵆灏嗗叧闂璡r\n{ex?.Message}",
-                    "閿欒", MessageBoxButton.OK,
+            MsgBoxHelper.ErrorMessage(Current.MainWindow, this.lang("App.AppUnhandledException", ex.Message),
+                    this.lang("App.Error"), MessageBoxButton.OK,
                     MessageBoxIcon.Error, DefaultButton.YesOK, 5);
-            });
         }
 
+        private static Mutex mutex;
         private void Application_Startup(object sender, StartupEventArgs e)
         {
-            LoadingWindow window = new LoadingWindow();
-            window.Show();
+            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());
+                //LoadingWindow window = new LoadingWindow();
+                Login window = new Login();
+                window.Show();
+            }
+            else
+            {
+                MessageBox.Show("绋嬪簭宸茬粡鍦ㄨ繍琛岋紒", "鎻愮ず");
+                this.Shutdown();
+            }
+        }
+
+        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