Refactor install location checking - fixes #69

This commit is contained in:
kramo
2023-04-14 14:12:27 +02:00
parent 8a7d716db6
commit 43e8317c46
8 changed files with 143 additions and 99 deletions

View File

@@ -22,28 +22,30 @@ from time import time
import yaml
from .check_install import check_install
def bottles_importer(parent_widget):
schema = parent_widget.schema
bottles_dir = Path(schema.get_string("bottles-location")).expanduser()
location_key = "bottles-location"
bottles_dir = Path(schema.get_string(location_key)).expanduser()
check = "library.yml"
if not (bottles_dir / "library.yml").is_file():
if (
Path("~/.var/app/com.usebottles.bottles/data/bottles/")
.expanduser()
.exists()
):
schema.set_string(
"bottles-location", "~/.var/app/com.usebottles.bottles/data/bottles/"
)
elif (parent_widget.data_dir / "bottles").exists():
schema.set_string(
"bottles-location", str(parent_widget.data_dir / "bottles")
)
else:
if not (bottles_dir / check).is_file():
locations = (
Path.home()
/ ".var"
/ "app"
/ "com.usebottles.bottles"
/ "data"
/ "bottles",
parent_widget.data_dir / "bottles",
)
bottles_dir = check_install(check, locations, (schema, location_key))
if not bottles_dir:
return
bottles_dir = Path(schema.get_string("bottles-location")).expanduser()
current_time = int(time())
data = (bottles_dir / "library.yml").read_text("utf-8")

View File

@@ -23,33 +23,36 @@ import os
from pathlib import Path
from time import time
from .check_install import check_install
def heroic_importer(parent_widget):
schema = parent_widget.schema
heroic_dir = Path(schema.get_string("heroic-location")).expanduser()
location_key = "heroic-location"
heroic_dir = Path(schema.get_string(location_key)).expanduser()
check = "config.json"
if not (heroic_dir / "config.json").exists():
if (
Path("~/.var/app/com.heroicgameslauncher.hgl/config/heroic/")
.expanduser()
.exists()
):
schema.set_string(
"heroic-location",
"~/.var/app/com.heroicgameslauncher.hgl/config/heroic/",
)
elif (parent_widget.config_dir / "heroic").exists():
schema.set_string(
"heroic-location", str(parent_widget.config_dir / "heroic")
)
elif os.name == "nt" and (Path(os.getenv("appdata")) / "heroic").exists():
schema.set_string(
"heroic-location", str(Path(os.getenv("appdata")) / "heroic")
)
else:
if not (heroic_dir / check).is_file():
locations = (
Path.home()
/ ".var"
/ "app"
/ "com.heroicgameslauncher.hgl"
/ "config"
/ "heroic",
parent_widget.config_dir / "heroic",
)
if os.name == "nt":
locations += (Path(os.getenv("appdata")) / "heroic",)
heroic_dir = check_install(check, locations, (schema, location_key))
if not heroic_dir:
return
heroic_dir = Path(schema.get_string("heroic-location")).expanduser()
schema = parent_widget.schema
check = "config.json"
current_time = int(time())
importer = parent_widget.importer
@@ -57,8 +60,10 @@ def heroic_importer(parent_widget):
# Import Epic games
if not schema.get_boolean("heroic-import-epic"):
pass
elif (heroic_dir / "lib-cache" / "library.json").exists():
data = (heroic_dir / "lib-cache" / "library.json").read_text("utf-8")
elif (heroic_dir / "store_cache" / "legendary_library.json").exists():
data = (heroic_dir / "store_cache" / "legendary_library.json").read_text(
"utf-8"
)
library = json.loads(data)
try:

View File

@@ -26,6 +26,8 @@ from time import time
import requests
from gi.repository import GdkPixbuf, Gio
from .check_install import check_install
def get_game(task, current_time, parent_widget, row):
values = {}
@@ -117,19 +119,23 @@ def get_games_async(parent_widget, rows, importer):
def itch_importer(parent_widget):
schema = parent_widget.schema
location_key = "itch-location"
itch_dir = Path(schema.get_string(location_key)).expanduser()
check = Path("db") / "butler.db"
database_path = (Path(schema.get_string("itch-location")) / "db").expanduser()
if not database_path.exists():
if Path("~/.var/app/io.itch.itch/config/itch/").expanduser().exists():
schema.set_string("itch-location", "~/.var/app/io.itch.itch/config/itch/")
elif (parent_widget.config_dir / "itch").exists():
schema.set_string("itch-location", str(parent_widget.config_dir / "itch"))
elif os.name == "nt" and (Path(os.getenv("appdata")) / "itch").exists():
schema.set_string("itch-location", str(Path(os.getenv("appdata")) / "itch"))
else:
if not (itch_dir / check).is_file():
locations = (
Path.home() / ".var" / "app" / "io.itch.itch" / "config" / "itch",
parent_widget.config_dir / "itch",
)
if os.name == "nt":
locations += (Path(os.getenv("appdata")) / "itch",)
if not check_install(check, locations, (schema, location_key)):
return
database_path = (Path(schema.get_string("itch-location")) / "db").expanduser()
database_path = (Path(schema.get_string(location_key)) / "db").expanduser()
db_cache_dir = parent_widget.cache_dir / "cartridges" / "itch"
db_cache_dir.mkdir(parents=True, exist_ok=True)

View File

@@ -22,36 +22,41 @@ from shutil import copyfile
from sqlite3 import connect
from time import time
from .check_install import check_install
def lutris_importer(parent_widget):
schema = parent_widget.schema
location_key = "lutris-location"
lutris_dir = Path(schema.get_string(location_key)).expanduser()
check = "pga.db"
database_path = (Path(schema.get_string("lutris-location"))).expanduser()
if not database_path.exists():
if Path("~/.var/app/net.lutris.Lutris/data/lutris/").expanduser().exists():
schema.set_string(
"lutris-location", "~/.var/app/net.lutris.Lutris/data/lutris/"
)
elif (parent_widget.data_dir / "lutris").exists():
schema.set_string("lutris-location", str(parent_widget.data_dir / "lutris"))
else:
if not (lutris_dir / check).is_file():
locations = (
Path.home() / ".var" / "app" / "net.lutris.Lutris" / "data" / "lutris",
parent_widget.data_dir / "lutris",
)
lutris_dir = check_install(check, locations, (schema, location_key))
if not lutris_dir:
return
cache_dir = Path(schema.get_string("lutris-cache-location")).expanduser()
if not cache_dir.exists():
if Path("~/.var/app/net.lutris.Lutris/cache/lutris/").expanduser().exists():
schema.set_string(
"lutris-cache-location", "~/.var/app/net.lutris.Lutris/cache/lutris/"
)
elif (parent_widget.cache_dir / "lutris").exists():
schema.set_string(
"lutris-cache-location", str(parent_widget.cache_dir / "lutris")
)
else:
cache_key = "lutris-cache-location"
cache_dir = Path(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",
parent_widget.cache_dir / "lutris",
)
cache_dir = check_install(check, cache_locations, (schema, location_key))
if not cache_dir:
return
database_path = (Path(schema.get_string("lutris-location"))).expanduser()
cache_dir = Path(schema.get_string("lutris-cache-location")).expanduser()
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.mkdir(parents=True, exist_ok=True)

View File

@@ -25,6 +25,8 @@ from time import time
import requests
from gi.repository import Gio
from .check_install import check_install
def update_values_from_data(content, values):
basic_data = content[values["appid"]]
@@ -125,35 +127,26 @@ def get_games_async(parent_widget, appmanifests, steam_dir, importer):
def steam_importer(parent_widget):
schema = parent_widget.schema
steam_dir = Path(schema.get_string("steam-location")).expanduser()
location_key = "steam-location"
steam_dir = Path(schema.get_string(location_key)).expanduser()
check = "steamapps"
def steam_not_found():
if Path("~/.var/app/com.valvesoftware.Steam/data/Steam/").expanduser().exists():
schema.set_string(
"steam-location", "~/.var/app/com.valvesoftware.Steam/data/Steam/"
)
elif Path("~/.steam/steam/").expanduser().exists():
schema.set_string("steam-location", "~/.steam/steam/")
elif (
os.name == "nt"
and (Path(os.getenv("programfiles(x86)")) / "Steam").exists()
):
schema.set_string(
"steam-location", str(Path(os.getenv("programfiles(x86)")) / "Steam")
)
if not (steam_dir / check).is_file():
subdirs = ("steam", "Steam")
if (steam_dir / "steamapps").exists():
pass
elif (steam_dir / "steam" / "steamapps").exists():
schema.set_string("steam-location", str(steam_dir / "steam"))
elif (steam_dir / "Steam" / "steamapps").exists():
schema.set_string("steam-location", str(steam_dir / "Steam"))
else:
steam_not_found()
steam_importer(parent_widget)
return
locations = (
Path.home() / ".steam" / "steam",
parent_widget.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 = Path(schema.get_string("steam-location")).expanduser()
appmanifests = []
steam_dirs = [Path(directory) for directory in schema.get_strv("steam-extra-dirs")]