Cleanups
This commit is contained in:
@@ -25,8 +25,8 @@ import yaml
|
||||
from .check_install import check_install
|
||||
|
||||
|
||||
def bottles_importer(parent_widget):
|
||||
schema = parent_widget.schema
|
||||
def bottles_importer(win):
|
||||
schema = win.schema
|
||||
location_key = "bottles-location"
|
||||
bottles_dir = Path(schema.get_string(location_key)).expanduser()
|
||||
check = "library.yml"
|
||||
@@ -39,7 +39,7 @@ def bottles_importer(parent_widget):
|
||||
/ "com.usebottles.bottles"
|
||||
/ "data"
|
||||
/ "bottles",
|
||||
parent_widget.data_dir / "bottles",
|
||||
win.data_dir / "bottles",
|
||||
)
|
||||
|
||||
bottles_dir = check_install(check, locations, (schema, location_key))
|
||||
@@ -52,7 +52,7 @@ def bottles_importer(parent_widget):
|
||||
|
||||
library = yaml.load(data, Loader=yaml.Loader)
|
||||
|
||||
importer = parent_widget.importer
|
||||
importer = win.importer
|
||||
importer.total_queue += len(library)
|
||||
importer.queue += len(library)
|
||||
|
||||
@@ -62,10 +62,7 @@ def bottles_importer(parent_widget):
|
||||
|
||||
values["game_id"] = f'bottles_{game["id"]}'
|
||||
|
||||
if (
|
||||
values["game_id"] in parent_widget.games
|
||||
and not parent_widget.games[values["game_id"]].removed
|
||||
):
|
||||
if values["game_id"] in win.games and not win.games[values["game_id"]].removed:
|
||||
importer.save_game()
|
||||
continue
|
||||
|
||||
|
||||
@@ -26,8 +26,8 @@ from time import time
|
||||
from .check_install import check_install
|
||||
|
||||
|
||||
def heroic_importer(parent_widget):
|
||||
schema = parent_widget.schema
|
||||
def heroic_importer(win):
|
||||
schema = win.schema
|
||||
location_key = "heroic-location"
|
||||
heroic_dir = Path(schema.get_string(location_key)).expanduser()
|
||||
check = "config.json"
|
||||
@@ -40,7 +40,7 @@ def heroic_importer(parent_widget):
|
||||
/ "com.heroicgameslauncher.hgl"
|
||||
/ "config"
|
||||
/ "heroic",
|
||||
parent_widget.config_dir / "heroic",
|
||||
win.config_dir / "heroic",
|
||||
)
|
||||
|
||||
if os.name == "nt":
|
||||
@@ -50,12 +50,12 @@ def heroic_importer(parent_widget):
|
||||
if not heroic_dir:
|
||||
return
|
||||
|
||||
schema = parent_widget.schema
|
||||
schema = win.schema
|
||||
check = "config.json"
|
||||
|
||||
current_time = int(time())
|
||||
|
||||
importer = parent_widget.importer
|
||||
importer = win.importer
|
||||
|
||||
# Import Epic games
|
||||
if not schema.get_boolean("heroic-import-epic"):
|
||||
@@ -80,8 +80,8 @@ def heroic_importer(parent_widget):
|
||||
values["game_id"] = f"heroic_epic_{app_name}"
|
||||
|
||||
if (
|
||||
values["game_id"] in parent_widget.games
|
||||
and not parent_widget.games[values["game_id"]].removed
|
||||
values["game_id"] in win.games
|
||||
and not win.games[values["game_id"]].removed
|
||||
):
|
||||
importer.save_game()
|
||||
continue
|
||||
@@ -128,8 +128,8 @@ def heroic_importer(parent_widget):
|
||||
values["game_id"] = f"heroic_gog_{app_name}"
|
||||
|
||||
if (
|
||||
values["game_id"] in parent_widget.games
|
||||
and not parent_widget.games[values["game_id"]].removed
|
||||
values["game_id"] in win.games
|
||||
and not win.games[values["game_id"]].removed
|
||||
):
|
||||
importer.save_game()
|
||||
continue
|
||||
@@ -176,8 +176,8 @@ def heroic_importer(parent_widget):
|
||||
values["game_id"] = f"heroic_sideload_{app_name}"
|
||||
|
||||
if (
|
||||
values["game_id"] in parent_widget.games
|
||||
and not parent_widget.games[values["game_id"]].removed
|
||||
values["game_id"] in win.games
|
||||
and not win.games[values["game_id"]].removed
|
||||
):
|
||||
importer.save_game()
|
||||
continue
|
||||
|
||||
@@ -29,15 +29,12 @@ from gi.repository import GdkPixbuf, Gio
|
||||
from .check_install import check_install
|
||||
|
||||
|
||||
def get_game(task, current_time, parent_widget, row):
|
||||
def get_game(task, current_time, win, row):
|
||||
values = {}
|
||||
|
||||
values["game_id"] = f"itch_{row[0]}"
|
||||
|
||||
if (
|
||||
values["game_id"] in parent_widget.games
|
||||
and not parent_widget.games[values["game_id"]].removed
|
||||
):
|
||||
if values["game_id"] in win.games and not win.games[values["game_id"]].removed:
|
||||
task.return_value((None, None))
|
||||
return
|
||||
|
||||
@@ -64,23 +61,22 @@ def get_game(task, current_time, parent_widget, row):
|
||||
|
||||
game_cover = GdkPixbuf.Pixbuf.new_from_stream_at_scale(
|
||||
tmp_file.read(), 2, 2, False
|
||||
).scale_simple(*parent_widget.image_size, GdkPixbuf.InterpType.BILINEAR)
|
||||
).scale_simple(*win.image_size, GdkPixbuf.InterpType.BILINEAR)
|
||||
|
||||
itch_pixbuf = GdkPixbuf.Pixbuf.new_from_stream(tmp_file.read())
|
||||
itch_pixbuf = itch_pixbuf.scale_simple(
|
||||
parent_widget.image_size[0],
|
||||
itch_pixbuf.get_height()
|
||||
* (parent_widget.image_size[0] / itch_pixbuf.get_width()),
|
||||
win.image_size[0],
|
||||
itch_pixbuf.get_height() * (win.image_size[0] / itch_pixbuf.get_width()),
|
||||
GdkPixbuf.InterpType.BILINEAR,
|
||||
)
|
||||
itch_pixbuf.composite(
|
||||
game_cover,
|
||||
0,
|
||||
(parent_widget.image_size[1] - itch_pixbuf.get_height()) / 2,
|
||||
(win.image_size[1] - itch_pixbuf.get_height()) / 2,
|
||||
itch_pixbuf.get_width(),
|
||||
itch_pixbuf.get_height(),
|
||||
0,
|
||||
(parent_widget.image_size[1] - itch_pixbuf.get_height()) / 2,
|
||||
(win.image_size[1] - itch_pixbuf.get_height()) / 2,
|
||||
1.0,
|
||||
1.0,
|
||||
GdkPixbuf.InterpType.BILINEAR,
|
||||
@@ -92,16 +88,16 @@ def get_game(task, current_time, parent_widget, row):
|
||||
task.return_value((values, game_cover))
|
||||
|
||||
|
||||
def get_games_async(parent_widget, rows, importer):
|
||||
def get_games_async(win, rows, importer):
|
||||
current_time = int(time())
|
||||
|
||||
# Wrap the function in another one as Gio.Task.run_in_thread does not allow for passing args
|
||||
def create_func(current_time, parent_widget, row):
|
||||
def create_func(current_time, win, row):
|
||||
def wrapper(task, *_unused):
|
||||
get_game(
|
||||
task,
|
||||
current_time,
|
||||
parent_widget,
|
||||
win,
|
||||
row,
|
||||
)
|
||||
|
||||
@@ -114,11 +110,11 @@ def get_games_async(parent_widget, rows, importer):
|
||||
|
||||
for row in rows:
|
||||
task = Gio.Task.new(None, None, update_games)
|
||||
task.run_in_thread(create_func(current_time, parent_widget, row))
|
||||
task.run_in_thread(create_func(current_time, win, row))
|
||||
|
||||
|
||||
def itch_importer(parent_widget):
|
||||
schema = parent_widget.schema
|
||||
def itch_importer(win):
|
||||
schema = win.schema
|
||||
location_key = "itch-location"
|
||||
itch_dir = Path(schema.get_string(location_key)).expanduser()
|
||||
check = Path("db") / "butler.db"
|
||||
@@ -126,7 +122,7 @@ def itch_importer(parent_widget):
|
||||
if not (itch_dir / check).is_file():
|
||||
locations = (
|
||||
Path.home() / ".var" / "app" / "io.itch.itch" / "config" / "itch",
|
||||
parent_widget.config_dir / "itch",
|
||||
win.config_dir / "itch",
|
||||
)
|
||||
|
||||
if os.name == "nt":
|
||||
@@ -137,7 +133,7 @@ def itch_importer(parent_widget):
|
||||
|
||||
database_path = (Path(schema.get_string(location_key)) / "db").expanduser()
|
||||
|
||||
db_cache_dir = parent_widget.cache_dir / "cartridges" / "itch"
|
||||
db_cache_dir = win.cache_dir / "cartridges" / "itch"
|
||||
db_cache_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Copy the file because sqlite3 doesn't like databases in /run/user/
|
||||
@@ -169,8 +165,8 @@ def itch_importer(parent_widget):
|
||||
# No need to unlink temp files as they disappear when the connection is closed
|
||||
database_tmp_path.unlink(missing_ok=True)
|
||||
|
||||
importer = parent_widget.importer
|
||||
importer = win.importer
|
||||
importer.total_queue += len(rows)
|
||||
importer.queue += len(rows)
|
||||
|
||||
get_games_async(parent_widget, rows, importer)
|
||||
get_games_async(win, rows, importer)
|
||||
|
||||
@@ -25,8 +25,8 @@ from time import time
|
||||
from .check_install import check_install
|
||||
|
||||
|
||||
def lutris_importer(parent_widget):
|
||||
schema = parent_widget.schema
|
||||
def lutris_importer(win):
|
||||
schema = win.schema
|
||||
location_key = "lutris-location"
|
||||
lutris_dir = Path(schema.get_string(location_key)).expanduser()
|
||||
check = "pga.db"
|
||||
@@ -34,7 +34,7 @@ def lutris_importer(parent_widget):
|
||||
if not (lutris_dir / check).is_file():
|
||||
locations = (
|
||||
Path.home() / ".var" / "app" / "net.lutris.Lutris" / "data" / "lutris",
|
||||
parent_widget.data_dir / "lutris",
|
||||
win.data_dir / "lutris",
|
||||
)
|
||||
|
||||
lutris_dir = check_install(check, locations, (schema, location_key))
|
||||
@@ -48,7 +48,7 @@ def lutris_importer(parent_widget):
|
||||
if not (cache_dir / cache_check).exists():
|
||||
cache_locations = (
|
||||
Path.home() / ".var" / "app" / "net.lutris.Lutris" / "cache" / "lutris",
|
||||
parent_widget.cache_dir / "lutris",
|
||||
win.cache_dir / "lutris",
|
||||
)
|
||||
|
||||
cache_dir = check_install(check, cache_locations, (schema, location_key))
|
||||
@@ -58,7 +58,7 @@ def lutris_importer(parent_widget):
|
||||
database_path = (Path(schema.get_string(location_key))).expanduser()
|
||||
cache_dir = Path(schema.get_string(cache_key)).expanduser()
|
||||
|
||||
db_cache_dir = parent_widget.cache_dir / "cartridges" / "lutris"
|
||||
db_cache_dir = win.cache_dir / "cartridges" / "lutris"
|
||||
db_cache_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Copy the file because sqlite3 doesn't like databases in /run/user/
|
||||
@@ -92,7 +92,7 @@ def lutris_importer(parent_widget):
|
||||
|
||||
current_time = int(time())
|
||||
|
||||
importer = parent_widget.importer
|
||||
importer = win.importer
|
||||
importer.total_queue += len(rows)
|
||||
importer.queue += len(rows)
|
||||
|
||||
@@ -101,10 +101,7 @@ def lutris_importer(parent_widget):
|
||||
|
||||
values["game_id"] = f"lutris_{row[3]}_{row[0]}"
|
||||
|
||||
if (
|
||||
values["game_id"] in parent_widget.games
|
||||
and not parent_widget.games[values["game_id"]].removed
|
||||
):
|
||||
if values["game_id"] in win.games and not win.games[values["game_id"]].removed:
|
||||
importer.save_game()
|
||||
continue
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ def update_values_from_data(content, values):
|
||||
return values
|
||||
|
||||
|
||||
def get_game(task, datatypes, current_time, parent_widget, appmanifest, steam_dir):
|
||||
def get_game(task, datatypes, current_time, win, appmanifest, steam_dir):
|
||||
values = {}
|
||||
|
||||
data = appmanifest.read_text("utf-8")
|
||||
@@ -56,10 +56,7 @@ def get_game(task, datatypes, current_time, parent_widget, appmanifest, steam_di
|
||||
|
||||
values["game_id"] = f'steam_{values["appid"]}'
|
||||
|
||||
if (
|
||||
values["game_id"] in parent_widget.games
|
||||
and not parent_widget.games[values["game_id"]].removed
|
||||
):
|
||||
if values["game_id"] in win.games and not win.games[values["game_id"]].removed:
|
||||
task.return_value((None, None))
|
||||
return
|
||||
|
||||
@@ -95,18 +92,18 @@ def get_game(task, datatypes, current_time, parent_widget, appmanifest, steam_di
|
||||
task.return_value((values, image_path if image_path.exists() else None))
|
||||
|
||||
|
||||
def get_games_async(parent_widget, appmanifests, steam_dir, importer):
|
||||
def get_games_async(win, appmanifests, steam_dir, importer):
|
||||
datatypes = ["appid", "name"]
|
||||
current_time = int(time())
|
||||
|
||||
# Wrap the function in another one as Gio.Task.run_in_thread does not allow for passing args
|
||||
def create_func(datatypes, current_time, parent_widget, appmanifest, steam_dir):
|
||||
def create_func(datatypes, current_time, win, appmanifest, steam_dir):
|
||||
def wrapper(task, *_unused):
|
||||
get_game(
|
||||
task,
|
||||
datatypes,
|
||||
current_time,
|
||||
parent_widget,
|
||||
win,
|
||||
appmanifest,
|
||||
steam_dir,
|
||||
)
|
||||
@@ -121,12 +118,12 @@ def get_games_async(parent_widget, appmanifests, steam_dir, importer):
|
||||
for appmanifest in appmanifests:
|
||||
task = Gio.Task.new(None, None, update_games)
|
||||
task.run_in_thread(
|
||||
create_func(datatypes, current_time, parent_widget, appmanifest, steam_dir)
|
||||
create_func(datatypes, current_time, win, appmanifest, steam_dir)
|
||||
)
|
||||
|
||||
|
||||
def steam_importer(parent_widget):
|
||||
schema = parent_widget.schema
|
||||
def steam_importer(win):
|
||||
schema = win.schema
|
||||
location_key = "steam-location"
|
||||
steam_dir = Path(schema.get_string(location_key)).expanduser()
|
||||
check = "steamapps"
|
||||
@@ -135,8 +132,8 @@ def steam_importer(parent_widget):
|
||||
subdirs = ("steam", "Steam")
|
||||
|
||||
locations = (
|
||||
Path.home() / ".steam" / "steam",
|
||||
parent_widget.data_dir / "Steam",
|
||||
Path.home() / ".steam",
|
||||
win.data_dir / "Steam",
|
||||
Path.home() / ".var" / "app" / "com.valvesoftware.Steam" / "data" / "Steam",
|
||||
)
|
||||
|
||||
@@ -161,8 +158,8 @@ def steam_importer(parent_widget):
|
||||
if open_file.is_file() and "appmanifest" in open_file.name:
|
||||
appmanifests.append(open_file)
|
||||
|
||||
importer = parent_widget.importer
|
||||
importer = win.importer
|
||||
importer.total_queue += len(appmanifests)
|
||||
importer.queue += len(appmanifests)
|
||||
|
||||
get_games_async(parent_widget, appmanifests, directory, importer)
|
||||
get_games_async(win, appmanifests, directory, importer)
|
||||
|
||||
Reference in New Issue
Block a user