diff --git a/SrcMod/Shell/Miscellaneous/GlobalUsings.cs b/SrcMod/Shell/Miscellaneous/GlobalUsings.cs index bbee376..b5c13b0 100644 --- a/SrcMod/Shell/Miscellaneous/GlobalUsings.cs +++ b/SrcMod/Shell/Miscellaneous/GlobalUsings.cs @@ -9,6 +9,7 @@ global using SrcMod.Shell.Interop; global using SrcMod.Shell.Modules; global using SrcMod.Shell.Modules.ObjectModels; global using SrcMod.Shell.ObjectModels; +global using SrcMod.Shell.ObjectModels.Source; global using SrcMod.Shell.ObjectModels.Steam; global using System; global using System.Collections; diff --git a/SrcMod/Shell/Mod.cs b/SrcMod/Shell/Mod.cs index 148b38b..c3bfdd3 100644 --- a/SrcMod/Shell/Mod.cs +++ b/SrcMod/Shell/Mod.cs @@ -18,14 +18,18 @@ public class Mod while (!string.IsNullOrEmpty(check)) { - if (File.Exists(Path.Combine(check, "GameInfo.txt"))) + string gameInfoPath = Path.Combine(check, "GameInfo.txt"); + if (File.Exists(gameInfoPath)) { // Root mod directory found, go from here. - // TODO: Parse VKV out of GameInfo.txt + + FileStream fs = new(gameInfoPath, FileMode.Open); + GameInfo? modInfo = SerializeVkv.Deserialize(fs); // TODO: constructor should be public i think + if (modInfo is null) continue; Mod mod = new() { - Name = Path.GetFileNameWithoutExtension(check), // TODO: replace with GameInfo: Title + Name = modInfo.Title, RootDirectory = check }; return mod; diff --git a/SrcMod/Shell/ObjectModels/Config.cs b/SrcMod/Shell/ObjectModels/Config.cs index 3494028..9ef3cdf 100644 --- a/SrcMod/Shell/ObjectModels/Config.cs +++ b/SrcMod/Shell/ObjectModels/Config.cs @@ -23,7 +23,7 @@ public class Config private static Changes? p_changes; // These variables should only exist in the Config class so they aren't marked as shared. - private string p_steamLocation; + private readonly string p_steamLocation; static Config() { @@ -92,14 +92,8 @@ public class Config string gameDirDataPath = Path.Combine(p_steamLocation, @"steamapps\libraryfolders.vdf"); - VkvSerializer serializer = new(new() - { - useEscapeCodes = true, - useQuotes = true - }); FileStream gameDirData = new(gameDirDataPath, FileMode.Open); - - LibraryFolder[]? folders = serializer.Deserialize(gameDirData); + LibraryFolder[]? folders = SerializeVkv.Deserialize(gameDirData); if (folders is null) { Write("[WARNING] Error parsing Steam game directories.", ConsoleColor.DarkYellow); @@ -177,7 +171,7 @@ public class Config } StreamReader reader = new(fullPath); JsonTextReader jsonReader = new(reader); - p_changes = Serializer.Deserialize(jsonReader); + p_changes = Tools.SerializerJson.Deserialize(jsonReader); jsonReader.Close(); reader.Close(); @@ -198,7 +192,7 @@ public class Config { Indentation = 4 }; - Serializer.Serialize(jsonWriter, p_changes); + Tools.SerializerJson.Serialize(jsonWriter, p_changes); jsonWriter.Close(); writer.Close(); } diff --git a/SrcMod/Shell/ObjectModels/Source/GameInfo.cs b/SrcMod/Shell/ObjectModels/Source/GameInfo.cs new file mode 100644 index 0000000..039e92f --- /dev/null +++ b/SrcMod/Shell/ObjectModels/Source/GameInfo.cs @@ -0,0 +1,68 @@ +namespace SrcMod.Shell.ObjectModels.Source; + +// Referencing https://developer.valvesoftware.com/wiki/Gameinfo.txt. +public class GameInfo +{ + // Name + public string Game; + public string Title; + public bool GameLogo; + + // Options + public string Type; // TODO: Make this an enum. + public bool NoDifficulty; + public bool HasPortals; + public bool NoCrosshair; + public bool AdvCrosshair; + public bool NoModels; + public bool NoHIModel; + + public Dictionary Hidden_Maps; + public Dictionary CommandLine; + + // Steam games list + public string Developer; + public string Developer_URL; + public string Manual; + public string Icon; + + // Engine and tools + public bool Nodegraph; + public string GameData; + public string InstancePath; + public bool SupportsDX8; + public bool SupportsVR; + public bool SupportsXBox360; + public FileSystemData FileSystem; + + internal GameInfo() + { + Game = string.Empty; + Title = string.Empty; + Type = string.Empty; + Hidden_Maps = new(); + CommandLine = new(); + Developer = string.Empty; + Developer_URL = string.Empty; + Manual = string.Empty; + Icon = string.Empty; + GameData = string.Empty; + FileSystem = new(); + InstancePath = string.Empty; + } + + public class FileSystemData + { + public int SteamAppID; + public int AdditionalContentId; + public int ToolsAppId; + + // Can't make the keys here enums because they can be strung together, + public Dictionary SearchPaths; + + internal FileSystemData() + { + SearchPaths = new(); + } + } +} diff --git a/SrcMod/Shell/Tools.cs b/SrcMod/Shell/Tools.cs index bd1c219..f1e0809 100644 --- a/SrcMod/Shell/Tools.cs +++ b/SrcMod/Shell/Tools.cs @@ -2,15 +2,27 @@ public static class Tools { - public static JsonSerializer Serializer { get; private set; } + public static JsonSerializer SerializerJson { get; private set; } + public static VkvSerializer SerializeVkv { get; private set; } static Tools() { - Serializer = JsonSerializer.Create(new() + SerializerJson = JsonSerializer.Create(new() { Formatting = Formatting.Indented, NullValueHandling = NullValueHandling.Ignore }); + + SerializeVkv = new VkvSerializer(new() + { + closeWhenFinished = true, + indentSize = 4, + resetStreamPosition = false, + serializeProperties = true, + spacing = SpacingMode.DoubleTab, + useEscapeCodes = true, + useQuotes = true + }); } public static void DisplayWithPages(IEnumerable lines, ConsoleColor? color = null)