From 8759ca4577849652215450c0b80672d28ba4fc93 Mon Sep 17 00:00:00 2001 From: John Preston Date: Sun, 26 Sep 2021 17:17:57 +0400 Subject: [PATCH] Rewrite bingmaps check to C++/WinRT. --- .../SourceFiles/platform/win/specific_win.cpp | 45 ++++++++++--------- Telegram/lib_base | 2 +- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/Telegram/SourceFiles/platform/win/specific_win.cpp b/Telegram/SourceFiles/platform/win/specific_win.cpp index 97c2f1c893..f8e8d85eb5 100644 --- a/Telegram/SourceFiles/platform/win/specific_win.cpp +++ b/Telegram/SourceFiles/platform/win/specific_win.cpp @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/win/windows_app_user_model_id.h" #include "platform/win/windows_dlls.h" #include "base/platform/base_platform_info.h" +#include "base/platform/win/base_windows_winrt.h" #include "base/call_delayed.h" #include "lang/lang_keys.h" #include "mainwindow.h" @@ -547,27 +548,29 @@ void psSendToMenu(bool send, bool silent) { } bool psLaunchMaps(const Data::LocationPoint &point) { - IApplicationAssociationRegistration *aar = nullptr; - - const auto hr = CoCreateInstance( - CLSID_ApplicationAssociationRegistration, - nullptr, - CLSCTX_INPROC, - __uuidof(IApplicationAssociationRegistration), - reinterpret_cast(&aar)); - - if (SUCCEEDED(hr && aar)) { - LPWSTR current_app = nullptr; - const auto result = aar->QueryCurrentDefault( - L"bingmaps", - AT_URLPROTOCOL, - AL_EFFECTIVE, - ¤t_app); - - if (FAILED(result)) { - return false; - } + const auto aar = base::WinRT::TryCreateInstance< + IApplicationAssociationRegistration + >(CLSID_ApplicationAssociationRegistration); + if (!aar) { + return false; } - return QDesktopServices::openUrl(qsl("bingmaps:?lvl=16&collection=point.%1_%2_Point").arg(point.latAsString()).arg(point.lonAsString())); + auto handler = (LPWSTR)nullptr; + const auto guard = gsl::finally([&] { + if (handler) { + ::CoTaskMemFree(handler); + } + }); + const auto result = aar->QueryCurrentDefault( + L"bingmaps", + AT_URLPROTOCOL, + AL_EFFECTIVE, + &handler); + if (FAILED(result) || !handler) { + return false; + } + + const auto url = u"bingmaps:?lvl=16&collection=point.%1_%2_Point"_q; + return QDesktopServices::openUrl( + url.arg(point.latAsString()).arg(point.lonAsString())); } diff --git a/Telegram/lib_base b/Telegram/lib_base index dae9570be2..5f1c3cb09c 160000 --- a/Telegram/lib_base +++ b/Telegram/lib_base @@ -1 +1 @@ -Subproject commit dae9570be294027a6ca4a4f2e9100077ef2c5e55 +Subproject commit 5f1c3cb09c1d9e6728090146c66ba34202e6aba6