From 7bf89fd93bc487e8445d6d85bb527251b7371a04 Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期一, 12 五月 2025 13:14:11 +0800
Subject: [PATCH] 优化项目;

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

diff --git a/WPFProject/App.xaml.cs b/WPFProject/App.xaml.cs
index 545b7cc..bbef0c0 100644
--- a/WPFProject/App.xaml.cs
+++ b/WPFProject/App.xaml.cs
@@ -2,6 +2,7 @@
 using HMI.Core.Util;
 using HMI.UI.Util;
 using log4net;
+using Microsoft.Win32;
 using Panuon.WPF.UI;
 using System;
 using System.IO;
@@ -18,6 +19,7 @@
     public partial class App : Application
     {
         private ILog log;
+        private LogCleanner logCleanner;
         public App()
         {
             log = LogManager.GetLogger("APP");
@@ -28,9 +30,30 @@
         {
             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);
+        }
+
+        /// <summary>
+        /// 鍚姩鍚庡線娉ㄥ唽琛ㄥ啓鐐逛笢瑗�
+        /// </summary>
+        private void WriteRegister()
+        {
+            string Company = "JingCe", Program = "HMI";
+            try
+            {
+                string registryPath = @$"SOFTWARE\{Company}\{Program}";
+
+                using RegistryKey key = Registry.LocalMachine.CreateSubKey(registryPath, true)
+                    ?? throw new Exception("鏃犳硶鍒涘缓鎴栨墦寮�娉ㄥ唽琛ㄩ敭");
+                string path = AppDomain.CurrentDomain.BaseDirectory;
+                key.SetValue("Location", path, RegistryValueKind.String);
+            }
+            catch (Exception ex)
+            {
+                log.Error("Write Register Failed.", ex);
+            }
         }
 
         private static Mutex mutex;
@@ -39,8 +62,10 @@
             mutex = new Mutex(true, "TestPlatform_OnlyRun_CRNS");
             if (mutex.WaitOne(0, false))
             {
+                WriteRegister();
+                logCleanner = new LogCleanner();
                 AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
-
+                LoggerHelper.Register(new CommonLogger());
                 LangUtil.Load();
                 SystemSetting.SystemSettingChanged += SystemSetting_SystemSettingChanged;
                 ToastHelper.Register(new MainToastHandler());

--
Gitblit v1.9.1