Skip to content

Commit

Permalink
Config: Correctly parse arguments of ToggleAction, SingleAction
Browse files Browse the repository at this point in the history
  • Loading branch information
d2phap committed Nov 12, 2024
1 parent 8a98e59 commit 46fb5d4
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion Source/Components/ImageGlass.Settings/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ public static void Load(IConfigurationRoot? items = null)
.GetChildren()
.ToDictionary(
i => BHelper.ParseEnum<MouseClickEvent>(i.Key),
i => i.Get<ToggleAction>());
i => ParseToggleAction(i));


// MouseWheelActions
Expand Down Expand Up @@ -2111,6 +2111,51 @@ private static void MigrateUserConfigFile()
#endregion // Config file migration


// ToggleAction, SingleAction Parser
#region ToggleAction, SingleAction Parser

private static ToggleAction? ParseToggleAction(IConfigurationSection sec)
{
if (!sec.Exists()) return null;

var toggleOn = ParseSingleAction(sec.GetSection(nameof(ToggleAction.ToggleOn)));
var toggleOff = ParseSingleAction(sec.GetSection(nameof(ToggleAction.ToggleOff)));

return new ToggleAction(toggleOn)
{
ToggleOff = toggleOff,
};
}


private static SingleAction? ParseSingleAction(IConfigurationSection sec)
{
if (!sec.Exists()) return null;

var exe = sec.GetValueEx(nameof(SingleAction.Executable), "");
var args = Array.Empty<object>();
SingleAction? nextAc = null;

// get Arguments
var argsSec = sec.GetSection(nameof(SingleAction.Arguments));
if (argsSec.Exists())
{
args = argsSec.Get<object[]>().ToArray();
}

// get NextAction
var nextSec = sec.GetSection(nameof(SingleAction.NextAction));
if (nextSec.Exists())
{
nextAc = ParseSingleAction(nextSec);
}

return new SingleAction(exe, args, nextAc);
}

#endregion // ToggleAction, SingleAction Parser


// ImageFormats
#region ImageFormats

Expand Down

0 comments on commit 46fb5d4

Please sign in to comment.