mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-25 15:19:53 -06:00
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:
@ -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();
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user