From d0ded5cd9bf5070a120bad58b5be21fe2ac6a4ff Mon Sep 17 00:00:00 2001
From: C3032 <C3032@BC3032>
Date: 星期六, 20 十二月 2025 16:41:09 +0800
Subject: [PATCH] test
---
IDViewer_2D/LBProjService.cs | 131 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 131 insertions(+), 0 deletions(-)
diff --git a/IDViewer_2D/LBProjService.cs b/IDViewer_2D/LBProjService.cs
new file mode 100644
index 0000000..f99e467
--- /dev/null
+++ b/IDViewer_2D/LBProjService.cs
@@ -0,0 +1,131 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.IO.Compression;
+
+namespace SmartScanner
+{
+ public static class LBProjService
+ {
+ private const string ConfigFileName = "config.json";
+ private const string ModelNameFileName = "model_name.txt";
+ private const string ModelDir = "model"; // 鍥哄畾妯″瀷鐩綍
+
+ /// <summary>
+ /// 鍒涘缓涓存椂鐩綍
+ /// </summary>
+ private static string CreateTempDirectory()
+ {
+ string tempDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
+ Directory.CreateDirectory(tempDir);
+ return tempDir;
+ }
+
+ /// <summary>
+ /// 鑾峰彇鎵�鏈夊彲鐢ㄦā鍨�
+ /// </summary>
+ public static string[] GetAvailableModels()
+ {
+ string modelPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ModelDir);
+
+ if (!Directory.Exists(modelPath))
+ {
+ Directory.CreateDirectory(modelPath);
+ return Array.Empty<string>();
+ }
+
+ return Directory.GetFiles(modelPath, "*.lb")
+ .Select(Path.GetFileName)
+ .ToArray();
+ }
+
+ /// <summary>
+ /// 鍒涘缓宸ョ▼鏂囦欢
+ /// </summary>
+ public static (bool Success, string Message) CreateLBProj(
+ string paramFilePath,
+ string modelFileName,
+ string outputPath)
+ {
+ try
+ {
+ // 楠岃瘉妯″瀷鏄惁瀛樺湪
+ string fullModelPath = Path.Combine(ModelDir, modelFileName);
+ if (!File.Exists(fullModelPath))
+ {
+ return (false, $"妯″瀷鏂囦欢 {modelFileName} 涓嶅瓨鍦ㄤ簬 {ModelDir} 鐩綍");
+ }
+
+ // 鍒涘缓涓存椂鐩綍骞舵墦鍖�
+ string tempDir = CreateTempDirectory();
+ try
+ {
+ // 1. 淇濆瓨鍙傛暟鏂囦欢
+ File.Copy(paramFilePath, Path.Combine(tempDir, ConfigFileName), true);
+
+ // 2. 淇濆瓨妯″瀷鏂囦欢鍚嶏紙闈炶矾寰勶級
+ File.WriteAllText(Path.Combine(tempDir, ModelNameFileName), modelFileName);
+
+ // 3. 鍒涘缓ZIP鍖�
+ ZipFile.CreateFromDirectory(tempDir, outputPath);
+ return (true, "宸ョ▼鏂囦欢鍒涘缓鎴愬姛");
+ }
+ finally
+ {
+ Directory.Delete(tempDir, true);
+ }
+ }
+ catch (Exception ex)
+ {
+ return (false, $"鍒涘缓澶辫触: {ex.Message}");
+ }
+ }
+
+ /// <summary>
+ /// 鍔犺浇宸ョ▼鏂囦欢
+ /// </summary>
+ public static (string ModelName, string configPath, string ConfigContent, string Message) LoadLBProj(string projectFilePath)
+ {
+ try
+ {
+ string tempDir = CreateTempDirectory();
+ try
+ {
+ ZipFile.ExtractToDirectory(projectFilePath, tempDir);
+
+ // 1. 璇诲彇妯″瀷鏂囦欢鍚�
+ string modelNameFile = Path.Combine(tempDir, ModelNameFileName);
+ if (!File.Exists(modelNameFile))
+ {
+ return (null, null, null, "宸ョ▼鏂囦欢涓己灏戞ā鍨嬪悕绉拌褰�");
+ }
+ string modelName = File.ReadAllText(modelNameFile);
+
+ // 2. 楠岃瘉妯″瀷鏄惁瀛樺湪
+ string fullModelPath = Path.Combine(ModelDir, modelName);
+ if (!File.Exists(fullModelPath))
+ {
+ return (null, null, null, $"妯″瀷 {modelName} 涓嶅瓨鍦ㄤ簬 {ModelDir} 鐩綍");
+ }
+
+ // 3. 璇诲彇閰嶇疆
+ string configPath = Path.Combine(tempDir, ConfigFileName);
+ string configContent = File.ReadAllText(configPath);
+
+ return (modelName, configPath, configContent, "鍔犺浇鎴愬姛");
+ }
+ finally
+ {
+ Directory.Delete(tempDir, true);
+ }
+ }
+ catch (Exception ex)
+ {
+ return (null, null, null, $"鍔犺浇澶辫触: 璇疯緭鍏ユ纭殑宸ョ▼鏂囦欢璺緞: {ex.Message}");
+ }
+ }
+ }
+}
--
Gitblit v1.9.3