-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConfiguration.cs
More file actions
280 lines (245 loc) · 9.45 KB
/
Configuration.cs
File metadata and controls
280 lines (245 loc) · 9.45 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
using System.Diagnostics.CodeAnalysis;
using Dalamud.Configuration;
namespace Heliosphere;
internal class Configuration : IPluginConfiguration {
internal const int LatestVersion = 3;
public int Version { get; set; } = LatestVersion;
/// <summary>
/// This is a unique ID only sent to Sentry. It can be accessed and sent via
/// support channels to make finding error reports easier.
/// </summary>
public Guid UserId = Guid.NewGuid();
public bool FirstTimeSetupComplete;
public LoginUpdateMode LoginUpdateMode = LoginUpdateMode.Update;
public bool IncludeTags = true;
public bool OpenPenumbraAfterInstall = true;
public bool WarnAboutBreakingChanges = true;
public bool ReplaceSortName = true;
public bool ReplaceModName = true;
public bool HideDefaultVariant = true;
public bool UseNotificationProgress = true;
public bool NotificationsStartMinimised;
public bool AllowCommandInstalls = true;
public bool AllowCommandOneClick;
public bool UseRecycleBin;
public bool ShowImagesInManager = true;
public string TitlePrefix = "[HS] ";
public string PenumbraFolder = "Heliosphere";
public Guid? DefaultCollectionId;
public bool OneClick;
public byte[]? OneClickSalt;
public string? OneClickHash;
public Guid? OneClickCollectionId;
public ulong MaxKibsPerSecond;
public ulong AltMaxKibsPerSecond;
public SpeedLimit LimitNormal = SpeedLimit.On;
public SpeedLimit LimitInstance = SpeedLimit.Default;
public SpeedLimit LimitCombat = SpeedLimit.Default;
public SpeedLimit LimitParty = SpeedLimit.Default;
public PenumbraIntegration Penumbra = new();
public Dictionary<Guid, PackageSettings> PackageSettings = [];
public Unsupported Unsupported = new();
/// <summary>
/// The migration number of the latest migration the user has run. These are
/// prompts that the user must approve, so this is only set after approval
/// and success.
/// </summary>
public uint LatestMigration;
[Obsolete("Use LoginUpdateMode")]
public bool AutoUpdate = true;
[Obsolete("Use LoginUpdateMode")]
public bool CheckForUpdates = true;
public Configuration() {
}
internal Configuration(Configuration other) {
this.Version = other.Version;
this.UserId = other.UserId;
this.FirstTimeSetupComplete = other.FirstTimeSetupComplete;
this.LoginUpdateMode = other.LoginUpdateMode;
this.IncludeTags = other.IncludeTags;
this.OpenPenumbraAfterInstall = other.OpenPenumbraAfterInstall;
this.WarnAboutBreakingChanges = other.WarnAboutBreakingChanges;
this.ReplaceSortName = other.ReplaceSortName;
this.ReplaceModName = other.ReplaceModName;
this.HideDefaultVariant = other.HideDefaultVariant;
this.UseNotificationProgress = other.UseNotificationProgress;
this.NotificationsStartMinimised = other.NotificationsStartMinimised;
this.AllowCommandInstalls = other.AllowCommandInstalls;
this.AllowCommandOneClick = other.AllowCommandOneClick;
this.UseRecycleBin = other.UseRecycleBin;
this.ShowImagesInManager = other.ShowImagesInManager;
this.TitlePrefix = other.TitlePrefix;
this.PenumbraFolder = other.PenumbraFolder;
this.DefaultCollectionId = other.DefaultCollectionId;
this.OneClick = other.OneClick;
this.OneClickSalt = other.OneClickSalt;
this.OneClickHash = other.OneClickHash;
this.OneClickCollectionId = other.OneClickCollectionId;
this.MaxKibsPerSecond = other.MaxKibsPerSecond;
this.AltMaxKibsPerSecond = other.AltMaxKibsPerSecond;
this.LimitNormal = other.LimitNormal;
this.LimitInstance = other.LimitInstance;
this.LimitCombat = other.LimitCombat;
this.LimitParty = other.LimitParty;
this.LatestMigration = other.LatestMigration;
this.Penumbra = new PenumbraIntegration {
ShowImages = other.Penumbra.ShowImages,
ShowButtons = other.Penumbra.ShowButtons,
ExpandSettingsDefault = other.Penumbra.ExpandSettingsDefault,
ImageSize = other.Penumbra.ImageSize,
};
this.PackageSettings = other.PackageSettings.ToDictionary(
entry => entry.Key,
entry => new PackageSettings {
LoginUpdateMode = entry.Value.LoginUpdateMode,
Update = entry.Value.Update,
}
);
this.Unsupported = new Unsupported {
AllowNetworkedInstalls = other.AllowCommandInstalls,
};
}
internal bool TryGetPackageSettings(
Guid packageId,
[NotNullWhen(true)]
out PackageSettings? settings
) {
return this.PackageSettings.TryGetValue(packageId, out settings);
}
internal PackageSettings GetPackageSettingsOrDefault(Guid packageId) {
return this.TryGetPackageSettings(packageId, out var settings)
? settings
: Heliosphere.PackageSettings.NewDefault;
}
private void Redact() {
if (this.OneClickSalt != null) {
this.OneClickSalt = [1];
}
if (this.OneClickHash != null) {
this.OneClickHash = "[redacted]";
}
}
internal static Configuration CloneAndRedact(Configuration other) {
var redacted = new Configuration(other);
redacted.Redact();
return redacted;
}
internal void CleanUp() {
// remove any default package settings
var defaultSettings = Heliosphere.PackageSettings.NewDefault;
var toRemove = this.PackageSettings.Keys.Where(key => this.PackageSettings[key] == defaultSettings);
foreach (var remove in toRemove) {
this.PackageSettings.Remove(remove);
}
}
internal enum SpeedLimit {
Default,
On,
Alternate,
}
}
[Serializable]
internal class PenumbraIntegration {
public bool ShowImages = true;
public bool ShowButtons = true;
public bool ExpandSettingsDefault = true;
public float ImageSize = 0.375f;
}
[Serializable]
internal class PackageSettings {
public required LoginUpdateMode? LoginUpdateMode = null;
public required UpdateSetting Update = UpdateSetting.Default;
internal static PackageSettings NewDefault { get; } = new() {
LoginUpdateMode = null,
Update = UpdateSetting.Default,
};
public override bool Equals(object? obj) {
if (obj == null || this.GetType() != obj.GetType() || obj is not PackageSettings other) {
return false;
}
return this.LoginUpdateMode == other.LoginUpdateMode
&& this.Update == other.Update;
}
public override int GetHashCode() {
return this.LoginUpdateMode.GetHashCode()
^ this.Update.GetHashCode();
}
internal enum UpdateSetting {
Default,
Never,
}
}
internal static class UpdateSettingExt {
internal static string Description(this PackageSettings.UpdateSetting setting) {
return setting switch {
PackageSettings.UpdateSetting.Default => "No special behaviour",
PackageSettings.UpdateSetting.Never => "Never update",
_ => "Unknown",
};
}
}
internal enum LoginUpdateMode {
None,
Check,
Update,
}
internal static class LoginUpdateModeExt {
internal static string Name(this LoginUpdateMode mode) {
return mode switch {
LoginUpdateMode.None => "Disabled",
LoginUpdateMode.Check => "Check only",
LoginUpdateMode.Update => "Automatically update",
_ => throw new ArgumentOutOfRangeException(paramName: nameof(mode)),
};
}
internal static string Name(this LoginUpdateMode? mode) {
if (mode == null) {
return "Use global setting";
}
return mode.Value.Name();
}
internal static string ToJsName(this LoginUpdateMode mode) {
return mode switch {
LoginUpdateMode.None => "none",
LoginUpdateMode.Check => "check",
LoginUpdateMode.Update => "update",
_ => throw new ArgumentOutOfRangeException(paramName: nameof(mode)),
};
}
internal static bool TryFromJsName(string name, out LoginUpdateMode mode) {
switch (name) {
case "none":
mode = LoginUpdateMode.None;
return true;
case "check":
mode = LoginUpdateMode.Check;
return true;
case "update":
mode = LoginUpdateMode.Update;
return true;
default:
mode = 0;
return false;
}
}
internal static string Help(this LoginUpdateMode mode) {
return mode switch {
LoginUpdateMode.None => "Do not check for or automatically apply mod updates on login",
LoginUpdateMode.Check => "Check for but do not automatically apply mod updates on login",
LoginUpdateMode.Update => "Check for and automatically apply mod updates on login",
_ => throw new ArgumentOutOfRangeException(paramName: nameof(mode)),
};
}
internal static string Help(this LoginUpdateMode? mode) {
if (mode == null) {
return "Use the global login update behaviour setting for this mod";
}
return mode.Value.Help();
}
}
internal class Unsupported {
public bool AllowNetworkedInstalls;
internal bool AnyEnabled() {
return this.AllowNetworkedInstalls;
}
}