mirror of
https://gitlab.com/the-no-frauds-club/cosmonarchy-bw-prerelease.git
synced 2026-09-17 01:01:12 +00:00
43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
"""Add a DllOverrides entry to a Wine prefix's user.reg.
|
||
|
|
|
||
|
|
Usage: add-dll-override.py USER_REG DLL VALUE
|
||
|
|
e.g. add-dll-override.py ~/.../Blizzard/user.reg ddraw native,builtin
|
||
|
|
|
||
|
|
Only safe while no wineserver is live for that prefix - Wine rewrites user.reg
|
||
|
|
from memory when the last process exits, which would drop the edit.
|
||
|
|
"""
|
||
|
|
import sys
|
||
|
|
|
||
|
|
SECTION = r'[Software\\Wine\\DllOverrides]'
|
||
|
|
|
||
|
|
|
||
|
|
def main(path, dll, value):
|
||
|
|
with open(path, encoding='utf-8', errors='surrogateescape') as fh:
|
||
|
|
text = fh.read()
|
||
|
|
|
||
|
|
entry = '"%s"="%s"\n' % (dll, value)
|
||
|
|
if entry in text:
|
||
|
|
print('already set: %s = %s' % (dll, value))
|
||
|
|
return 0
|
||
|
|
|
||
|
|
i = text.find(SECTION)
|
||
|
|
if i == -1:
|
||
|
|
text = text.rstrip('\n') + '\n\n' + SECTION + ' 0\n' + entry
|
||
|
|
else:
|
||
|
|
j = text.index('\n', i) + 1 # past the section header
|
||
|
|
while j < len(text) and text[j] == '#': # past #time= and friends
|
||
|
|
j = text.index('\n', j) + 1
|
||
|
|
text = text[:j] + entry + text[j:]
|
||
|
|
|
||
|
|
with open(path, 'w', encoding='utf-8', errors='surrogateescape') as fh:
|
||
|
|
fh.write(text)
|
||
|
|
print('set: %s = %s' % (dll, value))
|
||
|
|
return 0
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == '__main__':
|
||
|
|
if len(sys.argv) != 4:
|
||
|
|
sys.exit(__doc__)
|
||
|
|
sys.exit(main(*sys.argv[1:]))
|