Handle Resets when loading from archives

* Ask user to pick the rom(s) again (i.e. GBA & NDS)
when there are multiple files in the archive(s)

* Directly load if only 1 file

Signed-off-by: Madhav Kanbur <abcdjdj@gmail.com>
This commit is contained in:
Madhav Kanbur
2021-01-14 16:35:45 +05:30
parent 0892d25f4c
commit cb0111fd90
3 changed files with 46 additions and 12 deletions

View File

@ -22,6 +22,7 @@
#include <QFileInfo>
#include <QDir>
#include "main.h"
#include "FrontendUtil.h"
#include "Config.h"
#include "SharedConfig.h"
@ -504,16 +505,49 @@ int Reset()
}
else
{
SetupSRAMPath(0);
if (!NDS::LoadROM(ROMPath[ROMSlot_NDS], SRAMPath[ROMSlot_NDS], directboot))
return Load_ROMLoadError;
QString fileName(ROMPath[ROMSlot_NDS]);
if(fileName.endsWith(".nds"))
{
SetupSRAMPath(0);
if (!NDS::LoadROM(ROMPath[ROMSlot_NDS], SRAMPath[ROMSlot_NDS], directboot))
return Load_ROMLoadError;
}
else
{
QByteArray romBuffer;
QString romFileName = MainWindow::pickAndExtractFileFromArchive(fileName, &romBuffer);
if(romFileName.isEmpty())
return Load_ROMLoadError;
QString sramFile = QFileInfo(fileName).absolutePath() + QDir::separator() + QFileInfo(romFileName).completeBaseName() + ".sav";
strncpy(SRAMPath[0], QDir::cleanPath(sramFile).toStdString().c_str(), 1024);
if(!NDS::LoadROM((const u8*)romBuffer.constData(), romBuffer.size(), SRAMPath[ROMSlot_NDS], directboot))
return Load_ROMLoadError;
}
}
if (ROMPath[ROMSlot_GBA][0] != '\0')
{
SetupSRAMPath(1);
if (!NDS::LoadGBAROM(ROMPath[ROMSlot_GBA], SRAMPath[ROMSlot_GBA]))
return Load_ROMLoadError;
QString fileName(ROMPath[ROMSlot_GBA]);
if(fileName.endsWith(".gba"))
{
SetupSRAMPath(1);
if (!NDS::LoadGBAROM(ROMPath[ROMSlot_GBA], SRAMPath[ROMSlot_GBA]))
return Load_ROMLoadError;
}
else
{
QByteArray romBuffer;
QString romFileName = MainWindow::pickAndExtractFileFromArchive(fileName, &romBuffer);
if(romFileName.isEmpty())
return Load_ROMLoadError;
QString sramFile = QFileInfo(fileName).absolutePath() + QDir::separator() + QFileInfo(romFileName).completeBaseName() + ".sav";
strncpy(SRAMPath[1], QDir::cleanPath(sramFile).toStdString().c_str(), 1024);
if(!NDS::LoadGBAROM((const u8*)romBuffer.constData(), romBuffer.size(), romFileName.toStdString().c_str(), SRAMPath[ROMSlot_GBA]))
return Load_ROMLoadError;
}
}
LoadCheats();

View File

@ -1645,7 +1645,7 @@ QString MainWindow::pickAndExtractFileFromArchive(QString archiveFileName, QByte
archiveROMList.removeFirst();
bool ok;
QString toLoad = QInputDialog::getItem(this, "melonDS",
QString toLoad = QInputDialog::getItem(nullptr, "melonDS",
"The archive was found to have multiple files. Select which ROM you want to load.", archiveROMList.toList(), 0, false, &ok);
if(!ok) // User clicked on cancel
return QString();
@ -1658,7 +1658,7 @@ QString MainWindow::pickAndExtractFileFromArchive(QString archiveFileName, QByte
}
else
{
QMessageBox::critical(this, "melonDS", QString("There was an error while trying to extract the ROM from the archive: ") + extractResult[1]);
QMessageBox::critical(nullptr, "melonDS", QString("There was an error while trying to extract the ROM from the archive: ") + extractResult[1]);
}
}
else if (archiveROMList.size() == 2)
@ -1671,16 +1671,16 @@ QString MainWindow::pickAndExtractFileFromArchive(QString archiveFileName, QByte
}
else
{
QMessageBox::critical(this, "melonDS", QString("There was an error while trying to extract the ROM from the archive: ") + extractResult[1]);
QMessageBox::critical(nullptr, "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.");
QMessageBox::warning(nullptr, "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.");
QMessageBox::critical(nullptr, "melonDS", "The archive could not be read. It may be corrupt or you don't have the permissions.");
}
return romFileName;

View File

@ -177,7 +177,7 @@ public:
bool hasOGL;
QOpenGLContext* getOGLContext();
QString pickAndExtractFileFromArchive(QString archiveFileName, QByteArray *romBuffer);
static QString pickAndExtractFileFromArchive(QString archiveFileName, QByteArray *romBuffer);
protected:
void resizeEvent(QResizeEvent* event) override;