fix: 自定义基建选择被错误重置

This commit is contained in:
status102
2025-12-28 23:27:11 +08:00
parent f814ce6ff7
commit 3e926892b4
2 changed files with 24 additions and 14 deletions

View File

@@ -41,7 +41,6 @@ using Newtonsoft.Json.Linq;
using Serilog;
using Stylet;
using static MaaWpfGui.Main.AsstProxy;
using static MaaWpfGui.States.RunningState;
using Application = System.Windows.Application;
using Screen = Stylet.Screen;
using Task = System.Threading.Tasks.Task;
@@ -1748,7 +1747,16 @@ public class TaskQueueViewModel : Screen
return false;
}
return Instances.AsstProxy.AsstAppendTaskWithEncoding(TaskType.Infrast, InfrastTask.Serialize());
try
{
return Instances.AsstProxy.AsstAppendTaskWithEncoding(TaskType.Infrast, InfrastTask.Serialize());
}
catch (Exception ex)
{
_logger.Error(ex, "AppendInfrast error");
AddLog("Append Infrast Error: " + ex.Message, UiLogColor.Error);
return false;
}
}
private bool _inited = false;

View File

@@ -353,6 +353,16 @@ public class InfrastSettingsUserControlModel : TaskViewModel
SetAndNotify(ref _customInfrastFile, value);
ConfigurationHelper.SetValue(ConfigurationKeys.CustomInfrastFile, value);
ParseCustomInfrastPlan(true);
int index = CustomInfrastPlanList.Any(i => i.Period.Count > 0) ? -1 : 0;
if (index != CustomInfrastPlanSelect)
{
CustomInfrastPlanSelect = index;
}
else
{
NotifyOfPropertyChange(nameof(CustomInfrastPlanSelect));
}
}
}
@@ -529,18 +539,6 @@ public class InfrastSettingsUserControlModel : TaskViewModel
CustomInfrastPlanList = [];
Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("CustomInfrastFileParseFailed"), UiLogColor.Error);
}
finally
{
int index = CustomInfrastPlanList.Any(i => i.Period.Count > 0) ? -1 : 0;
if (index != CustomInfrastPlanSelect)
{
CustomInfrastPlanSelect = index;
}
else
{
NotifyOfPropertyChange(nameof(CustomInfrastPlanSelect));
}
}
}
/// <summary>
@@ -624,6 +622,10 @@ public class InfrastSettingsUserControlModel : TaskViewModel
if (InfrastMode != Mode.Custom)
{
}
else if (CustomInfrastPlanSelect != -1 && CustomInfrastPlanList.Count <= CustomInfrastPlanSelect)
{
throw new InvalidOperationException("CustomInfrastPlanSelect is out of range");
}
else if (CustomInfrastPlanSelect >= 0)
{
task.PlanIndex = CustomInfrastPlanSelect;