Some progress on gameinfo parsing (DOESNT WORK YET)

This commit is contained in:
That-One-Nerd 2023-05-11 21:45:03 -04:00
parent 62d3ba6492
commit be6e4a496b
5 changed files with 94 additions and 15 deletions

View File

@ -9,6 +9,7 @@ global using SrcMod.Shell.Interop;
global using SrcMod.Shell.Modules; global using SrcMod.Shell.Modules;
global using SrcMod.Shell.Modules.ObjectModels; global using SrcMod.Shell.Modules.ObjectModels;
global using SrcMod.Shell.ObjectModels; global using SrcMod.Shell.ObjectModels;
global using SrcMod.Shell.ObjectModels.Source;
global using SrcMod.Shell.ObjectModels.Steam; global using SrcMod.Shell.ObjectModels.Steam;
global using System; global using System;
global using System.Collections; global using System.Collections;

View File

@ -18,14 +18,18 @@ public class Mod
while (!string.IsNullOrEmpty(check)) 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. // Root mod directory found, go from here.
// TODO: Parse VKV out of GameInfo.txt
FileStream fs = new(gameInfoPath, FileMode.Open);
GameInfo? modInfo = SerializeVkv.Deserialize<GameInfo>(fs); // TODO: constructor should be public i think
if (modInfo is null) continue;
Mod mod = new() Mod mod = new()
{ {
Name = Path.GetFileNameWithoutExtension(check), // TODO: replace with GameInfo: Title Name = modInfo.Title,
RootDirectory = check RootDirectory = check
}; };
return mod; return mod;

View File

@ -23,7 +23,7 @@ public class Config
private static Changes? p_changes; private static Changes? p_changes;
// These variables should only exist in the Config class so they aren't marked as shared. // 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() static Config()
{ {
@ -92,14 +92,8 @@ public class Config
string gameDirDataPath = Path.Combine(p_steamLocation, @"steamapps\libraryfolders.vdf"); string gameDirDataPath = Path.Combine(p_steamLocation, @"steamapps\libraryfolders.vdf");
VkvSerializer serializer = new(new()
{
useEscapeCodes = true,
useQuotes = true
});
FileStream gameDirData = new(gameDirDataPath, FileMode.Open); FileStream gameDirData = new(gameDirDataPath, FileMode.Open);
LibraryFolder[]? folders = SerializeVkv.Deserialize<LibraryFolder[]>(gameDirData);
LibraryFolder[]? folders = serializer.Deserialize<LibraryFolder[]>(gameDirData);
if (folders is null) if (folders is null)
{ {
Write("[WARNING] Error parsing Steam game directories.", ConsoleColor.DarkYellow); Write("[WARNING] Error parsing Steam game directories.", ConsoleColor.DarkYellow);
@ -177,7 +171,7 @@ public class Config
} }
StreamReader reader = new(fullPath); StreamReader reader = new(fullPath);
JsonTextReader jsonReader = new(reader); JsonTextReader jsonReader = new(reader);
p_changes = Serializer.Deserialize<Changes?>(jsonReader); p_changes = Tools.SerializerJson.Deserialize<Changes?>(jsonReader);
jsonReader.Close(); jsonReader.Close();
reader.Close(); reader.Close();
@ -198,7 +192,7 @@ public class Config
{ {
Indentation = 4 Indentation = 4
}; };
Serializer.Serialize(jsonWriter, p_changes); Tools.SerializerJson.Serialize(jsonWriter, p_changes);
jsonWriter.Close(); jsonWriter.Close();
writer.Close(); writer.Close();
} }

View File

@ -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<string, int> Hidden_Maps;
public Dictionary<string, string> 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<string, string> SearchPaths;
internal FileSystemData()
{
SearchPaths = new();
}
}
}

View File

@ -2,15 +2,27 @@
public static class Tools 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() static Tools()
{ {
Serializer = JsonSerializer.Create(new() SerializerJson = JsonSerializer.Create(new()
{ {
Formatting = Formatting.Indented, Formatting = Formatting.Indented,
NullValueHandling = NullValueHandling.Ignore 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<string> lines, ConsoleColor? color = null) public static void DisplayWithPages(IEnumerable<string> lines, ConsoleColor? color = null)