mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-23 06:10:03 -06:00
Add Open ROM inside Archive function
instead of using file extensions
This commit is contained in:
@ -34,7 +34,6 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
#include <QSet>
|
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
@ -1028,6 +1027,9 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
|
|||||||
|
|
||||||
actOpenROM = menu->addAction("Open ROM...");
|
actOpenROM = menu->addAction("Open ROM...");
|
||||||
connect(actOpenROM, &QAction::triggered, this, &MainWindow::onOpenFile);
|
connect(actOpenROM, &QAction::triggered, this, &MainWindow::onOpenFile);
|
||||||
|
|
||||||
|
actOpenROMArchive = menu->addAction("Open ROM inside Archive...");
|
||||||
|
connect(actOpenROMArchive, &QAction::triggered, this, &MainWindow::onOpenFileArchive);
|
||||||
|
|
||||||
recentMenu = menu->addMenu("Open Recent");
|
recentMenu = menu->addMenu("Open Recent");
|
||||||
for(int i = 0; i < 10; ++i)
|
for(int i = 0; i < 10; ++i)
|
||||||
@ -1470,52 +1472,6 @@ void MainWindow::loadROM(QString filename)
|
|||||||
recentFileList.removeAll(filename);
|
recentFileList.removeAll(filename);
|
||||||
recentFileList.prepend(filename);
|
recentFileList.prepend(filename);
|
||||||
updateRecentFilesMenu();
|
updateRecentFilesMenu();
|
||||||
|
|
||||||
|
|
||||||
static const QSet<QString> compressedExts = {"zip", "7z", "rar", "tar", "tar.gz", "tar.xz", "tar.bz2"};
|
|
||||||
if (compressedExts.contains(QFileInfo(filename).completeSuffix()))
|
|
||||||
{
|
|
||||||
printf("Finding list of ROMs...\n");
|
|
||||||
QVector<QString> archiveROMList = Archive::ListArchive(filename.toUtf8().constData());
|
|
||||||
if (archiveROMList.size() > 2)
|
|
||||||
{
|
|
||||||
archiveROMList.removeFirst();
|
|
||||||
QString toLoad = QInputDialog::getItem(this, "melonDS",
|
|
||||||
"The archive was found to have multiple files. Select which ROM you want to load.", archiveROMList.toList(), 0, false);
|
|
||||||
printf("Extracting '%s'\n", toLoad.toUtf8().constData());
|
|
||||||
QVector<QString> extractResult = Archive::ExtractFileFromArchive(filename.toUtf8().constData(), toLoad.toUtf8().constData());
|
|
||||||
if (extractResult[0] != QString("Err"))
|
|
||||||
{
|
|
||||||
filename = extractResult[0];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
QMessageBox::critical(this, "melonDS", QString("There was an error while trying to extract the ROM from the archive: ") + extractResult[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (archiveROMList.size() == 2)
|
|
||||||
{
|
|
||||||
printf("Extracting the only ROM in archive\n");
|
|
||||||
QVector<QString> extractResult = Archive::ExtractFileFromArchive(filename.toUtf8().constData(), nullptr);
|
|
||||||
if (extractResult[0] != QString("Err"))
|
|
||||||
{
|
|
||||||
filename = extractResult[0];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
QMessageBox::critical(this, "melonDS", QString("There was an error while trying to extract the ROM from the archive: ") + extractResult[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ((archiveROMList.size() == 1) && (archiveROMList[0] == QString("OK")))
|
|
||||||
{
|
|
||||||
QMessageBox::warning(this, "melonDS", "The archive is intact, but there are no files inside.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
QMessageBox::critical(this, "melonDS", "The archive could not be read. It may be corrupt or you don't have the permissions.");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: validate the input file!!
|
// TODO: validate the input file!!
|
||||||
// * check that it is a proper ROM
|
// * check that it is a proper ROM
|
||||||
@ -1569,7 +1525,7 @@ void MainWindow::onOpenFile()
|
|||||||
QString filename = QFileDialog::getOpenFileName(this,
|
QString filename = QFileDialog::getOpenFileName(this,
|
||||||
"Open ROM",
|
"Open ROM",
|
||||||
Config::LastROMFolder,
|
Config::LastROMFolder,
|
||||||
"DS ROMs (*.nds *.dsi *.srl *.zip *.7z);;GBA ROMs (*.gba *.zip *.7z);;Other Compressed ROMs (*.zip *.7z *.rar *.tar *.tar.gz *.tar.xz *tar.bz2);;Any file (*.*)");
|
"DS ROMs (*.nds *.dsi *.srl);;GBA ROMs (*.gba *.zip);;Any file (*.*)");
|
||||||
if (filename.isEmpty())
|
if (filename.isEmpty())
|
||||||
{
|
{
|
||||||
emuThread->emuUnpause();
|
emuThread->emuUnpause();
|
||||||
@ -1579,6 +1535,63 @@ void MainWindow::onOpenFile()
|
|||||||
loadROM(filename);
|
loadROM(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::onOpenFileArchive()
|
||||||
|
{
|
||||||
|
emuThread->emuPause();
|
||||||
|
|
||||||
|
QString filename = QFileDialog::getOpenFileName(this,
|
||||||
|
"Open ROM Archive",
|
||||||
|
Config::LastROMFolder,
|
||||||
|
"Archived ROMs (*.zip *.7z *.rar *.tar *.tar.gz *.tar.xz *.tar.bz2);;Any file (*.*)");
|
||||||
|
if (filename.isEmpty())
|
||||||
|
{
|
||||||
|
emuThread->emuUnpause();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Finding list of ROMs...\n");
|
||||||
|
QVector<QString> archiveROMList = Archive::ListArchive(filename.toUtf8().constData());
|
||||||
|
if (archiveROMList.size() > 2)
|
||||||
|
{
|
||||||
|
archiveROMList.removeFirst();
|
||||||
|
QString toLoad = QInputDialog::getItem(this, "melonDS",
|
||||||
|
"The archive was found to have multiple files. Select which ROM you want to load.", archiveROMList.toList(), 0, false);
|
||||||
|
printf("Extracting '%s'\n", toLoad.toUtf8().constData());
|
||||||
|
QVector<QString> extractResult = Archive::ExtractFileFromArchive(filename.toUtf8().constData(), toLoad.toUtf8().constData());
|
||||||
|
if (extractResult[0] != QString("Err"))
|
||||||
|
{
|
||||||
|
filename = extractResult[0];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QMessageBox::critical(this, "melonDS", QString("There was an error while trying to extract the ROM from the archive: ") + extractResult[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (archiveROMList.size() == 2)
|
||||||
|
{
|
||||||
|
printf("Extracting the only ROM in archive\n");
|
||||||
|
QVector<QString> extractResult = Archive::ExtractFileFromArchive(filename.toUtf8().constData(), nullptr);
|
||||||
|
if (extractResult[0] != QString("Err"))
|
||||||
|
{
|
||||||
|
filename = extractResult[0];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QMessageBox::critical(this, "melonDS", QString("There was an error while trying to extract the ROM from the archive: ") + extractResult[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ((archiveROMList.size() == 1) && (archiveROMList[0] == QString("OK")))
|
||||||
|
{
|
||||||
|
QMessageBox::warning(this, "melonDS", "The archive is intact, but there are no files inside.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QMessageBox::critical(this, "melonDS", "The archive could not be read. It may be corrupt or you don't have the permissions.");
|
||||||
|
}
|
||||||
|
|
||||||
|
loadROM(filename);
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::onClearRecentFiles()
|
void MainWindow::onClearRecentFiles()
|
||||||
{
|
{
|
||||||
recentFileList.clear();
|
recentFileList.clear();
|
||||||
|
@ -191,6 +191,7 @@ signals:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onOpenFile();
|
void onOpenFile();
|
||||||
|
void onOpenFileArchive();
|
||||||
void onClickRecentFile();
|
void onClickRecentFile();
|
||||||
void onClearRecentFiles();
|
void onClearRecentFiles();
|
||||||
void onBootFirmware();
|
void onBootFirmware();
|
||||||
@ -251,6 +252,7 @@ public:
|
|||||||
QWidget* panel;
|
QWidget* panel;
|
||||||
|
|
||||||
QAction* actOpenROM;
|
QAction* actOpenROM;
|
||||||
|
QAction* actOpenROMArchive;
|
||||||
QAction* actBootFirmware;
|
QAction* actBootFirmware;
|
||||||
QAction* actSaveState[9];
|
QAction* actSaveState[9];
|
||||||
QAction* actLoadState[9];
|
QAction* actLoadState[9];
|
||||||
|
Reference in New Issue
Block a user