Closed sonic2kk closed 9 months ago
Version is bumped, shellcheck is green (apart from a couple of disable
s, one for a debug var and another for some style changes I didn't prioritise), and these functions shouldn't break any existing functionality. This should be ready to merge!
In future maybe we could add more logging, but I felt it was a bit too noisy for right now :-)
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: