Gameloop.Vdf
Gameloop.Vdf copied to clipboard
Add support for conditionals
I tried reading csgo\resource\csgo_german.txt
using System;
using System.Collections.Generic;
using System.IO;
using Gameloop.Vdf;
using Gameloop.Vdf.Linq;
using Gameloop.Vdf.JsonConverter;
namespace WeaponSkinParser
{
public class LanguageFile
{
public string Language { get; set; }
public FileInfo File { get; set; }
public LanguageFileContents Content { get; set; }
public LanguageFile(FileInfo file) {
File = file;
Language = file.FileNameWithoutExtension().ToLowerInvariant().Replace("csgo_", "");
var fcontent = file.ReadAllText();
VProperty volvo = VdfConvert.Deserialize(fcontent);
Content = VTokenExtensions.ToJson(volvo).ToObject<LanguageFileContents>();
}
}
public class LanguageFileContents
{
string Language { get; set; }
List<LanguageFileToken> Tokens { get; set; }
}
public class LanguageFileToken
{
string Token { get; set; }
string Text { get; set; }
}
}
Looks like the issue is caused by the platform conditionals. Vdf.NET has intentionally not supported them so far. I'll try to work on it.
Thanks
@Bluscream In the off chance that you're blocked on this, you could use a regex to strip the source data of conditionals and then parse that. It would come at the cost of some performance, but probably not unusable.
Uhh, is that really needed?
It won't be needed once proper support for conditionals is added to the library. If you need something that works until then, using a regex is an option.
Ill just wait, thank you ^^
Now i've got the same error when reading the gameinfo.txt of the sourcemod "Too Many Crates!"
gameinfo.txt
"GameInfo"
{
// This is what shows up in the 'Third Party Games' area of the Steam games list.
game "Too Many Crates!"
type singleplayer_only
developer "AwesomePossumGames"
developer_url "http://classes.dma.ucla.edu/Fall07/161A/projects/kyle/portfolio/index.html"
icon "materials/icon"
FileSystem
{
SteamAppId 215 // GCF for Source SDK Base
ToolsAppId 211 // Tools will load this (ie: source SDK caches) to get things like materials\debug, materials\editor, etc.
//
// The code that loads this file automatically does a few things here:
//
// 1. For each "Game" search path, it adds a "GameBin" path, in <dir>\bin
// 2. For each "Game" search path, it adds another "Game" path in front of it with _<langage> at the end.
// For example: c:\hl2\cstrike on a french machine would get a c:\hl2\cstrike_french path added to it.
// 3. For the first "Game" search path, it adds a search path called "MOD".
// 4. For the first "Game" search path, it adds a search path called "DEFAULT_WRITE_PATH".
//
//
// Search paths are relative to the base directory, which is where hl2.exe is found.
//
// |gameinfo_path| points at the directory where gameinfo.txt is.
// We always want to mount that directory relative to gameinfo.txt, so
// people can mount stuff in c:\mymod, and the main game resources are in
// someplace like c:\program files\valve\steam\steamapps\half-life 2.
//
SearchPaths
{
Game |gameinfo_path|.
Game hl2
}
}
}
"Incomplete data" is a vague error, couldn't you show at which line/column the parser shits itself?
"Incomplete data" is a vague error, couldn't you show at which line/column the parser shits itself?
That would be a pretty neat feature, thanks for the suggestion. Do you mind creating a separate issue for it?
Now i've got the same error when reading the gameinfo.txt of the sourcemod "Too Many Crates!"
The file you posted seems to be missing a lot of double-quotes. Is that accurate?
That's what the mod ships by default. I tried a bunch of different gameinfo.txt files from different games and mods and they all throw the same error
even the ones officially from HL2 use that format
I just tested with the gameinfo.txt file you provided and it seems to parse correctly. The code I used to test:
dynamic res = VdfConvert.Deserialize(File.ReadAllText("gameinfo.txt"));
Console.WriteLine(res.Value.FileSystem.SearchPaths.Game);
https://github.com/Bluscream/GMod-Mount-Manager/blob/master/Classes/GameInfo.cs#L46
this is my code
I just tested with the gameinfo.txt file you provided and it seems to parse correctly.
maybe it has to do with the line endings or encoding?
maybe it has to do with the line endings or encoding?
No way for me to tell unless you send me the raw file. Line endings can vary from line to line so your screenshot is insufficient. However, the parser already supports all line-endings so that's unlikely to be the issue.
Just tried running with your file. Deserialization succeeds as expected. Try creating a new project and running:
dynamic res = VdfConvert.Deserialize(File.ReadAllText("gameinfo.txt"));
Console.WriteLine(res.Value.FileSystem.SearchPaths.Game);
Oh WOW, i gave it the filepath, not its contents 🤦
Support added in eb8b8b8bc5a4b0d4d20dd0fd85b77679d4b9a9b1 .