ValveKeyValue
ValveKeyValue copied to clipboard
Improve handling of `#base` and `#include` directives
Hello! 👋
This PR makes two relatively small changes to improve handling of #base and #include directives.
I've been working with some .res files that have #base or #include directives which point to files that don't exist, and this PR silently skips those files. To my knowledge, this is how the Source engine treats such directives. Additionally, I've been working with some files that consist ONLY of these directives, which is also valid in the Source engine. This PR handles both cases.
Let me know if you'd like any changes or additions to this PR. I thought about adding tests but was kind of scared off by the test structure. I'd appreciate some help on that front if tests are desired.
Thanks!
Does it not work if your FileLoader simply returns an empty object? This needs a test too.
Does it not work if your
FileLoadersimply returns an empty object?
It does not, an error is thrown:
Unhandled exception. System.InvalidOperationException: Stack empty.
at System.Collections.Generic.Stack`1.ThrowForEmptyStack()
at System.Collections.Generic.Stack`1.Peek()
at ValveKeyValue.Deserialization.KVMergingObjectBuilder.FinalizeState() in C:\Users\vanca\Documents\git\SteamDatabase\ValveKeyValue\ValveKeyValue\ValveKeyValue\Deserialization\KVMergingObjectBuilder.cs:line 20
at ValveKeyValue.Deserialization.KVObjectBuilder.GetObject() in C:\Users\vanca\Documents\git\SteamDatabase\ValveKeyValue\ValveKeyValue\ValveKeyValue\Deserialization\KVObjectBuilder.cs:line 20
at ValveKeyValue.KVSerializer.Deserialize(Stream stream, KVSerializerOptions options) in C:\Users\vanca\Documents\git\SteamDatabase\ValveKeyValue\ValveKeyValue\ValveKeyValue\KVSerializer.cs:line 45
at REDACTED
This needs a test too.
Tests have been added 🙂
Perhaps instead of removing all the checks there should be a way for file loader to accept empty objects.
Have you tried an empty root object too?
Perhaps instead of removing all the checks there should be a way for file loader to accept empty objects.
I'm not sure what you mean.
Have you tried an empty root object too?
Yes. If a file that has #base or #include directives has even an empty root object, it would succeed without this PR. This PR only helps in the case where a file has only #base and #include directives with no root object.
I'd rather keep the checks that you removed, and instead explicitly support empty files/objects (consumers can provide empty root object at the moment).
@yaakov-h what do you think
I'd rather keep the checks that you removed, and instead explicitly support empty files/objects (consumers can provide empty root object at the moment).
What checks are you referring to? I don't think this PR removes any checks.
I'm gonna have to dig out my VKV-vs-tier1 validation tool and check exactly how Valve's handling works.