-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
VDF Parsing: Add More VDF Parsing Functions #967
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Can now insert values of all kinds including JSON values
…to change with getVdfSection
Version is bumped, shellcheck is green (apart from a couple of In future maybe we could add more logging, but I felt it was a bit too noisy for right now :-) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds various new VDF parsing functions that we can use when manipulating VDF block values.
getNestedVdfSection
- Allows for searching for the first match of a given VDF section path, including an optional indentation level to start searching from.getNestedVdfSection "/vdf/section/path" "startIndentation" "vdf_file"
getNestedVdfSection "Valve/Steam/ShaderCacheManager/App" "1" "$HOME/.local/share/Steam/config/config.vdf"
getVdfSectionValue
- Return the value of a VDF property within a given block.getVdfSectionValue "sectionString" "propertyName"
getVdfSectionValue "$( getNestedVdfSection "App/1234567890" "OverlayAppEnable" ""$HOME/.local/share/Steam/userdata/xxx/config/localconfig.vdf" )" "OverlayAppEnable"
createVdfPropertyString
- VDF properties follow a fixed format, this helper function can generate a VDF property string preparing it for entry in a VDF block.createVdfPropertyString "propertyName" "propertyValue"
createVdfPropertyString "DisableLaunchInVR" "0"
prepareJSONVdfProperty
- We need to escape JSON strings before entering them into a VDF file, in order to preserve the escape sequences that the VDF file expects. This function does the heavy lifting and even manages removing start and end quotes when needed.prepareJSONVdfProperty "stringifiedJSON"
prepareJSONVdfProperty "{"hello": "world", "foo": { "bar": ["foo", "bar"], "foobar": true, "barfoo": false }}"
substituteVdfSection
- Helper to replace an exact VDF section in a given VDF file with a manipulated one.substituteVdfSection "oldSection" "newSection" "vdf_file"
substituteVdfSection "$( getNestedVdfSection "App/1234567890" )" ""\1234567890\"\n{\n\t\t\"foo\"\t\t\"bar\"\n}" "vdf_path"
-- Indentation doesn't match here, but just an example (mainly meant for use byaddVdfSectionValue
andeditVdfSectionValue
below)addVdfSectionValue
- Add a new value to a VDF section. It will also auto-detect when we're dealing with a JSON stringaddVdfSectionValue "vdfSectionString" "newPropName" "newPropVal" "vdf_path"
addVdfSectionValue "$( getNestedVdfSection "App/1234567890" )" "MyProp" "0" "vdf_path"
editVdfSectionValue
- Edit an existing property's value within a given VDF section. Also auto-detects and handles JSON strings elegentlyeditVdfSectionValue "vdfSectionString" "updatePropName" "updatePropVal "vdf_path"
editVdfSectionValue "$( getNestedVdfSection "App/1234567890" )" "OverlayAppEnable" "1" "vdf_path"
There are also some (temporary) examples to proof out how we can use these functions in some upcoming work, such as for setting/updating a Non-Steam Game App entry in
localconfig.vdf
to toggle whether the Steam Overlay should be enabled for a given app. There is also an example of updating/creating theuser-collections
value to mark a Non-Steam Game as hidden. In future, we should be able to use this to add a Non-Steam Game to a collection, once we are able to reliably get the list of collection IDs by name to write into this JSON block.These functions are not really used yet outside of the debug scenarios in the code, but are a prerequisite to some upcoming work. They will allow us to do the following:
CompatToolMapping
entry when adding Non-Steam Gamesuser-collections
inlocalconfig.vdf
"Apps"/appid
section oflocalconfig.vdf
)user-collections
once we have the collection ID though.TODO: