mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 13:55:58 +00:00
feat: toggle Steam shader pre-caching from DroidDeck's Steam settings
This commit is contained in:
1 parent
f683ca1dea
commit
f88227ed74
12 files changed
+216
-5
No files matched your search
@@ -531,6 +531,10 @@ case $mode in
|
||||
fi
|
||||
droiddeck-seed-redists "$steam_root" || true
|
||||
fi
|
||||
if [ -n "${BL_SHADER_PRECACHE:-}" ]; then
|
||||
droiddeck-steam-shaders "$BL_SHADER_PRECACHE" "$XDG_DATA_HOME/Steam" \
|
||||
"${BL_X64_HOME:-$HOME/.droiddeck-x64}/.local/share/Steam" || true
|
||||
fi
|
||||
if [ "$steam_x64" = 0 ] && [ ! -f "$steam_root/steamapps/appmanifest_4427310.acf" ]; then
|
||||
step "asking the client to fetch the ARM64 Proton"
|
||||
set -- "$@" steam://install/4427310
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/python3
|
||||
"""Sets the Steam client's shader pre-caching (Settings > Downloads), before the client starts.
|
||||
|
||||
droiddeck-steam-shaders <0|1> <steam root>...
|
||||
|
||||
The client stores the toggle as InstallConfigStore/Software/Valve/Steam/ShaderCacheManager/
|
||||
DisableShaderCache in config/config.vdf: "1" when off, "0" when on. It keeps the setting in memory
|
||||
and writes config.vdf back on exit, so this runs only while the client is stopped. The launcher
|
||||
passes a value only after its own toggle changes; otherwise the client's toggle stays the user's."""
|
||||
from pathlib import Path
|
||||
import runpy
|
||||
import sys
|
||||
|
||||
|
||||
VDF = runpy.run_path(str(Path(__file__).with_name("droiddeck-steam-ui-scale")))
|
||||
PATH = ("Software", "Valve", "Steam", "ShaderCacheManager", "DisableShaderCache")
|
||||
|
||||
|
||||
def set_text(text, enabled):
|
||||
value = "0" if enabled else "1"
|
||||
updated, changed = VDF["seed_value"](text, PATH, value)
|
||||
if changed:
|
||||
return updated, True
|
||||
block = VDF["parse"](text).get("InstallConfigStore")
|
||||
for section in PATH[:-1]:
|
||||
block = block.get(section)
|
||||
current = block.get(PATH[-1])
|
||||
if isinstance(current, VDF["Block"]):
|
||||
raise ValueError("invalid DisableShaderCache setting")
|
||||
if current == value:
|
||||
return text, False
|
||||
at = block.offset(PATH[-1])
|
||||
end = VDF["TOKEN"].match(text, at).end()
|
||||
return text[:at] + f'"{value}"' + text[end:], True
|
||||
|
||||
|
||||
def apply(steam_root, enabled):
|
||||
config = Path(steam_root) / "config/config.vdf"
|
||||
text = config.read_text() if config.exists() else '"InstallConfigStore"\n{\n}\n'
|
||||
updated, changed = set_text(text, enabled)
|
||||
if changed:
|
||||
VDF["atomic_write"](config, updated)
|
||||
return changed
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 3 or sys.argv[1] not in ("0", "1"):
|
||||
print("usage: droiddeck-steam-shaders <0|1> <steam root>...", file=sys.stderr)
|
||||
sys.exit(2)
|
||||
enabled = sys.argv[1] == "1"
|
||||
status = 0
|
||||
for root in sys.argv[2:]:
|
||||
if not Path(root).is_dir():
|
||||
continue
|
||||
try:
|
||||
if apply(root, enabled):
|
||||
print(f"== steam: shader pre-caching {'on' if enabled else 'off'} in {root}")
|
||||
except (OSError, ValueError, RecursionError) as error:
|
||||
print(f"== steam: left shader pre-caching unchanged in {root}: {error}", file=sys.stderr)
|
||||
status = 1
|
||||
sys.exit(status)
|
||||
@@ -26,9 +26,10 @@ TOKEN = re.compile(r'\s+|//[^\n]*|"(?:\\.|[^"\\])*"|[{}]')
|
||||
|
||||
|
||||
class Block:
|
||||
def __init__(self, pairs, end):
|
||||
def __init__(self, pairs, end, offsets=()):
|
||||
self.pairs = pairs
|
||||
self.end = end
|
||||
self.offsets = offsets
|
||||
|
||||
def get(self, name):
|
||||
matches = [value for key, value in self.pairs if key.lower() == name.lower()]
|
||||
@@ -36,6 +37,9 @@ class Block:
|
||||
raise ValueError("duplicate UI setting")
|
||||
return matches[0] if matches else None
|
||||
|
||||
def offset(self, name):
|
||||
return next(at for (key, _), at in zip(self.pairs, self.offsets) if key.lower() == name.lower())
|
||||
|
||||
|
||||
def parse(text):
|
||||
tokens = []
|
||||
@@ -51,17 +55,17 @@ def parse(text):
|
||||
raise ValueError("invalid config.vdf")
|
||||
|
||||
def block(index, nested=False):
|
||||
pairs = []
|
||||
pairs, offsets = [], []
|
||||
while index < len(tokens):
|
||||
token, offset = tokens[index]
|
||||
if token == '}':
|
||||
if not nested:
|
||||
raise ValueError("unexpected closing brace")
|
||||
return Block(pairs, offset), index + 1
|
||||
return Block(pairs, offset, offsets), index + 1
|
||||
if not token.startswith('"') or index + 1 == len(tokens):
|
||||
raise ValueError("missing config value")
|
||||
key = token[1:-1]
|
||||
value = tokens[index + 1][0]
|
||||
value, at = tokens[index + 1]
|
||||
index += 2
|
||||
if value == '{':
|
||||
value, index = block(index, True)
|
||||
@@ -70,9 +74,10 @@ def parse(text):
|
||||
else:
|
||||
raise ValueError("invalid config value")
|
||||
pairs.append((key, value))
|
||||
offsets.append(at)
|
||||
if nested:
|
||||
raise ValueError("unclosed config block")
|
||||
return Block(pairs, len(text)), index
|
||||
return Block(pairs, len(text), offsets), index
|
||||
|
||||
return block(0)[0]
|
||||
|
||||
|
||||
Reference in new issue
Block a user