Exemple #1
0
def set(branches):
    """
    Set registry values.
    Branches should be a dict similar to:
    {
     'HKEY_CURRENT_USER\\Software\\Wine':
      {"Version": "winnt"},
    'HKEY_CURRENT_USER\\Control Panel\\Desktop':
      {"FontSmoothing": "2"}
    }"""
    registry = u'REGEDIT4\n'

    definedbranches = []
    for b in sorted(branches.keys()):
        branchwalk = b.split('\\')
        for i in range(len(branchwalk)-1):
            branch = u'\n[%s\\%s]\n' % (branchwalk[0], '\\'.join(branchwalk[1:i+2]))
            if branch not in definedbranches:
                registry += branch
                definedbranches.append(branch)
        # Add the values
        for key,value in sorted(branches[b].iteritems()):
            key = key.replace('\\', '\\\\').replace('"', '\\"')
            if type(value) is int:
                value = str(value)
            elif type(value) in (str, unicode):
                value = util.string_escape_char(
                    util.string_escape_char(value, '\\').replace('\\', '\\\\'),
                    '"'
                )
            if value == '-' or value == None:
                registry += u'"{key}"=-\n'.format(
                    key = key.decode('utf-8')
                )
            elif str(value).startswith('hex:') or str(value).startswith('dword:'):
                registry += u'"{key}"={value}\n'.format(
                    key = key.decode('utf-8'),
                    value = value
                )
            else:
                try:
                    registry += u'"{key}"="{value}"\n'.format(
                        key = key.replace('"', '\\"').decode('utf-8'),
                        value = value.decode('utf-8')
                    )
                except TypeError:
                    print(u"Error in creating .reg file.\n"+ \
                        u"\tKey: {0}\n\tValue: {1}".format(
                            key, value
                        ),
                    file=sys.stderr)
    registry += u'\n'
    _writeRegistry(registry)
Exemple #2
0
def set(branches):
    """
    Set registry values.
    Branches should be a dict similar to:
    {
     'HKEY_CURRENT_USER\\Software\\Wine':
      {"Version": "winnt"},
    'HKEY_CURRENT_USER\\Control Panel\\Desktop':
      {"FontSmoothing": "2"}
    }"""
    registry = u'REGEDIT4\n'

    definedbranches = []
    for b in sorted(branches.keys()):
        branchwalk = b.split('\\')
        for i in range(len(branchwalk) - 1):
            branch = u'\n[%s\\%s]\n' % (branchwalk[0], '\\'.join(
                branchwalk[1:i + 2]))
            if branch not in definedbranches:
                registry += branch
                definedbranches.append(branch)
        # Add the values
        for key, value in sorted(branches[b].iteritems()):
            key = key.replace('\\', '\\\\').replace('"', '\\"')
            if type(value) is int:
                value = str(value)
            elif type(value) in (str, unicode):
                value = util.string_escape_char(
                    util.string_escape_char(value, '\\').replace('\\', '\\\\'),
                    '"')
            if value == '-' or value == None:
                registry += u'"{key}"=-\n'.format(key=key.decode('utf-8'))
            elif str(value).startswith('hex:') or str(value).startswith(
                    'dword:'):
                registry += u'"{key}"={value}\n'.format(
                    key=key.decode('utf-8'), value=value)
            else:
                try:
                    registry += u'"{key}"="{value}"\n'.format(
                        key=key.replace('"', '\\"').decode('utf-8'),
                        value=value.decode('utf-8'))
                except TypeError:
                    print(u"Error in creating .reg file.\n"+ \
                        u"\tKey: {0}\n\tValue: {1}".format(
                            key, value
                        ),
                    file=sys.stderr)
    registry += u'\n'
    _writeRegistry(registry)
Exemple #3
0
def set_theme(theme):
    theme_file = _get_theme_file_from_name(theme)
    theme_file = util.unixtowin(theme_file)
    return registry.set({
        ('HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\' + 'CurrentVersion\\ThemeManager'):
        {
            "DllName": util.string_escape_char(theme_file, '\\'),
            "ThemeActive": '1'
        }
    })
Exemple #4
0
def set_theme(theme):
    theme_file = _get_theme_file_from_name(theme)
    theme_file = util.unixtowin(theme_file)
    return registry.set({
        ('HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\'+
         'CurrentVersion\\ThemeManager'): {
            "DllName": util.string_escape_char(theme_file, '\\'),
            "ThemeActive": '1'
        }
    })
Exemple #5
0
def get_codepage():
    filename = __get_branch_file('HKEY_LOCAL_MACHINE')[0]
    branch = 'System\\CurrentControlSet\\Control\\Nls\\CodePage'
    try:
        with open(filename, 'r') as _file:
            codepage = _file.read().lower().split(
                util.string_escape_char(
                    branch.lower(), '\\'))[1].split('"acp"="')[1].split('"')[0]
        return 'cp{0}'.format(codepage)
    except (IOError, TypeError, IndexError):
        # Windows default
        return 'cp1252'
Exemple #6
0
def get_codepage():
    filename = __get_branch_file('HKEY_LOCAL_MACHINE')[0]
    branch = 'System\\CurrentControlSet\\Control\\Nls\\CodePage'
    try:
        with open(filename, 'r') as _file:
            codepage = _file.read().lower().split(
                util.string_escape_char(branch.lower(), '\\')
            )[1].split('"acp"="')[1].split('"')[0]
        return 'cp{0}'.format(codepage)
    except (IOError, IndexError):
        # Windows default
        return 'cp1252'
Exemple #7
0
def __set_branch_values(branch, dict, items):
    # Make sure the dict keys exist
    dict = __branch_to_dict(branch, dict)
    # Set the value
    pathname = 'dict%s' % ''.join(
        ['[\'%s\']' % i for i in filter(len, branch.split('\\'))])
    for key, value in items.iteritems():
        try:
            exec('{path}[\'{key}\'] = value'.format(
                path=pathname, key=util.string_escape_char(key, ['\\', "'"])))
        except ValueError:
            error("Error in registry! Pathname: %s\tKey: %s\tValue: %s" %
                  (pathname, key, value))
    return dict
Exemple #8
0
def __set_branch_values(branch, dict, items):
    # Make sure the dict keys exist
    dict = __branch_to_dict(branch, dict)
    # Set the value
    pathname = 'dict%s' % ''.join([ '[\'%s\']' % i for i in filter(len, branch.split('\\')) ])
    for key, value in items.iteritems():
        try:
            exec ('{path}[\'{key}\'] = value'.format(
                path = pathname,
                key = util.string_escape_char(key, ['\\', "'"])
            ))
        except ValueError:
            error("Error in registry! Pathname: %s\tKey: %s\tValue: %s" % (pathname, key, value))
    return dict
Exemple #9
0
def write_metadata(prefix_path=None, data=None):
    """
    Save metadata to the prefix.
    The prefix used is by default the currently used one, but can be overriden
    by the prefix_path argument.
    The metadata can be specified by the data argument, else it is taken from
    the prefix's running environment."""
    if prefix_path is None:
        try:
            prefix_path = common.ENV.get('WINEPREFIX')
        except:
            raise StandardError, 'No prefix in use (that\'s weird...)'

    is_default_prefix = prefix_path == os.path.expanduser('~/.wine')

    info_default = get_default_metadata()
    info = get_metadata(prefix_path)

    if data is None:
        data = {}

    if info is None:
        raise IOError, "Prefix path does not exist."

    # Save the new type of prefix data no matter the previous type since nothing
    # will be overwritten in any case
    #if info.get('WINEPREFIXTYPE', 'simple') in ('unified', 'preunified', 'simple'):
    content = []
    for key, name in [
        ('WINEPREFIXNAME', 'ww_name'),
        ('WINEDLLPATH', 'ww_winedllpath'),
        ('WINELOADER', 'ww_wineloader'),
        ('WINESERVER', 'ww_wineserver'),
        ('WINE', 'ww_wine'),
        ('XDG_CONFIG_HOME', 'ww_xdgconfig'),
        ('XDG_DATA_HOME', 'ww_xdgdata'),
        ('WINEARCH', 'ww_winearch')
    ]:
        # Get variable, first try given data, then common.ENV, then saved info
        var = data.get(key, common.ENV.get(key, info.get(key, None)))
        # If variable is set
        if var is not None:
            # Don't report WINEPREFIXNAME for default prefix (it's always blank)
            if key == 'WINEPREFIXNAME' and is_default_prefix:
                continue
            # Ignore default variables
            if var == info_default[key]:
                continue
            # Escape shell characters - FIXME: The spec doesn't have this!
            #var = var.replace('\\', '\\\\').replace('$', '\\$').replace('"', '\\"')
            var = util.string_escape_char(var, ('\\', '$', '"'))
            # Replace WINEPREFIX with PWD so the directory can be moved
            var = var.replace(
                util.string_escape_char(prefix_path, ('\\', '$', '"')),
                '$PWD'
            )
            content.append('{0}="{1}"'.format(name, var))

    content = '\n'.join(content)
    with open(os.path.join(prefix_path, 'wrapper.cfg'), 'w') as _file:
        _file.write(content)

    # A preunified format prefix is the same as unified apart from the
    # metadata file, so delete the old metadata file, effectively converting
    # the prefix to unified format.
    if info.get('WINEPREFIXTYPE', 'simple') == 'preunified':
        #disabled for testing
        #os.remove(os.path.join(prefix_path, 'vineyard', 'name'))
        pass

    return content