def test_can_render_system_reg(self): registry_path = os.path.join(FIXTURES_PATH, 'system.reg') with open(registry_path, 'r') as registry_file: original_content = registry_file.read() system_reg = WineRegistry(registry_path) content = system_reg.render() self.assertEqual(content, original_content)
def check_registry(registry_path): with open(registry_path, 'r') as registry_file: original_content = registry_file.read() try: wine_registry = WineRegistry(registry_path) except: sys.stderr.write("Error parsing {}\n".format(registry_path)) raise content = wine_registry.render() if content != original_content: wrong_path = os.path.join(os.path.dirname(__file__), 'error.reg') with open(wrong_path, 'w') as wrong_reg: wrong_reg.write(content) print("Content of parsed registry doesn't match: {}".format( registry_path)) subprocess.call(["meld", registry_path, wrong_path]) sys.exit(2)
def get_steam_path(self): """Return Steam exe's path""" custom_path = self.runner_config.get("steam_path") or "" if custom_path: custom_path = os.path.abspath( os.path.expanduser(os.path.join(custom_path, "Steam.exe")) ) if system.path_exists(custom_path): return custom_path candidates = [ self.get_default_prefix(arch="win64"), self.get_default_prefix(arch="win32"), os.path.expanduser("~/.wine"), ] for prefix in candidates: # Try the default install path for default_path in [ "drive_c/Program Files (x86)/Steam/Steam.exe", "drive_c/Program Files/Steam/Steam.exe", ]: steam_path = os.path.join(prefix, default_path) if system.path_exists(steam_path): return steam_path # Try from the registry key user_reg = os.path.join(prefix, "user.reg") if not system.path_exists(user_reg): continue registry = WineRegistry(user_reg) steam_path = registry.query("Software/Valve/Steam", "SteamExe") if not steam_path: steam_path = self.get_open_command(registry) if not steam_path: continue return system.fix_path_case(registry.get_unix_path(steam_path)) return ""
def get_steam_path(self): """Return Steam exe's path""" custom_path = self.runner_config.get("steam_path") or "" if custom_path: custom_path = os.path.abspath( os.path.expanduser(os.path.join(custom_path, "Steam.exe")) ) if system.path_exists(custom_path): return custom_path candidates = [ self.get_default_prefix(arch="win64"), self.get_default_prefix(arch="win32"), os.path.expanduser("~/.wine"), ] for prefix in candidates: # Try the default install path for default_path in [ "drive_c/Program Files (x86)/Steam/Steam.exe", "drive_c/Program Files/Steam/Steam.exe", ]: steam_path = os.path.join(prefix, default_path) if system.path_exists(steam_path): return steam_path # Try from the registry key user_reg = os.path.join(prefix, "user.reg") if not system.path_exists(user_reg): continue registry = WineRegistry(user_reg) steam_path = registry.query("Software/Valve/Steam", "SteamExe") if not steam_path: steam_path = self.get_open_command(registry) if not steam_path: continue return system.fix_path_case(registry.get_unix_path(steam_path))
def set_registry_key(self, key, subkey, value): registry = WineRegistry(self.get_registry_path(key)) registry.set_value(self.get_key_path(key), subkey, value) registry.save()
def get_registry_key(self, key, subkey): registry = WineRegistry(self.get_registry_path(key)) return registry.query(self.get_key_path(key), subkey)
def setUp(self): self.registry_path = os.path.join(FIXTURES_PATH, 'user.reg') self.registry = WineRegistry(self.registry_path)
class TestWineRegistry(TestCase): def setUp(self): self.registry_path = os.path.join(FIXTURES_PATH, 'user.reg') self.registry = WineRegistry(self.registry_path) def test_can_load_registry(self): self.assertTrue(len(self.registry.keys) > 10) self.assertEqual(self.registry.version, 2) self.assertEqual(self.registry.arch, 'win64') def test_can_query_registry(self): value = self.registry.query('Control Panel/Keyboard', 'KeyboardSpeed') self.assertEqual(value, '31') def test_can_get_timestamp_as_int(self): key = self.registry.keys.get('Control Panel/Keyboard') self.assertEqual(key.timestamp, 1477412318) def test_can_get_timestamp_as_float(self): key = self.registry.keys.get('Control Panel/Sound') self.assertEqual(key.timestamp, 1475423303.7943190) def test_can_get_meta(self): key = self.registry.keys.get('Control Panel/Sound') self.assertEqual(key.get_meta('time'), '1d21cc468677196') def test_can_get_string_value(self): key = self.registry.keys.get('Control Panel/Desktop') self.assertEqual(key.get_subkey('DragFullWindows'), '0') def test_can_get_dword_value(self): key = self.registry.keys.get('Control Panel/Desktop') self.assertEqual(key.get_subkey('CaretWidth'), 1) def test_can_render_key(self): expected = ('[Software\\\\Wine\\\\Fonts] 1477412318\n' '#time=1d22edb71813e3c\n' '"Codepages"="1252,437"\n' '"LogPixels"=dword:00000000\n') key = self.registry.keys.get('Software/Wine/Fonts') self.assertEqual(key.render(), expected) def test_render_user_reg(self): content = self.registry.render() with open(self.registry_path, 'r') as registry_file: original_content = registry_file.read() self.assertEqual(content, original_content) def test_can_render_system_reg(self): registry_path = os.path.join(FIXTURES_PATH, 'system.reg') with open(registry_path, 'r') as registry_file: original_content = registry_file.read() system_reg = WineRegistry(registry_path) content = system_reg.render() self.assertEqual(content, original_content) def test_can_set_value_to_existing_subkey(self): self.assertEqual( self.registry.query('Control Panel/Desktop', 'DragWidth'), '4') self.registry.set_value('Control Panel/Desktop', 'DragWidth', '8') self.assertEqual( self.registry.query('Control Panel/Desktop', 'DragWidth'), '8') def test_can_set_value_to_a_new_sub_key(self): self.assertEqual( self.registry.query('Control Panel/Desktop', 'BliBlu'), None) self.registry.set_value('Control Panel/Desktop', 'BliBlu', 'yep') self.assertEqual( self.registry.query('Control Panel/Desktop', 'BliBlu'), 'yep') def test_can_set_value_to_a_new_key(self): self.assertEqual(self.registry.query('Wine/DX11', 'FullyWorking'), None) self.registry.set_value('Wine/DX11', 'FullyWorking', 'HellYeah') self.assertEqual(self.registry.query('Wine/DX11', 'FullyWorking'), 'HellYeah') def test_can_clear_a_key(self): path = 'Control Panel/Mouse' key = self.registry.keys.get(path) self.assertEqual(len(key.subkeys), 13) self.registry.clear_key(path) self.assertEqual(len(key.subkeys), 0)
def _return_local_game_path(launch_id): installs_path = UBISOFT_REGISTRY_LAUNCHER_INSTALLS registry = WineRegistry() game_path = registry.query("HKEY_LOCAL_MACHINE" + installs_path + f'\\{launch_id}', 'InstallDir') return os.path.normcase(os.path.normpath(game_path))
def clear_registry_key(self, key): registry = WineRegistry(self.get_registry_path(key)) registry.clear_key(self.get_key_path(key)) registry.save()
class TestWineRegistry(TestCase): def setUp(self): self.registry_path = os.path.join(FIXTURES_PATH, 'user.reg') self.registry = WineRegistry(self.registry_path) def test_can_load_registry(self): self.assertTrue(len(self.registry.keys) > 10) self.assertEqual(self.registry.version, 2) self.assertEqual(self.registry.arch, 'win64') def test_can_query_registry(self): value = self.registry.query('Control Panel/Keyboard', 'KeyboardSpeed') self.assertEqual(value, '31') def test_can_get_timestamp_as_int(self): key = self.registry.keys.get('Control Panel/Keyboard') self.assertEqual(key.timestamp, 1477412318) def test_can_get_timestamp_as_float(self): key = self.registry.keys.get('Control Panel/Sound') self.assertEqual(key.timestamp, 1475423303.7943190) def test_can_get_meta(self): key = self.registry.keys.get('Control Panel/Sound') self.assertEqual(key.get_meta('time'), '1d21cc468677196') def test_can_get_string_value(self): key = self.registry.keys.get('Control Panel/Desktop') self.assertEqual(key.get_subkey('DragFullWindows'), '0') def test_can_get_dword_value(self): key = self.registry.keys.get('Control Panel/Desktop') self.assertEqual(key.get_subkey('CaretWidth'), 1) def test_can_render_key(self): expected = ( '[Software\\\\Wine\\\\Fonts] 1477412318\n' '#time=1d22edb71813e3c\n' '"Codepages"="1252,437"\n' '"LogPixels"=dword:00000000\n' ) key = self.registry.keys.get('Software/Wine/Fonts') self.assertEqual(key.render(), expected) def test_render_user_reg(self): content = self.registry.render() with open(self.registry_path, 'r') as registry_file: original_content = registry_file.read() self.assertEqual(content, original_content) def test_can_render_system_reg(self): registry_path = os.path.join(FIXTURES_PATH, 'system.reg') with open(registry_path, 'r') as registry_file: original_content = registry_file.read() system_reg = WineRegistry(registry_path) content = system_reg.render() self.assertEqual(content, original_content) def test_can_set_value_to_existing_subkey(self): self.assertEqual(self.registry.query('Control Panel/Desktop', 'DragWidth'), '4') self.registry.set_value('Control Panel/Desktop', 'DragWidth', '8') self.assertEqual(self.registry.query('Control Panel/Desktop', 'DragWidth'), '8') def test_can_set_value_to_a_new_sub_key(self): self.assertEqual(self.registry.query('Control Panel/Desktop', 'BliBlu'), None) self.registry.set_value('Control Panel/Desktop', 'BliBlu', 'yep') self.assertEqual(self.registry.query('Control Panel/Desktop', 'BliBlu'), 'yep') def test_can_set_value_to_a_new_key(self): self.assertEqual(self.registry.query('Wine/DX11', 'FullyWorking'), None) self.registry.set_value('Wine/DX11', 'FullyWorking', 'HellYeah') self.assertEqual(self.registry.query('Wine/DX11', 'FullyWorking'), 'HellYeah') def test_can_clear_a_key(self): path = 'Control Panel/Mouse' key = self.registry.keys.get(path) self.assertEqual(len(key.subkeys), 13) self.registry.clear_key(path) self.assertEqual(len(key.subkeys), 0)
def clear_registry_subkeys(self, key, subkeys): registry = WineRegistry(self.get_registry_path(key)) registry.clear_subkeys(self.get_key_path(key), subkeys) registry.save()
def _get_registry_value_from_path(registry_path, key): registry = WineRegistry() return registry.query(registry_path, key)