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

View File

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

View File

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

View File

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

View File

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

View File

@@ -34,7 +34,8 @@ cartridges_sources = [
'utils/save_game.py', 'utils/save_game.py',
'utils/save_cover.py', 'utils/save_cover.py',
'utils/create_dialog.py', 'utils/create_dialog.py',
'utils/create_details_window.py' 'utils/create_details_window.py',
'utils/check_install.py'
] ]
install_data(cartridges_sources, install_dir: moduledir) install_data(cartridges_sources, install_dir: moduledir)

View File

@@ -0,0 +1,32 @@
# check_install.py
#
# Copyright 2022-2023 kramo
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: GPL-3.0-or-later
from pathlib import Path
def check_install(check, locations, setting=None, subdirs=(Path(),)):
for location in locations:
for subdir in subdirs:
if (location / subdir / check).is_file() or (
location / subdir / check
).exists():
if setting:
setting[0].set_string(setting[1], str(location))
return location

View File

@@ -21,7 +21,7 @@
from pathlib import Path from pathlib import Path
from shutil import copyfile from shutil import copyfile
from gi.repository import GdkPixbuf, Gio, GLib from gi.repository import GdkPixbuf, Gio
from PIL import Image, ImageSequence from PIL import Image, ImageSequence