-
Notifications
You must be signed in to change notification settings - Fork 815
Expand file tree
/
Copy pathInstallOptions.cs
More file actions
107 lines (96 loc) · 4.84 KB
/
InstallOptions.cs
File metadata and controls
107 lines (96 loc) · 4.84 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
using System.Text.Json.Nodes;
using UniGetUI.Core.Data;
namespace UniGetUI.PackageEngine.Serializable
{
public class InstallOptions: SerializableComponent<InstallOptions>
{
public bool SkipHashCheck { get; set; }
public bool InteractiveInstallation { get; set; }
public bool RunAsAdministrator { get; set; }
public string Architecture { get; set; } = "";
public string InstallationScope { get; set; } = "";
public List<string> CustomParameters { get; set; } = [];
public bool PreRelease { get; set; }
public string CustomInstallLocation { get; set; } = "";
public string Version { get; set; } = "";
public bool SkipMinorUpdates { get; set; }
public bool OverridesNextLevelOpts { get; set; }
public bool RemoveDataOnUninstall { get; set; }
public override InstallOptions Copy()
{
return new()
{
SkipHashCheck = SkipHashCheck,
Architecture = Architecture,
CustomInstallLocation = CustomInstallLocation,
CustomParameters = CustomParameters,
InstallationScope = InstallationScope,
InteractiveInstallation = InteractiveInstallation,
PreRelease = PreRelease,
RunAsAdministrator = RunAsAdministrator,
Version = Version,
SkipMinorUpdates = SkipMinorUpdates,
OverridesNextLevelOpts = OverridesNextLevelOpts,
RemoveDataOnUninstall = RemoveDataOnUninstall,
};
}
public override void LoadFromJson(JsonNode data)
{
// RemoveDataOnUninstall should not be loaded from disk
this.SkipHashCheck = data[nameof(SkipHashCheck)]?.GetVal<bool>() ?? false;
this.InteractiveInstallation = data[nameof(InteractiveInstallation)]?.GetVal<bool>() ?? false;
this.RunAsAdministrator = data[nameof(RunAsAdministrator)]?.GetVal<bool>() ?? false;
this.Architecture = data[nameof(Architecture)]?.GetVal<string>() ?? "";
this.InstallationScope = data[nameof(InstallationScope)]?.GetVal<string>() ?? "";
this.CustomParameters = new List<string>();
foreach (var element in data[nameof(CustomParameters)]?.AsArray2() ?? [])
if (element is not null)
this.CustomParameters.Add(element.GetVal<string>());
this.PreRelease = data[nameof(PreRelease)]?.GetVal<bool>() ?? false;
this.CustomInstallLocation = data[nameof(CustomInstallLocation)]?.GetVal<string>() ?? "";
this.Version = data[nameof(Version)]?.GetVal<string>() ?? "";
this.SkipMinorUpdates = data[nameof(SkipMinorUpdates)]?.GetVal<bool>() ?? false;
// if OverridesNextLevelOpts is not found on the JSON, set it to true or false depending
// on whether the current settings instances are different from the default values.
// This entry shall be checked the last one, to ensure all other properties are set
this.OverridesNextLevelOpts =
data[nameof(OverridesNextLevelOpts)]?.GetValue<bool>() ?? DiffersFromDefault();
}
public bool DiffersFromDefault()
{
return SkipHashCheck is not false ||
InteractiveInstallation is not false ||
RunAsAdministrator is not false ||
PreRelease is not false ||
SkipMinorUpdates is not false ||
Architecture.Any() ||
InstallationScope.Any() ||
CustomParameters.Where(x => x != "").Any() ||
CustomInstallLocation.Any() ||
RemoveDataOnUninstall is not false ||
Version.Any();
// OverridesNextLevelOpts does not need to be checked here, since
// this method is invoked before this property has been set
}
public InstallOptions() : base()
{
}
public InstallOptions(JsonNode data) : base(data)
{
}
public override string ToString()
{
string customparams = CustomParameters.Any() ? string.Join(",", CustomParameters) : "[]";
return $"<InstallOptions: SkipHashCheck={SkipHashCheck};" +
$"InteractiveInstallation={InteractiveInstallation};" +
$"RunAsAdministrator={RunAsAdministrator};" +
$"Version={Version};" +
$"Architecture={Architecture};" +
$"InstallationScope={InstallationScope};" +
$"InstallationScope={CustomInstallLocation};" +
$"CustomParameters={customparams};" +
$"RemoveDataOnUninstall={RemoveDataOnUninstall};" +
$"PreRelease={PreRelease}>";
}
}
}