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