fix filepath when launching another program index

This commit is contained in:
Maufeat
2026-08-23 12:14:38 +02:00
parent cd8540c4b4
commit e3b6f7a358
4 changed files with 41 additions and 9 deletions
+13
View File
@@ -3,6 +3,7 @@
#include <array>
#include <atomic>
#include <filesystem>
#include <memory>
#include <utility>
@@ -295,6 +296,8 @@ struct System::Impl {
SystemResultStatus Load(System& system, Frontend::EmuWindow& emu_window, const std::string& filepath, Service::AM::FrontendAppletParameters& params) {
InitializeKernel(system);
system.SetCurrentApplicationFilePath(filepath);
const auto file = GetGameFileFromPath(virtual_filesystem, filepath);
// Create the application process
@@ -489,6 +492,8 @@ struct System::Impl {
std::array<u64, Core::Hardware::NUM_CPU_CORES> dynarmic_ticks{};
std::array<u8, 0x20> build_id{};
std::string current_application_filepath;
/// Service manager
std::shared_ptr<Service::SM::ServiceManager> service_manager;
/// ContentProviderUnion instance
@@ -929,6 +934,14 @@ void System::ExecuteProgram(std::size_t program_index) {
}
}
const std::string& System::GetCurrentApplicationFilePath() const {
return impl->current_application_filepath;
}
void System::SetCurrentApplicationFilePath(const std::string& filepath) {
impl->current_application_filepath = filepath;
}
/// @brief Gets a reference to the user channel stack.
/// It is used to transfer data between programs.
std::vector<std::vector<u8>>& System::GetUserChannel() {
+3
View File
@@ -427,6 +427,9 @@ public:
bool TryPopGeneralChannel(std::vector<u8>& out_data);
[[nodiscard]] Service::Event& GetGeneralChannelEvent();
[[nodiscard]] const std::string& GetCurrentApplicationFilePath() const;
void SetCurrentApplicationFilePath(const std::string& filepath);
/// Type used for the frontend to designate a callback for System to exit the application.
using ExitCallback = std::function<void()>;
@@ -150,7 +150,7 @@ Result IApplicationFunctions::EnsureSaveData(Out<u64> out_size, Common::UUID use
Result IApplicationFunctions::GetDesiredLanguage(Out<u64> out_language_code) {
// FIXME: all of this stuff belongs to ns
// TODO(bunnei): This should be configurable
LOG_DEBUG(Service_AM, "called");
LOG_DEBUG(Service_AM, "called, program_id={:016X}", m_applet->program_id);
// Get supported languages from NACP, if possible
// Default to 0 (all languages supported)
@@ -430,15 +430,16 @@ Result IApplicationFunctions::ExecuteProgram(ProgramSpecifyKind kind, u64 value)
// https://switchbrew.org/wiki/Applet_Manager_services#CreateApplicationAndRequestToStart
Result IApplicationFunctions::CreateApplicationAndRequestToStart(u64 application_id) {
LOG_INFO(Service_AM, "called, application_id={:016X}", application_id);
LOG_INFO(Service_AM, "called, application_id={:016X} current_program_id={:016X}", application_id, m_applet->program_id);
// If application_id is 0, relaunch the current application
const u64 target_application_id =
(application_id == 0) ? m_applet->program_id : application_id;
// If application_id is 0 or matches the current application, relaunch the current application.
if (application_id == 0 || application_id == m_applet->program_id) {
system.GetUserChannel() = m_applet->user_channel_launch_parameter;
system.ExecuteProgram(0);
R_SUCCEED();
}
system.GetUserChannel() = m_applet->user_channel_launch_parameter;
system.ExecuteProgram(target_application_id);
R_SUCCEED();
R_THROW(ResultUnknown);
}
Result IApplicationFunctions::ClearUserChannel() {
+16 -1
View File
@@ -3086,12 +3086,27 @@ void MainWindow::OnLoadComplete() {
}
void MainWindow::OnExecuteProgram(std::size_t program_index) {
const u64 previous_program_id = QtCommon::system->GetApplicationProcessProgramID();
LOG_INFO(Frontend, "ExecuteProgram requested, program_index={} previous_program_id={:016X}",
program_index, previous_program_id);
ShutdownGame();
auto params = ApplicationAppletParameters();
params.program_index = static_cast<s32>(program_index);
params.launch_type = Service::AM::LaunchType::ApplicationInitiated;
BootGame(last_filename_booted, params);
if (previous_program_id != 0) {
params.previous_program_index = static_cast<s32>(previous_program_id & 0xFFF);
}
const auto& current_path = QtCommon::system->GetCurrentApplicationFilePath();
const auto filename = current_path.empty() ? last_filename_booted
: QString::fromStdString(current_path);
LOG_DEBUG(Frontend, "ExecuteProgram booting from path: {}", filename.toStdString());
BootGame(filename, params);
}
void MainWindow::OnExit() {