Add support for value type to set_regedit()

And indent this raw text output. :)
This commit is contained in:
Xodetaetl 2014-10-09 16:14:15 +02:00
parent 7e75d61b3e
commit e698042410
2 changed files with 27 additions and 14 deletions

View file

@ -241,8 +241,9 @@ Currently, the following tasks are implemented:
app: nt40
* wine / winesteam: ``set_regedit`` Modifies the Windows registry. Parameters
are ``path`` (the registry path), ``key``, ``value``, ``prefix`` (optional
WINEPREFIX), ``working_dir`` (optional working directory).
are ``path`` (the registry path, use backslashes), ``key``, ``value``,
``type`` (optional value type, default is REG_SZ (string)), ``prefix``
(optional WINEPREFIX).
Example:
@ -251,9 +252,10 @@ Currently, the following tasks are implemented:
- task:
name: set_regedit
prefix: $GAMEDIR
path: HKEY_CURRENT_USER\Software\Wine\AppDefaults\Sacrifice.exe
key: Version
value: nt40
path: HKEY_CURRENT_USER\Software\Valve\Steam
key: SuppressAutoRun
value: 00000000
type: REG_DWORD
Trying the installer locally

View file

@ -1,6 +1,8 @@
import os
import subprocess
from textwrap import dedent
from lutris import settings
from lutris.gui import dialogs
from lutris.util.log import logger
@ -11,21 +13,30 @@ WINE_DIR = os.path.join(settings.RUNNER_DIR, "wine")
DEFAULT_WINE = '1.7.13'
def set_regedit(path, key, value, wine_path=None, prefix=None):
""" Plays with the windows registry
path is something like HKEY_CURRENT_USER\Software\Wine\Direct3D
def set_regedit(path, key, value='', type_='REG_SZ',
wine_path=None, prefix=None):
"""Add keys to the windows registry
Path is something like HKEY_CURRENT_USER\Software\Wine\Direct3D
"""
logger.debug("Setting wine registry key : %s\\%s to %s",
path, key, value)
reg_path = os.path.join(settings.CACHE_DIR, 'winekeys.reg')
formatted_value = {
'REG_SZ': '"%s"' % value,
'REG_DWORD': 'dword:' + value,
'REG_BINARY': 'hex:' + value.replace(' ', ','),
'REG_MULTI_SZ': 'hex(2):' + value,
'REG_EXPAND_SZ': 'hex(7):' + value,
}
# Make temporary reg file
reg_file = open(reg_path, "w")
reg_file.write("""REGEDIT4
[%s]
"%s"="%s"
""" % (path, key, value))
reg_file.write(dedent(
"""
REGEDIT4
[%s]
"%s"=%s
""" % (path, key, formatted_value[type_])))
reg_file.close()
wineexec('regedit', args=reg_path, prefix=prefix, wine_path=wine_path)
os.remove(reg_path)