fix: validate SteamVR preference backups

This commit is contained in:
XxJSONDeruloxX committed 2026-10-15 20:14:22 -04:00
1 parent fd7cb249b1
commit d8de6895c1
2 files changed
+45 -2

No files matched your search

@@ -28,10 +28,27 @@ def write(path, value):
os.replace(temporary, path)
def saved_preferences(path):
try:
backup = read(path)
if not isinstance(backup.get('section'), bool) or not isinstance(backup.get('values'), dict):
raise ValueError('invalid backup object')
for key in OVERRIDES:
entry = backup['values'].get(key)
if not isinstance(entry, list) or len(entry) != 2 or not isinstance(entry[0], bool):
raise ValueError('invalid saved preference: ' + key)
return backup
except ValueError as error:
raise ValueError(f'Invalid preference backup {path}; repair the saved section/values and retry restore. '
'The backup and current preferences have been preserved.') from error
def update(operation, settings_path, backup_path):
settings = read(settings_path)
if operation == 'apply':
if not backup_path.exists():
if backup_path.exists():
saved_preferences(backup_path)
else:
section = settings.get('steamvr', {})
write(backup_path, {'section': 'steamvr' in settings,
'values': {key: [key in section, section.get(key)] for key in OVERRIDES}})
@@ -40,7 +57,7 @@ def update(operation, settings_path, backup_path):
elif operation == 'restore':
if not backup_path.exists():
return
backup = read(backup_path)
backup = saved_preferences(backup_path)
section = settings.setdefault('steamvr', {})
for key in OVERRIDES:
present, value = backup['values'][key]