1
0
Fork 0
mirror of synced 2024-06-02 02:34:40 +12:00

Fixed Errors, Auto update

This commit is contained in:
Dummerle 2021-01-11 14:18:10 +01:00
parent 80dfb2a87b
commit 8b7165a882
14 changed files with 114 additions and 183 deletions

View file

@ -16,7 +16,7 @@ Rare is currently considered beta software and in no way feature-complete. You *
Execute *pip install Rare* for all users
Or *pip install Rare --user* for only one user
### Simple Windows Windows
### Windows Simple
Download Rare.exe and place it somewhere in PATH
### Linux
@ -29,8 +29,10 @@ Download Rare.exe and place it somewhere in PATH
- In-app Browser to buy games
- Settings
### Todos
- Path LineEdits
- Sync saves
- More Settings
- Translations
- Design(Pretty Stylesheets, Icon view)
### Images

View file

@ -1,6 +1,6 @@
from PyQt5.QtWidgets import QMainWindow, QTabWidget, QWidget
from Rare.Tabs import SettingsTab, UpdateTab, GameListInstalled,GameListUninstalled, BrowserTab
from Rare.Tabs import SettingsTab, UpdateTab, GameListInstalled, GameListUninstalled, BrowserTab
class MainWindow(QMainWindow):
@ -22,6 +22,7 @@ class TabWidget(QTabWidget):
self.addTab(self.game_list, "Games")
self.uninstalled_games = GameListUninstalled(core)
self.uninstalled_games.finished.connect(self.installed)
self.addTab(self.uninstalled_games, "Install Games")
self.update_tab = UpdateTab(core)
@ -32,3 +33,7 @@ class TabWidget(QTabWidget):
self.settings = SettingsTab(core)
self.addTab(self.settings, "Settings")
def installed(self):
print("zs")
self.game_list.update_list()

View file

@ -1,10 +1,13 @@
import os
from logging import getLogger
from PyQt5.QtGui import QIntValidator
from PyQt5.QtWidgets import *
from Rare.utils import legendaryConfig
logger = getLogger("SettingsForm")
class SettingsForm(QGroupBox):
@ -141,4 +144,22 @@ class SettingsForm(QGroupBox):
def use_proton_template(self):
for i in self.rows:
pass # TODO
field, type_of_input, lgd_name = i
if lgd_name == "wrapper":
for file in os.listdir(os.path.expanduser("~/.steam/steam/steamapps/common")):
if file.startswith("Proton"):
protonpath = os.path.expanduser("~/.steam/steam/steamapps/common/" + file)
break
else:
logger.error("No Proton found")
QMessageBox.Warning("Error", "No Proton was found")
return
field.setText(os.path.join(protonpath, "proton") + " run")
elif lgd_name == "no_wine":
field.setCurrentIndex(1)
self.table.insertRow(self.table.rowCount())
self.table.setItem(self.table.rowCount() - 1, 0, QTableWidgetItem("STEAM_COMPAT_DATA_PATH"))
self.table.setItem(self.table.rowCount() - 1, 1, QTableWidgetItem(os.path.expanduser("~/.proton")))

View file

@ -7,6 +7,7 @@ class BrowserTab(QWebEngineView):
super(BrowserTab, self).__init__()
self.profile = QWebEngineProfile("storage", self)
self.webpage = QWebEnginePage(self.profile, self)
self.webpage.javaScriptConsoleMessage = lambda level, msg, line, sourceID: None
self.setPage(self.webpage)
self.load(QUrl("https://www.epicgames.com/store/"))
self.show()

View file

@ -15,9 +15,8 @@ class GameSettingsDialog(QDialog):
self.layout = QVBoxLayout()
self.layout.addWidget(QLabel("<h1>Settings</h1>"))
self.wine_prefix_text = QLabel("Wine prefix")
self.wine_prefix = QLineEdit(f"{os.path.expanduser('~')}/.wine")
self.wine_prefix.setPlaceholderText("Wineprefix")
self.uninstall_button = QPushButton("Uninstall Game")
self.settings = SettingsForm(self.game.app_name, game_settings, table=True)
@ -28,6 +27,10 @@ class GameSettingsDialog(QDialog):
self.layout.addWidget(self.settings)
if os.name != 'nt':
self.use_proton = QPushButton("Use Proton")
self.use_proton.clicked.connect(self.settings.use_proton_template)
self.layout.addWidget(self.use_proton)
self.layout.addWidget(self.uninstall_button)
self.layout.addWidget(self.exit_button)
@ -48,6 +51,10 @@ class GameSettingsDialog(QDialog):
if ret == QMessageBox.Ok:
self.action = "uninstall"
self.close()
return
else:
self.action = ""
self.close()
def exit_settings(self):
self.close()

View file

@ -53,6 +53,15 @@ class GameWidget(QWidget):
settings_icon = self.style().standardIcon(getattr(QStyle, 'SP_DirIcon'))
self.title_widget = QLabel(f"<h1>{self.title}</h1>")
self.launch_button = QPushButton(play_icon, "Launch")
self.launch_button.setFixedWidth(120)
'''
self.launch_button.setStyleSheet("""
QPushButton{
background-color: blue;
color: white;
}
""")
'''
self.launch_button.clicked.connect(self.launch)
if os.name != "nt":
self.wine_rating = QLabel("Wine Rating: " + self.get_rating())
@ -60,6 +69,7 @@ class GameWidget(QWidget):
self.version_label = QLabel("Version: " + str(self.version))
self.size_label = QLabel(f"Installed size: {round(self.size / (1024 ** 3), 2)} GB")
self.settings_button = QPushButton(settings_icon, " Settings (Icon TODO)")
self.settings_button.setFixedWidth(200)
self.settings_button.clicked.connect(self.settings)
self.childLayout.addWidget(self.title_widget)

View file

@ -16,22 +16,27 @@ logger = getLogger("InstalledList")
class GameListInstalled(QScrollArea):
def __init__(self, core: LegendaryCore):
super(GameListInstalled, self).__init__()
self.widget = QWidget()
self.core = core
self.init_ui()
# self.setLayout(self.layout)
def init_ui(self):
self.widget = QWidget()
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.layout = QVBoxLayout()
self.update_button = QPushButton("Update")
self.update_button.clicked.connect(lambda: self.__init__(self.core))
self.update_button.clicked.connect(self.update_list)
self.layout.addWidget(self.update_button)
self.widgets = {}
games = sorted(core.get_installed_list(), key=lambda game: game.title)
games = sorted(self.core.get_installed_list(), key=lambda game: game.title)
if games:
for i in games:
widget = GameWidget(i, core)
widget = GameWidget(i, self.core)
widget.signal.connect(self.remove_game)
self.widgets[i.app_name] = widget
self.layout.addWidget(widget)
@ -46,15 +51,13 @@ class GameListInstalled(QScrollArea):
self.widget.setLayout(self.layout)
self.setWidget(self.widget)
# self.setLayout(self.layout)
def remove_game(self, app_name: str):
logger.info(f"Uninstall {app_name}")
legendaryUtils.uninstall(app_name=app_name, core=self.core)
self.widgets[app_name].setVisible(False)
self.layout.removeWidget(self.widgets[app_name])
self.widgets[app_name].deleteLater()
self.widgets.pop(app_name)
self.__init__(self.core)
def import_games_prepare(self):
# Automatically import from windows
@ -70,9 +73,11 @@ class GameListInstalled(QScrollArea):
possible_wineprefixes = [os.path.expanduser("~/.wine/"), os.path.expanduser("~/Games/epic-games-store/")]
for wine_prefix in possible_wineprefixes:
imported += self.auto_import_games(f"{wine_prefix}drive_c/Program Files/Epic Games/")
QMessageBox.information(self, "Imported Games", f"Successfully imported {imported} Games")
logger.info("Restarting app to import games")
if imported > 0:
QMessageBox.information(self, "Imported Games", f"Successfully imported {imported} Games")
logger.info("Restarting app to import games")
else:
QMessageBox.information(self, "Imported Games", "No Games were found")
def auto_import_games(self, game_path):
imported = 0
@ -95,6 +100,12 @@ class GameListInstalled(QScrollArea):
imported += 1
return imported
def update(self):
self.__init__(self.core)
def update_list(self):
# self.__init__(self.core)
print("update")
self.core = LegendaryCore()
# self.core.login()
del self.widget
self.setWidget(QWidget())
self.init_ui()
self.update()

View file

@ -1,13 +1,14 @@
from PyQt5.QtCore import Qt
from PyQt5.QtCore import Qt, pyqtSignal
from PyQt5.QtWidgets import *
from Rare.Tabs.GamesUninstalled.GameWidget import UninstalledGameWidget
from legendary.core import LegendaryCore
from Rare.Tabs.GamesUninstalled.GameWidget import UninstalledGameWidget
from Rare.utils.Dialogs.ImportDialog import ImportDialog
class GameListUninstalled(QScrollArea):
finished = pyqtSignal()
def __init__(self, core: LegendaryCore):
super(GameListUninstalled, self).__init__()
self.core = core
@ -33,6 +34,7 @@ class GameListUninstalled(QScrollArea):
games = sorted(games, key=lambda x: x.app_title)
for game in games:
game_widget = UninstalledGameWidget(game)
game_widget.finished.connect(self.installed)
self.layout.addWidget(game_widget)
self.widgets_uninstalled.append(game_widget)
@ -49,4 +51,8 @@ class GameListUninstalled(QScrollArea):
def import_game(self):
import_dia = ImportDialog(self.core)
import_dia.import_dialog()
import_dia.import_dialog()
def installed(self):
print("xy")
self.finished.emit()

View file

@ -33,6 +33,8 @@ class Thread(QThread):
class UninstalledGameWidget(QWidget):
finished = pyqtSignal()
def __init__(self, game):
super(UninstalledGameWidget, self).__init__()
self.title = game.app_title
@ -45,8 +47,6 @@ class UninstalledGameWidget(QWidget):
pixmap = pixmap.scaled(120, 160)
self.image = QLabel()
self.image.setPixmap(pixmap)
else:
print(os.listdir(IMAGE_DIR) / game.app_name)
self.child_layout = QVBoxLayout()
@ -54,6 +54,7 @@ class UninstalledGameWidget(QWidget):
self.app_name_label = QLabel(f"App Name: {self.app_name}")
self.version_label = QLabel(f"Version: {self.version}")
self.install_button = QPushButton("Install")
self.install_button.setFixedWidth(120)
self.install_button.clicked.connect(self.install)
self.child_layout.addWidget(self.title_label)
@ -76,6 +77,8 @@ class UninstalledGameWidget(QWidget):
path = data.get("install_path")
logger.info(f"install {self.app_name} in path {path}")
# TODO
self.install_button.setDisabled(True)
self.install_button.setText("installing")
self.proc = QProcess()
self.proc.start("legendary", ["-y", "install", self.app_name, "--base-path", path])
self.proc.finished.connect(self.download_finished)
@ -85,5 +88,6 @@ class UninstalledGameWidget(QWidget):
def download_finished(self, code):
self.setVisible(False)
logger.info(f"Download finished code: {code}")
logger.info(f"Download finished. code: {code}")
QMessageBox.information(self, "Download finished", "Download has finished")
self.finished.emit()

View file

@ -1,148 +0,0 @@
import os
from logging import getLogger
from PyQt5.QtGui import QIntValidator
from PyQt5.QtWidgets import QTableWidget, QTableWidgetItem, QFormLayout, QGroupBox, QLineEdit, QPushButton, \
QLabel
from Rare.utils import legendaryConfig
class SettingsForm(QGroupBox):
config: dict
def __init__(self):
self.logger = getLogger(f"Legendary Settings")
config: dict
super(SettingsForm, self).__init__('Legendary Settings')
self.config = legendaryConfig.get_config()
if not self.config.get("Legendary"):
self.config["Legendary"] = {}
if not self.config["Legendary"].get("wine_executable"):
self.config["Legendary"]["wine_executable"] = ""
if not self.config["Legendary"].get("wine_prefix"):
self.config["Legendary"]["wine_prefix"] = ""
if not self.config["Legendary"].get("locale"):
self.config["Legendary"]["locale"] = ""
if not self.config["Legendary"].get("max_workers"):
self.config["Legendary"]["max_workers"] = ""
if not self.config["Legendary"].get("install_dir"):
self.config["Legendary"]["install_dir"] = ""
if not self.config["Legendary"].get("max_memory"):
self.config["Legendary"]["max_memory"] = ""
env_vars = self.config.get(f"default.env")
if env_vars:
self.table = QTableWidget(len(env_vars), 2)
for i, label in enumerate(env_vars):
self.table.setItem(i, 0, QTableWidgetItem(label))
self.table.setItem(i, 1, QTableWidgetItem(env_vars[label]))
else:
self.table = QTableWidget(0, 2)
self.table.setHorizontalHeaderLabels(["Variable", "Value"])
self.form = QFormLayout()
self.lgd_conf_wine_prefix = QLineEdit(self.config["Legendary"]["wine_prefix"])
self.lgd_conf_wine_prefix.setPlaceholderText("Default")
self.lgd_conf_wine_exec = QLineEdit(self.config["Legendary"]["wine_executable"])
self.lgd_conf_wine_exec.setPlaceholderText("Default")
self.lgd_conf_locale = QLineEdit(self.config["Legendary"]["locale"])
self.lgd_conf_locale.setPlaceholderText("Default")
only_int = QIntValidator()
self.max_workers = QLineEdit(self.config["Legendary"]["max_workers"])
self.max_workers.setPlaceholderText("Default")
self.max_workers.setValidator(only_int)
self.default_install_dir = QLineEdit(self.config["Legendary"]["install_dir"])
self.default_install_dir.setPlaceholderText("Default")
self.max_mem = QLineEdit(self.config["Legendary"]["max_memory"])
self.max_mem.setPlaceholderText("Default")
self.max_mem.setValidator(only_int)
self.add_button = QPushButton("Add Environment Variable")
self.delete_env_var = QPushButton("Delete selected Variable")
self.delete_env_var.clicked.connect(self.delete_var)
self.add_button.clicked.connect(self.add_variable)
if os.name != "nt":
self.form.addRow(QLabel("Default Wineprefix"), self.lgd_conf_wine_prefix)
self.form.addRow(QLabel("Wine executable"), self.lgd_conf_wine_exec)
self.form.addRow(QLabel("Max Workers"), self.max_workers)
self.form.addRow(QLabel("Default install dir"), self.default_install_dir)
self.form.addRow(QLabel("Max memory"), self.max_mem)
self.form.addRow(QLabel("Environment Variables"), self.table)
self.form.addRow(QLabel("Add Variable"), self.add_button)
self.form.addRow(QLabel("Delete Variable"), self.delete_env_var)
self.form.addRow(QLabel("Locale"), self.lgd_conf_locale)
self.submit_button = QPushButton("Update")
self.submit_button.clicked.connect(self.update_legendary_settings)
self.form.addRow(self.submit_button)
self.setLayout(self.form)
def add_variable(self):
print("add row")
self.table.insertRow(self.table.rowCount())
self.table.setItem(self.table.rowCount(), 0, QTableWidgetItem(""))
self.table.setItem(self.table.rowCount(), 1, QTableWidgetItem(""))
def delete_var(self):
self.table.removeRow(self.table.currentRow())
def update_legendary_settings(self):
self.logger.info("Updating Game Settings")
# Wine exec
if not self.config.get("Legendary"):
self.config["Legendary"] = {}
if self.lgd_conf_wine_exec.text() != "":
self.config["Legendary"]["wine_executable"] = self.lgd_conf_wine_exec.text()
elif "wine_executable" in self.config["Legendary"]:
self.config["Legendary"].pop("wine_executable")
# Wineprefix
if self.lgd_conf_wine_prefix.text() != '':
self.config["Legendary"]["wine_prefix"] = self.lgd_conf_wine_prefix.text()
elif "wine_prefix" in self.config["Legendary"]:
self.config["Legendary"].pop("wine_prefix")
# Locale
if self.lgd_conf_locale.text() != "":
self.config["Legendary"]["locale"] = self.lgd_conf_locale.text()
elif "locale" in self.config["Legendary"]:
self.config["Legendary"].pop("locale")
# Max Workers
if self.max_workers.text() != "":
self.config["Legendary"]["max_workers"] = self.max_workers.text()
elif "max_workers" in self.config["Legendary"]:
self.config["Legendary"].pop("max_workers")
# default installdir
if self.default_install_dir.text() != "":
self.config["Legendary"]["install_dir"] = self.default_install_dir.text()
elif "install_dir" in self.config["Legendary"]:
self.config["Legendary"].pop("install_dir")
# max mem
if self.max_mem.text() != "":
self.config["Legendary"]["max_memory"] = self.max_mem.text()
elif "max_memory" in self.config["Legendary"]:
self.config["Legendary"].pop("max_memory")
# Env vars
if self.table.rowCount() > 0:
self.config[f"default.env"] = {}
for row in range(self.table.rowCount()):
self.config[f"default.env"][self.table.item(row, 0).text()] = self.table.item(row, 1).text()
elif "default.env" in self.config:
self.config.pop("default.env")
if self.config.get("Legendary") == {}:
self.config.pop("Legendary")
legendaryConfig.set_config(self.config)
print(self.config)

View file

@ -41,9 +41,7 @@ class RareSettingsForm(QGroupBox):
self.parent().parent().parent().setStyleSheet("")
config["Rare"]["theme"] = "light"
config["Rare"]["IMAGE_DIR"] = self.image_dir_edit.text()
print(config["Rare"]["IMAGE_DIR"])
if self.image_dir_edit.text() != RareConfig.IMAGE_DIR:
print("Move")
shutil.move(RareConfig.IMAGE_DIR, self.image_dir_edit.text())
RareConfig.set_config(config)

View file

@ -3,7 +3,7 @@ from logging import getLogger
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QVBoxLayout, QLabel, QPushButton, QScrollArea
from Rare.Tabs.Settings.Rare import RareSettingsForm
from Rare.Tabs.Settings.RareSettingsForm import RareSettingsForm
from Rare.SettingsForm import SettingsForm
from Rare.utils.constants import default_settings, legendary_settings
from Rare.utils.legendaryUtils import get_name

View file

@ -11,13 +11,13 @@ rare_config.read(config_path + "config.ini")
if not os.path.exists(config_path):
os.makedirs(config_path)
rare_config["Rare"] = {
"IMAGE_DIR": os.path.expanduser("~/.rare/images"),
"IMAGE_DIR": os.path.expanduser("~/.cache/images"),
"theme": "dark"
}
rare_config.write(open(config_path + "config.ini", "w"))
elif not rare_config.sections():
rare_config["Rare"] = {
"IMAGE_DIR": os.path.expanduser("~/.rare/images"),
"IMAGE_DIR": os.path.expanduser("~/.cache/images"),
"theme": "dark"
}
rare_config.write(open(config_path + "config.ini", "w"))
@ -31,5 +31,6 @@ def set_config(new_config: {}):
rare_config.__dict__["_sections"] = new_config
rare_config.write(open(config_path + "config.ini", "w"))
IMAGE_DIR = rare_config["Rare"]["IMAGE_DIR"]
THEME = rare_config["Rare"]["theme"]

View file

@ -123,9 +123,22 @@ def get_name():
return core.lgd.userdata["displayName"]
def uninstall(app_name: str, lgd_core):
lgd_core.uninstall_game(core.get_installed_game(app_name))
# logger.info("Uninstalling " + app_name)
def uninstall(app_name: str, core):
igame = core.get_installed_game(app_name)
try:
# Remove DLC first so directory is empty when game uninstall runs
dlcs = core.get_dlc_for_game(app_name)
for dlc in dlcs:
if (idlc := core.get_installed_game(dlc.app_name)) is not None:
logger.info(f'Uninstalling DLC "{dlc.app_name}"...')
core.uninstall_game(idlc, delete_files=True)
logger.info(f'Removing "{igame.title}" from "{igame.install_path}"...')
core.uninstall_game(igame, delete_files=True, delete_root_directory=True)
logger.info('Game has been uninstalled.')
except Exception as e:
logger.warning(f'Removing game failed: {e!r}, please remove {igame.install_path} manually.')
def import_game(core: LegendaryCore, app_name: str, path: str):