Beispiel #1
0
class MainSrc:
    def __init__(self, qtobj, form):
        self.qtobj = qtobj
        self.form = form
        self.client_version = constants.VERSION
        self.log = Log().setup_logging()
        self.database = DatabaseClass(self.log)
        self.progressbar = ProgressBar()
        self.check_program_updates = True
        self.check_reshade_updates = True
        self.create_screenshots_folder = True
        self.show_info_messages = True
        self.use_dark_theme = True
        self.update_shaders = True
        self.need_apply = False
        self.selected_game = None
        self.game_config_form = None
        self.reshade_version = None
        self.program_version = None
        self.local_reshade_path = None
        self.new_version = None
        self.remote_reshade_version = None
        self.remote_reshade_download_url = None

    def start(self):
        self.log.info(f"STARTING {constants.FULL_PROGRAM_NAME}")

        self.progressbar.set_values(messages.checking_database, 15)
        utils.check_database_connection(self)
        utils.check_default_database_tables(self)
        utils.check_default_database_configs(self)

        self.progressbar.set_values(messages.checking_files, 30)
        utils.check_local_files(self)

        self.progressbar.set_values(messages.checking_configs, 45)
        self.set_variables()
        self.register_form_events()

        self.progressbar.set_values(messages.downloading_shaders, 60)
        if not os.path.isdir(constants.SHADERS_SRC_PATH)\
                or (self.update_shaders is not None and self.update_shaders is True):
            utils.download_shaders(self)

        self.progressbar.set_values(messages.checking_reshade_updates, 80)
        utils.check_reshade_updates(self)
        utils.check_reshade_dll_files(self)

        self.progressbar.set_values(messages.checking_program_updates, 90)
        utils.check_program_updates(self)

        self.progressbar.close()
        self.qtobj.main_tabWidget.setCurrentIndex(0)
        self.qtobj.programs_tableWidget.setColumnWidth(2, 130)
        self.qtobj.programs_tableWidget.horizontalHeader().setDefaultAlignment(
            Qt.AlignLeft)
        self.populate_table_widget()
        self.enable_widgets(False)

    def set_variables(self):
        config_sql = ConfigSql(self)
        rs_config = config_sql.get_configs()
        if rs_config is not None and len(rs_config) > 0:
            if not rs_config[0].get("use_dark_theme"):
                self.use_dark_theme = False
                self.qtobj.yes_dark_theme_radioButton.setChecked(False)
                self.qtobj.no_dark_theme_radioButton.setChecked(True)
            else:
                self.use_dark_theme = True
                self.qtobj.yes_dark_theme_radioButton.setChecked(True)
                self.qtobj.no_dark_theme_radioButton.setChecked(False)
            self.set_style_sheet()

            if not rs_config[0].get("check_program_updates"):
                self.check_program_updates = False
                self.qtobj.yes_check_program_updates_radioButton.setChecked(
                    False)
                self.qtobj.no_check_program_updates_radioButton.setChecked(
                    True)
            else:
                self.check_program_updates = True
                self.qtobj.yes_check_program_updates_radioButton.setChecked(
                    True)
                self.qtobj.no_check_program_updates_radioButton.setChecked(
                    False)

            if not rs_config[0].get("show_info_messages"):
                self.show_info_messages = False
                self.qtobj.yes_show_info_messages_radioButton.setChecked(False)
                self.qtobj.no_show_info_messages_radioButton.setChecked(True)
            else:
                self.show_info_messages = True
                self.qtobj.yes_show_info_messages_radioButton.setChecked(True)
                self.qtobj.no_show_info_messages_radioButton.setChecked(False)

            if not rs_config[0].get("check_reshade_updates"):
                self.check_reshade_updates = False
                self.qtobj.yes_check_reshade_updates_radioButton.setChecked(
                    False)
                self.qtobj.no_check_reshade_updates_radioButton.setChecked(
                    True)
            else:
                self.check_reshade_updates = True
                self.qtobj.yes_check_reshade_updates_radioButton.setChecked(
                    True)
                self.qtobj.no_check_reshade_updates_radioButton.setChecked(
                    False)

            if not rs_config[0].get("update_shaders"):
                self.update_shaders = False
                self.qtobj.yes_update_shaders_radioButton.setChecked(False)
                self.qtobj.no_update_shaders_radioButton.setChecked(True)
            else:
                self.update_shaders = True
                self.qtobj.yes_update_shaders_radioButton.setChecked(True)
                self.qtobj.no_update_shaders_radioButton.setChecked(False)

            if not rs_config[0].get("create_screenshots_folder"):
                self.create_screenshots_folder = False
                self.qtobj.yes_screenshots_folder_radioButton.setChecked(False)
                self.qtobj.no_screenshots_folder_radioButton.setChecked(True)
            else:
                self.create_screenshots_folder = True
                self.qtobj.yes_screenshots_folder_radioButton.setChecked(True)
                self.qtobj.no_screenshots_folder_radioButton.setChecked(False)

            if rs_config[0].get("program_version"):
                self.program_version = rs_config[0].get("program_version")

            if rs_config[0].get("reshade_version"):
                self.reshade_version = rs_config[0].get("reshade_version")

    def register_form_events(self):
        # TAB 1 - games
        self.qtobj.add_button.clicked.connect(lambda: events.add_game(self))
        self.qtobj.delete_button.clicked.connect(
            lambda: events.delete_game(self))
        self.qtobj.edit_path_button.clicked.connect(
            lambda: events.edit_game_path(self))
        self.qtobj.edit_preset_button.clicked.connect(
            lambda: events.open_preset_config_file(self))
        self.qtobj.apply_button.clicked.connect(lambda: events.apply_all(self))
        self.qtobj.update_button.clicked.connect(
            lambda: events.update_clicked())
        self.qtobj.programs_tableWidget.clicked.connect(
            self._table_widget_clicked)
        self.qtobj.programs_tableWidget.itemDoubleClicked.connect(
            self._table_widget_double_clicked)

        # TAB 2 - configs
        self.qtobj.yes_dark_theme_radioButton.clicked.connect(
            lambda: events.dark_theme_clicked(self, "YES"))
        self.qtobj.no_dark_theme_radioButton.clicked.connect(
            lambda: events.dark_theme_clicked(self, "NO"))

        self.qtobj.yes_check_program_updates_radioButton.clicked.connect(
            lambda: events.check_program_updates_clicked(self, "YES"))
        self.qtobj.no_check_program_updates_radioButton.clicked.connect(
            lambda: events.check_program_updates_clicked(self, "NO"))

        self.qtobj.yes_show_info_messages_radioButton.clicked.connect(
            lambda: events.show_info_messages_clicked(self, "YES"))
        self.qtobj.no_show_info_messages_radioButton.clicked.connect(
            lambda: events.show_info_messages_clicked(self, "NO"))

        self.qtobj.yes_check_reshade_updates_radioButton.clicked.connect(
            lambda: events.check_reshade_updates_clicked(self, "YES"))
        self.qtobj.no_check_reshade_updates_radioButton.clicked.connect(
            lambda: events.check_reshade_updates_clicked(self, "NO"))

        self.qtobj.yes_update_shaders_radioButton.clicked.connect(
            lambda: events.update_shaders_clicked(self, "YES"))
        self.qtobj.no_update_shaders_radioButton.clicked.connect(
            lambda: events.update_shaders_clicked(self, "NO"))

        self.qtobj.yes_screenshots_folder_radioButton.clicked.connect(
            lambda: events.create_screenshots_folder_clicked(self, "YES"))
        self.qtobj.no_screenshots_folder_radioButton.clicked.connect(
            lambda: events.create_screenshots_folder_clicked(self, "NO"))

        self.qtobj.edit_default_preset_plugin_button.clicked.connect(
            lambda: events.edit_default_preset_plugin_button_clicked(self))
        self.qtobj.reset_all_button.clicked.connect(
            lambda: events.reset_all_button_clicked(self))

        # TAB 3 - about
        self.qtobj.donate_button.clicked.connect(
            lambda: events.donate_clicked())

    def set_style_sheet(self):
        if self.use_dark_theme:
            self.form.setStyleSheet(open(constants.QSS_PATH, "r").read())
        else:
            self.form.setStyleSheet("")

    def populate_table_widget(self):
        self.qtobj.programs_tableWidget.horizontalHeader(
        ).setStretchLastSection(False)
        self.qtobj.programs_tableWidget.setRowCount(0)  # cleanning datagrid
        games_sql = GamesSql(self)
        rs_all_games = games_sql.get_games()
        if rs_all_games is not None and len(rs_all_games) > 0:
            for i in range(len(rs_all_games)):
                self.qtobj.programs_tableWidget.insertRow(i)
                self.qtobj.programs_tableWidget.setItem(
                    i, 0,
                    QtWidgets.QTableWidgetItem(rs_all_games[i].get("name")))
                self.qtobj.programs_tableWidget.setItem(
                    i, 1,
                    QtWidgets.QTableWidgetItem(
                        rs_all_games[i].get("architecture")))
                self.qtobj.programs_tableWidget.setItem(
                    i, 2,
                    QtWidgets.QTableWidgetItem(rs_all_games[i].get("api")))
                self.qtobj.programs_tableWidget.setItem(
                    i, 3,
                    QtWidgets.QTableWidgetItem(rs_all_games[i].get("path")))

        self.qtobj.programs_tableWidget.resizeColumnsToContents()
        highest_column_width = self.qtobj.programs_tableWidget.columnWidth(3)
        if highest_column_width < 600:
            self.qtobj.programs_tableWidget.horizontalHeader(
            ).setStretchLastSection(True)
        else:
            self.qtobj.programs_tableWidget.horizontalHeader(
            ).setSectionResizeMode(3, QtWidgets.QHeaderView.ResizeToContents)

    def enable_form(self, status: bool):
        if not status:
            self.selected_game = None
        self.qtobj.add_button.setEnabled(status)
        for i in range(0, self.qtobj.main_tabWidget.count()):
            self.qtobj.main_tabWidget.setTabEnabled(i, status)
        self.qtobj.main_tabWidget.setCurrentIndex(0)

    def enable_widgets(self, status: bool):
        if not status:
            self.selected_game = None
        self._set_state_apply_button()
        self.qtobj.delete_button.setEnabled(status)
        self.qtobj.edit_path_button.setEnabled(status)
        self.qtobj.edit_preset_button.setEnabled(status)
        self.qtobj.main_tabWidget.setCurrentIndex(0)

    def _set_state_apply_button(self):
        len_games = self.qtobj.programs_tableWidget.rowCount()
        if len_games == 0:
            self.qtobj.apply_button.setEnabled(False)
        else:
            self.qtobj.apply_button.setEnabled(True)

    def _table_widget_clicked(self, item):
        events.programs_tableWidget_clicked(self, item)

    def _table_widget_double_clicked(self):
        if self.selected_game is not None:
            qtutils.show_game_config_form(self, self.selected_game.name,
                                          self.selected_game.architecture)
Beispiel #2
0
class Launcher:
    def __init__(self):
        self.log = Log().setup_logging()
        self.progressbar = ProgressBar()
        self.database = DatabaseClass(self.log)
        self.program_path = os.path.join(utils.get_current_path(),
                                         constants.EXE_PROGRAM_NAME)
        self.new_version = None
        self.new_version_msg = None
        self.client_version = None

    def start(self):
        self.progressbar.set_values(messages.checking_files, 25)
        utils.check_local_files(self)
        if not os.path.isfile(self.program_path):
            self.program_path = os.path.join(constants.PROGRAM_PATH,
                                             constants.EXE_PROGRAM_NAME)
        self.progressbar.set_values(messages.checking_database, 50)
        utils.check_database_connection(self)
        utils.check_default_database_tables(self)
        utils.check_default_database_configs(self)
        self.progressbar.set_values(messages.checking_program_updates, 75)
        self.check_program_updates()
        self.progressbar.close()
        self.call_program()

    def check_program_updates(self):
        config_sql = ConfigSql(self)
        rs_config = config_sql.get_configs()
        if rs_config[0].get("program_version") is None:
            self.client_version = constants.VERSION
        else:
            self.client_version = rs_config[0].get("program_version")
        if rs_config[0].get("check_program_updates"):
            new_version_obj = utils.get_new_program_version(self)
            if new_version_obj.new_version_available:
                self.new_version = new_version_obj.new_version
                self.new_version_msg = new_version_obj.new_version_msg
                self.download_new_program_version()

    def download_new_program_version(self):
        program_url = f"{constants.GITHUB_EXE_PROGRAM_URL}{self.new_version}/{constants.EXE_PROGRAM_NAME}"
        r = requests.get(program_url)
        if r.status_code == 200:
            with open(self.program_path, "wb") as outfile:
                outfile.write(r.content)
            qtutils.show_message_window(
                self.log, "info",
                f"{messages.program_updated}v{self.new_version}")
        else:
            qtutils.show_message_window(self.log, "error",
                                        messages.error_dl_new_version)
            self.log.error(
                f"{messages.error_dl_new_version} {r.status_code} {r}")

    def call_program(self):
        code = None
        try:
            process = subprocess.run(self.program_path,
                                     shell=True,
                                     check=True,
                                     universal_newlines=True)
            code = process.returncode
        except Exception as e:
            if code is None and hasattr(e, "returncode"):
                self.log.error(
                    f"cmd:{self.program_path} - code:{e.returncode} - {e}")
            msg = f"{messages.error_executing_program}{constants.EXE_PROGRAM_NAME}\n"\
                  f"{messages.error_check_installation}"
            qtutils.show_message_window(self.log, "error", msg)