Skip to content

Instantly share code, notes, and snippets.

@strycore
Created June 8, 2013 15:18
Show Gist options
  • Save strycore/5735482 to your computer and use it in GitHub Desktop.
Save strycore/5735482 to your computer and use it in GitHub Desktop.
Parser for Steam VDF files
import os
import json
def vdf_parse(steam_config_file, config):
line = " "
while line:
line = steam_config_file.readline()
if not line or line.strip() == "}":
return config
line_elements = line.strip().split("\"")
if len(line_elements) == 3:
key = line_elements[1]
steam_config_file.readline() # skip '{'
config[key] = vdf_parse(steam_config_file, {})
else:
config[line_elements[1]] = line_elements[3]
return config
if __name__ == "__main__":
STEAM_ROOT = "/home/strider/Steam/"
config_file = os.path.join(STEAM_ROOT, "config/config.vdf")
with open(config_file, "r") as steam_config_file:
config = vdf_parse(steam_config_file, {})
print json.dumps(config, indent=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment