mirror of
https://github.com/WinampDesktop/winamp.git
synced 2025-06-19 19:35:41 -04:00
System: Confirm shutdown if memory card is being written
This commit is contained in:
@ -110,7 +110,7 @@ void AchievementLoginDialog::processLoginResult(bool result, const QString& mess
|
||||
tr("Hardcore mode will not be enabled until the system is reset. Do you want to reset the system now?")) ==
|
||||
QMessageBox::Yes)
|
||||
{
|
||||
g_emu_thread->resetSystem();
|
||||
g_emu_thread->resetSystem(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -154,7 +154,7 @@ void AchievementSettingsWidget::onHardcoreModeStateChanged()
|
||||
return;
|
||||
}
|
||||
|
||||
g_emu_thread->resetSystem();
|
||||
g_emu_thread->resetSystem(true);
|
||||
}
|
||||
|
||||
void AchievementSettingsWidget::onAchievementsNotificationDurationSliderChanged()
|
||||
|
@ -700,7 +700,7 @@ void MainWindow::quit()
|
||||
// Make sure VM is gone. It really should be if we're here.
|
||||
if (s_system_valid)
|
||||
{
|
||||
g_emu_thread->shutdownSystem(false);
|
||||
g_emu_thread->shutdownSystem(false, true);
|
||||
while (s_system_valid)
|
||||
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents, 1);
|
||||
}
|
||||
@ -990,7 +990,7 @@ void MainWindow::populateChangeDiscSubImageMenu(QMenu* menu, QActionGroup* actio
|
||||
QString path = QString::fromStdString(glentry->path);
|
||||
action->setCheckable(true);
|
||||
action->setChecked(path == s_current_game_path);
|
||||
connect(action, &QAction::triggered, [path = std::move(path)]() { g_emu_thread->changeDisc(path); });
|
||||
connect(action, &QAction::triggered, [path = std::move(path)]() { g_emu_thread->changeDisc(path, false, true); });
|
||||
menu->addAction(action);
|
||||
}
|
||||
}
|
||||
@ -1232,9 +1232,7 @@ void MainWindow::promptForDiscChange(const QString& path)
|
||||
|
||||
switchToEmulationView();
|
||||
|
||||
g_emu_thread->changeDisc(path);
|
||||
if (reset_system)
|
||||
g_emu_thread->resetSystem();
|
||||
g_emu_thread->changeDisc(path, reset_system, true);
|
||||
}
|
||||
|
||||
void MainWindow::onStartDiscActionTriggered()
|
||||
@ -1258,7 +1256,7 @@ void MainWindow::onChangeDiscFromFileActionTriggered()
|
||||
if (filename.isEmpty())
|
||||
return;
|
||||
|
||||
g_emu_thread->changeDisc(filename);
|
||||
g_emu_thread->changeDisc(filename, false, true);
|
||||
}
|
||||
|
||||
void MainWindow::onChangeDiscFromGameListActionTriggered()
|
||||
@ -1273,7 +1271,7 @@ void MainWindow::onChangeDiscFromDeviceActionTriggered()
|
||||
if (path.empty())
|
||||
return;
|
||||
|
||||
g_emu_thread->changeDisc(QString::fromStdString(path));
|
||||
g_emu_thread->changeDisc(QString::fromStdString(path), false, true);
|
||||
}
|
||||
|
||||
void MainWindow::onChangeDiscMenuAboutToShow()
|
||||
@ -1317,7 +1315,7 @@ void MainWindow::onFullscreenUIStateChange(bool running)
|
||||
|
||||
void MainWindow::onRemoveDiscActionTriggered()
|
||||
{
|
||||
g_emu_thread->changeDisc(QString());
|
||||
g_emu_thread->changeDisc(QString(), false, true);
|
||||
}
|
||||
|
||||
void MainWindow::onViewToolbarActionToggled(bool checked)
|
||||
@ -1511,7 +1509,7 @@ void MainWindow::onGameListEntryContextMenuRequested(const QPoint& point)
|
||||
else
|
||||
{
|
||||
connect(menu.addAction(tr("Change Disc")), &QAction::triggered, [this, entry]() {
|
||||
g_emu_thread->changeDisc(QString::fromStdString(entry->path));
|
||||
g_emu_thread->changeDisc(QString::fromStdString(entry->path), false, true);
|
||||
g_emu_thread->setSystemPaused(false);
|
||||
switchToEmulationView();
|
||||
});
|
||||
@ -2031,8 +2029,8 @@ void MainWindow::connectSignals()
|
||||
[this]() { requestShutdown(true, true, g_settings.save_state_on_exit); });
|
||||
connect(m_ui.actionPowerOffWithoutSaving, &QAction::triggered, this,
|
||||
[this]() { requestShutdown(false, false, false); });
|
||||
connect(m_ui.actionReset, &QAction::triggered, g_emu_thread, &EmuThread::resetSystem);
|
||||
connect(m_ui.actionPause, &QAction::toggled, [](bool active) { g_emu_thread->setSystemPaused(active); });
|
||||
connect(m_ui.actionReset, &QAction::triggered, this, []() { g_emu_thread->resetSystem(true); });
|
||||
connect(m_ui.actionPause, &QAction::toggled, this, [](bool active) { g_emu_thread->setSystemPaused(active); });
|
||||
connect(m_ui.actionScreenshot, &QAction::triggered, g_emu_thread, &EmuThread::saveScreenshot);
|
||||
connect(m_ui.actionScanForNewGames, &QAction::triggered, this, [this]() { refreshGameList(false); });
|
||||
connect(m_ui.actionRescanAllGames, &QAction::triggered, this, [this]() { refreshGameList(true); });
|
||||
@ -2862,7 +2860,7 @@ bool MainWindow::requestShutdown(bool allow_confirm /* = true */, bool allow_sav
|
||||
updateWindowState(true);
|
||||
|
||||
// Now we can actually shut down the VM.
|
||||
g_emu_thread->shutdownSystem(save_state);
|
||||
g_emu_thread->shutdownSystem(save_state, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1067,23 +1067,72 @@ void EmuThread::enumerateVibrationMotors()
|
||||
onVibrationMotorsEnumerated(qmotors);
|
||||
}
|
||||
|
||||
void EmuThread::shutdownSystem(bool save_state /* = true */)
|
||||
void EmuThread::confirmActionIfMemoryCardBusy(const QString& action, bool cancel_resume_on_accept,
|
||||
std::function<void(bool)> callback) const
|
||||
{
|
||||
DebugAssert(isOnThread());
|
||||
|
||||
if (!System::IsValid() || !System::IsSavingMemoryCards())
|
||||
{
|
||||
callback(true);
|
||||
return;
|
||||
}
|
||||
|
||||
QtHost::RunOnUIThread([action, cancel_resume_on_accept, callback = std::move(callback)]() mutable {
|
||||
auto lock = g_main_window->pauseAndLockSystem();
|
||||
|
||||
const bool result =
|
||||
(QMessageBox::question(lock.getDialogParent(), tr("Memory Card Busy"),
|
||||
tr("WARNING: Your game is still saving to the memory card. Continuing to %1 may "
|
||||
"IRREVERSIBLY DESTROY YOUR MEMORY CARD. We recommend resuming your game and waiting 5 "
|
||||
"seconds for it to finish saving.\n\nDo you want to %1 anyway?")
|
||||
.arg(action)) != QMessageBox::No);
|
||||
|
||||
if (cancel_resume_on_accept)
|
||||
lock.cancelResume();
|
||||
|
||||
Host::RunOnCPUThread([result, callback = std::move(callback)]() { callback(result); });
|
||||
});
|
||||
}
|
||||
|
||||
void EmuThread::shutdownSystem(bool save_state, bool check_memcard_busy)
|
||||
{
|
||||
if (!isOnThread())
|
||||
{
|
||||
System::CancelPendingStartup();
|
||||
QMetaObject::invokeMethod(this, "shutdownSystem", Qt::QueuedConnection, Q_ARG(bool, save_state));
|
||||
QMetaObject::invokeMethod(this, "shutdownSystem", Qt::QueuedConnection, Q_ARG(bool, save_state),
|
||||
Q_ARG(bool, check_memcard_busy));
|
||||
return;
|
||||
}
|
||||
|
||||
if (check_memcard_busy && System::IsSavingMemoryCards())
|
||||
{
|
||||
confirmActionIfMemoryCardBusy(tr("shut down"), true, [save_state](bool result) {
|
||||
if (result)
|
||||
g_emu_thread->shutdownSystem(save_state, false);
|
||||
else
|
||||
g_emu_thread->setSystemPaused(false);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
System::ShutdownSystem(save_state);
|
||||
}
|
||||
|
||||
void EmuThread::resetSystem()
|
||||
void EmuThread::resetSystem(bool check_memcard_busy)
|
||||
{
|
||||
if (!isOnThread())
|
||||
{
|
||||
QMetaObject::invokeMethod(this, &EmuThread::resetSystem, Qt::QueuedConnection);
|
||||
QMetaObject::invokeMethod(this, "resetSystem", Qt::QueuedConnection, Q_ARG(bool, check_memcard_busy));
|
||||
return;
|
||||
}
|
||||
|
||||
if (check_memcard_busy && System::IsSavingMemoryCards())
|
||||
{
|
||||
confirmActionIfMemoryCardBusy(tr("reset"), false, [](bool result) {
|
||||
if (result)
|
||||
g_emu_thread->resetSystem(false);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1103,11 +1152,21 @@ void EmuThread::setSystemPaused(bool paused, bool wait_until_paused /* = false *
|
||||
System::PauseSystem(paused);
|
||||
}
|
||||
|
||||
void EmuThread::changeDisc(const QString& new_disc_filename)
|
||||
void EmuThread::changeDisc(const QString& new_disc_filename, bool reset_system, bool check_memcard_busy)
|
||||
{
|
||||
if (!isOnThread())
|
||||
{
|
||||
QMetaObject::invokeMethod(this, "changeDisc", Qt::QueuedConnection, Q_ARG(const QString&, new_disc_filename));
|
||||
QMetaObject::invokeMethod(this, "changeDisc", Qt::QueuedConnection, Q_ARG(const QString&, new_disc_filename),
|
||||
Q_ARG(bool, reset_system), Q_ARG(bool, check_memcard_busy));
|
||||
return;
|
||||
}
|
||||
|
||||
if (check_memcard_busy && System::IsSavingMemoryCards())
|
||||
{
|
||||
confirmActionIfMemoryCardBusy(tr("change disc"), false, [new_disc_filename, reset_system](bool result) {
|
||||
if (result)
|
||||
g_emu_thread->changeDisc(new_disc_filename, reset_system, false);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1118,6 +1177,9 @@ void EmuThread::changeDisc(const QString& new_disc_filename)
|
||||
System::InsertMedia(new_disc_filename.toStdString().c_str());
|
||||
else
|
||||
System::RemoveMedia();
|
||||
|
||||
if (reset_system)
|
||||
System::ResetSystem();
|
||||
}
|
||||
|
||||
void EmuThread::changeDiscFromPlaylist(quint32 index)
|
||||
|
@ -168,10 +168,10 @@ public Q_SLOTS:
|
||||
void stopFullscreenUI();
|
||||
void bootSystem(std::shared_ptr<SystemBootParameters> params);
|
||||
void resumeSystemFromMostRecentState();
|
||||
void shutdownSystem(bool save_state = true);
|
||||
void resetSystem();
|
||||
void shutdownSystem(bool save_state, bool check_memcard_busy);
|
||||
void resetSystem(bool check_memcard_busy);
|
||||
void setSystemPaused(bool paused, bool wait_until_paused = false);
|
||||
void changeDisc(const QString& new_disc_filename);
|
||||
void changeDisc(const QString& new_disc_filename, bool reset_system, bool check_memcard_busy);
|
||||
void changeDiscFromPlaylist(quint32 index);
|
||||
void loadState(const QString& filename);
|
||||
void loadState(bool global, qint32 slot);
|
||||
@ -218,6 +218,8 @@ private:
|
||||
void createBackgroundControllerPollTimer();
|
||||
void destroyBackgroundControllerPollTimer();
|
||||
void setInitialState(std::optional<bool> override_fullscreen);
|
||||
void confirmActionIfMemoryCardBusy(const QString& action, bool cancel_resume_on_accept,
|
||||
std::function<void(bool)> callback) const;
|
||||
|
||||
QThread* m_ui_thread;
|
||||
QSemaphore m_started_semaphore;
|
||||
|
Reference in New Issue
Block a user