gui: add option to boot a game by choosing elf file

This commit is contained in:
Dzmitry Dubrova 2024-08-15 15:24:39 +03:00
parent a0fb47b0ab
commit 318857c19f
3 changed files with 28 additions and 0 deletions

View File

@ -328,6 +328,7 @@ void MainWindow::CreateConnects() {
// Package install. // Package install.
connect(ui->bootInstallPkgAct, &QAction::triggered, this, &MainWindow::InstallPkg); connect(ui->bootInstallPkgAct, &QAction::triggered, this, &MainWindow::InstallPkg);
connect(ui->bootGameAct, &QAction::triggered, this, &MainWindow::BootGame);
connect(ui->gameInstallPathAct, &QAction::triggered, this, &MainWindow::InstallDirectory); connect(ui->gameInstallPathAct, &QAction::triggered, this, &MainWindow::InstallDirectory);
// elf viewer // elf viewer
@ -484,6 +485,27 @@ void MainWindow::InstallPkg() {
} }
} }
void MainWindow::BootGame() {
QFileDialog dialog;
dialog.setFileMode(QFileDialog::ExistingFile);
dialog.setNameFilter(tr("ELF files (*.bin *.elf *.oelf)"));
if (dialog.exec()) {
QStringList fileNames = dialog.selectedFiles();
int nFiles = fileNames.size();
if (nFiles > 1) {
QMessageBox::critical(nullptr, "Game Boot", QString("Only one file can be selected!"));
} else {
std::filesystem::path path(fileNames[0].toStdString());
#ifdef _WIN64
path = std::filesystem::path(fileNames[0].toStdWString());
#endif
Core::Emulator emulator;
emulator.Run(path);
}
}
}
void MainWindow::InstallDragDropPkg(std::filesystem::path file, int pkgNum, int nPkg) { void MainWindow::InstallDragDropPkg(std::filesystem::path file, int pkgNum, int nPkg) {
if (Loader::DetectFileType(file) == Loader::FileTypes::Pkg) { if (Loader::DetectFileType(file) == Loader::FileTypes::Pkg) {
pkg = PKG(); pkg = PKG();

View File

@ -61,6 +61,7 @@ private:
void SetLastIconSizeBullet(); void SetLastIconSizeBullet();
void SetUiIcons(bool isWhite); void SetUiIcons(bool isWhite);
void InstallPkg(); void InstallPkg();
void BootGame();
void AddRecentFiles(QString filePath); void AddRecentFiles(QString filePath);
QIcon RecolorIcon(const QIcon& icon, bool isWhite); QIcon RecolorIcon(const QIcon& icon, bool isWhite);
bool isIconBlack = false; bool isIconBlack = false;

View File

@ -30,6 +30,7 @@ QT_BEGIN_NAMESPACE
class Ui_MainWindow { class Ui_MainWindow {
public: public:
QAction* bootInstallPkgAct; QAction* bootInstallPkgAct;
QAction* bootGameAct;
QAction* addElfFolderAct; QAction* addElfFolderAct;
QAction* exitAct; QAction* exitAct;
QAction* showGameListAct; QAction* showGameListAct;
@ -92,6 +93,8 @@ public:
bootInstallPkgAct = new QAction(MainWindow); bootInstallPkgAct = new QAction(MainWindow);
bootInstallPkgAct->setObjectName("bootInstallPkgAct"); bootInstallPkgAct->setObjectName("bootInstallPkgAct");
bootInstallPkgAct->setIcon(QIcon(":images/file_icon.png")); bootInstallPkgAct->setIcon(QIcon(":images/file_icon.png"));
bootGameAct = new QAction(MainWindow);
bootGameAct->setObjectName("bootGameAct");
addElfFolderAct = new QAction(MainWindow); addElfFolderAct = new QAction(MainWindow);
addElfFolderAct->setObjectName("addElfFolderAct"); addElfFolderAct->setObjectName("addElfFolderAct");
exitAct = new QAction(MainWindow); exitAct = new QAction(MainWindow);
@ -251,6 +254,7 @@ public:
menuBar->addAction(menuView->menuAction()); menuBar->addAction(menuView->menuAction());
menuBar->addAction(menuSettings->menuAction()); menuBar->addAction(menuSettings->menuAction());
menuFile->addAction(bootInstallPkgAct); menuFile->addAction(bootInstallPkgAct);
menuFile->addAction(bootGameAct);
menuFile->addAction(addElfFolderAct); menuFile->addAction(addElfFolderAct);
menuFile->addSeparator(); menuFile->addSeparator();
menuFile->addAction(menuRecent->menuAction()); menuFile->addAction(menuRecent->menuAction());
@ -290,6 +294,7 @@ public:
QCoreApplication::translate("MainWindow", "Open/Add Elf Folder", nullptr)); QCoreApplication::translate("MainWindow", "Open/Add Elf Folder", nullptr));
bootInstallPkgAct->setText( bootInstallPkgAct->setText(
QCoreApplication::translate("MainWindow", "Install Packages (PKG)", nullptr)); QCoreApplication::translate("MainWindow", "Install Packages (PKG)", nullptr));
bootGameAct->setText(QCoreApplication::translate("MainWindow", "Boot Game", nullptr));
#if QT_CONFIG(tooltip) #if QT_CONFIG(tooltip)
bootInstallPkgAct->setToolTip(QCoreApplication::translate( bootInstallPkgAct->setToolTip(QCoreApplication::translate(
"MainWindow", "Install application from a .pkg file", nullptr)); "MainWindow", "Install application from a .pkg file", nullptr));