PowerControl: Allow user to configure selectable TDP, CPU and GPU from PowerControl.dll.ini

This commit is contained in:
Kamil Trzciński 2023-02-08 14:09:19 +01:00
parent bec6b3538e
commit 6240ee4c46
5 changed files with 168 additions and 49 deletions

View file

@ -0,0 +1,56 @@
namespace PowerControl
{
public class PersistedOptions : CommonHelpers.BaseSettings
{
public const string OptionsKey = "Options";
public PersistedOptions(string name) : base(name + "Options")
{
}
public struct Option
{
public PersistedOptions Options { get; set; }
public string Key { get; set; }
public string FullKey(string setting)
{
return String.Format("{0}_{1}", Key, setting);
}
public bool Exist
{
get => Options.GetOptions().Contains(Key);
}
public Option Set<T>(string setting, T value)
{
// Get and persist value on first access
Options.Get(FullKey(setting), value, true);
return this;
}
public T Get<T>(string setting, T defaultValue)
{
// Get and do not persist value
return Options.Get(FullKey(setting), defaultValue, false);
}
}
public Option ForOption(string option)
{
return new Option() { Options = this, Key = option };
}
public void SetOptions(IEnumerable<Option> options)
{
Set<string>(OptionsKey, String.Join(",", options.Select((option) => option.Key)));
}
public string[] GetOptions()
{
var options = Get<string>(OptionsKey, "");
return options.Split(',', StringSplitOptions.RemoveEmptyEntries);
}
}
}