Added some config stuff. Next is modifying the config.

This commit is contained in:
That_One_Nerd 2023-04-17 19:11:33 -04:00
parent 3742b4a230
commit 4d342ae958
2 changed files with 40 additions and 12 deletions

View File

@ -21,10 +21,6 @@ public static class ConfigModule
private static void DisplayConfigColor()
{
Config config = Config.LoadedConfig;
List<string> dirs = config.GameDirectories is null ? new() : new(config.GameDirectories);
dirs.Add("config");
config.GameDirectories = dirs.ToArray();
Config.LoadedConfig = config;
Write("Steam Game Directories: ", null, false);
if (config.GameDirectories is null || config.GameDirectories.Length <= 0) Write("None", ConsoleColor.DarkGray);
@ -40,9 +36,20 @@ public static class ConfigModule
}
Write("]", ConsoleColor.DarkGray);
}
Write("Run Unsafe Commands: ", null, false);
ConsoleColor color = config.RunUnsafeCommands switch
{
AskMode.Never => ConsoleColor.Red,
AskMode.Always => ConsoleColor.Green,
AskMode.Ask or _ => ConsoleColor.DarkGray
};
Write(config.RunUnsafeCommands, color);
}
private static void DisplayConfigRaw()
{
// This is definitely a bit inefficient, but shouldn't be too much of an issue.
MemoryStream ms = new();
StreamWriter writer = new(ms, leaveOpen: true);
JsonTextWriter jsonWriter = new(writer);

View File

@ -170,15 +170,36 @@ public static class Tools
public static bool ValidateUnsafe()
{
Write("You are about to execute an unsafe command.\nProceed? > ", ConsoleColor.DarkYellow, false);
switch (Config.LoadedConfig.RunUnsafeCommands)
{
case AskMode.Always:
Write("[INFO] The shell has been configured to always run unsafe commands. " +
"This can be changed in the config.", ConsoleColor.DarkGray);
return true;
Console.ForegroundColor = ConsoleColor.Yellow;
Console.CursorVisible = true;
string result = Console.ReadLine()!.Trim().ToLower();
Console.CursorVisible = false;
Console.ResetColor();
case AskMode.Never:
Write("[ERROR] The shell has been configured to never run unsafe commands. " +
"This can be changed in the config.", ConsoleColor.Red);
return false;
return result == "y" || result == "yes" || result == "t" ||
result == "true" || result == "p" || result == "proceed";
case AskMode.Ask or _:
Write("You are about to execute an unsafe command.\nProceed? > ", ConsoleColor.DarkYellow, false);
Int2 start = (Console.CursorLeft, Console.CursorTop);
Write("\nTip: You can disable this dialog in the config.", ConsoleColor.DarkGray);
int finish = Console.CursorTop;
Console.SetCursorPosition(start.x, start.y);
Console.ForegroundColor = ConsoleColor.Yellow;
Console.CursorVisible = true;
string result = Console.ReadLine()!.Trim().ToLower();
Console.CursorVisible = false;
Console.ResetColor();
Console.SetCursorPosition(0, finish);
return result == "y" || result == "yes" || result == "t" ||
result == "true" || result == "p" || result == "proceed";
}
}
}