1
0
Fork 0
mirror of synced 2024-06-26 10:11:19 +12:00

Add Info for uninstalled Games

This commit is contained in:
Dummerle 2021-05-11 17:29:35 +02:00
parent 6a3166ceff
commit 61fe881c1a
7 changed files with 123 additions and 41 deletions

View file

@ -5,6 +5,7 @@ from PyQt5.QtWidgets import QMenu, QTabWidget, QWidget, QWidgetAction
from qtawesome import icon
from custom_legendary.core import LegendaryCore
from rare.components.dialogs.install_dialog import InstallDialog
from rare.components.tab_utils import TabBar, TabButtonWidget
from rare.components.tabs.account import MiniWidget
from rare.components.tabs.cloud_saves import SyncSaves
@ -66,11 +67,14 @@ class TabWidget(QTabWidget):
if not offline:
# Download finished
self.downloadTab.finished.connect(self.dl_finished)
# start download
self.games_tab.default_widget.game_list.install_game.connect(self.start_download)
# show uninstalled info
self.games_tab.default_widget.game_list.show_uninstalled_info.connect(self.games_tab.show_uninstalled)
# install dlc
self.games_tab.game_info.dlc_tab.install_dlc.connect(self.start_download)
# install game
self.games_tab.uninstalled_info_widget.install_button.clicked.connect(self.install_game)
# repair game
self.games_tab.game_info.info.verify_game.connect(lambda app_name: self.downloadTab.install_game(
InstallOptions(app_name, core.get_installed_game(app_name).install_path, repair=True)))
@ -84,6 +88,20 @@ class TabWidget(QTabWidget):
self.tabBarClicked.connect(lambda x: self.games_tab.layout.setCurrentIndex(0) if x == 0 else None)
self.setIconSize(QSize(25, 25))
def install_game(self):
app_name = self.games_tab.uninstalled_info_widget.game.app_name
infos = InstallDialog(app_name, self.core).get_information()
if infos != 0:
path, max_workers, force, ignore_free_space = infos
options = InstallOptions(app_name=app_name, max_workers=max_workers, path=path, force=force,
ignore_free_space=ignore_free_space)
self.start_download(options)
def start_download(self, options):
downloads = len(self.downloadTab.dl_queue) + len(self.downloadTab.update_widgets.keys()) + 1
self.setTabText(1, "Downloads" + ((" (" + str(downloads) + ")") if downloads != 0 else ""))
self.downloadTab.install_game(options)
# Sync game and delete dc rpc
def game_finished(self, app_name):
self.delete_presence.emit()
@ -97,11 +115,6 @@ class TabWidget(QTabWidget):
downloads = len(self.downloadTab.dl_queue) + len(self.downloadTab.update_widgets.keys())
self.setTabText(1, "Downloads" + ((" (" + str(downloads) + ")") if downloads != 0 else ""))
def start_download(self, options):
downloads = len(self.downloadTab.dl_queue) + len(self.downloadTab.update_widgets.keys()) + 1
self.setTabText(1, "Downloads" + ((" (" + str(downloads) + ")") if downloads != 0 else ""))
self.downloadTab.install_game(options)
def resizeEvent(self, event):
self.tabBar().setMinimumWidth(self.width())
super(TabWidget, self).resizeEvent(event)

View file

@ -1,4 +1,8 @@
from PyQt5.QtCore import pyqtSignal
import os
import json
from PyQt5.QtCore import pyqtSignal, QSettings
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QPushButton, QLabel
from custom_legendary.core import LegendaryCore
@ -9,16 +13,29 @@ class UninstalledInfo(QWidget):
game: Game
install_game = pyqtSignal(str)
grade_table = json.load(open(os.path.expanduser("~/.cache/rare/game_list.json")))
def __init__(self, core: LegendaryCore):
super(UninstalledInfo, self).__init__()
self.layout = QVBoxLayout()
self.ratings = {"platinum": self.tr("Platimum"),
"gold": self.tr("Gold"),
"silver": self.tr("Silver"),
"bronze": self.tr("Bronze"),
"fail": self.tr("Could not get grade from ProtonDB"),
"pending": "Not enough reports"}
self.core = core
self.settings = QSettings()
self.top_layout = QHBoxLayout()
left_layout = QVBoxLayout()
self.image = QLabel()
self.top_layout.addWidget(self.image)
left_layout.addWidget(self.image)
left_layout.addStretch(1)
self.top_layout.addLayout(left_layout)
self.right_layout = QVBoxLayout()
self.back = QPushButton(self.tr("Back"))
@ -36,8 +53,10 @@ class UninstalledInfo(QWidget):
self.install_button = QPushButton(self.tr("Install"))
self.right_layout.addWidget(self.install_button)
self.right_layout.addStretch(1)
self.top_layout.addLayout(self.right_layout)
self.top_layout.addStretch(1)
self.layout.addLayout(self.top_layout)
self.setLayout(self.layout)
@ -48,4 +67,22 @@ class UninstalledInfo(QWidget):
self.title.setText(f"<h2>{self.game.app_title}</h2>")
self.app_name.setText(app_name)
# TODO get grade (Pull request)
IMAGE_DIR = self.settings.value("img_dir", os.path.expanduser("~/.cache/rare/images"), str)
if os.path.exists(f"{IMAGE_DIR}/{self.game.app_name}/FinalArt.png"):
pixmap = QPixmap(f"{IMAGE_DIR}/{self.game.app_name}/FinalArt.png")
elif os.path.exists(f"{IMAGE_DIR}/{self.game.app_name}/DieselGameBoxTall.png"):
pixmap = QPixmap(f"{IMAGE_DIR}/{self.game.app_name}/DieselGameBoxTall.png")
elif os.path.exists(f"{IMAGE_DIR}/{self.game.app_name}/DieselGameBoxLogo.png"):
pixmap = QPixmap(f"{IMAGE_DIR}/{self.game.app_name}/DieselGameBoxLogo.png")
else:
# logger.warning(f"No Image found: {self.game.title}")
pixmap = None
if pixmap:
w = 200
pixmap = pixmap.scaled(w, int(w * 4 / 3))
self.image.setPixmap(pixmap)
rating = self.grade_table[app_name]["grade"]
self.rating.setText(self.ratings[rating])

View file

@ -140,10 +140,10 @@ class GameList(QStackedWidget):
pixmap = QPixmap(f"{IMAGE_DIR}/{igame.app_name}/UninstalledArt.png")
icon_widget = IconWidgetUninstalled(igame, self.core, pixmap)
icon_widget.install_game.connect(self.install)
icon_widget.show_uninstalled_info.connect(self.install)
list_widget = ListWidgetUninstalled(self.core, igame, pixmap)
list_widget.install_game.connect(self.install)
list_widget.show_uninstalled_info.connect(self.install)
self.icon_layout.addWidget(icon_widget)
self.list_layout.addWidget(list_widget)
@ -190,13 +190,15 @@ class GameList(QStackedWidget):
return True, pid
return False, 0
def install(self, options: InstallOptions):
icon_widget, list_widget = self.widgets[options.app_name]
icon_widget.mousePressEvent = lambda e: None
icon_widget.installing = True
list_widget.install_button.setDisabled(True)
list_widget.installing = True
self.install_game.emit(options)
def install(self, app_name):
self.show_uninstalled_info.emit(app_name)
# icon_widget, list_widget = self.widgets[options.app_name]
# icon_widget.mousePressEvent = lambda e: None
# icon_widget.installing = True
# list_widget.install_button.setDisabled(True)
# list_widget.installing = True
# self.install_game.emit(options)
def finished(self, app_name):
self.running_games.remove(app_name)

View file

@ -48,13 +48,18 @@ class BaseInstalledWidget(QGroupBox):
self.addAction(self.create_desktop)
if os.name == "posix":
if os.path.exists(os.path.expanduser(f"~/.local/share/applications/{self.igame.title}.desktop")):
self.create_start_menu = QAction(self.tr("Remove start menu link"))
else:
self.create_start_menu = QAction(self.tr("Create start menu link"))
start_menu_file = os.path.expanduser(f"~/.local/share/applications/{self.igame.title}.desktop")
elif os.name == "nt":
start_menu_file = os.path.expandvars("%appdata%/Microsoft/Windows/Start Menu")
else:
start_menu_file = ""
if os.path.exists(start_menu_file):
self.create_start_menu = QAction(self.tr("Remove start menu link"))
else:
self.create_start_menu = QAction(self.tr("Create start menu link"))
self.create_start_menu.triggered.connect(lambda: self.create_desktop_link("start_menu"))
self.addAction(self.create_start_menu)
self.create_start_menu.triggered.connect(lambda: self.create_desktop_link("start_menu"))
self.addAction(self.create_start_menu)
uninstall = QAction(self.tr("Uninstall"), self)
uninstall.triggered.connect(self.uninstall)

View file

@ -10,7 +10,7 @@ logger = getLogger("Uninstalled")
class BaseUninstalledWidget(QGroupBox):
install_game = pyqtSignal(InstallOptions)
show_uninstalled_info = pyqtSignal(str)
def __init__(self, game, core, pixmap):
super(BaseUninstalledWidget, self).__init__()
@ -22,9 +22,12 @@ class BaseUninstalledWidget(QGroupBox):
self.setContentsMargins(0, 0, 0, 0)
def install(self):
self.show_uninstalled_info.emit(self.game.app_name)
def installl(self):
infos = InstallDialog(self.game.app_name, self.core).get_information()
if infos != 0:
path, max_workers, force, ignore_free_space = infos
self.install_game.emit(
self.show_uninstalled_info.emit(
InstallOptions(app_name=self.game.app_name, max_workers=max_workers, path=path, force=force,
ignore_free_space=ignore_free_space))

View file

@ -13,7 +13,6 @@ logger = getLogger("Uninstalled")
class IconWidgetUninstalled(BaseUninstalledWidget):
install_game = pyqtSignal(InstallOptions)
def __init__(self, game: Game, core: LegendaryCore, pixmap):
super(IconWidgetUninstalled, self).__init__(game, core, pixmap)
@ -42,7 +41,7 @@ class IconWidgetUninstalled(BaseUninstalledWidget):
def enterEvent(self, e):
if not self.installing:
self.info_label.setText(self.tr("Install Game"))
self.info_label.setText(self.tr("Game Info"))
else:
self.info_label.setText(self.tr("Installation running"))

View file

@ -8,11 +8,13 @@ import requests
from PIL import Image, UnidentifiedImageError
from PyQt5.QtCore import pyqtSignal, QLocale, QSettings
# Windows
if os.name == "nt":
from win32com.client import Dispatch
from rare import lang_path, __version__, style_path
from custom_legendary.core import LegendaryCore
import id
logger = getLogger("Utils")
s = QSettings("Rare", "Rare")
IMAGE_DIR = s.value("img_dir", os.path.expanduser("~/.cache/rare/images"), type=str)
@ -150,10 +152,10 @@ def create_desktop_link(app_name, core: LegendaryCore, type_of_link="desktop"):
os.path.join(QSettings('Rare', 'Rare').value('img_dir', os.path.expanduser('~/.cache/rare/images'), str),
igame.app_name, 'Thumbnail.png')):
icon = os.path.join(QSettings('Rare', 'Rare').value('img_dir', os.path.expanduser('~/.cache/rare/images'), str),
igame.app_name, 'Thumbnail.png')
igame.app_name, 'Thumbnail')
else:
icon = os.path.join(QSettings('Rare', 'Rare').value('img_dir', os.path.expanduser('~/.cache/rare/images'), str),
igame.app_name, 'DieselGameBoxTall.png')
igame.app_name, 'DieselGameBoxTall')
# Linux
if os.name == "posix":
if type_of_link == "desktop":
@ -167,7 +169,7 @@ def create_desktop_link(app_name, core: LegendaryCore, type_of_link="desktop"):
desktop_file.write("[Desktop Entry]\n"
f"Name={igame.title}\n"
f"Type=Application\n"
f"Icon={icon}\n"
f"Icon={icon}.png\n"
f"Exec=rare launch {app_name}\n"
"Terminal=false\n"
"StartupWMClass=rare-game\n"
@ -176,12 +178,33 @@ def create_desktop_link(app_name, core: LegendaryCore, type_of_link="desktop"):
# Windows
elif os.name == "nt":
# Target of shortcut
if type_of_link == "desktop":
path = os.path.expanduser(f"~/Desktop/")
target_folder = os.path.expanduser('~/Desktop/')
elif type_of_link == "start_menu":
logger.info("Startmenu link is not supported on windows")
return
target_folder = os.path.expandvars("%appdata%/Microsoft/Windows/Start Menu")
else:
logger.warning("No valid type of link")
return
with open(path+igame.title+".bat", "w") as desktop_file:
desktop_file.write(f"rare launch {app_name}")
target = os.path.abspath(sys.argv[0])
# Name of link file
linkName = igame.title + '.lnk'
# Path to location of link file
pathLink = os.path.join(target_folder, linkName)
# Add shortcut
shell = Dispatch('WScript.Shell')
shortcut = shell.CreateShortCut(pathLink)
shortcut.Targetpath = target
shortcut.Arguments = f'launch {app_name}'
shortcut.WorkingDirectory = os.getcwd()
# Icon
if not os.path.exists(icon+".ico"):
img = Image.open(icon+".png")
img.save(icon+".ico")
logger.info("Create Icon")
shortcut.IconLocation = os.path.join(icon + ".ico")
shortcut.save()