This commit is contained in:
Dmugetsu 2025-02-14 23:27:58 -06:00
parent 7d807dc5d4
commit 09bebefcee
4 changed files with 25 additions and 10 deletions

View File

@ -295,6 +295,7 @@ void Emulator::Run(const std::filesystem::path& file, const std::vector<std::str
std::quick_exit(0); std::quick_exit(0);
} }
#ifdef ENABLE_QT_GUI
void Emulator::saveLastEbootPath(const QString& path) { void Emulator::saveLastEbootPath(const QString& path) {
lastEbootPath = path; lastEbootPath = path;
} }
@ -336,7 +337,7 @@ void Emulator::Restart() {
LOG_ERROR(Loader, "No previous EBOOT path found! Cannot restart."); LOG_ERROR(Loader, "No previous EBOOT path found! Cannot restart.");
return; return;
} }
#endif
// Relaunch emulator with last game // Relaunch emulator with last game
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
QString emulatorPath = QString emulatorPath =

View File

@ -39,9 +39,12 @@ public:
private: private:
void LoadSystemModules(const std::string& game_serial); void LoadSystemModules(const std::string& game_serial);
Common::ElfInfo game_info; Common::ElfInfo game_info;
#ifdef ENABLE_QT_GUI
QString lastEbootPath; QString lastEbootPath;
void saveLastEbootPath(const QString& path); void saveLastEbootPath(const QString& path);
QString getLastEbootPath(); QString getLastEbootPath();
#endif
bool isRunning = false; bool isRunning = false;
Core::MemoryManager* memory; Core::MemoryManager* memory;
Input::GameController* controller; Input::GameController* controller;

View File

@ -766,10 +766,12 @@ void MainWindow::BootGame() {
} }
} }
} }
#ifdef ENABLE_QT_GUI
QString MainWindow::getLastEbootPath() { QString MainWindow::getLastEbootPath() {
return QString(); return QString();
} }
#endif
void MainWindow::InstallDragDropPkg(std::filesystem::path file, int pkgNum, int nPkg) { void MainWindow::InstallDragDropPkg(std::filesystem::path file, int pkgNum, int nPkg) {
if (Loader::DetectFileType(file) == Loader::FileTypes::Pkg) { if (Loader::DetectFileType(file) == Loader::FileTypes::Pkg) {
@ -1240,7 +1242,10 @@ void MainWindow::StartEmulator(std::filesystem::path path) {
QMessageBox::critical(nullptr, tr("Run Game"), QString(tr("Game is already running!"))); QMessageBox::critical(nullptr, tr("Run Game"), QString(tr("Game is already running!")));
return; return;
} }
lastGamePath = path; // Store the last played game
isGameRunning = true; isGameRunning = true;
#ifdef __APPLE__ #ifdef __APPLE__
// SDL on macOS requires main thread. // SDL on macOS requires main thread.
Core::Emulator emulator; Core::Emulator emulator;
@ -1254,6 +1259,8 @@ void MainWindow::StartEmulator(std::filesystem::path path) {
#endif #endif
} }
#ifdef ENABLE_QT_GUI
void MainWindow::StopGame() { void MainWindow::StopGame() {
if (!isGameRunning) { if (!isGameRunning) {
QMessageBox::information(this, tr("Stop Game"), tr("No game is currently running.")); QMessageBox::information(this, tr("Stop Game"), tr("No game is currently running."));
@ -1278,20 +1285,21 @@ void MainWindow::RestartGame() {
return; return;
} }
std::vector<std::string> recentFiles = Config::getRecentFiles(); if (lastGamePath.empty()) {
if (recentFiles.empty()) {
QMessageBox::warning(this, tr("Restart Game"), tr("No recent game found.")); QMessageBox::warning(this, tr("Restart Game"), tr("No recent game found."));
return; return;
} }
QString lastGamePath = QString::fromStdString(recentFiles.front()); // Stop the current game properly
// Stop the current game first
StopGame(); StopGame();
// Wait for cleanup // Ensure the game has fully stopped before restarting
QThread::sleep(1); while (isGameRunning) {
QCoreApplication::processEvents();
QThread::msleep(100); // Small delay to allow cleanup
}
// Restart the game // Restart the emulator with the last played game
StartEmulator(Common::FS::PathFromQString(lastGamePath)); StartEmulator(lastGamePath);
} }
#endif

View File

@ -67,7 +67,10 @@ private:
void SetUiIcons(bool isWhite); void SetUiIcons(bool isWhite);
void InstallPkg(); void InstallPkg();
void BootGame(); void BootGame();
#ifdef ENABLE_QT_GUI
QString getLastEbootPath(); QString getLastEbootPath();
std::filesystem::path lastGamePath;
#endif
void AddRecentFiles(QString filePath); void AddRecentFiles(QString filePath);
void LoadTranslation(); void LoadTranslation();
void PlayBackgroundMusic(); void PlayBackgroundMusic();