manager: add proper support for options

This commit is contained in:
Pascal
2025-06-27 11:24:53 +02:00
parent d0e3d2fa61
commit 77a93b585a
8 changed files with 76 additions and 7 deletions

View File

@@ -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>();

View File

@@ -18,7 +18,5 @@ public class InstallOptionSet
[DefaultValue(false)]
public bool Multiselect { get; set; }
public List<int> Defaults { get; } = [];
public List<InstallOption> Options { get; } = [];
}

View 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;
}
}

View File

@@ -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; }

View File

@@ -7,6 +7,7 @@
<ItemGroup>
<PackageReference Include="Pilz.Cryptography" Version="2.1.2" />
<PackageReference Include="Pilz.Extensions" Version="2.1.1" />
</ItemGroup>
</Project>