Skip to content

Commit

Permalink
Merge pull request #407 from loathingKernel/develop
Browse files Browse the repository at this point in the history
RareLauncher: Fix console window wrapping and skip DLC check for launchable addons
  • Loading branch information
loathingKernel committed May 19, 2024
2 parents 50ff2ae + 71348db commit 94c2f76
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 41 deletions.
14 changes: 7 additions & 7 deletions rare/commands/launcher/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@
}


class PreLaunchThread(QRunnable):
class PreLaunch(QRunnable):
class Signals(QObject):
ready_to_launch = pyqtSignal(LaunchArgs)
started_pre_launch_command = pyqtSignal()
pre_launch_command_started = pyqtSignal()
pre_launch_command_finished = pyqtSignal(int) # exit_code
error_occurred = pyqtSignal(str)

def __init__(self, args: InitArgs, rgame: RareGameSlim, sync_action=None):
super(PreLaunchThread, self).__init__()
super(PreLaunch, self).__init__()
self.signals = self.Signals()
self.logger = getLogger(type(self).__name__)
self.args = args
Expand Down Expand Up @@ -76,7 +76,7 @@ def prepare_launch(self, args: InitArgs) -> Optional[LaunchArgs]:
if launch_args.pre_launch_command:
proc = get_configured_process()
proc.setProcessEnvironment(launch_args.environment)
self.signals.started_pre_launch_command.emit()
self.signals.pre_launch_command_started.emit()
pre_launch_command = shlex.split(launch_args.pre_launch_command)
# self.logger.debug("Executing prelaunch command %s, %s", pre_launch_command[0], pre_launch_command[1:])
proc.start(pre_launch_command[0], pre_launch_command[1:])
Expand Down Expand Up @@ -174,13 +174,13 @@ def __init__(self, args: InitArgs):

@pyqtSlot()
def __proc_log_stdout(self):
self.console.log(
self.console.log_stdout(
self.game_process.readAllStandardOutput().data().decode("utf-8", "ignore")
)

@pyqtSlot()
def __proc_log_stderr(self):
self.console.error(
self.console.log_stderr(
self.game_process.readAllStandardError().data().decode("utf-8", "ignore")
)

Expand Down Expand Up @@ -327,7 +327,7 @@ def error_occurred(self, error_str: str):
self.stop()

def start_prepare(self, sync_action=None):
worker = PreLaunchThread(self.args, self.rgame, sync_action)
worker = PreLaunch(self.args, self.rgame, sync_action)
worker.signals.ready_to_launch.connect(self.launch_game)
worker.signals.error_occurred.connect(self.error_occurred)
# worker.signals.started_pre_launch_command(None)
Expand Down
47 changes: 27 additions & 20 deletions rare/commands/launcher/console_dialog.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from typing import Union

from PyQt5.QtCore import QProcessEnvironment, pyqtSignal, QSize, Qt
Expand Down Expand Up @@ -31,8 +32,8 @@ def __init__(self, app_title: str, parent=None):
self.setGeometry(0, 0, 640, 480)
layout = QVBoxLayout()

self.console = ConsoleEdit(self)
layout.addWidget(self.console)
self.console_edit = ConsoleEdit(self)
layout.addWidget(self.console_edit)

button_layout = QHBoxLayout()

Expand All @@ -46,7 +47,7 @@ def __init__(self, app_title: str, parent=None):

self.clear_button = QPushButton(self.tr("Clear console"))
button_layout.addWidget(self.clear_button)
self.clear_button.clicked.connect(self.console.clear)
self.clear_button.clicked.connect(self.console_edit.clear)

button_layout.addItem(QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Fixed))

Expand Down Expand Up @@ -102,7 +103,7 @@ def save(self):
if "." not in file:
file += ".log"
with open(file, "w") as f:
f.write(self.console.toPlainText())
f.write(self.console_edit.toPlainText())
f.close()
self.save_button.setText(self.tr("Saved"))

Expand All @@ -113,15 +114,21 @@ def show_env(self):
self.env_variables.setTable(self.env)
self.env_variables.show()

def log(self, text: str, end: str = "\n"):
self.console.log(text + end)
def log(self, text: str):
self.console_edit.log(f"Rare: {text}")

def error(self, text, end: str = "\n"):
self.console.error(text + end)
def log_stdout(self, text: str):
self.console_edit.log(text)

def error(self, text):
self.console_edit.error(f"Rare: {text}")

def log_stderr(self, text):
self.console_edit.error(text)

def on_process_exit(self, app_title: str, status: Union[int, str]):
self.error(
self.tr("Application \"{}\" finished with \"{}\"\n").format(app_title, status)
self.tr("Application finished with exit code \"{}\"").format(status)
)
self.accept_close = True

Expand Down Expand Up @@ -170,17 +177,6 @@ def __init__(self, parent=None):
font = QFont("Monospace")
font.setStyleHint(QFont.Monospace)
self.setFont(font)
self._cursor_output = self.textCursor()

def log(self, text):
html = f"<p style=\"color:#aaa;white-space:pre\">{text}</p>"
self._cursor_output.insertHtml(html)
self.scroll_to_last_line()

def error(self, text):
html = f"<p style=\"color:#a33;white-space:pre\">{text}</p>"
self._cursor_output.insertHtml(html)
self.scroll_to_last_line()

def scroll_to_last_line(self):
cursor = self.textCursor()
Expand All @@ -189,3 +185,14 @@ def scroll_to_last_line(self):
QTextCursor.Up if cursor.atBlockStart() else QTextCursor.StartOfLine
)
self.setTextCursor(cursor)

def print_to_console(self, text: str, color: str):
html = f"<p style=\"color:{color};white-space:pre\">{text}</p>"
self.appendHtml(html)
self.scroll_to_last_line()

def log(self, text):
self.print_to_console(text, "#aaa")

def error(self, text):
self.print_to_console(text, "#a33")
4 changes: 2 additions & 2 deletions rare/commands/launcher/lgd_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from rare.models.base_game import RareGameSlim

logger = getLogger("Helper")
logger = getLogger("RareLauncherHelper")


class GameArgsError(Exception):
Expand Down Expand Up @@ -156,7 +156,7 @@ def get_launch_args(rgame: RareGameSlim, init_args: InitArgs = None) -> LaunchAr
if not rgame.is_installed:
raise GameArgsError("Game is not installed or has unsupported format")

if rgame.is_dlc:
if rgame.is_dlc and not rgame.is_launchable_addon:
raise GameArgsError("Game is a DLC")
if not os.path.exists(rgame.install_path):
raise GameArgsError("Game path does not exist")
Expand Down
10 changes: 5 additions & 5 deletions rare/ui/components/tabs/games/game_info/details.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def setupUi(self, GameDetails):
self.right_layout.setObjectName("right_layout")
self.details_layout = QtWidgets.QFormLayout()
self.details_layout.setSizeConstraint(QtWidgets.QLayout.SetFixedSize)
self.details_layout.setFieldGrowthPolicy(QtWidgets.QFormLayout.FieldsStayAtSizeHint)
self.details_layout.setFieldGrowthPolicy(QtWidgets.QFormLayout.AllNonFixedFieldsGrow)
self.details_layout.setLabelAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.details_layout.setContentsMargins(6, 6, 6, 6)
self.details_layout.setSpacing(12)
Expand Down Expand Up @@ -329,11 +329,11 @@ def retranslateUi(self, GameDetails):
self.favorites_check.setText(_translate("GameDetails", "Favorites"))
self.backlog_check.setText(_translate("GameDetails", "Backlog"))
self.lbl_dev.setText(_translate("GameDetails", "Developer"))
self.lbl_app_name.setText(_translate("GameDetails", "Application Name"))
self.lbl_app_name.setText(_translate("GameDetails", "Application name"))
self.lbl_version.setText(_translate("GameDetails", "Version"))
self.lbl_grade.setText(_translate("GameDetails", "ProtonDB Grade"))
self.lbl_install_size.setText(_translate("GameDetails", "Installation Size"))
self.lbl_install_path.setText(_translate("GameDetails", "Installation Path"))
self.lbl_grade.setText(_translate("GameDetails", "ProtonDB grade"))
self.lbl_install_size.setText(_translate("GameDetails", "Installation size"))
self.lbl_install_path.setText(_translate("GameDetails", "Installation path"))
self.lbl_platform.setText(_translate("GameDetails", "Platform"))
self.lbl_game_actions.setText(_translate("GameDetails", "Actions"))
self.modify_button.setText(_translate("GameDetails", "Modify"))
Expand Down
10 changes: 5 additions & 5 deletions rare/ui/components/tabs/games/game_info/details.ui
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
<enum>QLayout::SetFixedSize</enum>
</property>
<property name="fieldGrowthPolicy">
<enum>QFormLayout::FieldsStayAtSizeHint</enum>
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<property name="labelAlignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
Expand Down Expand Up @@ -162,7 +162,7 @@
</font>
</property>
<property name="text">
<string>Application Name</string>
<string>Application name</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
Expand Down Expand Up @@ -226,7 +226,7 @@
</font>
</property>
<property name="text">
<string>ProtonDB Grade</string>
<string>ProtonDB grade</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
Expand Down Expand Up @@ -261,7 +261,7 @@
</font>
</property>
<property name="text">
<string>Installation Size</string>
<string>Installation size</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
Expand Down Expand Up @@ -293,7 +293,7 @@
</font>
</property>
<property name="text">
<string>Installation Path</string>
<string>Installation path</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
Expand Down
7 changes: 6 additions & 1 deletion rare/ui/components/tabs/store/details.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def setupUi(self, StoreDetailsWidget):
self.right_layout.setObjectName("right_layout")
self.details_layout = QtWidgets.QFormLayout()
self.details_layout.setSizeConstraint(QtWidgets.QLayout.SetFixedSize)
self.details_layout.setFieldGrowthPolicy(QtWidgets.QFormLayout.FieldsStayAtSizeHint)
self.details_layout.setFieldGrowthPolicy(QtWidgets.QFormLayout.AllNonFixedFieldsGrow)
self.details_layout.setLabelAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.details_layout.setContentsMargins(6, 6, 6, 6)
self.details_layout.setSpacing(12)
Expand Down Expand Up @@ -153,6 +153,11 @@ def setupUi(self, StoreDetailsWidget):
self.actions_layout.addWidget(self.wishlist_button)
self.details_layout.setWidget(7, QtWidgets.QFormLayout.FieldRole, self.actions)
self.price = QtWidgets.QWidget(StoreDetailsWidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.price.sizePolicy().hasHeightForWidth())
self.price.setSizePolicy(sizePolicy)
self.price.setObjectName("price")
self.price_layout = QtWidgets.QHBoxLayout(self.price)
self.price_layout.setSizeConstraint(QtWidgets.QLayout.SetFixedSize)
Expand Down
8 changes: 7 additions & 1 deletion rare/ui/components/tabs/store/details.ui
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<enum>QLayout::SetFixedSize</enum>
</property>
<property name="fieldGrowthPolicy">
<enum>QFormLayout::FieldsStayAtSizeHint</enum>
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<property name="labelAlignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
Expand Down Expand Up @@ -310,6 +310,12 @@
</item>
<item row="4" column="1">
<widget class="QWidget" name="price" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QHBoxLayout" name="price_layout">
<property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum>
Expand Down

0 comments on commit 94c2f76

Please sign in to comment.