Преглед на файлове

20260305001 添加程序自启动库

向羽 孟 преди 1 месец
родител
ревизия
12fa268d2d

+ 9 - 3
MvvmScaffoldFrame48.DLL/ImageAlgorithm/ProcessingAlgorithm_CCDShuLi.cs

@@ -1,8 +1,10 @@
 using MvCameraControl;
+using MvvmScaffoldFrame48.DLL.ConfigTools;
 using MvvmScaffoldFrame48.DLL.LogTools;
 using MvvmScaffoldFrame48.DLL.SystemTools;
 using MvvmScaffoldFrame48.DLL.ThreadManager;
 using MvvmScaffoldFrame48.Model.StorageModel.ImageAlgorithm.ShuLI;
+using MvvmScaffoldFrame48.Model.StorageModel.ProcessingConfig;
 using System;
 using System.Collections.Generic;
 using System.Diagnostics;
@@ -37,17 +39,21 @@ namespace MvvmScaffoldFrame48.DLL.ImageAlgorithm
 
         public void Configure(string parameters)
         {
-            throw new NotImplementedException();
+            var parameter = XMLReadWrite.DeserializeFromString<ShuLiConfigClassModel>(parameters);
+            if (parameter != null)
+            {
+                shuLiConfig = parameter;
+            }
         }
 
         public object GetParameters()
         {
-            throw new NotImplementedException();
+            return shuLiConfig;
         }
 
         public string GetSaveJson()
         {
-            throw new NotImplementedException();
+            return XMLReadWrite.SerializeToString(shuLiConfig);
         }
 
         public object ProcessImage(IFrameOut imageData, int cameraId)

+ 1 - 0
MvvmScaffoldFrame48.DLL/MvvmScaffoldFrame48.Dll.csproj

@@ -89,6 +89,7 @@
     <Compile Include="ImageAlgorithm\ProcessingAlgorithm_CCDShuLi.cs" />
     <Compile Include="LogTools\TxtLog.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="SystemTools\AutoStartHelper.cs" />
     <Compile Include="SystemTools\RingBuffer.cs" />
     <Compile Include="SystemTools\SystemRunTimeTools.cs" />
     <Compile Include="SystemTools\TimeStampTools.cs" />

+ 69 - 0
MvvmScaffoldFrame48.DLL/SystemTools/AutoStartHelper.cs

@@ -0,0 +1,69 @@
+using Microsoft.Win32;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MvvmScaffoldFrame48.DLL.SystemTools
+{
+    public class AutoStartHelper
+    {
+        /// <summary>
+        /// 若出现自启动时相对路径异常的情况可以在程序启动时引用如下代码
+        /// Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
+        /// </summary>
+        // 注册表路径
+        private static readonly string RegistryPath = @"Software\Microsoft\Windows\CurrentVersion\Run";
+        // 应用名称,作为注册表键名
+        private static readonly string AppName = "CCDCount";
+
+        /// <summary>
+        /// 获取当前可执行文件路径
+        /// </summary>
+        public static string GetExecutablePath()
+        {
+            return Process.GetCurrentProcess().MainModule.FileName;
+        }
+
+        /// <summary>
+        /// 检查是否已设置自启动
+        /// </summary>
+        public static bool IsAutoStart()
+        {
+            using (var key = Registry.CurrentUser.OpenSubKey(RegistryPath, false))
+            {
+                if (key == null) return false;
+                var value = key.GetValue(AppName);
+                // 验证路径是否一致,防止exe移动后失效
+                return value != null && value.ToString() == GetExecutablePath();
+            }
+        }
+
+        /// <summary>
+        /// 设置或取消自启动
+        /// </summary>
+        /// <param name="isAutoStart">true 为启用,false 为禁用</param>
+        public static void SetAutoStart(bool isAutoStart)
+        {
+            using (var key = Registry.CurrentUser.OpenSubKey(RegistryPath, true))
+            {
+                if (key == null) return;
+
+                if (isAutoStart)
+                {
+                    if (!IsAutoStart())
+                    {
+                        key.SetValue(AppName, GetExecutablePath());
+                    }
+                }
+                else
+                {
+                    // false 参数表示值不存在时不抛出异常
+                    key.DeleteValue(AppName, false);
+                }
+            }
+        }
+    }
+}

+ 7 - 1
MvvmScaffoldFrame48.DLL/ThreadManager/ThreadManager.cs

@@ -3,6 +3,7 @@ using MvCameraControl;
 using MvvmScaffoldFrame48.DLL.CameraTools;
 using MvvmScaffoldFrame48.DLL.ConfigTools;
 using MvvmScaffoldFrame48.Model.ResultModel;
+using MvvmScaffoldFrame48.Model.StorageModel.ImageAlgorithm.ShuLI;
 using MvvmScaffoldFrame48.Model.StorageModel.ProcessingConfig;
 using MvvmScaffoldFrame48.Model.StorageModel.SystemConfig;
 using System;
@@ -220,6 +221,10 @@ namespace MvvmScaffoldFrame48.DLL.ThreadManager
                         FilterType = "FilterType"
                     });
                     break;
+                case "ProcessingAlgorithm_CCDShuLi":
+                    config.ProcessingAlgorithmName = "ProcessingAlgorithm_CCDShuLi";
+                    config.AlgorithmParameters = XMLReadWrite.SerializeToString(new ShuLiConfigClassModel());
+                    break;
             }
 
             return config;
@@ -259,9 +264,10 @@ namespace MvvmScaffoldFrame48.DLL.ThreadManager
             }
             else
             {
+                //测试用代码,此处应为创建空配置,后续由图形界面控制新建配置
                 _cameraConfigurations = new List<CameraProcessConfigModel>()
                 {
-                    CreateCameraConfiguration(0, "ProcessingAlgorithm"),
+                    CreateCameraConfiguration(0, "ProcessingAlgorithm_CCDShuLi"),
                 };
             }
             //SaveCameraConfigurations();