Move shared values to shared

This commit is contained in:
kramo
2023-05-21 17:28:29 +02:00
parent ab21e8b38b
commit 203393dea0
14 changed files with 186 additions and 154 deletions

View File

@@ -26,7 +26,7 @@ from . import shared
from .check_install import check_install
def bottles_installed(win, path=None):
def bottles_installed(path=None):
location_key = "bottles-location"
bottles_dir = (
path if path else Path(shared.schema.get_string(location_key)).expanduser()
@@ -39,7 +39,7 @@ def bottles_installed(win, path=None):
if path
else (
Path.home() / ".var/app/com.usebottles.bottles/data/bottles",
win.data_dir / "bottles",
shared.data_dir / "bottles",
)
)
@@ -48,8 +48,8 @@ def bottles_installed(win, path=None):
return bottles_dir
def bottles_importer(win):
bottles_dir = bottles_installed(win)
def bottles_importer():
bottles_dir = bottles_installed()
if not bottles_dir:
return
@@ -59,7 +59,7 @@ def bottles_importer(win):
library = yaml.load(data, Loader=yaml.Loader)
importer = win.importer
importer = shared.importer
importer.total_queue += len(library)
importer.queue += len(library)
@@ -69,7 +69,10 @@ def bottles_importer(win):
values["game_id"] = f'bottles_{game["id"]}'
if values["game_id"] in win.games and not win.games[values["game_id"]].removed:
if (
values["game_id"] in shared.win.games
and not shared.win.games[values["game_id"]].removed
):
importer.save_game()
continue

View File

@@ -27,7 +27,7 @@ from . import shared
from .check_install import check_install
def heroic_installed(win, path=None):
def heroic_installed(path=None):
location_key = "heroic-location"
heroic_dir = (
path if path else Path(shared.schema.get_string(location_key)).expanduser()
@@ -40,7 +40,7 @@ def heroic_installed(win, path=None):
if path
else (
Path.home() / ".var/app/com.heroicgameslauncher.hgl/config/heroic",
win.config_dir / "heroic",
shared.config_dir / "heroic",
)
)
@@ -52,13 +52,13 @@ def heroic_installed(win, path=None):
return heroic_dir
def heroic_importer(win):
heroic_dir = heroic_installed(win)
def heroic_importer():
heroic_dir = heroic_installed()
if not heroic_dir:
return
current_time = int(time())
importer = win.importer
importer = shared.importer
# Import Epic games
if not shared.schema.get_boolean("heroic-import-epic"):
@@ -82,8 +82,8 @@ def heroic_importer(win):
values["game_id"] = f"heroic_epic_{app_name}"
if (
values["game_id"] in win.games
and not win.games[values["game_id"]].removed
values["game_id"] in shared.win.games
and not shared.win.games[values["game_id"]].removed
):
importer.save_game()
continue
@@ -131,8 +131,8 @@ def heroic_importer(win):
values["game_id"] = f"heroic_gog_{app_name}"
if (
values["game_id"] in win.games
and not win.games[values["game_id"]].removed
values["game_id"] in shared.win.games
and not shared.win.games[values["game_id"]].removed
):
importer.save_game()
continue
@@ -179,8 +179,8 @@ def heroic_importer(win):
values["game_id"] = f"heroic_sideload_{app_name}"
if (
values["game_id"] in win.games
and not win.games[values["game_id"]].removed
values["game_id"] in shared.win.games
and not shared.win.games[values["game_id"]].removed
):
importer.save_game()
continue

View File

@@ -31,12 +31,15 @@ from .check_install import check_install
from .save_cover import resize_cover
def get_game(task, current_time, win, row):
def get_game(task, current_time, row):
values = {}
values["game_id"] = f"itch_{row[0]}"
if values["game_id"] in win.games and not win.games[values["game_id"]].removed:
if (
values["game_id"] in shared.win.games
and not shared.win.games[values["game_id"]].removed
):
task.return_value((None, None))
return
@@ -63,22 +66,22 @@ def get_game(task, current_time, win, row):
game_cover = GdkPixbuf.Pixbuf.new_from_stream_at_scale(
tmp_file.read(), 2, 2, False
).scale_simple(*win.image_size, GdkPixbuf.InterpType.BILINEAR)
).scale_simple(*shared.image_size, GdkPixbuf.InterpType.BILINEAR)
itch_pixbuf = GdkPixbuf.Pixbuf.new_from_stream(tmp_file.read())
itch_pixbuf = itch_pixbuf.scale_simple(
win.image_size[0],
itch_pixbuf.get_height() * (win.image_size[0] / itch_pixbuf.get_width()),
shared.image_size[0],
itch_pixbuf.get_height() * (shared.image_size[0] / itch_pixbuf.get_width()),
GdkPixbuf.InterpType.BILINEAR,
)
itch_pixbuf.composite(
game_cover,
0,
(win.image_size[1] - itch_pixbuf.get_height()) / 2,
(shared.image_size[1] - itch_pixbuf.get_height()) / 2,
itch_pixbuf.get_width(),
itch_pixbuf.get_height(),
0,
(win.image_size[1] - itch_pixbuf.get_height()) / 2,
(shared.image_size[1] - itch_pixbuf.get_height()) / 2,
1.0,
1.0,
GdkPixbuf.InterpType.BILINEAR,
@@ -91,16 +94,15 @@ def get_game(task, current_time, win, row):
task.return_value((values, game_cover))
def get_games_async(win, rows, importer):
def get_games_async(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, win, row):
def create_func(current_time, row):
def wrapper(task, *_args):
get_game(
task,
current_time,
win,
row,
)
@@ -111,15 +113,15 @@ def get_games_async(win, rows, importer):
# No need for an if statement as final_value would be None for games we don't want to save
importer.save_game(
final_values[0],
resize_cover(win, pixbuf=final_values[1]),
resize_cover(pixbuf=final_values[1]),
)
for row in rows:
task = Gio.Task.new(None, None, update_games)
task.run_in_thread(create_func(current_time, win, row))
task.run_in_thread(create_func(current_time, row))
def itch_installed(win, path=None):
def itch_installed(path=None):
location_key = "itch-location"
itch_dir = (
path if path else Path(shared.schema.get_string(location_key)).expanduser()
@@ -132,7 +134,7 @@ def itch_installed(win, path=None):
if path
else (
Path.home() / ".var/app/io.itch.itch/config/itch",
win.config_dir / "itch",
shared.config_dir / "itch",
)
)
@@ -144,14 +146,14 @@ def itch_installed(win, path=None):
return itch_dir
def itch_importer(win):
itch_dir = itch_installed(win)
def itch_importer():
itch_dir = itch_installed()
if not itch_dir:
return
database_path = (itch_dir / "db").expanduser()
db_cache_dir = win.cache_dir / "cartridges" / "itch"
db_cache_dir = shared.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/
@@ -183,8 +185,8 @@ def itch_importer(win):
# No need to unlink temp files as they disappear when the connection is closed
database_tmp_path.unlink(missing_ok=True)
importer = win.importer
importer = shared.importer
importer.total_queue += len(rows)
importer.queue += len(rows)
get_games_async(win, rows, importer)
get_games_async(rows, importer)

View File

@@ -26,7 +26,7 @@ from . import shared
from .check_install import check_install
def lutris_installed(win, path=None):
def lutris_installed(path=None):
location_key = "lutris-location"
lutris_dir = (
path if path else Path(shared.schema.get_string(location_key)).expanduser()
@@ -39,7 +39,7 @@ def lutris_installed(win, path=None):
if path
else (
Path.home() / ".var/app/net.lutris.Lutris/data/lutris",
win.data_dir / "lutris",
shared.data_dir / "lutris",
)
)
@@ -48,7 +48,7 @@ def lutris_installed(win, path=None):
return lutris_dir
def lutris_cache_exists(win, path=None):
def lutris_cache_exists(path=None):
cache_key = "lutris-cache-location"
cache_dir = path if path else Path(shared.schema.get_string(cache_key)).expanduser()
cache_check = "coverart"
@@ -59,7 +59,7 @@ def lutris_cache_exists(win, path=None):
if path
else (
Path.home() / ".var" / "app" / "net.lutris.Lutris" / "cache" / "lutris",
win.cache_dir / "lutris",
shared.cache_dir / "lutris",
)
)
@@ -70,16 +70,16 @@ def lutris_cache_exists(win, path=None):
return cache_dir
def lutris_importer(win):
lutris_dir = lutris_installed(win)
def lutris_importer():
lutris_dir = lutris_installed()
if not lutris_dir:
return
cache_dir = lutris_cache_exists(win)
cache_dir = lutris_cache_exists()
if not cache_dir:
return
db_cache_dir = win.cache_dir / "cartridges" / "lutris"
db_cache_dir = shared.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/
@@ -113,7 +113,7 @@ def lutris_importer(win):
current_time = int(time())
importer = win.importer
importer = shared.importer
importer.total_queue += len(rows)
importer.queue += len(rows)
@@ -122,7 +122,10 @@ def lutris_importer(win):
values["game_id"] = f"lutris_{row[3]}_{row[0]}"
if values["game_id"] in win.games and not win.games[values["game_id"]].removed:
if (
values["game_id"] in shared.win.games
and not shared.win.games[values["game_id"]].removed
):
importer.save_game()
continue

View File

@@ -43,7 +43,7 @@ def update_values_from_data(content, values):
return values
def get_game(task, datatypes, current_time, win, appmanifest, steam_dir):
def get_game(task, datatypes, current_time, appmanifest, steam_dir):
values = {}
data = appmanifest.read_text("utf-8")
@@ -57,7 +57,10 @@ def get_game(task, datatypes, current_time, win, appmanifest, steam_dir):
values["game_id"] = f'steam_{values["appid"]}'
if values["game_id"] in win.games and not win.games[values["game_id"]].removed:
if (
values["game_id"] in shared.win.games
and not shared.win.games[values["game_id"]].removed
):
task.return_value((None, None))
return
@@ -93,18 +96,17 @@ def get_game(task, datatypes, current_time, win, appmanifest, steam_dir):
task.return_value((values, image_path if image_path.exists() else None))
def get_games_async(win, appmanifests, steam_dir, importer):
def get_games_async(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, win, appmanifest, steam_dir):
def create_func(datatypes, current_time, appmanifest, steam_dir):
def wrapper(task, *_args):
get_game(
task,
datatypes,
current_time,
win,
appmanifest,
steam_dir,
)
@@ -118,12 +120,10 @@ def get_games_async(win, 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, win, appmanifest, steam_dir)
)
task.run_in_thread(create_func(datatypes, current_time, appmanifest, steam_dir))
def steam_installed(win, path=None):
def steam_installed(path=None):
location_key = "steam-location"
steam_dir = Path(shared.schema.get_string(location_key)).expanduser()
check = "steamapps"
@@ -136,7 +136,7 @@ def steam_installed(win, path=None):
else (
steam_dir,
Path.home() / ".steam",
win.data_dir / "Steam",
shared.data_dir / "Steam",
Path.home() / ".var/app/com.valvesoftware.Steam/data/Steam",
)
)
@@ -151,8 +151,8 @@ def steam_installed(win, path=None):
return steam_dir
def steam_importer(win):
steam_dir = steam_installed(win)
def steam_importer():
steam_dir = steam_installed()
if not steam_dir:
return
@@ -175,8 +175,8 @@ def steam_importer(win):
if open_file.is_file() and "appmanifest" in open_file.name:
appmanifests.append(open_file)
importer = win.importer
importer = shared.importer
importer.total_queue += len(appmanifests)
importer.queue += len(appmanifests)
get_games_async(win, appmanifests, steam_dir, importer)
get_games_async(appmanifests, steam_dir, importer)