From 8efb67d3af76c9080f5729af11a5cef8e18934f0 Mon Sep 17 00:00:00 2001 From: sirmangler Date: Mon, 15 May 2023 14:28:36 +0100 Subject: [PATCH] Add URI protocol / retropass support --- .gitignore | 1 + pcsx2-winrt/App.cpp | 105 ++++++++++++++++++++++++++++--- pcsx2-winrt/Package.appxmanifest | 11 +++- pcsx2-winrt/pcsx2-winrt.vcxproj | 4 +- pcsx2/ImGui/FullscreenUI.cpp | 4 +- pcsx2/pcsx2.vcxproj.filters | 1 + 6 files changed, 112 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index efff1e086714b..3187c03b2ba28 100644 --- a/.gitignore +++ b/.gitignore @@ -112,3 +112,4 @@ CMakeSettings.json /Search Results.txt /findstr_CLI.bat /findstr_CLI(1).bat +/pcsx2-winrt/pcsx2-winrt.vcxproj.filters diff --git a/pcsx2-winrt/App.cpp b/pcsx2-winrt/App.cpp index 09f7c13bc04c9..d5c3db7fa1cbf 100644 --- a/pcsx2-winrt/App.cpp +++ b/pcsx2-winrt/App.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -10,6 +11,7 @@ #include #include #include +#include #include @@ -19,6 +21,7 @@ #include #include #include +#include #include "fmt/core.h" @@ -410,14 +413,18 @@ void WinRTHost::ProcessEventQueue() { struct App : implements { std::thread m_cpu_thread; + winrt::hstring m_launchOnExit; + std::string m_bootPath; IFrameworkView CreateView() { return *this; } - void Initialize(CoreApplicationView const &) + void Initialize(CoreApplicationView const & v) { + v.Activated({this, &App::OnActivate}); + namespace WGI = winrt::Windows::Gaming::Input; if (!WinRTHost::InitializeConfig()) @@ -443,6 +450,74 @@ struct App : implements } } + void OnActivate(const winrt::Windows::ApplicationModel::Core::CoreApplicationView&, + const winrt::Windows::ApplicationModel::Activation::IActivatedEventArgs& args) + { + std::stringstream filePath; + + if (args.Kind() == Windows::ApplicationModel::Activation::ActivationKind::Protocol) + { + auto protocolActivatedEventArgs{ + args.as()}; + auto query = protocolActivatedEventArgs.Uri().QueryParsed(); + + for (uint32_t i = 0; i < query.Size(); i++) + { + auto arg = query.GetAt(i); + + // parse command line string + if (arg.Name() == winrt::hstring(L"cmd")) + { + std::string argVal = winrt::to_string(arg.Value()); + + // Strip the executable from the cmd argument + if (argVal.rfind("xbsx2.exe", 0) == 0) + { + argVal = argVal.substr(10, argVal.length()); + } + + std::istringstream iss(argVal); + std::string s; + + // Maintain slashes while reading the quotes + while (iss >> std::quoted(s, '"', (char)0)) + { + filePath << s; + } + } + else if (arg.Name() == winrt::hstring(L"launchOnExit")) + { + // For if we want to return to a frontend + m_launchOnExit = arg.Value(); + } + } + } + + std::string gamePath = filePath.str(); + if (!gamePath.empty() && gamePath != "") + { + std::unique_lock lk(m_event_mutex); + m_event_queue.push_back([gamePath]() { + VMBootParameters params{}; + params.filename = gamePath; + params.source_type = CDVD_SourceType::Iso; + + if (VMManager::HasValidVM()) { + return; + } + + if (!VMManager::Initialize(std::move(params))) { + return; + } + + VMManager::SetState(VMState::Running); + + GetMTGS().WaitForOpen(); + InputManager::ReloadDevices(); + }); + } + } + void Load(hstring const&) { } @@ -463,12 +538,14 @@ struct App : implements const winrt::Windows::UI::Core::BackRequestedEventArgs& args) { args.Handled(true); }); CommonHost::CPUThreadInitialize(); - GameList::Refresh(false, true); - ImGuiManager::InitializeFullscreenUI(); - if (!GetMTGS().WaitForOpen()) + WinRTHost::ProcessEventQueue(); + if (VMManager::GetState() != VMState::Running) { - return; + GameList::Refresh(false, true); + ImGuiManager::InitializeFullscreenUI(); + + GetMTGS().WaitForOpen(); } window.Dispatcher().RunAsync(CoreDispatcherPriority::Normal, []() { @@ -517,8 +594,22 @@ struct App : implements Sleep(1); } - CommonHost::CPUThreadShutdown(); - CoreApplication::Exit(); + if (!m_launchOnExit.empty()) + { + winrt::Windows::Foundation::Uri m_uri{m_launchOnExit}; + auto asyncOperation = winrt::Windows::System::Launcher::LaunchUriAsync(m_uri); + asyncOperation.Completed([](winrt::Windows::Foundation::IAsyncOperation const& sender, + winrt::Windows::Foundation::AsyncStatus const asyncStatus) { + CommonHost::CPUThreadShutdown(); + CoreApplication::Exit(); + return; + }); + } + else + { + CommonHost::CPUThreadShutdown(); + CoreApplication::Exit(); + } } void SetWindow(CoreWindow const& window) diff --git a/pcsx2-winrt/Package.appxmanifest b/pcsx2-winrt/Package.appxmanifest index 549bba965f061..98314568b51f7 100644 --- a/pcsx2-winrt/Package.appxmanifest +++ b/pcsx2-winrt/Package.appxmanifest @@ -3,11 +3,11 @@ + Version="2.0.1" /> pcsx2-winrt - a2 + SirMangler Assets\StoreLogo.png @@ -18,11 +18,16 @@ - + + + + + diff --git a/pcsx2-winrt/pcsx2-winrt.vcxproj b/pcsx2-winrt/pcsx2-winrt.vcxproj index f2edd74af0482..5811b551c9009 100644 --- a/pcsx2-winrt/pcsx2-winrt.vcxproj +++ b/pcsx2-winrt/pcsx2-winrt.vcxproj @@ -9,7 +9,7 @@ true true {5e7b753a-b43d-43aa-a373-bba85f9fac80} - pcsx2-winrt + xbsx2 pcsx2_winrt en-US 15.0 @@ -57,7 +57,7 @@ False - True + False True Always x64 diff --git a/pcsx2/ImGui/FullscreenUI.cpp b/pcsx2/ImGui/FullscreenUI.cpp index dbd0d2bfeafc1..64edd8c37ba91 100644 --- a/pcsx2/ImGui/FullscreenUI.cpp +++ b/pcsx2/ImGui/FullscreenUI.cpp @@ -1133,14 +1133,14 @@ void FullscreenUI::DrawLandingWindow() { DoStartBIOS(); } + #ifndef WINRT_XBOX if (MenuButton(ICON_FA_COMPACT_DISC " Start Disc", "Start a game from a disc in your PC's DVD drive.")) { DoStartDisc(); } -#endif // !WINRT_XBOX +#endif - if (MenuButton(ICON_FA_SLIDERS_H " Settings", "Change settings for the emulator.")) SwitchToSettings(); diff --git a/pcsx2/pcsx2.vcxproj.filters b/pcsx2/pcsx2.vcxproj.filters index c4628011e1d11..5e639d82c80a5 100644 --- a/pcsx2/pcsx2.vcxproj.filters +++ b/pcsx2/pcsx2.vcxproj.filters @@ -369,6 +369,7 @@ System\Ps2\GS\Renderers\Vulkan +