From 9843fbc036aa634767d7d8a226dd74b05ea52b6b Mon Sep 17 00:00:00 2001 From: uye <2396806385@qq.com> Date: Thu, 20 Jul 2023 22:41:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E5=99=A8=E9=85=8D=E7=BD=AE=E4=BB=8E=E6=9C=AA=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E6=97=B6=E7=9A=84=E9=80=BB=E8=BE=91=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MaaWpfGui/Helper/ConfigurationHelper.cs | 29 ++++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/MaaWpfGui/Helper/ConfigurationHelper.cs b/src/MaaWpfGui/Helper/ConfigurationHelper.cs index 093142ab54..105b00b1e9 100644 --- a/src/MaaWpfGui/Helper/ConfigurationHelper.cs +++ b/src/MaaWpfGui/Helper/ConfigurationHelper.cs @@ -15,6 +15,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Windows.Input; using MaaWpfGui.Constants; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -360,6 +361,24 @@ namespace MaaWpfGui.Helper return SetGlobalValue($"Timer.Timer{i + 1}Min", value); } + public static string GetTimerConfig(int i, string defaultValue) + { + // 防止未配置过任务时,读取到的是当前值,切换配置后仍会改变当前值 + var hasValue = _globalKvs.TryGetValue($"Timer.Timer{i + 1}.Config", out var value); + if (!hasValue) + { + SetGlobalValue($"Timer.Timer{i + 1}.Config", value); + return defaultValue; + } + + return GetGlobalValue($"Timer.Timer{i + 1}.Config", defaultValue); ; + } + + public static bool SetTimerConfig(int i, string value) + { + return SetGlobalValue($"Timer.Timer{i + 1}.Config", value); + } + public static string GetTaskOrder(string task, string defaultValue) { return GetValue("TaskQueue.Order." + task, defaultValue); @@ -370,16 +389,6 @@ namespace MaaWpfGui.Helper return SetValue("TaskQueue.Order." + task, value); } - public static string GetTimerConfig(int i, string defaultValue) - { - return GetValue($"Timer.Timer{i + 1}.Config", defaultValue); - } - - public static bool SetTimerConfig(int i, string value) - { - return SetValue($"Timer.Timer{i + 1}.Config", value); - } - public static void Release() { lock (_lock)