Skip to content

Commit

Permalink
Get installed games from SQLite database instead of registry
Browse files Browse the repository at this point in the history
  • Loading branch information
Rall3n committed Sep 3, 2020
1 parent ce976c6 commit d771177
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
23 changes: 11 additions & 12 deletions src/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
class AmazonGamesClient:
_CLIENT_NAME_ = 'Amazon Games'
install_location = ""
_local_games_cache = list()

def __init__(self):
self._get_install_location()
Expand Down Expand Up @@ -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']}")
Expand All @@ -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:
Expand Down
13 changes: 9 additions & 4 deletions src/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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)

Expand All @@ -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):
Expand Down

0 comments on commit d771177

Please sign in to comment.