-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModels.cs
More file actions
80 lines (68 loc) · 2.37 KB
/
Copy pathModels.cs
File metadata and controls
80 lines (68 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System.IO;
using System.Text.Json;
namespace WechatBot;
// 运行设置
public class Settings
{
public DelaySettings Delays { get; set; } = new();
public ScrollSettings Scroll { get; set; } = new();
public RetrySettings Retry { get; set; } = new();
public ScheduleSettings Schedule { get; set; } = new();
public RecognitionSettings Recognition { get; set; } = new();
/// <summary>主题名称:Dark 或 Light</summary>
public string Theme { get; set; } = "Dark";
private static readonly string SettingsPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"猪猪工作室", "微信自动化", "settings.json");
/// <summary>
/// 加载设置,失败时返回默认值并通过 warn 回调通知调用方
/// </summary>
public static Settings Load(Action<string>? warn = null)
{
if (!File.Exists(SettingsPath)) return new Settings();
try
{
var json = File.ReadAllText(SettingsPath);
return JsonSerializer.Deserialize<Settings>(json) ?? new Settings();
}
catch (Exception ex)
{
warn?.Invoke($"配置文件加载失败,使用默认设置:{ex.Message}");
return new Settings();
}
}
public void Save()
{
Directory.CreateDirectory(Path.GetDirectoryName(SettingsPath)!);
var json = JsonSerializer.Serialize(this, new JsonSerializerOptions { WriteIndented = true });
File.WriteAllText(SettingsPath, json);
}
}
public class DelaySettings
{
public double Step { get; set; } = 1.5;
public double Load { get; set; } = 3.0;
}
public class ScrollSettings
{
public int Times { get; set; } = 5;
public int Amount { get; set; } = 120;
}
public class RetrySettings
{
public int MaxAttempts { get; set; } = 3;
public double WaitBetween { get; set; } = 2.0;
}
public class ScheduleSettings
{
public bool Enabled { get; set; } = false;
public string Time { get; set; } = "10:00";
public List<int> Days { get; set; } = [1, 2, 3, 4, 5, 6, 7];
/// <summary>上次执行日期(yyyy-MM-dd),用于持久化防重复执行</summary>
public string? LastRunDate { get; set; }
}
public class RecognitionSettings
{
/// <summary>图像模板匹配阈值(0.0 ~ 1.0)</summary>
public double MatchThreshold { get; set; } = 0.8;
}