Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
91 lines (81 loc) · 3.34 KB
/
Copy pathProgram.cs
File metadata and controls
91 lines (81 loc) · 3.34 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
81
82
83
84
85
86
87
88
89
90
91
namespace SklandAutoSign;
internal static class Program
{
[STAThread]
private static async Task Main(string[] args)
{
ApplicationConfiguration.Initialize();
if (args.Any(x => string.Equals(x, "--self-test", StringComparison.OrdinalIgnoreCase)))
{
Environment.ExitCode = await SelfTestRunner.RunAsync();
return;
}
if (args.Any(x =>
string.Equals(x, "--run", StringComparison.OrdinalIgnoreCase) ||
string.Equals(x, "--maaend", StringComparison.OrdinalIgnoreCase)))
{
await HeadlessRunner.RunAsync();
return;
}
Application.Run(new MainForm());
}
}
internal static class SelfTestRunner
{
public static async Task<int> RunAsync()
{
var results = new List<string>();
try
{
const string secret = "diagnostic-secret";
string encrypted = SecretProtector.Protect(secret);
if (encrypted == secret || SecretProtector.Unprotect(encrypted) != secret)
throw new InvalidOperationException("DPAPI 加解密往返测试失败。");
results.Add("PASS DPAPI 加解密");
string normalized = SklandClient.NormalizeToken("{\"code\":0,\"data\":{\"content\":\"test-token\"}}");
if (normalized != "test-token")
throw new InvalidOperationException("Token JSON 解析测试失败。");
results.Add("PASS Token JSON 解析");
using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(15) };
using HttpResponseMessage response = await http.GetAsync("https://zonai.skland.com/api/v1/game/player/binding");
string responseText = await response.Content.ReadAsStringAsync();
if (!responseText.Contains("10002", StringComparison.Ordinal))
throw new InvalidOperationException("森空岛端点连通性测试未得到预期响应。");
results.Add("PASS 森空岛端点连通性");
results.Add("SELF-TEST PASSED");
File.WriteAllLines(Path.Combine(AppContext.BaseDirectory, "self-test.log"), results, new System.Text.UTF8Encoding(false));
return 0;
}
catch (Exception ex)
{
results.Add($"SELF-TEST FAILED: {ex.Message}");
File.WriteAllLines(Path.Combine(AppContext.BaseDirectory, "self-test.log"), results, new System.Text.UTF8Encoding(false));
return 1;
}
}
}
internal static class HeadlessRunner
{
public static async Task RunAsync()
{
try
{
AppSettings settings = SettingsStore.Load();
if (string.IsNullOrWhiteSpace(settings.EncryptedToken))
{
LogWriter.Write("静默签到跳过:尚未保存账号 Token。");
return;
}
string token = SecretProtector.Unprotect(settings.EncryptedToken);
using var client = new SklandClient();
IReadOnlyList<SignResult> results = await client.SignSelectedAsync(
token, settings.EnableArknights, settings.EnableEndfield);
foreach (SignResult result in results)
LogWriter.Write(result.Message);
}
catch (Exception ex)
{
LogWriter.Write($"静默签到失败:{ex.Message}");
}
}
}