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

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