Some progress on gameinfo parsing (DOESNT WORK YET)
This commit is contained in:
parent
62d3ba6492
commit
be6e4a496b
@ -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;
|
||||
|
||||
@ -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<GameInfo>(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;
|
||||
|
||||
@ -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<LibraryFolder[]>(gameDirData);
|
||||
LibraryFolder[]? folders = SerializeVkv.Deserialize<LibraryFolder[]>(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<Changes?>(jsonReader);
|
||||
p_changes = Tools.SerializerJson.Deserialize<Changes?>(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();
|
||||
}
|
||||
|
||||
68
SrcMod/Shell/ObjectModels/Source/GameInfo.cs
Normal file
68
SrcMod/Shell/ObjectModels/Source/GameInfo.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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<string> lines, ConsoleColor? color = null)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user