import games from egs
This commit is contained in:
parent
45b3275bbf
commit
614cf0b35e
|
@ -55,7 +55,8 @@ class GameWidget(QWidget):
|
|||
self.title_widget = QLabel(f"<h1>{self.title}</h1>")
|
||||
self.launch_button = QPushButton(play_icon, "Launch")
|
||||
self.launch_button.clicked.connect(self.launch)
|
||||
self.wine_rating = QLabel("Wine Rating: " + self.get_rating())
|
||||
if os.name != "nt":
|
||||
self.wine_rating = QLabel("Wine Rating: " + self.get_rating())
|
||||
self.developer_label = QLabel("Dev: "+ self.dev)
|
||||
self.version_label = QLabel("Version: " + str(self.version))
|
||||
self.size_label = QLabel(f"Installed size: {round(self.size / (1024 ** 3), 2)} GB")
|
||||
|
@ -65,7 +66,8 @@ class GameWidget(QWidget):
|
|||
self.childLayout.addWidget(self.title_widget)
|
||||
self.childLayout.addWidget(self.launch_button)
|
||||
self.childLayout.addWidget(self.developer_label)
|
||||
self.childLayout.addWidget(self.wine_rating)
|
||||
if os.name != "nt":
|
||||
self.childLayout.addWidget(self.wine_rating)
|
||||
self.childLayout.addWidget(self.version_label)
|
||||
self.childLayout.addWidget(self.size_label)
|
||||
self.childLayout.addWidget(self.settings_button)
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
import json
|
||||
import os
|
||||
import string
|
||||
from logging import getLogger
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtWidgets import *
|
||||
from legendary.core import LegendaryCore
|
||||
|
||||
from Rare.Tabs.GamesInstalled.GameWidget import GameWidget
|
||||
from legendary.core import LegendaryCore
|
||||
from Rare.utils import legendaryUtils
|
||||
|
||||
logger = getLogger("InstalledList")
|
||||
|
||||
|
@ -19,11 +23,22 @@ class GameListInstalled(QScrollArea):
|
|||
|
||||
self.layout = QVBoxLayout()
|
||||
self.widgets = {}
|
||||
for i in sorted(core.get_installed_list(), key=lambda game: game.title):
|
||||
widget = GameWidget(i, core)
|
||||
widget.signal.connect(self.remove_game)
|
||||
self.widgets[i.app_name] = widget
|
||||
self.layout.addWidget(widget)
|
||||
games = sorted(core.get_installed_list(), key=lambda game: game.title)
|
||||
if games:
|
||||
|
||||
for i in games:
|
||||
widget = GameWidget(i, core)
|
||||
widget.signal.connect(self.remove_game)
|
||||
self.widgets[i.app_name] = widget
|
||||
self.layout.addWidget(widget)
|
||||
|
||||
else:
|
||||
not_installed_label = QLabel("No Games are installed. Do you want to import them?")
|
||||
not_installed_button = QPushButton("Import Games")
|
||||
not_installed_button.clicked.connect(self.import_games_prepare)
|
||||
self.layout.addWidget(not_installed_label)
|
||||
self.layout.addWidget(not_installed_button)
|
||||
|
||||
self.widget.setLayout(self.layout)
|
||||
self.setWidget(self.widget)
|
||||
|
||||
|
@ -35,3 +50,33 @@ class GameListInstalled(QScrollArea):
|
|||
self.layout.removeWidget(self.widgets[app_name])
|
||||
self.widgets[app_name].deleteLater()
|
||||
self.widgets.pop(app_name)
|
||||
|
||||
def import_games_prepare(self):
|
||||
# Automatically import from windows
|
||||
if os.name == "nt":
|
||||
available_drives = ['%s:' % d for d in string.ascii_uppercase if os.path.exists('%s:' % d)]
|
||||
for drive in available_drives:
|
||||
path = f"{drive}/Program Files/Epic Games/"
|
||||
self.auto_import_games(path)
|
||||
else:
|
||||
possible_wineprefixes = [os.path.expanduser("~/.wine/"), os.path.expanduser("~/Games/epic-games-store/")]
|
||||
for wine_prefix in possible_wineprefixes:
|
||||
self.auto_import_games(f"{wine_prefix}drive_c/Program Files/Epic Games/")
|
||||
|
||||
logger.info("Restarting app to import games")
|
||||
|
||||
def auto_import_games(self, game_path):
|
||||
if not os.path.exists(game_path):
|
||||
return
|
||||
|
||||
for path in os.listdir(game_path):
|
||||
json_path = game_path + path + "/.egstore"
|
||||
print(json_path)
|
||||
if not os.path.isdir(json_path):
|
||||
logger.info(f"Game at {game_path+path} doesn't exist")
|
||||
continue
|
||||
|
||||
for file in os.listdir(json_path):
|
||||
if file.endswith(".mancpn"):
|
||||
app_name = json.load(open(os.path.join(json_path, file)))["AppName"]
|
||||
legendaryUtils.import_game(self.core, app_name, game_path + path)
|
||||
|
|
|
@ -24,8 +24,8 @@ class SettingsForm(QGroupBox):
|
|||
self.config[self.app_name]["wine_prefix"] = ""
|
||||
if not self.config[self.app_name].get("language"):
|
||||
self.config[self.app_name]["language"] = ""
|
||||
if not self.config["Legendary"].get("offline"):
|
||||
self.config["Legendary"]["offline"] = ""
|
||||
# if not self.config["Legendary"].get("offline"):
|
||||
# self.config["Legendary"]["offline"] = ""
|
||||
|
||||
env_vars = self.config.get(f"{self.app_name}.env")
|
||||
if env_vars:
|
||||
|
@ -48,7 +48,7 @@ class SettingsForm(QGroupBox):
|
|||
self.language = QLineEdit(self.config[self.app_name]["language"])
|
||||
self.language.setPlaceholderText("Default")
|
||||
|
||||
self.offline = QCheckBox(self.config["offline"] == "false")
|
||||
# self.offline = QCheckBox(self.config["offline"] == "false")
|
||||
|
||||
|
||||
self.add_button = QPushButton("Add Environment Variable")
|
||||
|
@ -92,6 +92,7 @@ class SettingsForm(QGroupBox):
|
|||
# Wineprefix
|
||||
if self.game_conf_wine_prefix.text() != '':
|
||||
self.config[self.app_name]["wine_prefix"] = self.game_conf_wine_prefix.text()
|
||||
pass
|
||||
elif "wine_prefix" in self.config[self.app_name]:
|
||||
self.config[self.app_name].pop("wine_prefix")
|
||||
|
||||
|
@ -112,3 +113,4 @@ class SettingsForm(QGroupBox):
|
|||
if self.config.get(self.app_name) == {}:
|
||||
self.config.pop(self.app_name)
|
||||
legendaryConfig.set_config(self.config)
|
||||
print(self.config)
|
|
@ -4,10 +4,13 @@ from PyQt5.QtWidgets import *
|
|||
from Rare.Tabs.GamesUninstalled.GameWidget import UninstalledGameWidget
|
||||
from legendary.core import LegendaryCore
|
||||
|
||||
from Rare.utils.Dialogs.ImportDialog import ImportDialog
|
||||
|
||||
|
||||
class GameListUninstalled(QScrollArea):
|
||||
def __init__(self, parent, core: LegendaryCore):
|
||||
super(GameListUninstalled, self).__init__(parent=parent)
|
||||
self.core = core
|
||||
self.widget = QWidget()
|
||||
self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
|
||||
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
|
||||
|
@ -17,8 +20,10 @@ class GameListUninstalled(QScrollArea):
|
|||
self.filter = QLineEdit()
|
||||
self.filter.textChanged.connect(self.filter_games)
|
||||
self.filter.setPlaceholderText("Filter Games")
|
||||
self.import_button = QPushButton("Import installed Game from Epic Games Store")
|
||||
self.import_button.clicked.connect(self.import_game)
|
||||
self.layout.addWidget(self.filter)
|
||||
|
||||
self.layout.addWidget(self.import_button)
|
||||
self.widgets_uninstalled = []
|
||||
games = []
|
||||
installed = [i.app_name for i in core.get_installed_list()]
|
||||
|
@ -41,3 +46,7 @@ class GameListUninstalled(QScrollArea):
|
|||
i.setVisible(True)
|
||||
else:
|
||||
i.setVisible(False)
|
||||
|
||||
def import_game(self):
|
||||
import_dia = ImportDialog(self.core)
|
||||
import_dia.import_dialog()
|
|
@ -145,3 +145,4 @@ class SettingsForm(QGroupBox):
|
|||
if self.config.get("Legendary") == {}:
|
||||
self.config.pop("Legendary")
|
||||
legendaryConfig.set_config(self.config)
|
||||
print(self.config)
|
||||
|
|
|
@ -1 +1 @@
|
|||
__version__ = "0.4.1"
|
||||
__version__ = "0.4.2"
|
||||
|
|
59
Rare/utils/Dialogs/ImportDialog.py
Normal file
59
Rare/utils/Dialogs/ImportDialog.py
Normal file
|
@ -0,0 +1,59 @@
|
|||
import json
|
||||
import os
|
||||
from logging import getLogger
|
||||
|
||||
from PyQt5.QtWidgets import *
|
||||
from legendary.core import LegendaryCore
|
||||
|
||||
from Rare.utils import legendaryUtils
|
||||
|
||||
logger = getLogger("ImportDialog")
|
||||
|
||||
|
||||
class ImportDialog(QDialog):
|
||||
def __init__(self, core: LegendaryCore):
|
||||
super(ImportDialog, self).__init__()
|
||||
self.core = core
|
||||
self.title_text = QLabel("Select Path")
|
||||
self.path_field = QLineEdit()
|
||||
self.info_text = QLabel("")
|
||||
self.import_button = QPushButton("Import")
|
||||
self.import_button.clicked.connect(self.button_click)
|
||||
|
||||
self.layout = QVBoxLayout()
|
||||
self.layout.addWidget(self.title_text)
|
||||
self.layout.addWidget(self.path_field)
|
||||
self.layout.addWidget(self.info_text)
|
||||
self.layout.addWidget(self.import_button)
|
||||
|
||||
self.setLayout(self.layout)
|
||||
|
||||
def button_click(self):
|
||||
if self.import_game():
|
||||
self.close()
|
||||
else:
|
||||
self.info_text.setText("Failed to import Game")
|
||||
|
||||
def import_game(self):
|
||||
path = self.path_field.text()
|
||||
print()
|
||||
if not path.endswith("/"):
|
||||
path = path + "/"
|
||||
file = ""
|
||||
|
||||
for i in os.listdir(os.path.join(path, ".egstore")):
|
||||
if i.endswith(".mancpn"):
|
||||
file = path + ".egstore/" + i
|
||||
break
|
||||
else:
|
||||
logger.warning("File was not found")
|
||||
return False
|
||||
app_name = json.load(open(file, "r"))["AppName"]
|
||||
if legendaryUtils.import_game(self.core, app_name=app_name, path=path):
|
||||
return True
|
||||
else:
|
||||
logger.warning("Failed to import")
|
||||
return False
|
||||
|
||||
def import_dialog(self):
|
||||
self.exec_()
|
0
Rare/utils/Dialogs/__init__.py
Normal file
0
Rare/utils/Dialogs/__init__.py
Normal file
|
@ -1,5 +1,6 @@
|
|||
import json
|
||||
import os
|
||||
import sys
|
||||
from logging import getLogger
|
||||
|
||||
import requests
|
||||
|
@ -78,3 +79,6 @@ def download_images(signal: pyqtSignal, core: LegendaryCore):
|
|||
else:
|
||||
logger.warning(f"File {IMAGE_DIR}/{game.app_name}/DieselGameBoxTall.png dowsn't exist")
|
||||
signal.emit(i)
|
||||
|
||||
def restart():
|
||||
os.execv(sys.executable, ['python'] + sys.argv)
|
|
@ -2,7 +2,7 @@ import logging
|
|||
import os
|
||||
import subprocess
|
||||
|
||||
from PyQt5.QtCore import QProcess, QProcessEnvironment, QThread
|
||||
from PyQt5.QtCore import QProcess, QProcessEnvironment
|
||||
from legendary.core import LegendaryCore
|
||||
|
||||
logger = logging.getLogger("LGD")
|
||||
|
@ -128,3 +128,27 @@ def uninstall(app_name: str, lgd_core):
|
|||
# logger.info("Uninstalling " + app_name)
|
||||
|
||||
|
||||
def import_game(core: LegendaryCore, app_name: str, path: str):
|
||||
logger.info("Import " + app_name)
|
||||
igame = core.get_game(app_name)
|
||||
manifest, jgame = core.import_game(igame, path)
|
||||
exe_path = os.path.join(path, manifest.meta.launch_exe.lstrip('/'))
|
||||
total = len(manifest.file_manifest_list.elements)
|
||||
found = sum(os.path.exists(os.path.join(path, f.filename))
|
||||
for f in manifest.file_manifest_list.elements)
|
||||
ratio = found / total
|
||||
if not os.path.exists(exe_path):
|
||||
logger.error(f"Game {igame.app_title} failed to import")
|
||||
return False
|
||||
if ratio < 0.95:
|
||||
logger.error(
|
||||
"Game files are missing. It may be not the lates version ore it is corrupt")
|
||||
return False
|
||||
core.install_game(jgame)
|
||||
if jgame.needs_verification:
|
||||
logger.info(logger.info(
|
||||
f'NOTE: The game installation will have to be verified before it can be updated '
|
||||
f'with legendary. Run "legendary repair {app_name}" to do so.'))
|
||||
|
||||
logger.info("Successfully imported Game: " + igame.app_title)
|
||||
return True
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
legendary_gl>=0.20.1
|
||||
legendary-gl
|
||||
requests==2.25.1
|
||||
Pillow==8.0.1
|
||||
PyQt5==5.15.2
|
||||
|
|
2
setup.py
2
setup.py
|
@ -14,7 +14,7 @@ setuptools.setup(
|
|||
long_description=long_description,
|
||||
long_description_content_type="text/markdown",
|
||||
url="https://github.com/Dummerle/Rare",
|
||||
packages=["Rare", "Rare.Styles", "Rare.utils", "Rare.Tabs", "Rare.Tabs.Settings", "Rare.Tabs.GamesInstalled", "Rare.Tabs.GamesUninstalled"],
|
||||
packages=setuptools.find_packages(where="Rare/"),
|
||||
classifiers=[
|
||||
"Programming Language :: Python :: 3",
|
||||
"Programming Language :: Python :: 3.8",
|
||||
|
|
Loading…
Reference in a new issue