Skip to content

Commit

Permalink
Add URI protocol / retropass support
Browse files Browse the repository at this point in the history
  • Loading branch information
SirMangler authored and TheRhysWyrill committed Jul 9, 2023
1 parent 6c00e94 commit 8efb67d
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,4 @@ CMakeSettings.json
/Search Results.txt
/findstr_CLI.bat
/findstr_CLI(1).bat
/pcsx2-winrt/pcsx2-winrt.vcxproj.filters
105 changes: 98 additions & 7 deletions pcsx2-winrt/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
#include <windows.h>
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.ApplicationModel.Activation.h>
#include <winrt/Windows.ApplicationModel.Core.h>
#include <winrt/Windows.UI.Core.h>
#include <winrt/Windows.UI.Composition.h>
#include <winrt/Windows.UI.Input.h>
#include <winrt/Windows.UI.ViewManagement.Core.h>
#include <winrt/Windows.Graphics.Display.Core.h>
#include <winrt/Windows.Gaming.Input.h>
#include <winrt/Windows.System.h>

#include <gamingdeviceinformation.h>

Expand All @@ -19,6 +21,7 @@
#include <condition_variable>
#include <mutex>
#include <thread>
#include <sstream>

#include "fmt/core.h"

Expand Down Expand Up @@ -410,14 +413,18 @@ void WinRTHost::ProcessEventQueue() {
struct App : implements<App, IFrameworkViewSource, IFrameworkView>
{
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())
Expand All @@ -443,6 +450,74 @@ struct App : implements<App, IFrameworkViewSource, IFrameworkView>
}
}

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<Windows::ApplicationModel::Activation::ProtocolActivatedEventArgs>()};
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<std::mutex> 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&)
{
}
Expand All @@ -463,12 +538,14 @@ struct App : implements<App, IFrameworkViewSource, IFrameworkView>
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, []() {
Expand Down Expand Up @@ -517,8 +594,22 @@ struct App : implements<App, IFrameworkViewSource, IFrameworkView>
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<bool> const& sender,
winrt::Windows::Foundation::AsyncStatus const asyncStatus) {
CommonHost::CPUThreadShutdown();
CoreApplication::Exit();
return;
});
}
else
{
CommonHost::CPUThreadShutdown();
CoreApplication::Exit();
}
}

void SetWindow(CoreWindow const& window)
Expand Down
11 changes: 8 additions & 3 deletions pcsx2-winrt/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<Identity
Name="595c25f0-b370-4d7a-9b14-3027fbd69ecf"
Publisher="CN=SirMangler"
Version="1.0.24.0" />
Version="2.0.1" />
<mp:PhoneIdentity PhoneProductId="595c25f0-b370-4d7a-9b14-3027fbd69ecf" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
<Properties>
<DisplayName>pcsx2-winrt</DisplayName>
<PublisherDisplayName>a2</PublisherDisplayName>
<PublisherDisplayName>SirMangler</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
</Properties>
<Dependencies>
Expand All @@ -18,11 +18,16 @@
</Resources>
<Applications>
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="pcsx2_winrt.App">
<uap:VisualElements DisplayName="pcsx2-winrt" Description="A project for a C++/WinRT Universal Windows Platform (UWP) app directly implementing CoreApplication"
<uap:VisualElements DisplayName="XBSX2.0" Description="PCSX2 for UWP/Xbox."
Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" BackgroundColor="transparent">
<uap:SplashScreen Image="Assets\SplashScreen.png" />
<uap:DefaultTile/>
</uap:VisualElements>
<Extensions>
<uap:Extension Category="windows.protocol">
<uap:Protocol Name="xbsx2"/>
</uap:Extension>
</Extensions>
</Application>
</Applications>
<Capabilities>
Expand Down
4 changes: 2 additions & 2 deletions pcsx2-winrt/pcsx2-winrt.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<CppWinRTRootNamespaceAutoMerge>true</CppWinRTRootNamespaceAutoMerge>
<MinimalCoreWin>true</MinimalCoreWin>
<ProjectGuid>{5e7b753a-b43d-43aa-a373-bba85f9fac80}</ProjectGuid>
<ProjectName>pcsx2-winrt</ProjectName>
<ProjectName>xbsx2</ProjectName>
<RootNamespace>pcsx2_winrt</RootNamespace>
<DefaultLanguage>en-US</DefaultLanguage>
<MinimumVisualStudioVersion>15.0</MinimumVisualStudioVersion>
Expand Down Expand Up @@ -57,7 +57,7 @@
</ImportGroup>
<PropertyGroup Label="UserMacros">
<GenerateAppInstallerFile>False</GenerateAppInstallerFile>
<AppxAutoIncrementPackageRevision>True</AppxAutoIncrementPackageRevision>
<AppxAutoIncrementPackageRevision>False</AppxAutoIncrementPackageRevision>
<GenerateTestArtifacts>True</GenerateTestArtifacts>
<AppxBundle>Always</AppxBundle>
<AppxBundlePlatforms>x64</AppxBundlePlatforms>
Expand Down
4 changes: 2 additions & 2 deletions pcsx2/ImGui/FullscreenUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
1 change: 1 addition & 0 deletions pcsx2/pcsx2.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@
<None Include="GS\Renderers\Vulkan\VKEntryPoints.inl">
<Filter>System\Ps2\GS\Renderers\Vulkan</Filter>
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Patch.cpp">
Expand Down

0 comments on commit 8efb67d

Please sign in to comment.