-
Notifications
You must be signed in to change notification settings - Fork 8.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use WinGet API to improve Quick Fix results #17614
Changes from 6 commits
da66ca6
6943f2c
1ceda62
23013ba
7e48278
dd2e524
49d60f8
ef4d64c
3ef9f09
84cc026
a0f2d88
bf8d8c2
c436521
910f559
dde86c1
b5454e3
6cfc031
987ad91
215d2c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. See LICENSE in the project root for license information. --> | ||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Native-Platform Condition="'$(Platform)' == 'Win32'">x86</Native-Platform> | ||
<Native-Platform Condition="'$(Platform)' != 'Win32'">$(Platform)</Native-Platform> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="$(WinGetPackageRoot)\lib\Microsoft.Management.Deployment.winmd"> | ||
<IsWinMDFile>true</IsWinMDFile> | ||
<Implementation>$(WinGetPackageRoot)\runtimes\win10-$(Native-Platform)\native\winrtact.dll</Implementation> | ||
|
||
</Reference> | ||
</ItemGroup> | ||
<Target Name="_FixWinGetWinmdPackaging" BeforeTargets="_ComputeAppxPackagePayload"> | ||
<ItemGroup> | ||
<PackagingOutputs Include="$(WinGetPackageRoot)\lib\Microsoft.Management.Deployment.winmd"> | ||
<OutputGroup>CustomOutputGroupForPackaging</OutputGroup> | ||
<ProjectName>$(ProjectName)</ProjectName> | ||
<Implementation>winrtact.dll</Implementation> | ||
|
||
<TargetPath>Microsoft.Management.Deployment.winmd</TargetPath> | ||
</PackagingOutputs> | ||
</ItemGroup> | ||
</Target> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝: it's so gross that we have to write this ourselves There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, which is why the nuget package is soon going to include a DLL that handles this part (exposes the activation factory so that one can just use WinRT language projections as normal). |
||
// Licensed under the MIT license. | ||
// | ||
// Module Name: | ||
// - WindowsPackageManagerFactory.h | ||
// | ||
// Abstract: | ||
// - These set of factories are designed to create production-level instances of WinGet objects. | ||
// Elevated sessions require manual activation of WinGet objects, | ||
// while non-elevated sessions can use the standard WinRT activation system. | ||
// Author: | ||
// - Carlos Zamora (carlos-zamora) 23-Jul-2024 | ||
|
||
#pragma once | ||
|
||
#include "../../types/inc/utils.hpp" | ||
#include <combaseapi.h> | ||
#include <wil/result_macros.h> | ||
#include <wil/win32_helpers.h> | ||
#include <type_traits> | ||
carlos-zamora marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#include <winrt/Microsoft.Management.Deployment.h> | ||
|
||
namespace winrt::TerminalApp::implementation | ||
{ | ||
class WindowsPackageManagerFactory | ||
{ | ||
public: | ||
static WindowsPackageManagerFactory& Instance() | ||
{ | ||
static WindowsPackageManagerFactory instance; | ||
return instance; | ||
} | ||
carlos-zamora marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Delete copy constructor and assignment operator | ||
WindowsPackageManagerFactory(const WindowsPackageManagerFactory&) = delete; | ||
WindowsPackageManagerFactory& operator=(const WindowsPackageManagerFactory&) = delete; | ||
|
||
winrt::Microsoft::Management::Deployment::PackageManager CreatePackageManager() | ||
{ | ||
return CreateInstance<winrt::Microsoft::Management::Deployment::PackageManager>(); | ||
} | ||
|
||
winrt::Microsoft::Management::Deployment::FindPackagesOptions CreateFindPackagesOptions() | ||
{ | ||
return CreateInstance<winrt::Microsoft::Management::Deployment::FindPackagesOptions>(); | ||
} | ||
|
||
winrt::Microsoft::Management::Deployment::CreateCompositePackageCatalogOptions CreateCreateCompositePackageCatalogOptions() | ||
{ | ||
return CreateInstance<winrt::Microsoft::Management::Deployment::CreateCompositePackageCatalogOptions>(); | ||
} | ||
|
||
winrt::Microsoft::Management::Deployment::InstallOptions CreateInstallOptions() | ||
{ | ||
return CreateInstance<winrt::Microsoft::Management::Deployment::InstallOptions>(); | ||
} | ||
|
||
winrt::Microsoft::Management::Deployment::UninstallOptions CreateUninstallOptions() | ||
{ | ||
return CreateInstance<winrt::Microsoft::Management::Deployment::UninstallOptions>(); | ||
} | ||
|
||
winrt::Microsoft::Management::Deployment::PackageMatchFilter CreatePackageMatchFilter() | ||
{ | ||
return CreateInstance<winrt::Microsoft::Management::Deployment::PackageMatchFilter>(); | ||
} | ||
|
||
private: | ||
wil::unique_hmodule _winrtactModule; | ||
|
||
|
||
WindowsPackageManagerFactory() | ||
{ | ||
if (::Microsoft::Console::Utils::IsRunningElevated()) | ||
{ | ||
_winrtactModule.reset(LoadLibraryExW(L"winrtact.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32)); | ||
|
||
} | ||
} | ||
|
||
template<typename T> | ||
T CreateInstance(const guid& clsid, const guid& iid) | ||
{ | ||
if (::Microsoft::Console::Utils::IsRunningElevated()) | ||
{ | ||
winrt::com_ptr<::IUnknown> result{}; | ||
try | ||
{ | ||
extern HRESULT WinGetServerManualActivation_CreateInstance(REFCLSID rclsid, REFIID riid, UINT32 flags, void** out); | ||
|
||
auto createFn = reinterpret_cast<HRESULT (*)(REFCLSID, REFIID, UINT32, void**)>(GetProcAddress(_winrtactModule.get(), "WinGetServerManualActivation_CreateInstance")); | ||
THROW_LAST_ERROR_IF(!createFn); | ||
THROW_IF_FAILED(createFn(clsid, iid, 0, result.put_void())); | ||
return result.as<T>(); | ||
carlos-zamora marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
catch (...) | ||
{ | ||
} | ||
} | ||
return winrt::create_instance<T>(clsid, CLSCTX_ALL); | ||
} | ||
|
||
template<typename T> | ||
T CreateInstance() | ||
{ | ||
winrt::guid clsid, iid; | ||
if (std::is_same<T, winrt::Microsoft::Management::Deployment::PackageManager>::value) | ||
{ | ||
clsid = winrt::guid{ "C53A4F16-787E-42A4-B304-29EFFB4BF597" }; | ||
iid = winrt::guid_of<winrt::Microsoft::Management::Deployment::IPackageManager>(); | ||
} | ||
else if (std::is_same<T, winrt::Microsoft::Management::Deployment::FindPackagesOptions>::value) | ||
{ | ||
clsid = winrt::guid{ "572DED96-9C60-4526-8F92-EE7D91D38C1A" }; | ||
iid = winrt::guid_of<winrt::Microsoft::Management::Deployment::IFindPackagesOptions>(); | ||
} | ||
else if (std::is_same<T, winrt::Microsoft::Management::Deployment::CreateCompositePackageCatalogOptions>::value) | ||
{ | ||
clsid = winrt::guid{ "526534B8-7E46-47C8-8416-B1685C327D37" }; | ||
iid = winrt::guid_of<winrt::Microsoft::Management::Deployment::ICreateCompositePackageCatalogOptions>(); | ||
} | ||
else if (std::is_same<T, winrt::Microsoft::Management::Deployment::InstallOptions>::value) | ||
{ | ||
clsid = winrt::guid{ "1095F097-EB96-453B-B4E6-1613637F3B14" }; | ||
iid = winrt::guid_of<winrt::Microsoft::Management::Deployment::IInstallOptions>(); | ||
} | ||
else if (std::is_same<T, winrt::Microsoft::Management::Deployment::UninstallOptions>::value) | ||
{ | ||
clsid = winrt::guid{ "E1D9A11E-9F85-4D87-9C17-2B93143ADB8D" }; | ||
iid = winrt::guid_of<winrt::Microsoft::Management::Deployment::IUninstallOptions>(); | ||
} | ||
else if (std::is_same<T, winrt::Microsoft::Management::Deployment::PackageMatchFilter>::value) | ||
{ | ||
clsid = winrt::guid{ "D02C9DAF-99DC-429C-B503-4E504E4AB000" }; | ||
iid = winrt::guid_of<winrt::Microsoft::Management::Deployment::IPackageMatchFilter>(); | ||
} | ||
|
||
return CreateInstance<T>(clsid, iid); | ||
} | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
<TerminalCppWinrt>true</TerminalCppWinrt> | ||
<TerminalThemeHelpers>true</TerminalThemeHelpers> | ||
<TerminalMUX>true</TerminalMUX> | ||
<TerminalWinGetInterop>true</TerminalWinGetInterop> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need this for WindowsTerminal.exe in addition to TerminalApp? Is this cause the dependency doesn't get rolled up? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct. Just tested it without it. The QF menu won't appear. |
||
</PropertyGroup> | ||
|
||
<Import Project="..\..\..\common.openconsole.props" Condition="'$(OpenConsoleDir)'==''" /> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝: weird to me that this isn't just in their nuget package
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are working on improving this facet.