mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-08-04 08:22:32 +00:00
Changed all QT stuff to std (still cant fetch correctly the lastgamepath)
This commit is contained in:
parent
2d33b026bb
commit
d642033ae4
@ -294,12 +294,11 @@ void Core::Emulator::Run(const std::filesystem::path& file, const std::vector<st
|
|||||||
std::quick_exit(0);
|
std::quick_exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_QT_GUI
|
void Emulator::saveLastEbootPath(const std::string& path) {
|
||||||
void Emulator::saveLastEbootPath(const QString& path) {
|
|
||||||
lastEbootPath = path;
|
lastEbootPath = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Emulator::getLastEbootPath() {
|
std::string Emulator::getLastEbootPath() const {
|
||||||
return lastEbootPath;
|
return lastEbootPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -313,7 +312,7 @@ void Emulator::StopEmulation() {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
is_running = false;
|
is_running = false;
|
||||||
qDebug() << "Stopping emulator...";
|
LOG_INFO(Loader, "Stopping emulator...");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Emulator::Restart() {
|
void Emulator::Restart() {
|
||||||
@ -328,32 +327,14 @@ void Emulator::Restart() {
|
|||||||
StopEmulation();
|
StopEmulation();
|
||||||
|
|
||||||
// Wait a moment before restarting
|
// Wait a moment before restarting
|
||||||
QThread::sleep(2);
|
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||||
|
|
||||||
// Retrieve last known EBOOT path
|
// Retrieve last known EBOOT path
|
||||||
QString lastEbootPath = getLastEbootPath();
|
std::string lastEbootPath = getLastEbootPath();
|
||||||
if (lastEbootPath.isEmpty()) {
|
if (lastEbootPath.empty()) {
|
||||||
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
|
|
||||||
#ifdef Q_OS_WIN
|
|
||||||
QString emulatorPath =
|
|
||||||
QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/shadps4.exe";
|
|
||||||
QProcess::startDetached(emulatorPath, QStringList() << lastEbootPath);
|
|
||||||
#elif defined(Q_OS_LINUX)
|
|
||||||
QString emulatorPath =
|
|
||||||
QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/Shadps4-qt.AppImage";
|
|
||||||
QProcess::startDetached(emulatorPath, QStringList() << lastEbootPath);
|
|
||||||
#elif defined(Q_OS_MAC)
|
|
||||||
QString emulatorPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) +
|
|
||||||
"/shadps4.app/Contents/MacOS/shadps4";
|
|
||||||
QProcess::startDetached(emulatorPath, QStringList() << lastEbootPath);
|
|
||||||
|
|
||||||
isRunning = true;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
|
||||||
void Core::Emulator::LoadSystemModules(const std::string& game_serial) {
|
void Core::Emulator::LoadSystemModules(const std::string& game_serial) {
|
||||||
|
@ -34,16 +34,13 @@ public:
|
|||||||
void StopEmulation();
|
void StopEmulation();
|
||||||
bool is_running = false;
|
bool is_running = false;
|
||||||
void Restart();
|
void Restart();
|
||||||
|
void saveLastEbootPath(const std::string& path);
|
||||||
|
std::string getLastEbootPath() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void LoadSystemModules(const std::string& game_serial);
|
void LoadSystemModules(const std::string& game_serial);
|
||||||
Common::ElfInfo game_info;
|
Common::ElfInfo game_info;
|
||||||
|
std::string lastEbootPath;
|
||||||
#ifdef ENABLE_QT_GUI
|
|
||||||
QString lastEbootPath;
|
|
||||||
void saveLastEbootPath(const QString& path);
|
|
||||||
QString getLastEbootPath();
|
|
||||||
#endif
|
|
||||||
bool isRunning = false;
|
bool isRunning = false;
|
||||||
Core::MemoryManager* memory;
|
Core::MemoryManager* memory;
|
||||||
Input::GameController* controller;
|
Input::GameController* controller;
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
#ifdef ENABLE_DISCORD_RPC
|
#ifdef ENABLE_DISCORD_RPC
|
||||||
#include "common/discord_rpc_handler.h"
|
#include "common/discord_rpc_handler.h"
|
||||||
#endif
|
#endif
|
||||||
|
#include <SDL3/SDL_messagebox.h>
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
|
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
@ -766,12 +767,6 @@ void MainWindow::BootGame() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef ENABLE_QT_GUI
|
|
||||||
|
|
||||||
QString MainWindow::getLastEbootPath() {
|
|
||||||
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) {
|
||||||
@ -1223,6 +1218,10 @@ void MainWindow::OnLanguageChanged(const std::string& locale) {
|
|||||||
LoadTranslation();
|
LoadTranslation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ShowMessageBox(const std::string& title, const std::string& message) {
|
||||||
|
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, title.c_str(), message.c_str(), NULL);
|
||||||
|
}
|
||||||
|
|
||||||
bool MainWindow::eventFilter(QObject* obj, QEvent* event) {
|
bool MainWindow::eventFilter(QObject* obj, QEvent* event) {
|
||||||
if (event->type() == QEvent::KeyPress) {
|
if (event->type() == QEvent::KeyPress) {
|
||||||
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
|
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
|
||||||
@ -1242,10 +1241,7 @@ 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;
|
||||||
@ -1259,47 +1255,44 @@ 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."));
|
ShowMessageBox("Stop Game", "No game is currently running.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the emulator instance and stop it
|
Core::Emulator& emulator = Core::Emulator::GetInstance();
|
||||||
Core::Emulator& emulator = Core::Emulator::GetInstance(); // Use the correct instance method
|
|
||||||
emulator.StopEmulation();
|
emulator.StopEmulation();
|
||||||
|
|
||||||
isGameRunning = false;
|
if (isGameRunning == true)
|
||||||
QMessageBox::information(this, tr("Stop Game"), tr("Game has been stopped successfully."));
|
;
|
||||||
|
ShowMessageBox("Stop Game", "Game has been stopped successfully.");
|
||||||
SDL_Event quitEvent;
|
SDL_Event quitEvent;
|
||||||
quitEvent.type = SDL_EVENT_QUIT + 1;
|
quitEvent.type = SDL_EVENT_QUIT + 1;
|
||||||
SDL_PushEvent(&quitEvent);
|
SDL_PushEvent(&quitEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string MainWindow::getLastEbootPath() {
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::RestartGame() {
|
void MainWindow::RestartGame() {
|
||||||
if (!isGameRunning) {
|
if (!isGameRunning) {
|
||||||
QMessageBox::warning(this, tr("Restart Game"), tr("No game is running to restart."));
|
ShowMessageBox("Restart Game", "No game is running to restart.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string lastGamePath = getLastEbootPath();
|
||||||
|
|
||||||
if (lastGamePath.empty()) {
|
if (lastGamePath.empty()) {
|
||||||
QMessageBox::warning(this, tr("Restart Game"), tr("No recent game found."));
|
ShowMessageBox("Restart Game", "No recent game found.");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop the current game properly
|
|
||||||
StopGame();
|
StopGame();
|
||||||
|
|
||||||
// Ensure the game has fully stopped before restarting
|
|
||||||
while (isGameRunning) {
|
while (isGameRunning) {
|
||||||
QCoreApplication::processEvents();
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
QThread::msleep(100); // Small delay to allow cleanup
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restart the emulator with the last played game
|
|
||||||
StartEmulator(lastGamePath);
|
StartEmulator(lastGamePath);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
@ -67,10 +67,9 @@ private:
|
|||||||
void SetUiIcons(bool isWhite);
|
void SetUiIcons(bool isWhite);
|
||||||
void InstallPkg();
|
void InstallPkg();
|
||||||
void BootGame();
|
void BootGame();
|
||||||
#ifdef ENABLE_QT_GUI
|
std::string lastGamePath;
|
||||||
QString getLastEbootPath();
|
std::string getLastEbootPath();
|
||||||
std::filesystem::path lastGamePath;
|
|
||||||
#endif
|
|
||||||
void AddRecentFiles(QString filePath);
|
void AddRecentFiles(QString filePath);
|
||||||
void LoadTranslation();
|
void LoadTranslation();
|
||||||
void PlayBackgroundMusic();
|
void PlayBackgroundMusic();
|
||||||
|
@ -10,6 +10,11 @@
|
|||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include "common/memory_patcher.h"
|
#include "common/memory_patcher.h"
|
||||||
#endif
|
#endif
|
||||||
|
#include <chrono>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <thread>
|
||||||
#include "SDL3/SDL_events.h"
|
#include "SDL3/SDL_events.h"
|
||||||
#include "SDL3/SDL_hints.h"
|
#include "SDL3/SDL_hints.h"
|
||||||
#include "SDL3/SDL_init.h"
|
#include "SDL3/SDL_init.h"
|
||||||
@ -32,6 +37,11 @@
|
|||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
#include "SDL3/SDL_metal.h"
|
#include "SDL3/SDL_metal.h"
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#else
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Input {
|
namespace Input {
|
||||||
|
|
||||||
@ -384,52 +394,67 @@ void WindowSDL::WaitEvent() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WindowSDL::RelaunchEmulator() {
|
void WindowSDL::RelaunchEmulator() {
|
||||||
#ifdef Q_OS_WIN
|
#ifdef _WIN32
|
||||||
QString emulatorPath = QCoreApplication::applicationFilePath(); // Get current executable path
|
char emulatorPath[MAX_PATH];
|
||||||
QString emulatorDir = QFileInfo(emulatorPath).absolutePath(); // Get working directory
|
GetModuleFileNameA(nullptr, emulatorPath, MAX_PATH); // Get current executable path
|
||||||
QString scriptFileName =
|
|
||||||
QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/relaunch.ps1";
|
|
||||||
QString scriptContent =
|
|
||||||
QStringLiteral(
|
|
||||||
"Start-Sleep -Seconds 2\n"
|
|
||||||
"Start-Process -FilePath '%1' -WorkingDirectory ([WildcardPattern]::Escape('%2'))\n")
|
|
||||||
.arg(emulatorPath, emulatorDir);
|
|
||||||
|
|
||||||
QFile scriptFile(scriptFileName);
|
std::string emulatorDir = std::string(emulatorPath);
|
||||||
if (scriptFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
size_t pos = emulatorDir.find_last_of("\\/");
|
||||||
QTextStream out(&scriptFile);
|
if (pos != std::string::npos) {
|
||||||
scriptFile.write("\xEF\xBB\xBF"); // UTF-8 BOM
|
emulatorDir = emulatorDir.substr(0, pos); // Extract directory
|
||||||
out << scriptContent;
|
}
|
||||||
|
|
||||||
|
std::string scriptFileName = std::getenv("TEMP") + std::string("\\relaunch.ps1");
|
||||||
|
std::ofstream scriptFile(scriptFileName);
|
||||||
|
|
||||||
|
if (scriptFile.is_open()) {
|
||||||
|
scriptFile << "Start-Sleep -Seconds 2\n"
|
||||||
|
<< "Start-Process -FilePath '" << emulatorPath
|
||||||
|
<< "' -WorkingDirectory ([WildcardPattern]::Escape('" << emulatorDir << "'))\n";
|
||||||
scriptFile.close();
|
scriptFile.close();
|
||||||
|
|
||||||
// Execute PowerShell script
|
// Execute PowerShell script
|
||||||
QProcess::startDetached("powershell.exe", QStringList() << "-ExecutionPolicy"
|
std::string command =
|
||||||
<< "Bypass"
|
"powershell.exe -ExecutionPolicy Bypass -File \"" + scriptFileName + "\"";
|
||||||
<< "-File" << scriptFileName);
|
system(command.c_str());
|
||||||
|
} else {
|
||||||
|
std::cerr << "Failed to create relaunch script" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(Q_OS_LINUX) || defined(Q_OS_MAC)
|
#elif defined(__linux__) || defined(__APPLE__)
|
||||||
QString emulatorPath = QCoreApplication::applicationFilePath(); // Get current executable path
|
char emulatorPath[1024];
|
||||||
QString emulatorDir = QFileInfo(emulatorPath).absolutePath(); // Get working directory
|
ssize_t count = readlink("/proc/self/exe", emulatorPath, sizeof(emulatorPath) - 1);
|
||||||
QString scriptFileName = "/tmp/relaunch.sh";
|
if (count != -1) {
|
||||||
QString scriptContent = QStringLiteral("#!/bin/bash\n"
|
emulatorPath[count] = '\0';
|
||||||
"sleep 2\n"
|
} else {
|
||||||
"cd '%2'\n"
|
std::cerr << "Failed to get executable path" << std::endl;
|
||||||
"./'%1' &\n")
|
return;
|
||||||
.arg(QFileInfo(emulatorPath).fileName(), emulatorDir);
|
}
|
||||||
|
|
||||||
QFile scriptFile(scriptFileName);
|
std::string emulatorDir = std::string(emulatorPath);
|
||||||
if (scriptFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
size_t pos = emulatorDir.find_last_of("/");
|
||||||
QTextStream out(&scriptFile);
|
if (pos != std::string::npos) {
|
||||||
out << scriptContent;
|
emulatorDir = emulatorDir.substr(0, pos); // Extract directory
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string scriptFileName = "/tmp/relaunch.sh";
|
||||||
|
std::ofstream scriptFile(scriptFileName);
|
||||||
|
|
||||||
|
if (scriptFile.is_open()) {
|
||||||
|
scriptFile << "#!/bin/bash\n"
|
||||||
|
<< "sleep 2\n"
|
||||||
|
<< "cd '" << emulatorDir << "'\n"
|
||||||
|
<< "./'" << emulatorPath + pos + 1 << "' &\n";
|
||||||
scriptFile.close();
|
scriptFile.close();
|
||||||
|
|
||||||
// Make script executable
|
// Make script executable
|
||||||
scriptFile.setPermissions(QFileDevice::ExeOwner | QFileDevice::ReadOwner |
|
chmod(scriptFileName.c_str(), S_IRWXU);
|
||||||
QFileDevice::WriteOwner);
|
|
||||||
|
|
||||||
// Execute bash script
|
// Execute bash script
|
||||||
QProcess::startDetached("bash", QStringList() << scriptFileName);
|
std::string command = "bash " + scriptFileName;
|
||||||
|
system(command.c_str());
|
||||||
|
} else {
|
||||||
|
std::cerr << "Failed to create relaunch script" << std::endl;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user