Include PoC implementation of LegendaryCLI
for the import_game
method
This commit is contained in:
parent
e58d33ee5d
commit
04a76ed2ff
|
@ -1,5 +1,6 @@
|
|||
import json
|
||||
import os
|
||||
from argparse import Namespace
|
||||
from dataclasses import dataclass
|
||||
from enum import IntEnum
|
||||
from logging import getLogger
|
||||
|
@ -10,6 +11,7 @@ from PyQt5.QtCore import Qt, QModelIndex, pyqtSignal, QRunnable, QObject, QThrea
|
|||
from PyQt5.QtGui import QStandardItemModel
|
||||
from PyQt5.QtWidgets import QFileDialog, QGroupBox, QCompleter, QTreeView, QHeaderView, qApp, QMessageBox
|
||||
|
||||
from rare.lgndr.cli import LegendaryCLI
|
||||
from rare.shared import LegendaryCoreSingleton, GlobalSignalsSingleton, ApiResultsSingleton
|
||||
from rare.ui.components.tabs.games.import_sync.import_group import Ui_ImportGroup
|
||||
from rare.utils import legendary_utils
|
||||
|
@ -295,3 +297,18 @@ class ImportGroup(QGroupBox):
|
|||
|
||||
def import_progress(self, progress: int):
|
||||
pass
|
||||
|
||||
def __import_game(self, app_name, path):
|
||||
args = Namespace(
|
||||
app_path=path,
|
||||
app_name=app_name,
|
||||
platform='Windows',
|
||||
disable_check=False,
|
||||
skip_dlcs=False,
|
||||
with_dlcs=False,
|
||||
yes=False,
|
||||
log_dest=self.ui.info_label,
|
||||
)
|
||||
cli = LegendaryCLI()
|
||||
cli.core = LegendaryCoreSingleton()
|
||||
cli.import_game(args)
|
||||
|
|
40
rare/lgndr/cli.py
Normal file
40
rare/lgndr/cli.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
import logging
|
||||
|
||||
import legendary.cli
|
||||
from PyQt5.QtWidgets import QLabel, QMessageBox
|
||||
from legendary.cli import LegendaryCLI as LegendaryCLIReal
|
||||
|
||||
from .core import LegendaryCore
|
||||
|
||||
logger = logging.getLogger('cli')
|
||||
|
||||
|
||||
def get_boolean_choice(message):
|
||||
choice = QMessageBox.question(None, "Import DLCs?", message)
|
||||
return True if choice == QMessageBox.StandardButton.Yes else False
|
||||
|
||||
|
||||
class UILogHandler(logging.Handler):
|
||||
def __init__(self, dest: QLabel):
|
||||
super(UILogHandler, self).__init__()
|
||||
self.widget = dest
|
||||
|
||||
def emit(self, record: logging.LogRecord) -> None:
|
||||
self.widget.setText(record.getMessage())
|
||||
|
||||
|
||||
class LegendaryCLI(LegendaryCLIReal):
|
||||
|
||||
def __init__(self):
|
||||
self.core = None
|
||||
self.logger = logging.getLogger('cli')
|
||||
self.logging_queue = None
|
||||
|
||||
def import_game(self, args):
|
||||
handler = UILogHandler(args.log_dest)
|
||||
logger.addHandler(handler)
|
||||
old_choice = legendary.cli.get_boolean_choice
|
||||
legendary.cli.get_boolean_choice = get_boolean_choice
|
||||
super(LegendaryCLI, self).import_game(args)
|
||||
legendary.cli.get_boolean_choice = old_choice
|
||||
logger.removeHandler(handler)
|
Loading…
Reference in a new issue