manager: add proper support for options
This commit is contained in:
@@ -15,6 +15,9 @@ public class InstallOption : IActionSet
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public Side Side { get; set; } = Side.Both;
|
||||
|
||||
[DefaultValue(false)]
|
||||
public bool Default { get; }
|
||||
|
||||
public List<UpdateAction> UninstallActions { get; } = [];
|
||||
|
||||
IEnumerable<InstallAction> IActionSet.Actions => UninstallActions.Cast<InstallAction>();
|
||||
|
||||
@@ -18,7 +18,5 @@ public class InstallOptionSet
|
||||
[DefaultValue(false)]
|
||||
public bool Multiselect { get; set; }
|
||||
|
||||
public List<int> Defaults { get; } = [];
|
||||
|
||||
public List<InstallOption> Options { get; } = [];
|
||||
}
|
||||
|
||||
28
ModpackUpdater/InstallOptionValueDictionary.cs
Normal file
28
ModpackUpdater/InstallOptionValueDictionary.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
namespace ModpackUpdater;
|
||||
|
||||
public class InstallOptionValueDictionary : Dictionary<string, bool>
|
||||
{
|
||||
public void SetOption(InstallOptionSet set, InstallOption option, bool value)
|
||||
{
|
||||
if (!set.Options.Contains(option))
|
||||
throw new KeyNotFoundException("Options seems to be not a part of the option set.");
|
||||
if (option.Default == value)
|
||||
UnsetOption(set, option);
|
||||
else
|
||||
this[$"{set.Id}.{option.Id}"] = value;
|
||||
}
|
||||
|
||||
public void UnsetOption(InstallOptionSet set, InstallOption option)
|
||||
{
|
||||
if (!set.Options.Contains(option))
|
||||
throw new KeyNotFoundException("Options seems to be not a part of the option set.");
|
||||
Remove($"{set.Id}.{option.Id}");
|
||||
}
|
||||
|
||||
public bool GetOptionValue(InstallOptionSet set, InstallOption option)
|
||||
{
|
||||
if (TryGetValue($"{set.Id}.{option.Id}", out var value))
|
||||
return value;
|
||||
return option.Default;
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ public class ModpackInfo
|
||||
public Version Version { get; set; }
|
||||
public string ConfigUrl { get; set; }
|
||||
public string ExtrasKey { get; set; }
|
||||
public InstallOptionValueDictionary Options { get; } = [];
|
||||
|
||||
[JsonIgnore]
|
||||
public string LocaLPath { get; private set; }
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Pilz.Cryptography" Version="2.1.2" />
|
||||
<PackageReference Include="Pilz.Extensions" Version="2.1.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user