From 7800bcd0bdb5fd36c0f3195bdb0a8b38a7815638 Mon Sep 17 00:00:00 2001 From: Alexander Babikov Date: Wed, 17 Dec 2025 21:53:48 +0500 Subject: [PATCH] Manager: Pass asset path to VMs if specified on command line (#6569) * Manager: Pass asset path to VMs if specified on command line * Manager: Merge `VMManagerSystem::launchSettings` into `VMManagerSystem::launchMainProcess` --- src/include/86box/86box.h | 7 ++-- src/qt/qt_vmmanager_system.cpp | 72 +++++++--------------------------- src/qt/qt_vmmanager_system.hpp | 2 +- 3 files changed, 19 insertions(+), 62 deletions(-) diff --git a/src/include/86box/86box.h b/src/include/86box/86box.h index a1406d201..f8765aecb 100644 --- a/src/include/86box/86box.h +++ b/src/include/86box/86box.h @@ -159,9 +159,10 @@ extern int confirm_exit_cmdl; /* (O) do not ask for confirmation on quit if set extern uint64_t unique_id; extern uint64_t source_hwnd; #endif -extern char rom_path[1024]; /* (O) full path to ROMs */ -extern char log_path[1024]; /* (O) full path of logfile */ -extern char vm_name[1024]; /* (O) display name of the VM */ +extern char rom_path[1024]; /* (O) full path to ROMs */ +extern char asset_path[1024]; /* (O) full path to assets */ +extern char log_path[1024]; /* (O) full path of logfile */ +extern char vm_name[1024]; /* (O) display name of the VM */ #ifdef USE_INSTRUMENT extern uint8_t instru_enabled; extern uint64_t instru_run_ms; diff --git a/src/qt/qt_vmmanager_system.cpp b/src/qt/qt_vmmanager_system.cpp index 748d60b85..46d0451e8 100644 --- a/src/qt/qt_vmmanager_system.cpp +++ b/src/qt/qt_vmmanager_system.cpp @@ -392,9 +392,8 @@ VMManagerSystem::has86BoxBinary() } void -VMManagerSystem::launchMainProcess() +VMManagerSystem::launch86Box(bool settings) { - if (!has86BoxBinary()) { qWarning("No binary found! returning"); return; @@ -408,22 +407,31 @@ VMManagerSystem::launchMainProcess() return; } } - // If the system is already running, bring it to front + // If the system is already running, bring it to front or instruct it to show settings if (process->processId() != 0) { #ifdef Q_OS_WINDOWS if (this->id) { SetForegroundWindow((HWND) this->id); } #endif + if (settings) + socket_server->serverSendMessage(VMManagerProtocol::ManagerMessage::ShowSettings); return; } + + // Otherwise, launch the system setProcessEnvVars(); + window_obscured = settings; QString program = main_binary.filePath(); QStringList args; args << "--vmpath" << config_dir; args << "--vmname" << displayName; + if (settings) + args << "--settings"; if (rom_path[0] != '\0') args << "--rompath" << QString(rom_path); + if (asset_path[0] != '\0') + args << "--assetpath" << QString(asset_path); if (global_cfg_overridden) args << "--global" << QString(global_cfg_path); if (!hook_enabled) @@ -442,7 +450,7 @@ VMManagerSystem::launchMainProcess() connect(process, QOverload::of(&QProcess::finished), [=](const int exitCode, const QProcess::ExitStatus exitStatus) { if (exitCode != 0 || exitStatus != QProcess::NormalExit) { - qInfo().nospace().noquote() << "Abnormal program termination while launching main process: exit code " << exitCode << ", exit status " << exitStatus; + qInfo().nospace().noquote() << "Abnormal program termination while launching system: exit code " << exitCode << ", exit status " << exitStatus; QMessageBox::critical(this, tr("Virtual machine crash"), tr("The virtual machine \"%1\"'s process has unexpectedly terminated with exit code %2.").arg(displayName, QString("%1 (0x%2)").arg(QString::number(exitCode), QString::number(exitCode, 16)))); return; @@ -455,65 +463,13 @@ VMManagerSystem::launchMainProcess() void VMManagerSystem::startButtonPressed() { - launchMainProcess(); + launch86Box(false); } void VMManagerSystem::launchSettings() { - if (!has86BoxBinary()) { - qWarning("No binary found! returning"); - return; - } - - // start the server first to get the socket name - if (!serverIsRunning) { - if (!startServer()) { - // FIXME: Better error handling - qInfo("Failed to start VM Manager server"); - return; - } - } - - // If the system is already running, instruct it to show settings - if (process->processId() != 0) { -#ifdef Q_OS_WINDOWS - if (this->id) { - SetForegroundWindow((HWND) this->id); - } -#endif - socket_server->serverSendMessage(VMManagerProtocol::ManagerMessage::ShowSettings); - return; - } - - // Otherwise, launch the system with the settings parameter - setProcessEnvVars(); - window_obscured = true; - QString program = main_binary.filePath(); - QStringList open_command_args; - QStringList args; - args << "--vmpath" << config_dir << "--settings"; - if (rom_path[0] != '\0') - args << "--rompath" << QString(rom_path); - if (global_cfg_overridden) - args << "--global" << QString(global_cfg_path); - process->setProgram(program); - process->setArguments(args); - qDebug() << Q_FUNC_INFO << " Full Command:" << process->program() << " " << process->arguments(); - process->start(); - - disconnect(process, QOverload::of(&QProcess::finished), nullptr, nullptr); - connect(process, QOverload::of(&QProcess::finished), - [=](const int exitCode, const QProcess::ExitStatus exitStatus) { - if (exitCode != 0 || exitStatus != QProcess::NormalExit) { - qInfo().nospace().noquote() << "Abnormal program termination while launching settings: exit code " << exitCode << ", exit status " << exitStatus; - QMessageBox::critical(this, tr("Virtual machine crash"), - tr("The virtual machine \"%1\"'s process has unexpectedly terminated with exit code %2.").arg(displayName, QString("%1 (0x%2)").arg(QString::number(exitCode), QString::number(exitCode, 16)))); - return; - } - - configurationChangeReceived(); - }); + launch86Box(true); } void diff --git a/src/qt/qt_vmmanager_system.hpp b/src/qt/qt_vmmanager_system.hpp index 62789b70a..ca79f4e3c 100644 --- a/src/qt/qt_vmmanager_system.hpp +++ b/src/qt/qt_vmmanager_system.hpp @@ -120,7 +120,7 @@ public: [[nodiscard]] bool isProcessRunning() const; [[nodiscard]] qint64 processId() const; public slots: - void launchMainProcess(); + void launch86Box(bool settings = false); void launchSettings(); void startButtonPressed(); void restartButtonPressed();