Ejemplo n.º 1
0
def _get_pp_data_from_registry(reg_file_path):
    reg_path = 'HKLM\\SYSTEM\\' + REG_KEY + ':' + REG_KEY_VAL
    tmp_pp_file = tempfile.NamedTemporaryFile(prefix='reg_pp_table_',
                                              delete=False)
    msg = ' Soft PowerPlay data from {}\n  key:value > {}\n'
    try:
        from Registry import Registry
    except ImportError as e:
        print('ERROR: -f/--from-registry option requires python-registry',
              'package, consider installing it with PIP.')
        sys.exit(-2)
    try:
        reg = Registry.Registry(reg_file_path)
        key = reg.open(REG_KEY)
        data_type = key.value(REG_KEY_VAL).value_type_str()
        registry_data = key.value(REG_KEY_VAL).raw_data()
    except Exception as e:
        print(('ERROR: Can not get' + msg).format(reg_file_path, reg_path))
        print(e)
        return None
    print(('Successfully loaded' + msg).format(reg_file_path, reg_path))
    decode._write_binary_file(tmp_pp_file.name, registry_data)
    tmp_pp_file.close()

    return tmp_pp_file.name
Ejemplo n.º 2
0
def _write_pp_to_reg_file(filename, data, debug=False):
    if _check_file_writeable(filename):
        reg_string = REG_KEY_VAL[3:] + '"=hex:' + data.hex(',')
        reg_lines = [
            reg_string[i:i + 75] for i in range(0, len(reg_string), 75)
        ]
        reg_lines[0] = '"' + REG_KEY_VAL[:3] + reg_lines[0]
        formatted_reg_string = '\\\r\n  '.join(reg_lines)
        reg_pp_data = REG_HEADER + formatted_reg_string + 2 * '\r\n'
        if debug:
            print(reg_pp_data)
        decode._write_binary_file(filename, reg_pp_data.encode('utf-16'))
        print('Written {} Soft PowerPlay bytes to {}'.format(
            len(data), filename))
    else:
        print('Can not write to {}'.format(filename))
    return 0
Ejemplo n.º 3
0
def set(ctx, variable_path_set, to_registry, write):
    """Sets value to one or multiple PP parameters

    The parameter path and value must be specified in
    "/<param>=<value> notation", for example:

    \b
        upp set /PowerTuneTable/TDP=75 /SclkDependencyTable/7/Sclk=107000

    Multiple PP parameters can be set at the same time.
    The PP tables will not be changed unless additional
    --write option is set.

    Optionally, if -t/--to-registry output is specified, an additional Windows
    registry format file with '.reg' extension will be generated, for example:

    \b
        upp set /PowerTuneTable/TDP=75 --to-registry=test

    will produce the file test.reg in the current working directory.
    """
    debug = ctx.obj['DEBUG']
    pp_file = ctx.obj['PPBINARY']
    set_pairs = []
    for set_pair_str in variable_path_set:
        var, val = _validate_set_pair(set_pair_str)
        if var and val:
            var_path = _normalize_var_path(var)
            res = decode.get_value(pp_file, var_path)
            if res:
                if (val.isdigit()):
                    set_pairs += [var_path + [int(val)]]
                else:
                    set_pairs += [var_path + [float(val)]]
            else:
                print('ERROR: Incorrect variable path:', var)
                return 2
        else:
            return 2

    pp_bytes = decode._read_binary_file(pp_file)
    data = decode.select_pp_struct(pp_bytes)

    for set_list in set_pairs:
        decode.set_value(pp_file,
                         pp_bytes,
                         set_list[:-1],
                         set_list[-1],
                         data_dict=data,
                         write=False,
                         debug=debug)
    if write:
        print("Commiting changes to '{}'.".format(pp_file))
        decode._write_binary_file(pp_file, pp_bytes)
    else:
        print("WARNING: Nothing was written to '{}'.".format(pp_file),
              "Add --write option to commit the changes for real!")
    if to_registry:
        _write_pp_to_reg_file(to_registry + '.reg', pp_bytes, debug=debug)

    return 0