From 8f10cc4af522fca88ef83b0df77e2c3006385e87 Mon Sep 17 00:00:00 2001 From: Cullen Waters Date: Mon, 5 Dec 2016 15:42:04 -0500 Subject: [PATCH] Making sidecar configurable via config file instead of hardcoded (#16) --- Source/Shared/local_config.cpp | 10 +++++ Source/Shared/local_config.h | 2 + Source/System/Sidecar/app_service_client.cpp | 39 +++++++++++++------- Source/System/Sidecar/app_service_client.h | 11 ++++-- Source/System/Sidecar/user_impl_sidecar.cpp | 5 ++- 5 files changed, 48 insertions(+), 19 deletions(-) diff --git a/Source/Shared/local_config.cpp b/Source/Shared/local_config.cpp index 7e1eb0e4..c7051f18 100644 --- a/Source/Shared/local_config.cpp +++ b/Source/Shared/local_config.cpp @@ -161,6 +161,16 @@ bool local_config::use_first_party_token() return get_bool_from_config(_T("FirstParty"), false, false); } +string_t local_config::sidecar_pfn() +{ + return get_value_from_config(_T("SidecarPFN"), false, _T("")); +} + +string_t local_config::sidecar_appchannel() +{ + return get_value_from_config(_T("SidecarAppChannel"), false, _T("")); +} + #if XSAPI_I string_t local_config::apns_environment() { diff --git a/Source/Shared/local_config.h b/Source/Shared/local_config.h index 7b1ba1ec..71c21ee3 100644 --- a/Source/Shared/local_config.h +++ b/Source/Shared/local_config.h @@ -46,6 +46,8 @@ public: virtual string_t sandbox(); virtual string_t client_secret(); virtual bool use_first_party_token(); + virtual string_t sidecar_pfn(); + virtual string_t sidecar_appchannel(); virtual string_t get_value_from_local_storage(_In_ const string_t& name); virtual xbox_live_result write_value_to_local_storage(_In_ const string_t& name, _In_ const string_t& value); diff --git a/Source/System/Sidecar/app_service_client.cpp b/Source/System/Sidecar/app_service_client.cpp index 37426e7b..c9d251aa 100644 --- a/Source/System/Sidecar/app_service_client.cpp +++ b/Source/System/Sidecar/app_service_client.cpp @@ -127,6 +127,8 @@ namespace app_service { std::mutex m_pendingRequestsLock; pplx::event m_connectionReady; HWND m_hWnd = NULL; + Platform::String^ m_pfn = _T(""); + Platform::String^ m_appChannelName = _T(""); pplx::task ensure_connection(); void on_service_closed(_In_ AppServiceConnection ^sender, _In_ AppServiceClosedEventArgs ^args); @@ -148,9 +150,9 @@ namespace app_service { m_connectionReady.reset(); m_connection = ref new AppServiceConnection(); - //TODO cuwaters: remove the hardcoded app identity information - m_connection->AppServiceName = "xblsidecar-33535007"; - m_connection->PackageFamilyName = "38133JasonSandlin.8845AE5E9DE2_txz1v18ddy4v6";//Windows::ApplicationModel::Package::Current->Id->FamilyName; + m_connection->AppServiceName = m_appChannelName; + m_connection->PackageFamilyName = m_pfn; + return create_task(m_connection->OpenAsync()) .then([](pplx::task statusTask) { @@ -231,9 +233,8 @@ namespace app_service { } REQUEST message = { requestTracker->request_id(), params... }; - //TODO: cuwaters remove hard-coded app identity bits auto createWindowTask = uiMode == ui_mode::allowed ? - concurrency::create_task(Windows::System::Launcher::LaunchUriAsync(ref new Windows::Foundation::Uri("xblsidecar-33535007://"))) : + concurrency::create_task(Windows::System::Launcher::LaunchUriAsync(ref new Windows::Foundation::Uri(m_appChannelName))) : task_from_result(true); return createWindowTask @@ -271,11 +272,15 @@ namespace app_service { } } // anonymous namespace - pplx::task> sign_in( - _In_ bool showUI, - _In_ bool forceRefresh + pplx::task> sign_in( + _In_ bool showUI, + _In_ bool forceRefresh, + _In_ std::shared_ptr config ) - { + { + m_pfn = ref new Platform::String(config->sidecar_pfn().c_str()); + m_appChannelName = ref new Platform::String(config->sidecar_appchannel().c_str()); + auto task = send_app_service_request_and_wait_for_response( showUI ? ui_mode::allowed : ui_mode::not_allowed, showUI, @@ -291,9 +296,13 @@ namespace app_service { _In_ const string_t& headers, _In_ const std::vector& bytes, _In_ bool promptForCredentialsIfNeeded, - _In_ bool forceRefresh + _In_ bool forceRefresh, + _In_ std::shared_ptr config ) - { + { + m_pfn = ref new Platform::String(config->sidecar_pfn().c_str()); + m_appChannelName = ref new Platform::String(config->sidecar_appchannel().c_str()); + auto task = send_app_service_request_and_wait_for_response( promptForCredentialsIfNeeded ? ui_mode::allowed : ui_mode::not_allowed, httpMethod, @@ -308,9 +317,13 @@ namespace app_service { } pplx::task> show_title_achievements_ui( - _In_ uint32_t titleId + _In_ uint32_t titleId, + _In_ std::shared_ptr config ) - { + { + m_pfn = ref new Platform::String(config->sidecar_pfn().c_str()); + m_appChannelName = ref new Platform::String(config->sidecar_appchannel().c_str()); + auto task = send_app_service_request_and_wait_for_response( ui_mode::allowed, titleId); diff --git a/Source/System/Sidecar/app_service_client.h b/Source/System/Sidecar/app_service_client.h index d2c8fea4..7b05fc39 100644 --- a/Source/System/Sidecar/app_service_client.h +++ b/Source/System/Sidecar/app_service_client.h @@ -25,7 +25,8 @@ namespace app_service pplx::task> sign_in( _In_ bool showUI, - _In_ bool forceRefresh + _In_ bool forceRefresh, + _In_ std::shared_ptr config ); pplx::task > @@ -36,15 +37,17 @@ namespace app_service _In_ const string_t& headers, _In_ const std::vector& bytes, _In_ bool promptForCredentialsIfNeeded, - _In_ bool forceRefresh + _In_ bool forceRefresh, + _In_ std::shared_ptr config ); pplx::task> show_title_achievements_ui( - _In_ uint32_t titleId + _In_ uint32_t titleId, + _In_ std::shared_ptr config ); - void set_hwnd(_In_ HWND hWnd); + void set_hwnd(_In_ HWND hWnd); } } diff --git a/Source/System/Sidecar/user_impl_sidecar.cpp b/Source/System/Sidecar/user_impl_sidecar.cpp index a56bc4b4..e48a6d54 100644 --- a/Source/System/Sidecar/user_impl_sidecar.cpp +++ b/Source/System/Sidecar/user_impl_sidecar.cpp @@ -30,7 +30,7 @@ pplx::task> user_impl_sidecar::sign_in_impl( ) { std::weak_ptr thisWeakPtr = std::dynamic_pointer_cast(shared_from_this()); - auto task = app_service::client::sign_in(showUI, forceRefresh) + auto task = app_service::client::sign_in(showUI, forceRefresh, m_localConfig) .then([thisWeakPtr](xbox_live_result result) { std::shared_ptr pThis(thisWeakPtr.lock()); @@ -77,7 +77,8 @@ user_impl_sidecar::internal_get_token_and_signature( headers, bytes, promptForCredentialsIfNeeded, - forceRefresh + forceRefresh, + m_localConfig ) .then([thisWeakPtr](xbox_live_result result) {