From b2e411aab2b4f4e53280bcf93e19cf83e64540fe Mon Sep 17 00:00:00 2001 From: tfarcraw <123211521@163.com> Date: Fri, 20 Nov 2026 09:52:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=81=E4=B9=85=E4=BF=9D=E5=AD=98=E6=AD=A5?= =?UTF-8?q?=E9=AA=A4=E7=B4=AF=E8=AE=A1=E6=AC=A1=E6=95=B0=E5=B9=B6=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=89=8B=E5=8A=A8=E9=87=8D=E7=BD=AE=E8=AE=A1=E6=95=B0?= =?UTF-8?q?=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- .../Models/StepCountsStore.cs | 51 +++++++++++++++++++ .../VVMs/SopPage/SopPage.axaml | 1 + .../VVMs/SopPage/SopPageViewModel.cs | 23 +++++++++ .../Sop/SopEngine.cs | 20 +++++++- .../Sop/SopRunStatistics.cs | 24 +++++++++ tests/Avalonia.Smoke/Program.cs | 39 ++++++++++++++ 7 files changed, 158 insertions(+), 2 deletions(-) create mode 100644 src/SopHelper.Avalonia/Models/StepCountsStore.cs diff --git a/README.md b/README.md index 5d2a69e..3d57afb 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ pwsh -File tools/Publish-Avalonia.ps1 `--import-recipes 原数据根目录` 可以导入已有配方,`--check-standalone` / `--check-runtime` 检查本地手部模型和使用模拟 AI 的步骤门控,`--check-gpu` 额外要求手部推理使用 GPU;这些本地诊断不代表真实 D3 接口联调成功。 -主界面每个步骤显示正常次数和异常次数:正常完成计入正常,异常跳过计入异常;按配方累计本次运行的结果,复位、停止或重新应用配方不会清零,重启软件后重新统计。 +主界面每个步骤显示正常次数和异常次数:正常完成计入正常,异常跳过计入异常;按配方保存在 `workspace/step-counts.json`,复位、停止、重新应用配方或重启软件均保留;仅点击“重置步骤”后的“重置计数”按钮,才会清零当前已应用配方的计数,不影响步骤进度及其他配方。 ## 验证 diff --git a/src/SopHelper.Avalonia/Models/StepCountsStore.cs b/src/SopHelper.Avalonia/Models/StepCountsStore.cs new file mode 100644 index 0000000..61f170a --- /dev/null +++ b/src/SopHelper.Avalonia/Models/StepCountsStore.cs @@ -0,0 +1,51 @@ +using System.IO; +using System.Text.Json; +using SopHelper.Engine.Sop; +using SopHelper.Presentation; + +namespace SopHelper.Models; + +/// 按配方持久保存步骤累计结果,独立于运行参数和配方编辑。 +public sealed class StepCountsStore(string root) : IStepCountStore +{ + private static readonly object FileGate = new(); + public static StepCountsStore Current => new(DesktopPlatform.WorkspaceRoot); + public string FilePath => Path.Combine(root, "workspace", "step-counts.json"); + + private Dictionary> Read() + { + if (!File.Exists(FilePath)) return new(StringComparer.OrdinalIgnoreCase); + var all = JsonSerializer.Deserialize>>(File.ReadAllText(FilePath)) + ?? throw new InvalidDataException("累计次数文件内容为空"); + if (all.Values.Any(steps => steps is null || steps.Any(pair => pair.Key <= 0 + || pair.Value.NormalCount < 0 || pair.Value.AbnormalCount < 0))) + throw new InvalidDataException("累计次数文件包含无效步骤或负数"); + return new(all, StringComparer.OrdinalIgnoreCase); + } + + public IReadOnlyDictionary Load(string recipeName) + { + lock (FileGate) return Read().GetValueOrDefault(recipeName) ?? []; + } + + public void Save(string recipeName, IReadOnlyDictionary counts) + { + lock (FileGate) + { + var all = Read(); + all[recipeName] = new(counts); + Directory.CreateDirectory(Path.GetDirectoryName(FilePath)!); + var temporary = FilePath + ".tmp"; + try + { + using (var stream = new FileStream(temporary, FileMode.Create, FileAccess.Write, FileShare.None)) + { + JsonSerializer.Serialize(stream, all, new JsonSerializerOptions { WriteIndented = true }); + stream.Flush(flushToDisk: true); + } + File.Move(temporary, FilePath, overwrite: true); + } + finally { if (File.Exists(temporary)) File.Delete(temporary); } + } + } +} diff --git a/src/SopHelper.Avalonia/VVMs/SopPage/SopPage.axaml b/src/SopHelper.Avalonia/VVMs/SopPage/SopPage.axaml index c3a2adc..627bfc2 100644 --- a/src/SopHelper.Avalonia/VVMs/SopPage/SopPage.axaml +++ b/src/SopHelper.Avalonia/VVMs/SopPage/SopPage.axaml @@ -94,6 +94,7 @@