From ec15e78564717d854f738d0811377359686b67cc Mon Sep 17 00:00:00 2001 From: That-One-Nerd Date: Mon, 17 Apr 2023 20:12:52 -0400 Subject: [PATCH] Added some config modifier commands. Definitely not very automated, stuff to do later. --- SrcMod/Shell/Modules/ConfigModule.cs | 101 +++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/SrcMod/Shell/Modules/ConfigModule.cs b/SrcMod/Shell/Modules/ConfigModule.cs index a206493..58e88a0 100644 --- a/SrcMod/Shell/Modules/ConfigModule.cs +++ b/SrcMod/Shell/Modules/ConfigModule.cs @@ -4,6 +4,7 @@ public static class ConfigModule { [Command("display")] + [Command("list")] public static void DisplayConfig(ConfigDisplayMode mode = ConfigDisplayMode.All) { switch (mode) @@ -26,6 +27,106 @@ public static class ConfigModule } } + [Command("add")] + [Command("append")] + public static void AppendConfigVariable(string name, string value) + { + Config config = Config.LoadedConfig; + + switch (name.Trim().ToLower()) + { + case "gamedirectories": + config.GameDirectories = config.GameDirectories.Append(value).ToArray(); + break; + + case "rununsafecommands": + throw new($"The config variable \"{name}\" is a single variable and cannot be appended to."); + + default: throw new($"Unknown config variable \"{name}\""); + } + + Config.LoadedConfig = config; + } + + [Command("delete")] + [Command("remove")] + public static void RemoveConfigVariable(string name, string value) + { + Config config = Config.LoadedConfig; + + switch (name.Trim().ToLower()) + { + case "gamedirectories": + config.GameDirectories = config.GameDirectories + .Where(x => x.Trim().ToLower() != value.Trim().ToLower()) + .ToArray(); + break; + + case "rununsafecommands": + throw new($"The config variable \"{name}\" is a single variable and cannot be appended to."); + + default: throw new($"Unknown config variable \"{name}\""); + } + + Config.LoadedConfig = config; + } + + [Command("reset")] + public static void ResetConfig(string name = "all") + { + Config config = Config.LoadedConfig; + + switch (name.Trim().ToLower()) + { + case "gamedirectories": + config.GameDirectories = Config.Defaults.GameDirectories; + break; + + case "rununsafecommands": + config.RunUnsafeCommands = Config.Defaults.RunUnsafeCommands; + break; + + case "all": + config = Config.Defaults; + break; + + default: throw new($"Unknown config variable \"{name}\""); + } + + Config.LoadedConfig = config; + } + + [Command("set")] + public static void SetConfigVariable(string name, string value) + { + Config config = Config.LoadedConfig; + + switch (name.Trim().ToLower()) + { + case "gamedirectories": + throw new($"The config variable \"{name}\" is a list and must be added or removed to."); + + case "rununsafecommands": + if (int.TryParse(value, out int intRes)) + { + AskMode mode = (AskMode)intRes; + if (!Enum.IsDefined(mode)) throw new($"(AskMode){value} is not a valid AskMode."); + config.RunUnsafeCommands = mode; + } + else if (Enum.TryParse(value, true, out AskMode modeRes)) + { + if (!Enum.IsDefined(modeRes)) throw new($"\"{value}\" is not a valid AskMode."); + config.RunUnsafeCommands = modeRes; + } + else throw new($"\"{value}\" is not a valid AskMode."); + break; + + default: throw new($"Unknown config variable \"{name}\""); + } + + Config.LoadedConfig = config; + } + private static void DisplayConfigAll() { DisplayConfigGameDirectories();