alterNERDtive-base: added config.dump plugin context

Dumps a list of all configuration options + their current value to the VoiceAttack log. Will also mention if they are set to the default.
This commit is contained in:
alterNERDtive 2020-12-07 16:29:07 +01:00
parent 58435a350e
commit f6a4861a06
2 changed files with 62 additions and 2 deletions

View file

@ -46,6 +46,11 @@ namespace alterNERDtive
| plugin contexts | | plugin contexts |
\================*/ \================*/
private static void Context_Config_Dump(dynamic vaProxy)
{
Config.DumpConfig();
}
private static void Context_Config_Setup(dynamic vaProxy) private static void Context_Config_Setup(dynamic vaProxy)
{ {
Log.Debug("Loading default configuration …"); Log.Debug("Loading default configuration …");
@ -282,12 +287,15 @@ namespace alterNERDtive
Context_Startup(vaProxy); Context_Startup(vaProxy);
break; break;
// config // config
case "config.setup": case "config.dump":
Context_Config_Setup(vaProxy); Context_Config_Dump(vaProxy);
break; break;
case "config.getvariables": case "config.getvariables":
Context_Config_SetVariables(vaProxy); Context_Config_SetVariables(vaProxy);
break; break;
case "config.setup":
Context_Config_Setup(vaProxy);
break;
case "config.versionmigration": case "config.versionmigration":
Context_Config_VersionMigration(vaProxy); Context_Config_VersionMigration(vaProxy);
break; break;

View file

@ -270,6 +270,58 @@ namespace alterNERDtive.util
ApplyDefault(id, key); ApplyDefault(id, key);
} }
} }
public void DumpConfig()
{
foreach (string id in Defaults.Keys)
{
DumpConfig(id);
}
}
public void DumpConfig(string id)
{
Log.Notice($"===== {id} configuration: =====");
foreach (string name in Defaults[id].Keys)
{
DumpConfig(id, name);
}
}
public void DumpConfig(string id, string name)
{
Option option = Defaults[id][name];
string variable = $"{id}.{option.Name}#";
dynamic defaultValue = option.DefaultValue;
dynamic value;
if (defaultValue is bool)
{
value = VA.GetBoolean(variable);
}
else if (defaultValue is DateTime)
{
value = VA.GetDate(variable);
}
else if (defaultValue is decimal)
{
value = VA.GetDecimal(variable);
}
else if (defaultValue is int)
{
value = VA.GetInt(variable);
}
else if (defaultValue is short)
{
value = VA.GetSmallInt(variable);
}
else if (defaultValue is string)
{
value = VA.GetText(variable);
}
else
{
throw new InvalidDataException($"Invalid data type for option '{id}.{name}': '{defaultValue}'");
}
Log.Notice($"{variable} = {value}{(value == defaultValue? " (default)" : "")}");
}
} }
public class PythonProxy public class PythonProxy