From 76985896cb3a0cc8def2be5fef8c22e8f583afb4 Mon Sep 17 00:00:00 2001 From: uye <99072975+ABA2396@users.noreply.github.com> Date: Mon, 9 Jun 2025 22:29:57 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"fix:=20=E9=81=BF=E5=85=8D=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1=E6=97=B6=E7=94=9F=E6=88=90=E4=B8=8D=E5=BF=85=E8=A6=81?= =?UTF-8?q?=E7=9A=84data=E6=96=87=E4=BB=B6=E5=A4=B9"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 2ac878dbbdff781b6a3465ec8a9d8e4b3f925150. --- .gitignore | 3 +++ src/MaaWpfGui/Helper/JsonDataHelper.cs | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 8531917a7a..83e0b5bc21 100644 --- a/.gitignore +++ b/.gitignore @@ -467,3 +467,6 @@ Thumbs.db # macOS Finder Shit .DS_Store + +# wpf 设计器会运行代码) +data/ \ No newline at end of file diff --git a/src/MaaWpfGui/Helper/JsonDataHelper.cs b/src/MaaWpfGui/Helper/JsonDataHelper.cs index 8571ec9bb0..904e4edb26 100644 --- a/src/MaaWpfGui/Helper/JsonDataHelper.cs +++ b/src/MaaWpfGui/Helper/JsonDataHelper.cs @@ -22,10 +22,25 @@ namespace MaaWpfGui.Helper { public static class JsonDataHelper { - private static readonly string _dataDir = "data"; + private static readonly string _dataDir = Path.Combine(Environment.CurrentDirectory, "data"); private static readonly object _lock = new(); private static readonly ILogger _logger = Log.ForContext("SourceContext", "JsonDataHelper"); + static JsonDataHelper() + { + try + { + if (!Directory.Exists(_dataDir)) + { + Directory.CreateDirectory(_dataDir); + } + } + catch (Exception ex) + { + _logger.Error(ex, "Failed to create data directory."); + } + } + /// /// 从 data/{key}.json 读取对象,如果不存在则返回 defaultValue /// @@ -76,7 +91,6 @@ namespace MaaWpfGui.Helper { try { - Directory.CreateDirectory(_dataDir); var json = JsonConvert.SerializeObject(value, Formatting.Indented); File.WriteAllText(filePath, json); return true;