Improve imports

This commit is contained in:
kramo
2023-02-03 21:44:57 +01:00
parent 79275caa15
commit 2bfc58f22d
4 changed files with 71 additions and 47 deletions

View File

@@ -11,6 +11,9 @@
"--socket=wayland", "--socket=wayland",
"--talk-name=org.freedesktop.Flatpak", "--talk-name=org.freedesktop.Flatpak",
"--filesystem=~/.steam/steam/", "--filesystem=~/.steam/steam/",
"--filesystem=xdg-config/heroic/",
"--filesystem=xdg-data/bottles/",
"--filesystem=~/.var/app/com.valvesoftware.Steam/data/Steam/",
"--filesystem=~/.var/app/com.heroicgameslauncher.hgl/config/heroic/", "--filesystem=~/.var/app/com.heroicgameslauncher.hgl/config/heroic/",
"--filesystem=~/.var/app/com.usebottles.bottles/data/bottles/" "--filesystem=~/.var/app/com.usebottles.bottles/data/bottles/"
], ],

View File

@@ -26,27 +26,33 @@ def bottles_parser(parent_widget, action):
from .save_cover import save_cover from .save_cover import save_cover
schema = parent_widget.schema schema = parent_widget.schema
bottles_dir = os.path.expanduser(os.path.join(schema.get_string("bottles-location"))) bottles_dir = os.path.expanduser(schema.get_string("bottles-location"))
def bottles_not_found(): def bottles_not_found():
filechooser = Gtk.FileDialog.new() if os.path.exists(os.path.expanduser("~/.var/app/com.usebottles.bottles/data/bottles/")):
schema.set_string("bottles-location", "~/.var/app/com.usebottles.bottles/data/bottles/")
action(None, None)
elif os.path.exists(os.path.join(os.environ.get("XDG_DATA_HOME"), "bottles")):
schema.set_string("bottles-location", os.path.join(os.environ.get("XDG_DATA_HOME"), "bottles"))
action(None, None)
else:
filechooser = Gtk.FileDialog.new()
def set_bottles_dir(source, result, _): def set_bottles_dir(source, result, _):
try: try:
schema.set_string("bottles-location", filechooser.select_folder_finish(result).get_path()) schema.set_string("bottles-location", filechooser.select_folder_finish(result).get_path())
bottles_dir = bottles_dir = os.path.join(schema.get_string("bottles-location")) action(None, None)
action(None, None) except GLib.GError:
except GLib.GError: return
return
def choose_folder(widget): def choose_folder(widget):
filechooser.select_folder(parent_widget, None, set_bottles_dir, None) filechooser.select_folder(parent_widget, None, set_bottles_dir, None)
def response(widget, response): def response(widget, response):
if response == "choose_folder": if response == "choose_folder":
choose_folder(widget) choose_folder(widget)
create_dialog(parent_widget, _("Couldn't Import Games"), _("Bottles directory cannot be found."), "choose_folder", _("Set Bottles Location")).connect("response", response) create_dialog(parent_widget, _("Couldn't Import Games"), _("Bottles directory cannot be found."), "choose_folder", _("Set Bottles Location")).connect("response", response)
if os.path.isfile(os.path.join(bottles_dir, "library.yml")): if os.path.isfile(os.path.join(bottles_dir, "library.yml")):
pass pass
@@ -54,6 +60,8 @@ def bottles_parser(parent_widget, action):
bottles_not_found() bottles_not_found()
return {} return {}
bottles_dir = os.path.expanduser(schema.get_string("bottles-location"))
datatypes = ["path", "id", "name", "thumbnail"] datatypes = ["path", "id", "name", "thumbnail"]
bottles_games = {} bottles_games = {}
current_time = int(time.time()) current_time = int(time.time())

View File

@@ -26,28 +26,33 @@ def heroic_parser(parent_widget, action):
from .save_cover import save_cover from .save_cover import save_cover
schema = parent_widget.schema schema = parent_widget.schema
heroic_dir = os.path.expanduser(os.path.join(schema.get_string("heroic-location"))) heroic_dir = os.path.expanduser(schema.get_string("heroic-location"))
def heroic_not_found(): def heroic_not_found():
filechooser = Gtk.FileDialog.new() if os.path.exists(os.path.expanduser("~/.var/app/com.heroicgameslauncher.hgl/config/heroic/")):
schema.set_string("heroic-location", "~/.var/app/com.heroicgameslauncher.hgl/config/heroic/")
action(None, None)
elif os.path.exists(os.path.join(os.environ.get("XDG_CONFIG_HOME"), "heroic")):
schema.set_string("heroic-location", os.path.join(os.environ.get("XDG_CONFIG_HOME"), "heroic"))
action(None, None)
else:
filechooser = Gtk.FileDialog.new()
def set_heroic_dir(source, result, _): def set_heroic_dir(source, result, _):
try: try:
schema.set_string("heroic-location", filechooser.select_folder_finish(result).get_path()) schema.set_string("heroic-location", filechooser.select_folder_finish(result).get_path())
heroic_dir = heroic_dir = os.path.join(schema.get_string("heroic-location")) action(None, None)
action(None, None) except GLib.GError:
except GLib.GError: return
return
def choose_folder(widget): def choose_folder(widget):
filechooser.select_folder(parent_widget, None, set_heroic_dir, None) filechooser.select_folder(parent_widget, None, set_heroic_dir, None)
def response(widget, response): def response(widget, response):
if response == "choose_folder": if response == "choose_folder":
choose_folder(widget) choose_folder(widget)
create_dialog(parent_widget, _("Couldn't Import Games"), _("Heroic directory cannot be found."), create_dialog(parent_widget, _("Couldn't Import Games"), _("Heroic directory cannot be found."), "choose_folder", _("Set Heroic Location")).connect("response", response)
"choose_folder", _("Set Heroic Location")).connect("response", response)
if os.path.exists(os.path.join(heroic_dir, "config.json")): if os.path.exists(os.path.join(heroic_dir, "config.json")):
pass pass
@@ -55,6 +60,8 @@ def heroic_parser(parent_widget, action):
heroic_not_found() heroic_not_found()
return {} return {}
heroic_dir = os.path.expanduser(schema.get_string("heroic-location"))
heroic_games = {} heroic_games = {}
current_time = int(time.time()) current_time = int(time.time())

View File

@@ -26,27 +26,33 @@ def steam_parser(parent_widget, action):
from .save_cover import save_cover from .save_cover import save_cover
schema = parent_widget.schema schema = parent_widget.schema
steam_dir = os.path.expanduser(os.path.join(schema.get_string("steam-location"))) steam_dir = os.path.expanduser(schema.get_string("steam-location"))
def steam_not_found(): def steam_not_found():
filechooser = Gtk.FileDialog.new() if os.path.exists(os.path.expanduser("~/.var/app/com.valvesoftware.Steam/data/Steam/")):
schema.set_string("steam-location", "~/.var/app/com.valvesoftware.Steam/data/Steam/")
action(None, None)
elif os.path.exists(os.path.expanduser("~/.steam/steam/")):
schema.set_string("steam-location", "~/.steam/steam/")
action(None, None)
else:
filechooser = Gtk.FileDialog.new()
def set_steam_dir(source, result, _): def set_steam_dir(source, result, _):
try: try:
schema.set_string("steam-location", filechooser.select_folder_finish(result).get_path()) schema.set_string("steam-location", filechooser.select_folder_finish(result).get_path())
steam_dir = steam_dir = os.path.join(schema.get_string("steam-location")) action(None, None)
action(None, None) except GLib.GError:
except GLib.GError: return
return
def choose_folder(widget): def choose_folder(widget):
filechooser.select_folder(parent_widget, None, set_steam_dir, None) filechooser.select_folder(parent_widget, None, set_steam_dir, None)
def response(widget, response): def response(widget, response):
if response == "choose_folder": if response == "choose_folder":
choose_folder(widget) choose_folder(widget)
create_dialog(parent_widget, _("Couldn't Import Games"), _("Steam directory cannot be found."), "choose_folder", _("Set Steam Location")).connect("response", response) create_dialog(parent_widget, _("Couldn't Import Games"), _("Steam directory cannot be found."), "choose_folder", _("Set Steam Location")).connect("response", response)
if os.path.exists(os.path.join(steam_dir, "steamapps")): if os.path.exists(os.path.join(steam_dir, "steamapps")):
pass pass
@@ -58,7 +64,7 @@ def steam_parser(parent_widget, action):
steam_not_found() steam_not_found()
return {} return {}
steam_dir = schema.get_string("steam-location") steam_dir = os.path.expanduser(schema.get_string("steam-location"))
appmanifests = [] appmanifests = []
datatypes = ["appid", "name"] datatypes = ["appid", "name"]