diff --git a/.gitignore b/.gitignore index 83e0b5bc21..8531917a7a 100644 --- a/.gitignore +++ b/.gitignore @@ -467,6 +467,3 @@ 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 904e4edb26..8571ec9bb0 100644 --- a/src/MaaWpfGui/Helper/JsonDataHelper.cs +++ b/src/MaaWpfGui/Helper/JsonDataHelper.cs @@ -22,25 +22,10 @@ namespace MaaWpfGui.Helper { public static class JsonDataHelper { - private static readonly string _dataDir = Path.Combine(Environment.CurrentDirectory, "data"); + private static readonly string _dataDir = "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 /// @@ -91,6 +76,7 @@ namespace MaaWpfGui.Helper { try { + Directory.CreateDirectory(_dataDir); var json = JsonConvert.SerializeObject(value, Formatting.Indented); File.WriteAllText(filePath, json); return true;