-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathAppConfig.cs
More file actions
139 lines (98 loc) · 5.06 KB
/
Copy pathAppConfig.cs
File metadata and controls
139 lines (98 loc) · 5.06 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using System.Collections.Generic;
using Newtonsoft.Json;
namespace GeneralUpdate.Tools.Configuration;
/// <summary>
/// Top-level application configuration model.
/// Persisted to <c>%APPDATA%/GeneralUpdate.Tools/config.json</c>.
/// </summary>
public class AppConfig
{
/// <summary>Configuration schema version, for migration support.</summary>
[JsonProperty("_schemaVersion")]
public int SchemaVersion { get; set; } = 1;
// ── UI Preferences ────────────────────────────────────────
[JsonProperty("language")]
public string Language { get; set; } = "zh-CN";
[JsonProperty("theme")]
public string Theme { get; set; } = "Light";
[JsonProperty("windowWidth")]
public double WindowWidth { get; set; } = 960;
[JsonProperty("windowHeight")]
public double WindowHeight { get; set; } = 640;
[JsonProperty("windowMaximized")]
public bool WindowMaximized { get; set; }
// ── Path Memory ───────────────────────────────────────────
[JsonProperty("lastPatchOldDir")]
public string LastPatchOldDir { get; set; } = string.Empty;
[JsonProperty("lastPatchNewDir")]
public string LastPatchNewDir { get; set; } = string.Empty;
[JsonProperty("lastPatchOutputDir")]
public string LastPatchOutputDir { get; set; } = string.Empty;
[JsonProperty("lastSimulateAppDir")]
public string LastSimulateAppDir { get; set; } = string.Empty;
[JsonProperty("lastSimulatePatchFile")]
public string LastSimulatePatchFile { get; set; } = string.Empty;
[JsonProperty("lastSimulateOutputDir")]
public string LastSimulateOutputDir { get; set; } = string.Empty;
[JsonProperty("lastConfigClientPath")]
public string LastConfigClientPath { get; set; } = string.Empty;
[JsonProperty("lastConfigUpgradePath")]
public string LastConfigUpgradePath { get; set; } = string.Empty;
[JsonProperty("lastOssOutputDir")]
public string LastOssOutputDir { get; set; } = string.Empty;
[JsonProperty("lastExtensionDir")]
public string LastExtensionDir { get; set; } = string.Empty;
[JsonProperty("lastExtensionOutputDir")]
public string LastExtensionOutputDir { get; set; } = string.Empty;
// ── Upload Configuration ──────────────────────────────────
[JsonProperty("uploadServerUrl")]
public string UploadServerUrl { get; set; } = string.Empty;
[JsonProperty("uploadEndpoint")]
public string UploadEndpoint { get; set; } = "/api/v1/packages/upload";
[JsonProperty("uploadTimeoutSeconds")]
public int UploadTimeoutSeconds { get; set; } = 300;
[JsonProperty("uploadRetryCount")]
public int UploadRetryCount { get; set; } = 3;
[JsonProperty("autoUploadEnabled")]
public bool AutoUploadEnabled { get; set; }
[JsonProperty("uploadAuth")]
public AuthCredential UploadAuth { get; set; } = new();
// ── Simulation Configuration ──────────────────────────────
[JsonProperty("simulationServerPort")]
public string SimulationServerPort { get; set; } = "5000";
[JsonProperty("simulationRequireAuth")]
public bool SimulationRequireAuth { get; set; }
[JsonProperty("simulationAuth")]
public AuthCredential SimulationAuth { get; set; } = new();
[JsonProperty("simulationPlatformType")]
public string SimulationPlatformType { get; set; } = "Windows";
[JsonProperty("simulationAppType")]
public string SimulationAppType { get; set; } = "Client";
// ── Feature Switches ──────────────────────────────────────
[JsonProperty("encryptionScanEnabled")]
public bool EncryptionScanEnabled { get; set; } = true;
[JsonProperty("autoValidateSemver")]
public bool AutoValidateSemver { get; set; } = true;
[JsonProperty("showJsonPreview")]
public bool ShowJsonPreview { get; set; } = true;
// ── Sanitization ───────────────────────────────────────────
/// <summary>
/// Repair invalid values that may have been introduced by manual JSON editing
/// or deserialization of an unknown/invalid enum value.
/// Called automatically by <see cref="ConfigService.Load"/> after deserialization.
/// </summary>
internal void Sanitize()
{
// Repair null nested objects (should never be null, but guard against manual JSON edits)
UploadAuth ??= new AuthCredential();
SimulationAuth ??= new AuthCredential();
// Validate numeric ranges
if (UploadTimeoutSeconds < 10)
UploadTimeoutSeconds = 300;
if (UploadRetryCount is < 0 or > 10)
UploadRetryCount = 3;
// Repair invalid enum values in auth credentials
UploadAuth.Sanitize();
SimulationAuth.Sanitize();
}
}