Skip to content

Commit 468a54e

Browse files
authored
执行调度器任务增加继续执行功能 (#1658)
* 完全跳过的配置组,不发送通知。给周期配置增加说明。 * 启动参数增加 --no-single ,允许多开,实现特殊需求(重启需要)。增加了一个重启bgi的方法。增加了任务进度的功能,执行调度器任务时,会记录当前任务执行位置,当关闭后(比如F11),下次可以通过继续菜单,选择记录,从上次关闭任务处执行。 * 调整继续执行,最后一次成功的下一个任务执行 * 设置,其他设置,增加了调度器任务,遇到异常时,连续累计一定次数时,重启BGI,和可配置的重启游戏。 * 连续任务支持循环,右键支持从连续的某一个任务开始执行。修改了一些配置变量的写法,使之不会保存到json文件中。
1 parent bb07092 commit 468a54e

File tree

15 files changed

+897
-63
lines changed

15 files changed

+897
-63
lines changed

BetterGenshinImpact/Core/Config/AllConfig.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,13 @@ public partial class AllConfig : ObservableObject
7474

7575
[ObservableProperty]
7676
private List<ValueTuple<string, int, string, string>> _nextScheduledTask = [];
77-
77+
78+
/// <summary>
79+
/// 连续执行任务时,从此任务开始执行
80+
/// </summary>
81+
[JsonIgnore]
82+
public string NextScriptGroupName { get; set; }= string.Empty;
83+
7884
/// <summary>
7985
/// 一条龙选中使用的配置
8086
/// </summary>

BetterGenshinImpact/Core/Config/OtherConfig.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.DirectoryServices.ActiveDirectory;
23
using CommunityToolkit.Mvvm.ComponentModel;
34

45
namespace BetterGenshinImpact.Core.Config;
@@ -13,7 +14,25 @@ public partial class OtherConfig : ObservableObject
1314
//自动领取派遣任务城市
1415
[ObservableProperty]
1516
private string _autoFetchDispatchAdventurersGuildCountry = "无";
17+
[ObservableProperty]
18+
private AutoRestart _autoRestartConfig = new();
19+
public partial class AutoRestart : ObservableObject
20+
{
21+
[ObservableProperty]
22+
private bool _enabled = false;
23+
24+
//调度器任务连续异常退出几次任务自动重启
25+
[ObservableProperty]
26+
private int _failureCount = 5;
27+
28+
//是否同时重启游戏,需开启首页启动配置:同时启动原神、自动进入游戏,此配置才会生效
29+
[ObservableProperty]
30+
private bool _restartGameTogether = false;
31+
32+
}
1633

34+
//public partial class OtherConfig : ObservableObject
35+
1736
/// <summary>
1837
/// 游戏语言名称
1938
/// </summary>

BetterGenshinImpact/Core/Script/Group/ScriptGroup.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
using BetterGenshinImpact.Service;
2-
using CommunityToolkit.Mvvm.ComponentModel;
3-
using System;
4-
using System.Collections.Generic;
1+
using System;
52
using System.Collections.ObjectModel;
63
using System.Collections.Specialized;
7-
using System.Text.Json;
8-
4+
using BetterGenshinImpact.Service;
5+
using CommunityToolkit.Mvvm.ComponentModel;
6+
using Newtonsoft.Json;
7+
using JsonSerializer = System.Text.Json.JsonSerializer;
98
namespace BetterGenshinImpact.Core.Script.Group;
109

1110
/// <summary>
@@ -24,6 +23,14 @@ public partial class ScriptGroup : ObservableObject
2423
[ObservableProperty]
2524
private ObservableCollection<ScriptGroupProject> _projects = [];
2625

26+
[System.Text.Json.Serialization.JsonIgnore]
27+
public bool NextFlag
28+
{
29+
get => _nextFlag;
30+
set => SetProperty(ref _nextFlag, value);
31+
}
32+
private bool _nextFlag;
33+
2734
public ScriptGroup()
2835
{
2936
Projects.CollectionChanged += ProjectsCollectionChanged;
@@ -41,7 +48,7 @@ public string ToJson()
4148

4249
public static ScriptGroup FromJson(string json)
4350
{
44-
var group = Newtonsoft.Json.JsonConvert.DeserializeObject<ScriptGroup>(json) ?? throw new Exception("解析配置组JSON配置失败");
51+
var group = JsonConvert.DeserializeObject<ScriptGroup>(json) ?? throw new Exception("解析配置组JSON配置失败");
4552
ResetGroupInfo(group);
4653
return group;
4754
}

BetterGenshinImpact/Core/Script/Group/ScriptGroupProject.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,29 @@ public partial class ScriptGroupProject : ObservableObject
7272
[JsonIgnore]
7373
public ScriptGroup? GroupInfo { get; set; }
7474

75+
private bool? _nextFlag = false;
76+
private bool? _skipFlag = false;
77+
7578
/// <summary>
7679
/// 下一个从此执行标志
7780
/// </summary>
7881
[JsonIgnore]
79-
[ObservableProperty]
80-
public bool? _nextFlag = false;
82+
public bool? NextFlag
83+
{
84+
get => _nextFlag;
85+
set => SetProperty(ref _nextFlag, value);
86+
}
87+
88+
/// <summary>
89+
/// 直接跳过标志
90+
/// </summary>
91+
[JsonIgnore]
92+
public bool? SkipFlag
93+
{
94+
get => _skipFlag;
95+
set => SetProperty(ref _skipFlag, value);
96+
}
97+
8198

8299
[ObservableProperty]
83100
private bool? _allowJsNotification = true;

BetterGenshinImpact/GameTask/RunnerContext.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
using System;
22
using System.Collections.Generic;
3-
using BetterGenshinImpact.GameTask.AutoFight.Model;
4-
using BetterGenshinImpact.Model;
5-
using Microsoft.Extensions.Logging;
63
using System.Threading;
74
using System.Threading.Tasks;
5+
using BetterGenshinImpact.GameTask.AutoFight.Model;
86
using BetterGenshinImpact.GameTask.AutoPathing.Suspend;
97
using BetterGenshinImpact.GameTask.Common.Job;
10-
using OpenCvSharp;
11-
using Wpf.Ui.Controls;
8+
using BetterGenshinImpact.Model;
9+
using Microsoft.Extensions.Logging;
1210
using static BetterGenshinImpact.GameTask.Common.TaskControl;
1311

1412
namespace BetterGenshinImpact.GameTask;
@@ -23,6 +21,8 @@ public class RunnerContext : Singleton<RunnerContext>
2321
/// </summary>
2422
public bool IsContinuousRunGroup { get; set; }
2523

24+
public TaskProgress.TaskProgress? taskProgress { get; set; }
25+
2626
/// <summary>
2727
/// 暂停逻辑
2828
/// </summary>
@@ -112,6 +112,7 @@ public void Reset()
112112
isAutoFetchDispatch = false;
113113
SuspendableDictionary.Clear();
114114
AutoPickTriggerStopCount = 0;
115+
taskProgress = null;
115116
}
116117

117118
/// <summary>

BetterGenshinImpact/GameTask/SystemControl.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,25 @@ public static void ActivateWindow()
185185

186186
ActivateWindow(TaskContext.Instance().GameHandle);
187187
}
188+
public static void RestartApplication(string[] newArgs)
189+
{
190+
// 获取当前程序路径
191+
string exePath = Process.GetCurrentProcess().MainModule.FileName;
192+
193+
// 构建参数字符串
194+
string arguments = string.Join(" ", [..newArgs,"--no-single"]);
195+
196+
// 启动新进程
197+
Process.Start(new ProcessStartInfo
198+
{
199+
FileName = exePath,
200+
Arguments = arguments,
201+
UseShellExecute = false
202+
});
188203

204+
// 关闭当前程序
205+
Environment.Exit(0);
206+
}
189207
public static void FocusWindow(nint hWnd)
190208
{
191209
if (User32.IsWindow(hWnd))
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text.Json;
4+
using System.Text.Json.Serialization;
5+
using BetterGenshinImpact.Service;
6+
using CommunityToolkit.Mvvm.ComponentModel;
7+
8+
namespace BetterGenshinImpact.GameTask.TaskProgress;
9+
10+
public partial class TaskProgress : ObservableObject
11+
{
12+
13+
[ObservableProperty] private List<string> _scriptGroupNames = new();
14+
15+
[ObservableProperty] private string? _lastScriptGroupName;
16+
[ObservableProperty] private ScriptGroupProjectInfo? _lastSuccessScriptGroupProjectInfo;
17+
[ObservableProperty] private string? _currentScriptGroupName;
18+
[ObservableProperty] private ScriptGroupProjectInfo? _currentScriptGroupProjectInfo;
19+
[ObservableProperty] private string _name = DateTime.Now.ToString("yyyyMMddHHmmss");
20+
[ObservableProperty] private DateTime _startTime = DateTime.Now;
21+
[ObservableProperty] private DateTime? _endTime = null;
22+
[ObservableProperty] private List<ScriptGroupProjectInfo>? _history = new();
23+
[ObservableProperty] private bool _loop = false;
24+
//记录完成了几圈
25+
[ObservableProperty] private int _loopCount = 0;
26+
private int _consecutiveFailureCount = 0;
27+
28+
private Progress? _next;
29+
/// <summary>
30+
/// 连续失败次数
31+
/// </summary>
32+
[JsonIgnore]
33+
public int ConsecutiveFailureCount
34+
{
35+
get => _consecutiveFailureCount;
36+
set => SetProperty(ref _consecutiveFailureCount, value);
37+
}
38+
39+
/// <summary>
40+
/// 进度信息,如果next不为空,则从next执行
41+
/// </summary>
42+
[JsonIgnore]
43+
public Progress? Next
44+
{
45+
get => _next;
46+
set => SetProperty(ref _next, value);
47+
}
48+
public partial class Progress : ObservableObject
49+
{
50+
[ObservableProperty] private string _groupName = string.Empty;
51+
[ObservableProperty] private int _index = 0;
52+
[ObservableProperty] private string _projectName = string.Empty;
53+
[ObservableProperty] private string _folderName = string.Empty;
54+
}
55+
public partial class ScriptGroupProjectInfo : ObservableObject
56+
{
57+
[ObservableProperty] private string _groupName = string.Empty;
58+
[ObservableProperty] private bool _taskEnd = false;
59+
[ObservableProperty] private int _index = 0;
60+
[ObservableProperty] private string _name = string.Empty;
61+
[ObservableProperty] private string _folderName = string.Empty;
62+
[ObservableProperty] private DateTime _startTime = DateTime.Now;
63+
[ObservableProperty] private DateTime? _endTime = null;
64+
//状态 1 成功 2 失败
65+
[ObservableProperty] private int _status = 1;
66+
}
67+
public string ToJson()
68+
{
69+
return JsonSerializer.Serialize(this, ConfigService.JsonOptions);
70+
}
71+
}

0 commit comments

Comments
 (0)