Skip to content

Commit

Permalink
Use name instead of id when caching game categories
Browse files Browse the repository at this point in the history
When running the client in offline mode, we do not get game ids as they must be retrieved from the API. Therefore, game names must be used as the cache keys instead.
  • Loading branch information
orende committed Jul 3, 2023
1 parent 3f8d0db commit 42308e9
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions minigalaxy/ui/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def __get_installed_games(self) -> List[Game]:
game_id = 0
else:
game_id = int(game_id)
category = game_categories_dict.get(game_id, "")
category = game_categories_dict.get(name, "")
games.append(Game(name=name, game_id=game_id, install_dir=full_path, category=category))
else:
games.extend(get_installed_windows_games(full_path, game_categories_dict))
Expand All @@ -183,7 +183,7 @@ def __add_games_from_api(self):
self.games[self.games.index(game)].url = game.url
self.games[self.games.index(game)].category = game.category
if len(game.category) > 0: # exclude games without set category
game_category_dict[str(game.id)] = game.category
game_category_dict[game.name] = game.category
update_game_categories_file(game_category_dict)


Expand All @@ -194,13 +194,12 @@ def get_installed_windows_games(full_path, game_categories_dict=None):
if re.match(r'^goggame-[0-9]*\.info$', file):
with open(os.path.join(full_path, file), 'rb') as info_file:
info = json.loads(info_file.read().decode('utf-8-sig'))
game_id = int(info["gameId"])
game = Game(
name=info["name"],
game_id=game_id,
game_id=int(info["gameId"]),
install_dir=full_path,
platform="windows",
category=(game_categories_dict or {}).get(game_id, "")
category=(game_categories_dict or {}).get(info["name"], "")
)
games.append(game)
return games
Expand Down

0 comments on commit 42308e9

Please sign in to comment.