Some config display changes. WIP
This commit is contained in:
parent
0c07c9cfe5
commit
3742b4a230
@ -4,8 +4,67 @@
|
|||||||
public static class ConfigModule
|
public static class ConfigModule
|
||||||
{
|
{
|
||||||
[Command("display")]
|
[Command("display")]
|
||||||
public static void DisplayConfig()
|
public static void DisplayConfig(ConfigDisplayMode mode = ConfigDisplayMode.Color)
|
||||||
{
|
{
|
||||||
// TODO
|
switch (mode)
|
||||||
|
{
|
||||||
|
case ConfigDisplayMode.Raw:
|
||||||
|
DisplayConfigRaw();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ConfigDisplayMode.Color:
|
||||||
|
DisplayConfigColor();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Write("[", ConsoleColor.DarkGray);
|
||||||
|
for (int i = 0; i < config.GameDirectories.Length; i++)
|
||||||
|
{
|
||||||
|
Write(" \"", ConsoleColor.DarkGray, false);
|
||||||
|
Write(config.GameDirectories[i], ConsoleColor.White, false);
|
||||||
|
if (i < config.GameDirectories.Length - 1) Write("\",", ConsoleColor.DarkGray);
|
||||||
|
else Write("\"", ConsoleColor.DarkGray);
|
||||||
|
}
|
||||||
|
Write("]", ConsoleColor.DarkGray);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static void DisplayConfigRaw()
|
||||||
|
{
|
||||||
|
MemoryStream ms = new();
|
||||||
|
StreamWriter writer = new(ms, leaveOpen: true);
|
||||||
|
JsonTextWriter jsonWriter = new(writer);
|
||||||
|
|
||||||
|
Serializer.Serialize(jsonWriter, Config.LoadedConfig);
|
||||||
|
|
||||||
|
jsonWriter.Close();
|
||||||
|
writer.Close();
|
||||||
|
ms.Position = 0;
|
||||||
|
|
||||||
|
StreamReader reader = new(ms);
|
||||||
|
string msg = reader.ReadToEnd();
|
||||||
|
|
||||||
|
Write(msg);
|
||||||
|
|
||||||
|
reader.Close();
|
||||||
|
ms.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum ConfigDisplayMode
|
||||||
|
{
|
||||||
|
Raw,
|
||||||
|
Color
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,7 +21,15 @@ public struct Config
|
|||||||
|
|
||||||
static Config()
|
static Config()
|
||||||
{
|
{
|
||||||
Defaults = new();
|
Defaults = new()
|
||||||
|
{
|
||||||
|
GameDirectories = new[]
|
||||||
|
{
|
||||||
|
"testing 1",
|
||||||
|
"testing 2"
|
||||||
|
},
|
||||||
|
RunUnsafeCommands = AskMode.Ask
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public string[] GameDirectories;
|
public string[] GameDirectories;
|
||||||
@ -29,17 +37,20 @@ public struct Config
|
|||||||
|
|
||||||
public Config ApplyChanges(ConfigChanges changes) => this with
|
public Config ApplyChanges(ConfigChanges changes) => this with
|
||||||
{
|
{
|
||||||
GameDirectories = changes.GameDirectories ?? GameDirectories,
|
GameDirectories = GameDirectories.Union(changes.GameDirectories ?? Array.Empty<string>()).ToArray(),
|
||||||
RunUnsafeCommands = changes.RunUnsafeCommands ?? RunUnsafeCommands
|
RunUnsafeCommands = changes.RunUnsafeCommands ?? RunUnsafeCommands
|
||||||
};
|
};
|
||||||
public ConfigChanges GetChanges(Config? baseConfig = null)
|
public ConfigChanges GetChanges(Config? baseConfig = null)
|
||||||
{
|
{
|
||||||
Config reference = baseConfig ?? Defaults;
|
Config reference = baseConfig ?? Defaults;
|
||||||
return new()
|
ConfigChanges changes = new()
|
||||||
{
|
{
|
||||||
GameDirectories = reference.GameDirectories == GameDirectories ? null : GameDirectories,
|
GameDirectories = reference.GameDirectories == GameDirectories ? null :
|
||||||
|
GameDirectories.Where(x => !reference.GameDirectories.Contains(x)).ToArray(),
|
||||||
RunUnsafeCommands = reference.RunUnsafeCommands == RunUnsafeCommands ? null : RunUnsafeCommands
|
RunUnsafeCommands = reference.RunUnsafeCommands == RunUnsafeCommands ? null : RunUnsafeCommands
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return changes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadConfig(string basePath)
|
public static void LoadConfig(string basePath)
|
||||||
|
|||||||
@ -168,30 +168,6 @@ public static class Tools
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void WriteAutoColor(object? message, bool newLine = true)
|
|
||||||
{
|
|
||||||
ConsoleColor? col = null;
|
|
||||||
if (message is null) col = ConsoleColor.DarkGray;
|
|
||||||
else if (message is bool typeBool)
|
|
||||||
{
|
|
||||||
if (typeBool) col = ConsoleColor.Green;
|
|
||||||
else col = ConsoleColor.Red;
|
|
||||||
}
|
|
||||||
else if (message is sbyte || message is byte || message is short || message is ushort ||
|
|
||||||
message is int || message is uint || message is long || message is ulong ||
|
|
||||||
message is float || message is double || message is decimal) col = ConsoleColor.DarkGreen;
|
|
||||||
else if (message is char) col = ConsoleColor.DarkYellow;
|
|
||||||
else if (message is AskMode typeAskMode) col = typeAskMode switch
|
|
||||||
{
|
|
||||||
AskMode.Never => ConsoleColor.Red,
|
|
||||||
AskMode.Ask => ConsoleColor.DarkGray,
|
|
||||||
AskMode.Always => ConsoleColor.Green,
|
|
||||||
_ => null
|
|
||||||
};
|
|
||||||
|
|
||||||
Write(message, col, newLine);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool ValidateUnsafe()
|
public static bool ValidateUnsafe()
|
||||||
{
|
{
|
||||||
Write("You are about to execute an unsafe command.\nProceed? > ", ConsoleColor.DarkYellow, false);
|
Write("You are about to execute an unsafe command.\nProceed? > ", ConsoleColor.DarkYellow, false);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user