Use new functions in preferences

This commit is contained in:
kramo
2023-04-14 16:10:40 +02:00
parent 6edd85e80a
commit 6b2678c5f6
7 changed files with 167 additions and 136 deletions

View File

@@ -25,26 +25,32 @@ import yaml
from .check_install import check_install
def bottles_importer(win):
schema = win.schema
def bottles_installed(win, path=None):
location_key = "bottles-location"
bottles_dir = Path(schema.get_string(location_key)).expanduser()
bottles_dir = (
path if path else Path(win.schema.get_string(location_key)).expanduser()
)
check = "library.yml"
if not (bottles_dir / check).is_file():
locations = (
Path.home()
/ ".var"
/ "app"
/ "com.usebottles.bottles"
/ "data"
/ "bottles",
win.data_dir / "bottles",
(Path(),)
if path
else (
Path.home() / ".var/app/com.usebottles.bottles/data/bottles",
win.data_dir / "bottles",
)
)
bottles_dir = check_install(check, locations, (schema, location_key))
if not bottles_dir:
return
bottles_dir = check_install(check, locations, (win.schema, location_key))
return bottles_dir
def bottles_importer(win):
bottles_dir = bottles_installed(win)
if not bottles_dir:
return
current_time = int(time())

View File

@@ -26,39 +26,41 @@ from time import time
from .check_install import check_install
def heroic_importer(win):
schema = win.schema
def heroic_installed(win, path=None):
location_key = "heroic-location"
heroic_dir = Path(schema.get_string(location_key)).expanduser()
heroic_dir = (
path if path else Path(win.schema.get_string(location_key)).expanduser()
)
check = "config.json"
if not (heroic_dir / check).is_file():
locations = (
Path.home()
/ ".var"
/ "app"
/ "com.heroicgameslauncher.hgl"
/ "config"
/ "heroic",
win.config_dir / "heroic",
(Path(),)
if path
else (
Path.home() / ".var/app/com.heroicgameslauncher.hgl/config/heroic",
win.config_dir / "heroic",
)
)
if os.name == "nt":
if os.name == "nt" and not path:
locations += (Path(os.getenv("appdata")) / "heroic",)
heroic_dir = check_install(check, locations, (schema, location_key))
if not heroic_dir:
return
heroic_dir = check_install(check, locations, (win.schema, location_key))
schema = win.schema
check = "config.json"
return heroic_dir
def heroic_importer(win):
heroic_dir = heroic_installed(win)
if not heroic_dir:
return
current_time = int(time())
importer = win.importer
# Import Epic games
if not schema.get_boolean("heroic-import-epic"):
if not win.schema.get_boolean("heroic-import-epic"):
pass
elif (heroic_dir / "store_cache" / "legendary_library.json").exists():
data = (heroic_dir / "store_cache" / "legendary_library.json").read_text(
@@ -112,7 +114,7 @@ def heroic_importer(win):
pass
# Import GOG games
if not schema.get_boolean("heroic-import-gog"):
if not win.schema.get_boolean("heroic-import-gog"):
pass
elif (heroic_dir / "gog_store" / "installed.json").exists():
data = (heroic_dir / "gog_store" / "installed.json").read_text("utf-8")
@@ -160,7 +162,7 @@ def heroic_importer(win):
importer.save_game(values, image_path if image_path.exists() else None)
# Import sideloaded games
if not schema.get_boolean("heroic-import-sideload"):
if not win.schema.get_boolean("heroic-import-sideload"):
pass
elif (heroic_dir / "sideload_apps" / "library.json").exists():
data = (heroic_dir / "sideload_apps" / "library.json").read_text("utf-8")

View File

@@ -113,25 +113,35 @@ def get_games_async(win, rows, importer):
task.run_in_thread(create_func(current_time, win, row))
def itch_importer(win):
schema = win.schema
def itch_installed(win, path=None):
location_key = "itch-location"
itch_dir = Path(schema.get_string(location_key)).expanduser()
itch_dir = path if path else Path(win.schema.get_string(location_key)).expanduser()
check = Path("db") / "butler.db"
if not (itch_dir / check).is_file():
locations = (
Path.home() / ".var" / "app" / "io.itch.itch" / "config" / "itch",
win.config_dir / "itch",
(Path(),)
if path
else (
Path.home() / ".var/app/io.itch.itch/config/itch",
win.config_dir / "itch",
)
)
if os.name == "nt":
if os.name == "nt" and not path:
locations += (Path(os.getenv("appdata")) / "itch",)
if not check_install(check, locations, (schema, location_key)):
return
itch_dir = check_install(check, locations, (win.schema, location_key))
database_path = (Path(schema.get_string(location_key)) / "db").expanduser()
return itch_dir
def itch_importer(win):
itch_dir = itch_installed(win)
if not itch_dir:
return
database_path = (itch_dir / "db").expanduser()
db_cache_dir = win.cache_dir / "cartridges" / "itch"
db_cache_dir.mkdir(parents=True, exist_ok=True)

View File

@@ -25,38 +25,56 @@ from time import time
from .check_install import check_install
def lutris_importer(win):
schema = win.schema
def lutris_installed(win, path=None):
location_key = "lutris-location"
lutris_dir = Path(schema.get_string(location_key)).expanduser()
lutris_dir = (
path if path else Path(win.schema.get_string(location_key)).expanduser()
)
check = "pga.db"
if not (lutris_dir / check).is_file():
locations = (
Path.home() / ".var" / "app" / "net.lutris.Lutris" / "data" / "lutris",
win.data_dir / "lutris",
(Path(),)
if path
else (
Path.home() / ".var/app/net.lutris.Lutris/data/lutris",
win.data_dir / "lutris",
)
)
lutris_dir = check_install(check, locations, (schema, location_key))
if not lutris_dir:
return
lutris_dir = check_install(check, locations, (win.schema, location_key))
return lutris_dir
def lutris_cache_exists(win, path=None):
cache_key = "lutris-cache-location"
cache_dir = Path(schema.get_string(cache_key)).expanduser()
cache_dir = path if path else Path(win.schema.get_string(cache_key)).expanduser()
cache_check = "coverart"
if not (cache_dir / cache_check).exists():
cache_locations = (
Path.home() / ".var" / "app" / "net.lutris.Lutris" / "cache" / "lutris",
win.cache_dir / "lutris",
(Path(),)
if path
else (
Path.home() / ".var" / "app" / "net.lutris.Lutris" / "cache" / "lutris",
win.cache_dir / "lutris",
)
)
cache_dir = check_install(check, cache_locations, (schema, location_key))
if not cache_dir:
return
cache_dir = check_install(cache_check, cache_locations, (win.schema, cache_key))
database_path = (Path(schema.get_string(location_key))).expanduser()
cache_dir = Path(schema.get_string(cache_key)).expanduser()
return cache_dir
def lutris_importer(win):
lutris_dir = lutris_installed(win)
if not lutris_dir:
return
cache_dir = lutris_cache_exists(win)
if not cache_dir:
return
db_cache_dir = win.cache_dir / "cartridges" / "lutris"
db_cache_dir.mkdir(parents=True, exist_ok=True)
@@ -64,7 +82,7 @@ def lutris_importer(win):
# Copy the file because sqlite3 doesn't like databases in /run/user/
database_tmp_path = db_cache_dir / "pga.db"
for db_file in database_path.glob("pga.db*"):
for db_file in lutris_dir.glob("pga.db*"):
copyfile(db_file, (db_cache_dir / db_file.name))
db_request = """
@@ -87,7 +105,7 @@ def lutris_importer(win):
# No need to unlink temp files as they disappear when the connection is closed
database_tmp_path.unlink(missing_ok=True)
if not schema.get_boolean("lutris-import-steam"):
if not win.schema.get_boolean("lutris-import-steam"):
rows = [row for row in rows if not row[3] == "steam"]
current_time = int(time())

View File

@@ -122,31 +122,42 @@ def get_games_async(win, appmanifests, steam_dir, importer):
)
def steam_importer(win):
schema = win.schema
def steam_installed(win, path=None):
location_key = "steam-location"
steam_dir = Path(schema.get_string(location_key)).expanduser()
steam_dir = Path(win.schema.get_string(location_key)).expanduser()
check = "steamapps"
if not (steam_dir / check).is_file():
subdirs = ("steam", "Steam")
locations = (
Path.home() / ".steam",
win.data_dir / "Steam",
Path.home() / ".var" / "app" / "com.valvesoftware.Steam" / "data" / "Steam",
(path,)
if path
else (
steam_dir,
Path.home() / ".steam",
win.data_dir / "Steam",
Path.home() / ".var/app/com.valvesoftware.Steam/data/Steam",
)
)
if os.name == "nt":
locations += (Path(os.getenv("programfiles(x86)")) / "Steam",)
steam_dir = check_install(check, locations, (schema, location_key), subdirs)
if not steam_dir:
return
steam_dir = check_install(check, locations, (win.schema, location_key), subdirs)
return steam_dir
def steam_importer(win):
steam_dir = steam_installed(win)
if not steam_dir:
return
appmanifests = []
steam_dirs = [Path(directory) for directory in schema.get_strv("steam-extra-dirs")]
steam_dirs = [
Path(directory) for directory in win.schema.get_strv("steam-extra-dirs")
]
steam_dirs.append(steam_dir)
for directory in steam_dirs: