Gameloop.Vdf icon indicating copy to clipboard operation
Gameloop.Vdf copied to clipboard

Add support for conditionals

Open Bluscream opened this issue 4 years ago • 18 comments

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; }
    }
}

Bluscream avatar Sep 15 '19 17:09 Bluscream

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.

shravan2x avatar Oct 20 '19 21:10 shravan2x

Thanks

Bluscream avatar Oct 21 '19 01:10 Bluscream

@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.

shravan2x avatar Oct 23 '19 09:10 shravan2x

Uhh, is that really needed?

Bluscream avatar Oct 23 '19 13:10 Bluscream

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.

shravan2x avatar Oct 23 '19 21:10 shravan2x

Ill just wait, thank you ^^

Bluscream avatar Oct 23 '19 22:10 Bluscream

Now i've got the same error when reading the gameinfo.txt of the sourcemod "Too Many Crates!"

image

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
		}
	}
}

Bluscream avatar May 15 '20 23:05 Bluscream

"Incomplete data" is a vague error, couldn't you show at which line/column the parser shits itself?

Bluscream avatar May 16 '20 00:05 Bluscream

"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?

shravan2x avatar May 16 '20 00:05 shravan2x

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

Bluscream avatar May 16 '20 01:05 Bluscream

even the ones officially from HL2 use that format

image

Bluscream avatar May 16 '20 01:05 Bluscream

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);

shravan2x avatar May 16 '20 02:05 shravan2x

https://github.com/Bluscream/GMod-Mount-Manager/blob/master/Classes/GameInfo.cs#L46

this is my code

Bluscream avatar May 16 '20 02:05 Bluscream

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?

image

Bluscream avatar May 16 '20 02:05 Bluscream

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.

shravan2x avatar May 16 '20 02:05 shravan2x

gameinfo.txt

Bluscream avatar May 16 '20 02:05 Bluscream

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);

shravan2x avatar May 16 '20 04:05 shravan2x

Oh WOW, i gave it the filepath, not its contents 🤦

Bluscream avatar May 16 '20 06:05 Bluscream