diff --git a/src/client.py b/src/client.py index ef3119e..0f0c709 100644 --- a/src/client.py +++ b/src/client.py @@ -13,7 +13,6 @@ class AmazonGamesClient: _CLIENT_NAME_ = 'Amazon Games' install_location = "" - _local_games_cache = list() def __init__(self): self._get_install_location() @@ -67,14 +66,17 @@ def owned_games_db_path(self): if self.install_location: return Path(self.install_location, '..', 'Data', 'Games', 'Sql', 'GameProductInfo.sqlite').resolve() + @property + def installed_games_db_path(self): + if self.install_location: + return Path(self.install_location, '..', 'Data', 'Games', 'Sql', 'GameInstallInfo.sqlite').resolve() + @property def cookies_path(self): if self.install_location: return os.path.join(self.install_location, "Electron3", "Cookies") def get_installed_games(self): - local_games_list = list() - for program in get_uninstall_programs_list(): if not program['UninstallString'] or 'Amazon Game Remover.exe'.lower() not in program['UninstallString'].lower(): # self.logger.info(f"LocalGame - UninstallString: {program['DisplayName']} {program['UninstallString']}") @@ -86,19 +88,16 @@ def get_installed_games(self): game_id = re.search(r'-p\s([a-z\d\-]+)', program['UninstallString'])[1] - if game_id: - local_games_list.append({ - 'game_id': game_id, - 'program': program - }) - - self._local_games_cache = local_games_list - return self._local_games_cache + yield { + 'game_id': game_id, + 'program': program + } def uninstall_game(self, game_id): - for game in self._local_games_cache: + for game in self.get_installed_games(): if game['game_id'] == game_id: AmazonGamesClient._exec(game["program"]["UninstallString"]) + break def start_client(self): if not self.is_running: diff --git a/src/plugin.py b/src/plugin.py index a9ae6ac..ccf63c8 100644 --- a/src/plugin.py +++ b/src/plugin.py @@ -20,6 +20,7 @@ class AmazonGamesPlugin(Plugin): _owned_games_db = None + _local_games_db = None def __init__(self, reader, writer, token): super().__init__(Platform.Amazon, __version__, reader, writer, token) @@ -34,6 +35,9 @@ def _init_db(self): if not self._owned_games_db: self._owned_games_db = DBClient(self._client.owned_games_db_path) + if not self._local_games_db: + self._local_games_db = DBClient(self._client.installed_games_db_path) + def _on_auth(self): self.logger.info("Auth finished") self._init_db() @@ -69,8 +73,8 @@ def _update_owned_games(self): def _get_local_games(self): try: return { - row['game_id']: LocalGame(row['game_id'], LocalGameState.Installed) - for row in self._client.get_installed_games() + row['Id']: LocalGame(row['Id'], LocalGameState.Installed) + for row in self._local_games_db.select('DbSet', rows=['Id', 'Installed']) if row['Installed'] } except Exception: self.logger.exception('Failed to get local games') @@ -110,7 +114,7 @@ async def authenticate(self, stored_credentials=None): return self._on_auth() async def pass_login_credentials(self, step, credentials, cookies): - if 'splash_continue' in credentials['end_uri'] or 'missing_app_retry' in credentials['end_uri']: + if any(x in credentials['end_uri'] for x in ['splash_continue', 'missing_app_retry']): if not self._client.is_installed: return create_next_step(START_URI.MISSING_APP, END_URI.MISSING_APP_RETRY) @@ -134,13 +138,14 @@ def tick(self): if self._owned_games_db and self._local_games_cache is not None: self._update_local_games() - if self._owned_games_cache is not None: + if self._local_games_db and self._owned_games_cache is not None: self._update_owned_games() async def launch_game(self, game_id): AmazonGamesPlugin._scheme_command('play', game_id) async def install_game(self, game_id): + # FIXME Opens launcher and an install dialog, but no action AmazonGamesPlugin._scheme_command('play', game_id) async def uninstall_game(self, game_id):