Fix custom install locations check logic
This commit is contained in:
@@ -28,22 +28,18 @@ from .check_install import check_install
|
||||
|
||||
def bottles_installed(path=None):
|
||||
location_key = "bottles-location"
|
||||
bottles_dir = (
|
||||
path if path else Path(shared.schema.get_string(location_key)).expanduser()
|
||||
)
|
||||
check = "library.yml"
|
||||
|
||||
if not (bottles_dir / check).is_file():
|
||||
locations = (
|
||||
(Path(),)
|
||||
if path
|
||||
else (
|
||||
Path.home() / ".var/app/com.usebottles.bottles/data/bottles",
|
||||
shared.data_dir / "bottles",
|
||||
)
|
||||
locations = (
|
||||
(path,)
|
||||
if path
|
||||
else (
|
||||
Path.home() / ".var/app/com.usebottles.bottles/data/bottles",
|
||||
shared.data_dir / "bottles",
|
||||
)
|
||||
)
|
||||
|
||||
bottles_dir = check_install(check, locations, (shared.schema, location_key))
|
||||
bottles_dir = check_install(check, locations, (shared.schema, location_key))
|
||||
|
||||
return bottles_dir
|
||||
|
||||
|
||||
@@ -29,25 +29,21 @@ from .check_install import check_install
|
||||
|
||||
def heroic_installed(path=None):
|
||||
location_key = "heroic-location"
|
||||
heroic_dir = (
|
||||
path if path else Path(shared.schema.get_string(location_key)).expanduser()
|
||||
)
|
||||
check = "config.json"
|
||||
|
||||
if not (heroic_dir / check).is_file():
|
||||
locations = (
|
||||
(Path(),)
|
||||
if path
|
||||
else (
|
||||
Path.home() / ".var/app/com.heroicgameslauncher.hgl/config/heroic",
|
||||
shared.config_dir / "heroic",
|
||||
)
|
||||
locations = (
|
||||
(path,)
|
||||
if path
|
||||
else (
|
||||
Path.home() / ".var/app/com.heroicgameslauncher.hgl/config/heroic",
|
||||
shared.config_dir / "heroic",
|
||||
)
|
||||
)
|
||||
|
||||
if os.name == "nt" and not path:
|
||||
locations += (Path(os.getenv("appdata")) / "heroic",)
|
||||
if os.name == "nt" and not path:
|
||||
locations += (Path(os.getenv("appdata")) / "heroic",)
|
||||
|
||||
heroic_dir = check_install(check, locations, (shared.schema, location_key))
|
||||
heroic_dir = check_install(check, locations, (shared.schema, location_key))
|
||||
|
||||
return heroic_dir
|
||||
|
||||
@@ -63,7 +59,7 @@ def heroic_importer():
|
||||
# Import Epic games
|
||||
if not shared.schema.get_boolean("heroic-import-epic"):
|
||||
pass
|
||||
elif (heroic_dir / "store_cache" / "legendary_library.json").exists():
|
||||
elif (heroic_dir / "store_cache" / "legendary_library.json").is_file():
|
||||
library = json.load(
|
||||
(heroic_dir / "store_cache" / "legendary_library.json").open()
|
||||
)
|
||||
@@ -108,7 +104,7 @@ def heroic_importer():
|
||||
).hexdigest()
|
||||
)
|
||||
|
||||
importer.save_game(values, image_path if image_path.exists() else None)
|
||||
importer.save_game(values, image_path if image_path.is_file() else None)
|
||||
|
||||
except KeyError:
|
||||
pass
|
||||
@@ -116,9 +112,9 @@ def heroic_importer():
|
||||
# Import GOG games
|
||||
if not shared.schema.get_boolean("heroic-import-gog"):
|
||||
pass
|
||||
elif (heroic_dir / "gog_store" / "installed.json").exists() and (
|
||||
elif (heroic_dir / "gog_store" / "installed.json").is_file() and (
|
||||
heroic_dir / "store_cache" / "gog_library.json"
|
||||
).exists():
|
||||
).is_file():
|
||||
installed = json.load((heroic_dir / "gog_store" / "installed.json").open())
|
||||
|
||||
importer.total_queue += len(installed["installed"])
|
||||
@@ -161,12 +157,12 @@ def heroic_importer():
|
||||
values["added"] = current_time
|
||||
values["last_played"] = 0
|
||||
|
||||
importer.save_game(values, image_path if image_path.exists() else None)
|
||||
importer.save_game(values, image_path if image_path.is_file() else None)
|
||||
|
||||
# Import sideloaded games
|
||||
if not shared.schema.get_boolean("heroic-import-sideload"):
|
||||
pass
|
||||
elif (heroic_dir / "sideload_apps" / "library.json").exists():
|
||||
elif (heroic_dir / "sideload_apps" / "library.json").is_file():
|
||||
library = json.load((heroic_dir / "sideload_apps" / "library.json").open())
|
||||
|
||||
importer.total_queue += len(library["games"])
|
||||
@@ -201,4 +197,4 @@ def heroic_importer():
|
||||
/ sha256(item["art_square"].encode()).hexdigest()
|
||||
)
|
||||
|
||||
importer.save_game(values, image_path if image_path.exists() else None)
|
||||
importer.save_game(values, image_path if image_path.is_file() else None)
|
||||
|
||||
@@ -123,25 +123,21 @@ def get_games_async(rows, importer):
|
||||
|
||||
def itch_installed(path=None):
|
||||
location_key = "itch-location"
|
||||
itch_dir = (
|
||||
path if path else Path(shared.schema.get_string(location_key)).expanduser()
|
||||
)
|
||||
check = Path("db") / "butler.db"
|
||||
|
||||
if not (itch_dir / check).is_file():
|
||||
locations = (
|
||||
(Path(),)
|
||||
if path
|
||||
else (
|
||||
Path.home() / ".var/app/io.itch.itch/config/itch",
|
||||
shared.config_dir / "itch",
|
||||
)
|
||||
locations = (
|
||||
(path,)
|
||||
if path
|
||||
else (
|
||||
Path.home() / ".var/app/io.itch.itch/config/itch",
|
||||
shared.config_dir / "itch",
|
||||
)
|
||||
)
|
||||
|
||||
if os.name == "nt" and not path:
|
||||
locations += (Path(os.getenv("appdata")) / "itch",)
|
||||
if os.name == "nt" and not path:
|
||||
locations += (Path(os.getenv("appdata")) / "itch",)
|
||||
|
||||
itch_dir = check_install(check, locations, (shared.schema, location_key))
|
||||
itch_dir = check_install(check, locations, (shared.schema, location_key))
|
||||
|
||||
return itch_dir
|
||||
|
||||
|
||||
@@ -28,44 +28,36 @@ from .check_install import check_install
|
||||
|
||||
def lutris_installed(path=None):
|
||||
location_key = "lutris-location"
|
||||
lutris_dir = (
|
||||
path if path else Path(shared.schema.get_string(location_key)).expanduser()
|
||||
)
|
||||
check = "pga.db"
|
||||
|
||||
if not (lutris_dir / check).is_file():
|
||||
locations = (
|
||||
(Path(),)
|
||||
if path
|
||||
else (
|
||||
Path.home() / ".var/app/net.lutris.Lutris/data/lutris",
|
||||
shared.data_dir / "lutris",
|
||||
)
|
||||
locations = (
|
||||
(path,)
|
||||
if path
|
||||
else (
|
||||
Path.home() / ".var/app/net.lutris.Lutris/data/lutris",
|
||||
shared.data_dir / "lutris",
|
||||
)
|
||||
)
|
||||
|
||||
lutris_dir = check_install(check, locations, (shared.schema, location_key))
|
||||
lutris_dir = check_install(check, locations, (shared.schema, location_key))
|
||||
|
||||
return lutris_dir
|
||||
|
||||
|
||||
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"
|
||||
|
||||
if not (cache_dir / cache_check).exists():
|
||||
cache_locations = (
|
||||
(Path(),)
|
||||
if path
|
||||
else (
|
||||
Path.home() / ".var" / "app" / "net.lutris.Lutris" / "cache" / "lutris",
|
||||
shared.cache_dir / "lutris",
|
||||
)
|
||||
cache_locations = (
|
||||
(path,)
|
||||
if path
|
||||
else (
|
||||
Path.home() / ".var" / "app" / "net.lutris.Lutris" / "cache" / "lutris",
|
||||
shared.cache_dir / "lutris",
|
||||
)
|
||||
)
|
||||
|
||||
cache_dir = check_install(
|
||||
cache_check, cache_locations, (shared.schema, cache_key)
|
||||
)
|
||||
cache_dir = check_install(cache_check, cache_locations, (shared.schema, cache_key))
|
||||
|
||||
return cache_dir
|
||||
|
||||
@@ -137,4 +129,4 @@ def lutris_importer():
|
||||
values["source"] = f"lutris_{row[3]}"
|
||||
|
||||
image_path = cache_dir / "coverart" / f"{row[2]}.jpg"
|
||||
importer.save_game(values, image_path if image_path.exists() else None)
|
||||
importer.save_game(values, image_path if image_path.is_file() else None)
|
||||
|
||||
@@ -90,11 +90,11 @@ def get_game(task, datatypes, current_time, appmanifest, steam_dir):
|
||||
open_file.raise_for_status()
|
||||
content = open_file.json()
|
||||
except requests.exceptions.RequestException:
|
||||
task.return_value((values, image_path if image_path.exists() else None))
|
||||
task.return_value((values, image_path if image_path.is_file() else None))
|
||||
return
|
||||
|
||||
values = update_values_from_data(content, values)
|
||||
task.return_value((values, image_path if image_path.exists() else None))
|
||||
task.return_value((values, image_path if image_path.is_file() else None))
|
||||
|
||||
|
||||
def get_games_async(appmanifests, steam_dir, importer):
|
||||
@@ -129,25 +129,22 @@ def steam_installed(path=None):
|
||||
steam_dir = Path(shared.schema.get_string(location_key)).expanduser()
|
||||
check = "steamapps"
|
||||
|
||||
if not (steam_dir / check).is_file():
|
||||
subdirs = ("steam", "Steam")
|
||||
locations = (
|
||||
(path,)
|
||||
if path
|
||||
else (
|
||||
steam_dir,
|
||||
Path.home() / ".steam",
|
||||
shared.data_dir / "Steam",
|
||||
Path.home() / ".var/app/com.valvesoftware.Steam/data/Steam",
|
||||
)
|
||||
subdirs = ("steam", "Steam")
|
||||
locations = (
|
||||
(path,)
|
||||
if path
|
||||
else (
|
||||
steam_dir,
|
||||
Path.home() / ".steam",
|
||||
shared.data_dir / "Steam",
|
||||
Path.home() / ".var/app/com.valvesoftware.Steam/data/Steam",
|
||||
)
|
||||
)
|
||||
|
||||
if os.name == "nt":
|
||||
locations += (Path(os.getenv("programfiles(x86)")) / "Steam",)
|
||||
if os.name == "nt":
|
||||
locations += (Path(os.getenv("programfiles(x86)")) / "Steam",)
|
||||
|
||||
steam_dir = check_install(
|
||||
check, locations, (shared.schema, location_key), subdirs
|
||||
)
|
||||
steam_dir = check_install(check, locations, (shared.schema, location_key), subdirs)
|
||||
|
||||
return steam_dir
|
||||
|
||||
@@ -168,7 +165,7 @@ def steam_importer():
|
||||
steam_dirs = [steam_dir]
|
||||
|
||||
for directory in steam_dirs:
|
||||
if not (directory / "steamapps").exists():
|
||||
if not (directory / "steamapps").is_dir():
|
||||
steam_dirs.remove(directory)
|
||||
|
||||
for directory in steam_dirs:
|
||||
|
||||
@@ -126,7 +126,7 @@ class PreferencesWindow(Adw.PreferencesWindow):
|
||||
if response == "choose_folder":
|
||||
self.choose_folder(widget, set_cache_dir)
|
||||
|
||||
if lutris_cache_exists(self.win, path):
|
||||
if lutris_cache_exists(path):
|
||||
self.import_changed = True
|
||||
self.set_subtitle(self, "lutris-cache")
|
||||
|
||||
@@ -257,7 +257,7 @@ class PreferencesWindow(Adw.PreferencesWindow):
|
||||
getattr(win, f'{source_id.replace("-", "_")}_action_row').set_subtitle(
|
||||
# Remove the path if the dir is picked via the Flatpak portal
|
||||
re.sub(
|
||||
"/run/user/\\d*/doc/......../",
|
||||
"/run/user/\\d*/doc/.*/",
|
||||
"",
|
||||
str(
|
||||
Path(shared.schema.get_string(f"{source_id}-location")).expanduser()
|
||||
|
||||
@@ -23,10 +23,9 @@ from pathlib import Path
|
||||
def check_install(check, locations, setting=None, subdirs=(Path(),)):
|
||||
for location in locations:
|
||||
for subdir in (Path(),) + subdirs:
|
||||
if (location / subdir / check).is_file() or (
|
||||
location / subdir / check
|
||||
).exists():
|
||||
if (location / subdir / check).exists():
|
||||
if setting:
|
||||
setting[0].set_string(setting[1], str(location / subdir))
|
||||
|
||||
return location / subdir
|
||||
|
||||
return False
|
||||
|
||||
@@ -94,7 +94,7 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
||||
|
||||
games = {}
|
||||
|
||||
if shared.games_dir.exists():
|
||||
if shared.games_dir.is_dir():
|
||||
for open_file in shared.games_dir.iterdir():
|
||||
data = json.load(open_file.open())
|
||||
games[data["game_id"]] = data
|
||||
|
||||
Reference in New Issue
Block a user