mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2024-11-14 13:27:41 -07:00
same shit with Import Savefile
Some checks are pending
macOS / ${{ matrix.arch }} (arm64) (push) Waiting to run
macOS / ${{ matrix.arch }} (x86_64) (push) Waiting to run
macOS / Universal binary (push) Blocked by required conditions
Ubuntu / x86_64 (push) Waiting to run
Ubuntu / aarch64 (push) Waiting to run
Windows / build (push) Waiting to run
Some checks are pending
macOS / ${{ matrix.arch }} (arm64) (push) Waiting to run
macOS / ${{ matrix.arch }} (x86_64) (push) Waiting to run
macOS / Universal binary (push) Blocked by required conditions
Ubuntu / x86_64 (push) Waiting to run
Ubuntu / aarch64 (push) Waiting to run
Windows / build (push) Waiting to run
This commit is contained in:
parent
8b6628b070
commit
979f1ed615
@ -618,6 +618,26 @@ void EmuThread::handleMessages()
|
|||||||
emuInstance->undoStateLoad();
|
emuInstance->undoStateLoad();
|
||||||
msgResult = 1;
|
msgResult = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case msg_ImportSavefile:
|
||||||
|
{
|
||||||
|
msgResult = 0;
|
||||||
|
auto f = Platform::OpenFile(msg.param.value<QString>().toStdString(), Platform::FileMode::Read);
|
||||||
|
if (!f) break;
|
||||||
|
|
||||||
|
u32 len = FileLength(f);
|
||||||
|
|
||||||
|
std::unique_ptr<u8[]> data = std::make_unique<u8[]>(len);
|
||||||
|
Platform::FileRewind(f);
|
||||||
|
Platform::FileRead(data.get(), len, 1, f);
|
||||||
|
|
||||||
|
assert(emuInstance->nds != nullptr);
|
||||||
|
emuInstance->nds->SetNDSSave(data.get(), len);
|
||||||
|
|
||||||
|
CloseFile(f);
|
||||||
|
msgResult = 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
msgSemaphore.release();
|
msgSemaphore.release();
|
||||||
@ -771,6 +791,14 @@ int EmuThread::undoStateLoad()
|
|||||||
return msgResult;
|
return msgResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int EmuThread::importSavefile(const QString& filename)
|
||||||
|
{
|
||||||
|
sendMessage(msg_EmuReset);
|
||||||
|
sendMessage({.type = msg_ImportSavefile, .param = filename});
|
||||||
|
waitMessage(2);
|
||||||
|
return msgResult;
|
||||||
|
}
|
||||||
|
|
||||||
void EmuThread::updateRenderer()
|
void EmuThread::updateRenderer()
|
||||||
{
|
{
|
||||||
if (videoRenderer != lastVideoRenderer)
|
if (videoRenderer != lastVideoRenderer)
|
||||||
|
@ -80,6 +80,8 @@ public:
|
|||||||
msg_LoadState,
|
msg_LoadState,
|
||||||
msg_SaveState,
|
msg_SaveState,
|
||||||
msg_UndoStateLoad,
|
msg_UndoStateLoad,
|
||||||
|
|
||||||
|
msg_ImportSavefile,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Message
|
struct Message
|
||||||
@ -119,6 +121,8 @@ public:
|
|||||||
int loadState(const QString& filename);
|
int loadState(const QString& filename);
|
||||||
int undoStateLoad();
|
int undoStateLoad();
|
||||||
|
|
||||||
|
int importSavefile(const QString& filename);
|
||||||
|
|
||||||
bool emuIsRunning();
|
bool emuIsRunning();
|
||||||
bool emuIsActive();
|
bool emuIsActive();
|
||||||
|
|
||||||
|
@ -1483,23 +1483,17 @@ void MainWindow::onUndoStateLoad()
|
|||||||
|
|
||||||
void MainWindow::onImportSavefile()
|
void MainWindow::onImportSavefile()
|
||||||
{
|
{
|
||||||
emuThread->emuPause();
|
|
||||||
QString path = QFileDialog::getOpenFileName(this,
|
QString path = QFileDialog::getOpenFileName(this,
|
||||||
"Select savefile",
|
"Select savefile",
|
||||||
globalCfg.GetQString("LastROMFolder"),
|
globalCfg.GetQString("LastROMFolder"),
|
||||||
"Savefiles (*.sav *.bin *.dsv);;Any file (*.*)");
|
"Savefiles (*.sav *.bin *.dsv);;Any file (*.*)");
|
||||||
|
|
||||||
if (path.isEmpty())
|
if (path.isEmpty())
|
||||||
{
|
|
||||||
emuThread->emuUnpause();
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
Platform::FileHandle* f = Platform::OpenFile(path.toStdString(), Platform::FileMode::Read);
|
if (!Platform::FileExists(path.toStdString()))
|
||||||
if (!f)
|
|
||||||
{
|
{
|
||||||
QMessageBox::critical(this, "melonDS", "Could not open the given savefile.");
|
QMessageBox::critical(this, "melonDS", "Could not open the given savefile.");
|
||||||
emuThread->emuUnpause();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1510,24 +1504,15 @@ void MainWindow::onImportSavefile()
|
|||||||
"The emulation will be reset and the current savefile overwritten.",
|
"The emulation will be reset and the current savefile overwritten.",
|
||||||
QMessageBox::Ok, QMessageBox::Cancel) != QMessageBox::Ok)
|
QMessageBox::Ok, QMessageBox::Cancel) != QMessageBox::Ok)
|
||||||
{
|
{
|
||||||
emuThread->emuUnpause();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
emuInstance->reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 len = FileLength(f);
|
if (!emuThread->importSavefile(path))
|
||||||
|
{
|
||||||
std::unique_ptr<u8[]> data = std::make_unique<u8[]>(len);
|
QMessageBox::critical(this, "melonDS", "Could not import the given savefile.");
|
||||||
Platform::FileRewind(f);
|
return;
|
||||||
Platform::FileRead(data.get(), len, 1, f);
|
}
|
||||||
|
|
||||||
assert(emuInstance->nds != nullptr);
|
|
||||||
emuInstance->nds->SetNDSSave(data.get(), len);
|
|
||||||
|
|
||||||
CloseFile(f);
|
|
||||||
emuThread->emuUnpause();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onQuit()
|
void MainWindow::onQuit()
|
||||||
|
Loading…
Reference in New Issue
Block a user