diff --git a/src/utils/save_cover.py b/src/utils/save_cover.py index 5b0c5e5..7c5e395 100644 --- a/src/utils/save_cover.py +++ b/src/utils/save_cover.py @@ -29,8 +29,6 @@ def save_cover(game, parent_widget, file_path, pixbuf=None, game_id=None): "cartridges", "covers", ) - if not os.path.exists(covers_dir): - os.makedirs(covers_dir) if game_id is None: game_id = game["game_id"] @@ -41,6 +39,9 @@ def save_cover(game, parent_widget, file_path, pixbuf=None, game_id=None): def cover_callback(*_unused): pass + if not os.path.exists(covers_dir): + os.makedirs(covers_dir) + open_file = Gio.File.new_for_path(os.path.join(covers_dir, game_id + ".tiff")) parent_widget.pixbufs[game_id] = pixbuf pixbuf.save_to_streamv_async( diff --git a/src/utils/steam_parser.py b/src/utils/steam_parser.py index 09506ae..eb9f7a5 100644 --- a/src/utils/steam_parser.py +++ b/src/utils/steam_parser.py @@ -115,7 +115,7 @@ def get_game(task, datatypes, current_time, parent_widget, appmanifest, steam_di return -def get_games_async(parent_widget, appmanifests, steam_dir, import_dialog): +def get_games_async(parent_widget, appmanifests, steam_dir, import_dialog, progressbar): datatypes = ["appid", "name"] current_time = int(time.time()) @@ -133,9 +133,12 @@ def get_games_async(parent_widget, appmanifests, steam_dir, import_dialog): def update_games(_task, result, parent_widget): nonlocal queue + nonlocal total_queue nonlocal import_dialog + nonlocal progressbar queue -= 1 + progressbar.set_fraction(1 - (queue / total_queue)) try: final_values = result.propagate_value()[1] @@ -176,8 +179,10 @@ def get_games_async(parent_widget, appmanifests, steam_dir, import_dialog): _(f"Successfully imported {games_no} games."), ) + total_queue = 0 for appmanifest in appmanifests: queue += 1 + total_queue += 1 cancellable = Gio.Cancellable.new() GLib.timeout_add_seconds(5, cancellable.cancel) @@ -249,16 +254,18 @@ def steam_parser(parent_widget, action): steam_dir = os.path.expanduser(schema.get_string("steam-location")) + progressbar = Gtk.ProgressBar(margin_start=12, margin_end=12) import_statuspage = Adw.StatusPage( title=_("Importing Games…"), description=_("Talking to Steam"), + child=progressbar, ) import_dialog = Adw.Window( content=import_statuspage, modal=True, default_width=350, - default_height=200, + default_height=-1, transient_for=parent_widget, deletable=False, ) @@ -280,4 +287,4 @@ def steam_parser(parent_widget, action): if os.path.isfile(path) and "appmanifest" in open_file: appmanifests.append(path) - get_games_async(parent_widget, appmanifests, directory, import_dialog) + get_games_async(parent_widget, appmanifests, directory, import_dialog, progressbar)