2024-04-04 06:42:44 +00:00
|
|
|
// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team
|
2024-07-30 11:42:36 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0+
|
2021-12-13 12:12:54 +00:00
|
|
|
|
|
|
|
#include "BIOSSettingsWidget.h"
|
2022-06-04 05:53:31 +00:00
|
|
|
#include "QtHost.h"
|
2021-12-13 12:12:54 +00:00
|
|
|
#include "QtUtils.h"
|
|
|
|
#include "SettingWidgetBinder.h"
|
2023-10-14 08:45:09 +00:00
|
|
|
#include "SettingsWindow.h"
|
2021-12-13 12:12:54 +00:00
|
|
|
|
2024-04-04 06:42:44 +00:00
|
|
|
#include "pcsx2/Host.h"
|
|
|
|
#include "pcsx2/ps2/BiosTools.h"
|
|
|
|
|
|
|
|
#include "common/FileSystem.h"
|
|
|
|
|
|
|
|
#include <QtGui/QIcon>
|
|
|
|
#include <QtWidgets/QFileDialog>
|
|
|
|
#include <algorithm>
|
|
|
|
|
2023-10-14 08:45:09 +00:00
|
|
|
BIOSSettingsWidget::BIOSSettingsWidget(SettingsWindow* dialog, QWidget* parent)
|
2021-12-13 12:12:54 +00:00
|
|
|
: QWidget(parent)
|
2023-06-13 12:43:11 +00:00
|
|
|
, m_dialog(dialog)
|
2021-12-13 12:12:54 +00:00
|
|
|
{
|
2022-02-15 14:29:18 +00:00
|
|
|
SettingsInterface* sif = dialog->getSettingsInterface();
|
|
|
|
|
2021-12-13 12:12:54 +00:00
|
|
|
m_ui.setupUi(this);
|
|
|
|
|
2022-02-15 14:29:18 +00:00
|
|
|
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.fastBoot, "EmuCore", "EnableFastBoot", true);
|
2023-06-13 12:43:11 +00:00
|
|
|
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.fastBootFastForward, "EmuCore", "EnableFastBootFastForward", false);
|
2022-06-14 10:05:11 +00:00
|
|
|
SettingWidgetBinder::BindWidgetToFolderSetting(sif, m_ui.searchDirectory, m_ui.browseSearchDirectory, m_ui.openSearchDirectory,
|
2022-08-05 12:44:01 +00:00
|
|
|
m_ui.resetSearchDirectory, "Folders", "Bios", Path::Combine(EmuFolders::DataRoot, "bios"));
|
2021-12-13 12:12:54 +00:00
|
|
|
|
2022-07-28 21:20:31 +00:00
|
|
|
dialog->registerWidgetHelp(m_ui.fastBoot, tr("Fast Boot"), tr("Checked"),
|
2021-12-13 12:12:54 +00:00
|
|
|
tr("Patches the BIOS to skip the console's boot animation."));
|
|
|
|
|
2023-06-17 09:51:35 +00:00
|
|
|
dialog->registerWidgetHelp(m_ui.fastBootFastForward, tr("Fast Forward Boot"), tr("Unchecked"),
|
2023-06-13 12:43:11 +00:00
|
|
|
tr("Removes emulation speed throttle until the game starts to reduce startup time."));
|
|
|
|
|
2021-12-13 12:12:54 +00:00
|
|
|
refreshList();
|
|
|
|
|
2022-06-14 10:05:11 +00:00
|
|
|
connect(m_ui.searchDirectory, &QLineEdit::textChanged, this, &BIOSSettingsWidget::refreshList);
|
2021-12-13 12:12:54 +00:00
|
|
|
connect(m_ui.refresh, &QPushButton::clicked, this, &BIOSSettingsWidget::refreshList);
|
|
|
|
connect(m_ui.fileList, &QTreeWidget::currentItemChanged, this, &BIOSSettingsWidget::listItemChanged);
|
2024-04-12 12:22:58 +00:00
|
|
|
connect(m_ui.fastBoot, &QCheckBox::checkStateChanged, this, &BIOSSettingsWidget::fastBootChanged);
|
2021-12-13 12:12:54 +00:00
|
|
|
}
|
|
|
|
|
2024-04-04 06:42:44 +00:00
|
|
|
BIOSSettingsWidget::~BIOSSettingsWidget() = default;
|
2021-12-13 12:12:54 +00:00
|
|
|
|
|
|
|
void BIOSSettingsWidget::refreshList()
|
|
|
|
{
|
2024-04-04 06:42:44 +00:00
|
|
|
const std::string search_dir = m_ui.searchDirectory->text().toStdString();
|
|
|
|
populateList(m_ui.fileList, search_dir);
|
2021-12-13 12:12:54 +00:00
|
|
|
}
|
|
|
|
|
2024-04-04 06:42:44 +00:00
|
|
|
void BIOSSettingsWidget::populateList(QTreeWidget* list, const std::string& directory)
|
2023-06-23 13:18:10 +00:00
|
|
|
{
|
2024-04-04 06:42:44 +00:00
|
|
|
const std::string selected_bios = Host::GetBaseStringSettingValue("Filenames", "BIOS");
|
|
|
|
const QString res_path = QtHost::GetResourcesBasePath();
|
2023-06-23 13:18:10 +00:00
|
|
|
|
2024-04-04 06:42:44 +00:00
|
|
|
QSignalBlocker blocker(list);
|
|
|
|
list->clear();
|
|
|
|
list->setEnabled(false);
|
|
|
|
qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
|
|
|
|
|
|
|
|
FileSystem::FindResultsArray files;
|
|
|
|
FileSystem::FindFiles(directory.c_str(), "*", FILESYSTEM_FIND_FILES | FILESYSTEM_FIND_HIDDEN_FILES, &files);
|
|
|
|
|
|
|
|
u32 bios_version, bios_region;
|
|
|
|
std::string bios_description, bios_zone;
|
2021-12-13 12:12:54 +00:00
|
|
|
|
2024-04-04 06:42:44 +00:00
|
|
|
for (const FILESYSTEM_FIND_DATA& fd : files)
|
2021-12-13 12:12:54 +00:00
|
|
|
{
|
2024-04-04 06:42:44 +00:00
|
|
|
if (!IsBIOS(fd.FileName.c_str(), bios_version, bios_description, bios_region, bios_zone))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const std::string_view bios_name = Path::GetFileName(fd.FileName);
|
|
|
|
|
2021-12-13 12:12:54 +00:00
|
|
|
QTreeWidgetItem* item = new QTreeWidgetItem();
|
2024-04-04 06:42:44 +00:00
|
|
|
item->setText(0, QtUtils::StringViewToQString(bios_name));
|
|
|
|
item->setText(1, QString::fromStdString(bios_description));
|
2021-12-13 12:12:54 +00:00
|
|
|
|
2024-04-04 06:42:44 +00:00
|
|
|
switch (bios_region)
|
2021-12-13 12:12:54 +00:00
|
|
|
{
|
2022-11-22 15:39:44 +00:00
|
|
|
case 0: // Japan
|
2022-06-04 05:53:31 +00:00
|
|
|
item->setIcon(0, QIcon(QStringLiteral("%1/icons/flags/NTSC-J.png").arg(res_path)));
|
2021-12-13 12:12:54 +00:00
|
|
|
break;
|
|
|
|
|
2022-11-22 15:39:44 +00:00
|
|
|
case 1: // USA
|
2022-06-04 05:53:31 +00:00
|
|
|
item->setIcon(0, QIcon(QStringLiteral("%1/icons/flags/NTSC-U.png").arg(res_path)));
|
2021-12-13 12:12:54 +00:00
|
|
|
break;
|
|
|
|
|
2022-11-22 15:39:44 +00:00
|
|
|
case 2: // Europe
|
2022-06-04 05:53:31 +00:00
|
|
|
item->setIcon(0, QIcon(QStringLiteral("%1/icons/flags/PAL-E.png").arg(res_path)));
|
2021-12-13 12:12:54 +00:00
|
|
|
break;
|
|
|
|
|
2022-11-22 15:39:44 +00:00
|
|
|
case 3: // Oceania
|
|
|
|
item->setIcon(0, QIcon(QStringLiteral("%1/icons/flags/PAL-A.png").arg(res_path)));
|
2022-02-10 20:02:55 +00:00
|
|
|
break;
|
|
|
|
|
2022-11-22 15:39:44 +00:00
|
|
|
case 4: // Asia
|
2022-06-04 05:53:31 +00:00
|
|
|
item->setIcon(0, QIcon(QStringLiteral("%1/icons/flags/NTSC-HK.png").arg(res_path)));
|
2022-02-14 18:39:24 +00:00
|
|
|
break;
|
|
|
|
|
2022-11-22 15:39:44 +00:00
|
|
|
case 5: // Russia
|
|
|
|
item->setIcon(0, QIcon(QStringLiteral("%1/icons/flags/PAL-R.png").arg(res_path)));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 6: // China
|
|
|
|
item->setIcon(0, QIcon(QStringLiteral("%1/icons/flags/NTSC-C.png").arg(res_path)));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 7: // Mexico, flag is missing
|
|
|
|
|
|
|
|
case 8: // T10K
|
|
|
|
case 9: // Test
|
|
|
|
case 10: // Free
|
2021-12-13 12:12:54 +00:00
|
|
|
default:
|
2022-06-04 05:53:31 +00:00
|
|
|
item->setIcon(0, QIcon(QStringLiteral("%1/icons/flags/NTSC-J.png").arg(res_path)));
|
2021-12-13 12:12:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-06-23 13:18:10 +00:00
|
|
|
list->addTopLevelItem(item);
|
2021-12-13 12:12:54 +00:00
|
|
|
|
2024-04-04 06:42:44 +00:00
|
|
|
if (selected_bios == bios_name)
|
2023-06-23 13:18:10 +00:00
|
|
|
{
|
|
|
|
list->selectionModel()->setCurrentIndex(list->indexFromItem(item), QItemSelectionModel::Select);
|
2021-12-13 12:12:54 +00:00
|
|
|
item->setSelected(true);
|
2023-06-23 13:18:10 +00:00
|
|
|
}
|
2021-12-13 12:12:54 +00:00
|
|
|
}
|
2024-04-04 06:42:44 +00:00
|
|
|
|
|
|
|
list->setEnabled(true);
|
2021-12-13 12:12:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BIOSSettingsWidget::listItemChanged(const QTreeWidgetItem* current, const QTreeWidgetItem* previous)
|
|
|
|
{
|
2022-09-07 07:44:10 +00:00
|
|
|
Host::SetBaseStringSettingValue("Filenames", "BIOS", current->text(0).toUtf8().constData());
|
|
|
|
Host::CommitBaseSettingChanges();
|
2022-10-20 09:08:42 +00:00
|
|
|
|
|
|
|
g_emu_thread->applySettings();
|
2021-12-13 12:12:54 +00:00
|
|
|
}
|
|
|
|
|
2023-06-13 12:43:11 +00:00
|
|
|
void BIOSSettingsWidget::fastBootChanged()
|
|
|
|
{
|
|
|
|
const bool enabled = m_dialog->getEffectiveBoolValue("EmuCore", "EnableFastBoot", true);
|
|
|
|
m_ui.fastBootFastForward->setEnabled(enabled);
|
|
|
|
}
|