Qt: Support changing running GS dump by drag/dropping

This commit is contained in:
Stenzek 2023-03-03 21:31:10 +10:00 committed by refractionpcsx2
parent 5d95a503bf
commit 8505e9203a
3 changed files with 36 additions and 3 deletions

View File

@ -2065,7 +2065,7 @@ static QString getFilenameFromMimeData(const QMimeData* md)
// only one url accepted
const QList<QUrl> urls(md->urls());
if (urls.size() == 1)
filename = urls.front().toLocalFile();
filename = QDir::toNativeSeparators(urls.front().toLocalFile());
}
return filename;
@ -2925,11 +2925,23 @@ void MainWindow::doStartFile(std::optional<CDVD_SourceType> source, const QStrin
void MainWindow::doDiscChange(CDVD_SourceType source, const QString& path)
{
const bool is_gs_dump = VMManager::IsGSDumpFileName(path.toStdString());
if (is_gs_dump != GSDumpReplayer::IsReplayingDump())
{
QMessageBox::critical(this, tr("Error"), tr("Cannot switch from game to GS dump or vice versa."));
return;
}
else if (is_gs_dump)
{
Host::RunOnCPUThread([path = path.toStdString()]() { GSDumpReplayer::ChangeDump(path.c_str()); });
return;
}
bool reset_system = false;
if (!m_was_disc_change_request)
{
QMessageBox message(QMessageBox::Question, tr("Confirm Disc Change"),
tr("Do you want to swap discs or boot the new image (via system reset)?"));
tr("Do you want to swap discs or boot the new image (via system reset)?"), QMessageBox::NoButton, this);
message.addButton(tr("Swap Disc"), QMessageBox::ActionRole);
QPushButton* reset_button = message.addButton(tr("Reset"), QMessageBox::ActionRole);
QPushButton* cancel_button = message.addButton(QMessageBox::Cancel);

View File

@ -101,7 +101,7 @@ int GSDumpReplayer::GetLoopCount()
bool GSDumpReplayer::Initialize(const char* filename)
{
Common::Timer timer;
Console.WriteLn("(GSDumpReplayer) Reading file...");
Console.WriteLn("(GSDumpReplayer) Reading file '%s'...", filename);
s_dump_file = GSDumpFile::OpenGSDump(filename);
if (!s_dump_file || !s_dump_file->ReadFile())
@ -125,6 +125,25 @@ bool GSDumpReplayer::Initialize(const char* filename)
return true;
}
bool GSDumpReplayer::ChangeDump(const char* filename)
{
Console.WriteLn("(GSDumpReplayer) Switching to '%s'...", filename);
std::unique_ptr<GSDumpFile> new_dump(GSDumpFile::OpenGSDump(filename));
if (!new_dump || !new_dump->ReadFile())
{
Host::ReportFormattedErrorAsync("GSDumpReplayer", "Failed to open or read '%s'.", filename);
return false;
}
s_dump_file = std::move(new_dump);
s_current_packet = 0;
// Don't forget to reset the GS!
GSDumpReplayerCpuReset();
return true;
}
void GSDumpReplayer::Reset()
{
GSDumpReplayerCpuReset();
@ -185,6 +204,7 @@ void GSDumpReplayerCpuReset()
s_needs_state_loaded = true;
s_current_packet = 0;
s_dump_frame_number = 0;
hwReset();
}
static void GSDumpReplayerLoadInitialState()

View File

@ -30,6 +30,7 @@ bool IsRunner();
void SetIsDumpRunner(bool is_runner);
bool Initialize(const char* filename);
bool ChangeDump(const char* filename);
void Reset();
void Shutdown();