commit 9171c1cf8e15c50b94705e3fe1061cf955fdc2e1 parent 5b00741faf07d0ac72aea3bda07b08ac4fbc25f6 Author: Chacón <lechacon@users.noreply.github.com> Date: Wed, 22 Sep 2021 08:20:41 -0700 Add sample project for calling COM interface (#1449) Diffstat:
31 files changed, 1401 insertions(+), 5 deletions(-)
diff --git a/.github/actions/spelling/allow.txt b/.github/actions/spelling/allow.txt @@ -84,6 +84,7 @@ cwctype datatelemetry dbconn DBId +debugbreak declspec decltype declval @@ -163,6 +164,7 @@ gdi getline github githubusercontent +globals hfile HGLOBAL HIDECANCEL @@ -201,6 +203,7 @@ ILogger impl Inet inno +INotify INPROC Inq installertype @@ -212,6 +215,7 @@ INSTALLPATH INSTALLUILEVEL interop INVALIDARG +IObservable iomanip iostream IOutput @@ -312,6 +316,7 @@ OAuth ofstream opencode opensource +openxmlformats ostream ostringstream OSVERSIONINFOEXW diff --git a/.github/actions/spelling/excludes.txt b/.github/actions/spelling/excludes.txt @@ -23,6 +23,7 @@ ignore$ \.vdproj$ \.wapproj$ \.wav$ +\.winmd$ ^cgmanifest\.json$ ^Localization/ ^NOTICE$ diff --git a/src/AppInstallerCLICore/Resources.h b/src/AppInstallerCLICore/Resources.h @@ -224,7 +224,9 @@ namespace AppInstaller::CLI::Resource WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelAuthor); WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelCopyright); WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelCopyrightUrl); + WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelDependencies); WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelDescription); + WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelExternalDependencies); WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelInstaller); WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelInstallerLocale); WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelInstallerProductId); @@ -235,6 +237,7 @@ namespace AppInstaller::CLI::Resource WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelLicense); WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelLicenseUrl); WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelMoniker); + WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelPackageDependencies); WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelPackageUrl); WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelPrivacyUrl); WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelPublisher); @@ -243,6 +246,8 @@ namespace AppInstaller::CLI::Resource WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelReleaseNotes); WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelReleaseNotesUrl); WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelVersion); + WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelWindowsFeaturesDependencies); + WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelWindowsLibrariesDependencies); WINGET_DEFINE_RESOURCE_STRINGID(ShowVersion); WINGET_DEFINE_RESOURCE_STRINGID(SilentArgumentDescription); WINGET_DEFINE_RESOURCE_STRINGID(SingleCharAfterDashError); diff --git a/src/AppInstallerCLICore/Workflows/ShowFlow.cpp b/src/AppInstallerCLICore/Workflows/ShowFlow.cpp @@ -152,23 +152,23 @@ namespace AppInstaller::CLI::Workflow if (dependencies.HasAny()) { - info << Execution::ManifestInfoEmphasis << " Dependencies: " << std::endl; + info << Execution::ManifestInfoEmphasis << " "_liv << Resource::String::ShowLabelDependencies << ' ' << std::endl; if (dependencies.HasAnyOf(Manifest::DependencyType::WindowsFeature)) { - info << " - WindowsFeatures: " << std::endl; + info << " - "_liv << Resource::String::ShowLabelWindowsFeaturesDependencies << ' ' << std::endl; dependencies.ApplyToType(Manifest::DependencyType::WindowsFeature, [&info](Manifest::Dependency dependency) {info << " "_liv << dependency.Id << std::endl; }); } if (dependencies.HasAnyOf(Manifest::DependencyType::WindowsLibrary)) { - info << " - WindowsLibraries: " << std::endl; + info << " - "_liv << Resource::String::ShowLabelWindowsLibrariesDependencies << ' ' << std::endl; dependencies.ApplyToType(Manifest::DependencyType::WindowsLibrary, [&info](Manifest::Dependency dependency) {info << " "_liv << dependency.Id << std::endl; }); } if (dependencies.HasAnyOf(Manifest::DependencyType::Package)) { - info << " - PackageDependencies: " << std::endl; + info << " - "_liv << Resource::String::ShowLabelPackageDependencies << ' ' << std::endl; dependencies.ApplyToType(Manifest::DependencyType::Package, [&info](Manifest::Dependency dependency) { info << " "_liv << dependency.Id; @@ -179,7 +179,7 @@ namespace AppInstaller::CLI::Workflow if (dependencies.HasAnyOf(Manifest::DependencyType::External)) { - info << " - ExternalDependencies: " << std::endl; + info << " - "_liv << Resource::String::ShowLabelExternalDependencies << ' ' << std::endl; dependencies.ApplyToType(Manifest::DependencyType::External, [&info](Manifest::Dependency dependency) {info << " "_liv << dependency.Id << std::endl; }); } } diff --git a/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw b/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw @@ -1017,6 +1017,21 @@ Do you agree to the terms?</value> <data name="ShowLabelVersion" xml:space="preserve"> <value>Version:</value> </data> + <data name="ShowLabelDependencies" xml:space="preserve"> + <value>Dependencies:</value> + </data> + <data name="ShowLabelWindowsFeaturesDependencies" xml:space="preserve"> + <value>Windows Features:</value> + </data> + <data name="ShowLabelWindowsLibrariesDependencies" xml:space="preserve"> + <value>Windows Libraries:</value> + </data> + <data name="ShowLabelPackageDependencies" xml:space="preserve"> + <value>Package Dependencies:</value> + </data> + <data name="ShowLabelExternalDependencies" xml:space="preserve"> + <value>External Dependencies:</value> + </data> <data name="PromptOptionNo" xml:space="preserve"> <value>No</value> </data> diff --git a/tools/SampleWinGetUWPCaller/AppInstallerCaller.sln b/tools/SampleWinGetUWPCaller/AppInstallerCaller.sln @@ -0,0 +1,51 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30704.19 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AppInstallerCaller", "AppInstallerCaller\AppInstallerCaller.vcxproj", "{37F1FD2A-4D63-45A0-82AA-66EF126CB322}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|ARM = Debug|ARM + Debug|ARM64 = Debug|ARM64 + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|ARM = Release|ARM + Release|ARM64 = Release|ARM64 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {37F1FD2A-4D63-45A0-82AA-66EF126CB322}.Debug|ARM.ActiveCfg = Debug|ARM + {37F1FD2A-4D63-45A0-82AA-66EF126CB322}.Debug|ARM.Build.0 = Debug|ARM + {37F1FD2A-4D63-45A0-82AA-66EF126CB322}.Debug|ARM.Deploy.0 = Debug|ARM + {37F1FD2A-4D63-45A0-82AA-66EF126CB322}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {37F1FD2A-4D63-45A0-82AA-66EF126CB322}.Debug|ARM64.Build.0 = Debug|ARM64 + {37F1FD2A-4D63-45A0-82AA-66EF126CB322}.Debug|ARM64.Deploy.0 = Debug|ARM64 + {37F1FD2A-4D63-45A0-82AA-66EF126CB322}.Debug|x64.ActiveCfg = Debug|x64 + {37F1FD2A-4D63-45A0-82AA-66EF126CB322}.Debug|x64.Build.0 = Debug|x64 + {37F1FD2A-4D63-45A0-82AA-66EF126CB322}.Debug|x64.Deploy.0 = Debug|x64 + {37F1FD2A-4D63-45A0-82AA-66EF126CB322}.Debug|x86.ActiveCfg = Debug|Win32 + {37F1FD2A-4D63-45A0-82AA-66EF126CB322}.Debug|x86.Build.0 = Debug|Win32 + {37F1FD2A-4D63-45A0-82AA-66EF126CB322}.Debug|x86.Deploy.0 = Debug|Win32 + {37F1FD2A-4D63-45A0-82AA-66EF126CB322}.Release|ARM.ActiveCfg = Release|ARM + {37F1FD2A-4D63-45A0-82AA-66EF126CB322}.Release|ARM.Build.0 = Release|ARM + {37F1FD2A-4D63-45A0-82AA-66EF126CB322}.Release|ARM.Deploy.0 = Release|ARM + {37F1FD2A-4D63-45A0-82AA-66EF126CB322}.Release|ARM64.ActiveCfg = Release|ARM64 + {37F1FD2A-4D63-45A0-82AA-66EF126CB322}.Release|ARM64.Build.0 = Release|ARM64 + {37F1FD2A-4D63-45A0-82AA-66EF126CB322}.Release|ARM64.Deploy.0 = Release|ARM64 + {37F1FD2A-4D63-45A0-82AA-66EF126CB322}.Release|x64.ActiveCfg = Release|x64 + {37F1FD2A-4D63-45A0-82AA-66EF126CB322}.Release|x64.Build.0 = Release|x64 + {37F1FD2A-4D63-45A0-82AA-66EF126CB322}.Release|x64.Deploy.0 = Release|x64 + {37F1FD2A-4D63-45A0-82AA-66EF126CB322}.Release|x86.ActiveCfg = Release|Win32 + {37F1FD2A-4D63-45A0-82AA-66EF126CB322}.Release|x86.Build.0 = Release|Win32 + {37F1FD2A-4D63-45A0-82AA-66EF126CB322}.Release|x86.Deploy.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {D7D1DE2E-A7C1-4FB3-A191-C848562A3EBD} + EndGlobalSection +EndGlobal diff --git a/tools/SampleWinGetUWPCaller/AppInstallerCaller/App.cpp b/tools/SampleWinGetUWPCaller/AppInstallerCaller/App.cpp @@ -0,0 +1,119 @@ +#include "pch.h" + +#include "App.h" +#include "MainPage.h" + +using namespace winrt; +using namespace Windows::ApplicationModel; +using namespace Windows::ApplicationModel::Activation; +using namespace Windows::Foundation; +using namespace Windows::UI::Xaml; +using namespace Windows::UI::Xaml::Controls; +using namespace Windows::UI::Xaml::Navigation; +using namespace AppInstallerCaller; +using namespace AppInstallerCaller::implementation; + +/// <summary> +/// Initializes the singleton application object. This is the first line of authored code +/// executed, and as such is the logical equivalent of main() or WinMain(). +/// </summary> +App::App() +{ + InitializeComponent(); + Suspending({ this, &App::OnSuspending }); + +#if defined _DEBUG && !defined DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION + UnhandledException([this](IInspectable const&, UnhandledExceptionEventArgs const& e) + { + if (IsDebuggerPresent()) + { + auto errorMessage = e.Message(); + __debugbreak(); + } + }); +#endif +} + +/// <summary> +/// Invoked when the application is launched normally by the end user. Other entry points +/// will be used such as when the application is launched to open a specific file. +/// </summary> +/// <param name="e">Details about the launch request and process.</param> +void App::OnLaunched(LaunchActivatedEventArgs const& e) +{ + Frame rootFrame{ nullptr }; + auto content = Window::Current().Content(); + if (content) + { + rootFrame = content.try_as<Frame>(); + } + + // Do not repeat app initialization when the Window already has content, + // just ensure that the window is active + if (rootFrame == nullptr) + { + // Create a Frame to act as the navigation context and associate it with + // a SuspensionManager key + rootFrame = Frame(); + + rootFrame.NavigationFailed({ this, &App::OnNavigationFailed }); + + if (e.PreviousExecutionState() == ApplicationExecutionState::Terminated) + { + // Restore the saved session state only when appropriate, scheduling the + // final launch steps after the restore is complete + } + + if (e.PrelaunchActivated() == false) + { + if (rootFrame.Content() == nullptr) + { + // When the navigation stack isn't restored navigate to the first page, + // configuring the new page by passing required information as a navigation + // parameter + rootFrame.Navigate(xaml_typename<AppInstallerCaller::MainPage>(), box_value(e.Arguments())); + } + // Place the frame in the current Window + Window::Current().Content(rootFrame); + // Ensure the current window is active + Window::Current().Activate(); + } + } + else + { + if (e.PrelaunchActivated() == false) + { + if (rootFrame.Content() == nullptr) + { + // When the navigation stack isn't restored navigate to the first page, + // configuring the new page by passing required information as a navigation + // parameter + rootFrame.Navigate(xaml_typename<AppInstallerCaller::MainPage>(), box_value(e.Arguments())); + } + // Ensure the current window is active + Window::Current().Activate(); + } + } +} + +/// <summary> +/// Invoked when application execution is being suspended. Application state is saved +/// without knowing whether the application will be terminated or resumed with the contents +/// of memory still intact. +/// </summary> +/// <param name="sender">The source of the suspend request.</param> +/// <param name="e">Details about the suspend request.</param> +void App::OnSuspending([[maybe_unused]] IInspectable const& sender, [[maybe_unused]] SuspendingEventArgs const& e) +{ + // Save application state and stop any background activity +} + +/// <summary> +/// Invoked when Navigation to a certain page fails +/// </summary> +/// <param name="sender">The Frame which failed navigation</param> +/// <param name="e">Details about the navigation failure</param> +void App::OnNavigationFailed(IInspectable const&, NavigationFailedEventArgs const& e) +{ + throw hresult_error(E_FAIL, hstring(L"Failed to load Page ") + e.SourcePageType().Name); +}+ \ No newline at end of file diff --git a/tools/SampleWinGetUWPCaller/AppInstallerCaller/App.h b/tools/SampleWinGetUWPCaller/AppInstallerCaller/App.h @@ -0,0 +1,14 @@ +#pragma once +#include "App.xaml.g.h" + +namespace winrt::AppInstallerCaller::implementation +{ + struct App : AppT<App> + { + App(); + + void OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs const&); + void OnSuspending(IInspectable const&, Windows::ApplicationModel::SuspendingEventArgs const&); + void OnNavigationFailed(IInspectable const&, Windows::UI::Xaml::Navigation::NavigationFailedEventArgs const&); + }; +} diff --git a/tools/SampleWinGetUWPCaller/AppInstallerCaller/App.idl b/tools/SampleWinGetUWPCaller/AppInstallerCaller/App.idl @@ -0,0 +1,3 @@ +namespace AppInstallerCaller +{ +} diff --git a/tools/SampleWinGetUWPCaller/AppInstallerCaller/App.xaml b/tools/SampleWinGetUWPCaller/AppInstallerCaller/App.xaml @@ -0,0 +1,7 @@ +<Application + x:Class="AppInstallerCaller.App" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:local="using:AppInstallerCaller"> + +</Application> diff --git a/tools/SampleWinGetUWPCaller/AppInstallerCaller/AppInstallerCaller.vcxproj b/tools/SampleWinGetUWPCaller/AppInstallerCaller/AppInstallerCaller.vcxproj @@ -0,0 +1,203 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.210503.1\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.210503.1\build\native\Microsoft.Windows.CppWinRT.props')" /> + <PropertyGroup Label="Globals"> + <CppWinRTOptimized>true</CppWinRTOptimized> + <CppWinRTRootNamespaceAutoMerge>true</CppWinRTRootNamespaceAutoMerge> + <CppWinRTGenerateWindowsMetadata>true</CppWinRTGenerateWindowsMetadata> + <MinimalCoreWin>true</MinimalCoreWin> + <ProjectGuid>{37f1fd2a-4d63-45a0-82aa-66ef126cb322}</ProjectGuid> + <ProjectName>AppInstallerCaller</ProjectName> + <RootNamespace>AppInstallerCaller</RootNamespace> + <DefaultLanguage>en-US</DefaultLanguage> + <MinimumVisualStudioVersion>15.0</MinimumVisualStudioVersion> + <AppContainerApplication>true</AppContainerApplication> + <ApplicationType>Windows Store</ApplicationType> + <ApplicationTypeRevision>10.0</ApplicationTypeRevision> + <WindowsTargetPlatformVersion Condition=" '$(WindowsTargetPlatformVersion)' == '' ">10.0.19041.0</WindowsTargetPlatformVersion> + <WindowsTargetPlatformMinVersion>10.0.19041.0</WindowsTargetPlatformMinVersion> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Debug|ARM"> + <Configuration>Debug</Configuration> + <Platform>ARM</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Debug|ARM64"> + <Configuration>Debug</Configuration> + <Platform>ARM64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Debug|Win32"> + <Configuration>Debug</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Debug|x64"> + <Configuration>Debug</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|ARM"> + <Configuration>Release</Configuration> + <Platform>ARM</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|ARM64"> + <Configuration>Release</Configuration> + <Platform>ARM64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|Win32"> + <Configuration>Release</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|x64"> + <Configuration>Release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <PlatformToolset>v140</PlatformToolset> + <PlatformToolset Condition="'$(VisualStudioVersion)' == '15.0'">v141</PlatformToolset> + <PlatformToolset Condition="'$(VisualStudioVersion)' == '16.0'">v142</PlatformToolset> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration"> + <UseDebugLibraries>true</UseDebugLibraries> + <LinkIncremental>true</LinkIncremental> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Configuration"> + <UseDebugLibraries>false</UseDebugLibraries> + <WholeProgramOptimization>true</WholeProgramOptimization> + <LinkIncremental>false</LinkIncremental> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets"> + <Import Project="PropertySheet.props" /> + </ImportGroup> + <PropertyGroup Label="UserMacros"> + <GenerateAppInstallerFile>False</GenerateAppInstallerFile> + <AppxPackageSigningEnabled>True</AppxPackageSigningEnabled> + <AppxPackageSigningTimestampDigestAlgorithm>SHA256</AppxPackageSigningTimestampDigestAlgorithm> + <AppxAutoIncrementPackageRevision>True</AppxAutoIncrementPackageRevision> + <GenerateTestArtifacts>True</GenerateTestArtifacts> + <AppxBundlePlatforms>x64</AppxBundlePlatforms> + <HoursBetweenUpdateChecks>0</HoursBetweenUpdateChecks> + <AppxBundle>Always</AppxBundle> + </PropertyGroup> + <ItemDefinitionGroup> + <ClCompile> + <PrecompiledHeader>Use</PrecompiledHeader> + <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> + <PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile> + <WarningLevel>Level4</WarningLevel> + <AdditionalOptions>%(AdditionalOptions) /bigobj</AdditionalOptions> + <!--Temporarily disable cppwinrt heap enforcement to work around xaml compiler generated std::shared_ptr use --> + <AdditionalOptions Condition="'$(CppWinRTHeapEnforcement)'==''">/DWINRT_NO_MAKE_DETECTION %(AdditionalOptions)</AdditionalOptions> + <DisableSpecificWarnings> + </DisableSpecificWarnings> + <PreprocessorDefinitions>WIN32_LEAN_AND_MEAN;WINRT_LEAN_AND_MEAN;%(PreprocessorDefinitions)</PreprocessorDefinitions> + </ClCompile> + <Link> + <GenerateWindowsMetadata>false</GenerateWindowsMetadata> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'"> + <ClCompile> + <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + </ClCompile> + <PostBuildEvent> + <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + </Command> + </PostBuildEvent> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)'=='Release'"> + <ClCompile> + <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + </ClCompile> + <Link> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + </Link> + <PostBuildEvent> + <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + </Command> + </PostBuildEvent> + </ItemDefinitionGroup> + <ItemGroup> + <ClInclude Include="InstallingPackageView.h" /> + <ClInclude Include="pch.h" /> + <ClInclude Include="App.h"> + <DependentUpon>App.xaml</DependentUpon> + </ClInclude> + <ClInclude Include="MainPage.h"> + <DependentUpon>MainPage.xaml</DependentUpon> + </ClInclude> + </ItemGroup> + <ItemGroup> + <ApplicationDefinition Include="App.xaml"> + <SubType>Designer</SubType> + </ApplicationDefinition> + <Page Include="MainPage.xaml"> + <SubType>Designer</SubType> + </Page> + </ItemGroup> + <ItemGroup> + <AppxManifest Include="Package.appxmanifest"> + <SubType>Designer</SubType> + </AppxManifest> + </ItemGroup> + <ItemGroup> + <Image Include="Assets\LockScreenLogo.scale-200.png" /> + <Image Include="Assets\SplashScreen.scale-200.png" /> + <Image Include="Assets\Square150x150Logo.scale-200.png" /> + <Image Include="Assets\Square44x44Logo.scale-200.png" /> + <Image Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png" /> + <Image Include="Assets\StoreLogo.png" /> + <Image Include="Assets\Wide310x150Logo.scale-200.png" /> + </ItemGroup> + <ItemGroup> + <ClCompile Include="InstallingPackageView.cpp" /> + <ClCompile Include="pch.cpp"> + <PrecompiledHeader>Create</PrecompiledHeader> + </ClCompile> + <ClCompile Include="App.cpp"> + <DependentUpon>App.xaml</DependentUpon> + </ClCompile> + <ClCompile Include="MainPage.cpp"> + <DependentUpon>MainPage.xaml</DependentUpon> + </ClCompile> + <ClCompile Include="$(GeneratedFilesDir)module.g.cpp" /> + </ItemGroup> + <ItemGroup> + <Midl Include="App.idl"> + <DependentUpon>App.xaml</DependentUpon> + </Midl> + <Midl Include="MainPage.idl"> + <DependentUpon>MainPage.xaml</DependentUpon> + </Midl> + </ItemGroup> + <ItemGroup> + <None Include="packages.config" /> + <None Include="PropertySheet.props" /> + </ItemGroup> + <ItemGroup> + <Reference Include="Microsoft.Management.Deployment"> + <HintPath>GeneratedFromServer\Microsoft.Management.Deployment.winmd</HintPath> + <IsWinMDFile>true</IsWinMDFile> + </Reference> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + <Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.210503.1\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.210503.1\build\native\Microsoft.Windows.CppWinRT.targets')" /> + </ImportGroup> + <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> + <PropertyGroup> + <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> + </PropertyGroup> + <Error Condition="!Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.210503.1\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.CppWinRT.2.0.210503.1\build\native\Microsoft.Windows.CppWinRT.props'))" /> + <Error Condition="!Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.210503.1\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.CppWinRT.2.0.210503.1\build\native\Microsoft.Windows.CppWinRT.targets'))" /> + </Target> +</Project>+ \ No newline at end of file diff --git a/tools/SampleWinGetUWPCaller/AppInstallerCaller/AppInstallerCaller.vcxproj.filters b/tools/SampleWinGetUWPCaller/AppInstallerCaller/AppInstallerCaller.vcxproj.filters @@ -0,0 +1,54 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup> + <ApplicationDefinition Include="App.xaml" /> + </ItemGroup> + <ItemGroup> + <Page Include="MainPage.xaml" /> + </ItemGroup> + <ItemGroup> + <Midl Include="App.idl" /> + <Midl Include="MainPage.idl" /> + </ItemGroup> + <ItemGroup> + <ClCompile Include="pch.cpp" /> + <ClCompile Include="App.cpp" /> + <ClCompile Include="MainPage.cpp" /> + <ClCompile Include="$(GeneratedFilesDir)module.g.cpp" /> + <ClCompile Include="InstallingPackageView.cpp" /> + </ItemGroup> + <ItemGroup> + <ClInclude Include="pch.h" /> + <ClInclude Include="InstallingPackageView.h" /> + </ItemGroup> + <ItemGroup> + <Image Include="Assets\Wide310x150Logo.scale-200.png"> + <Filter>Assets</Filter> + </Image> + <Image Include="Assets\StoreLogo.png"> + <Filter>Assets</Filter> + </Image> + <Image Include="Assets\Square150x150Logo.scale-200.png"> + <Filter>Assets</Filter> + </Image> + <Image Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png"> + <Filter>Assets</Filter> + </Image> + <Image Include="Assets\Square44x44Logo.scale-200.png"> + <Filter>Assets</Filter> + </Image> + <Image Include="Assets\SplashScreen.scale-200.png"> + <Filter>Assets</Filter> + </Image> + <Image Include="Assets\LockScreenLogo.scale-200.png"> + <Filter>Assets</Filter> + </Image> + </ItemGroup> + <ItemGroup> + <AppxManifest Include="Package.appxmanifest" /> + </ItemGroup> + <ItemGroup> + <None Include="PropertySheet.props" /> + <None Include="packages.config" /> + </ItemGroup> +</Project>+ \ No newline at end of file diff --git a/tools/SampleWinGetUWPCaller/AppInstallerCaller/Assets/LockScreenLogo.scale-200.png b/tools/SampleWinGetUWPCaller/AppInstallerCaller/Assets/LockScreenLogo.scale-200.png Binary files differ. diff --git a/tools/SampleWinGetUWPCaller/AppInstallerCaller/Assets/SplashScreen.scale-200.png b/tools/SampleWinGetUWPCaller/AppInstallerCaller/Assets/SplashScreen.scale-200.png Binary files differ. diff --git a/tools/SampleWinGetUWPCaller/AppInstallerCaller/Assets/Square150x150Logo.scale-200.png b/tools/SampleWinGetUWPCaller/AppInstallerCaller/Assets/Square150x150Logo.scale-200.png Binary files differ. diff --git a/tools/SampleWinGetUWPCaller/AppInstallerCaller/Assets/Square44x44Logo.scale-200.png b/tools/SampleWinGetUWPCaller/AppInstallerCaller/Assets/Square44x44Logo.scale-200.png Binary files differ. diff --git a/tools/SampleWinGetUWPCaller/AppInstallerCaller/Assets/Square44x44Logo.targetsize-24_altform-unplated.png b/tools/SampleWinGetUWPCaller/AppInstallerCaller/Assets/Square44x44Logo.targetsize-24_altform-unplated.png Binary files differ. diff --git a/tools/SampleWinGetUWPCaller/AppInstallerCaller/Assets/StoreLogo.png b/tools/SampleWinGetUWPCaller/AppInstallerCaller/Assets/StoreLogo.png Binary files differ. diff --git a/tools/SampleWinGetUWPCaller/AppInstallerCaller/Assets/Wide310x150Logo.scale-200.png b/tools/SampleWinGetUWPCaller/AppInstallerCaller/Assets/Wide310x150Logo.scale-200.png Binary files differ. diff --git a/tools/SampleWinGetUWPCaller/AppInstallerCaller/GeneratedFromServer/Microsoft.Management.Deployment.winmd b/tools/SampleWinGetUWPCaller/AppInstallerCaller/GeneratedFromServer/Microsoft.Management.Deployment.winmd Binary files differ. diff --git a/tools/SampleWinGetUWPCaller/AppInstallerCaller/InstallingPackageView.cpp b/tools/SampleWinGetUWPCaller/AppInstallerCaller/InstallingPackageView.cpp @@ -0,0 +1,85 @@ +#include "pch.h" +#include "InstallingPackageView.h" +#include "InstallingPackageView.g.cpp" +#include <winrt/Windows.UI.Core.h> + +namespace winrt::AppInstallerCaller::implementation +{ + winrt::Microsoft::Management::Deployment::CatalogPackage InstallingPackageView::Package() + { + return m_package; + } + + void InstallingPackageView::Package(winrt::Microsoft::Management::Deployment::CatalogPackage const& value) + { + m_package = value;; + } + + InstallingPackageView::AsyncOperation_t InstallingPackageView::AsyncOperation() + { + return m_asyncOperation; + } + + winrt::Windows::Foundation::IAsyncAction UpdateUIProgress( + winrt::Microsoft::Management::Deployment::InstallProgress progress, + winrt::AppInstallerCaller::InstallingPackageView view) + { + co_await winrt::resume_foreground(view.Dispatcher()); + view.Progress(progress.DownloadProgress * 100); + } + + void InstallingPackageView::AsyncOperation(InstallingPackageView::AsyncOperation_t const& value) + { + m_asyncOperation = value; + m_asyncOperation.Progress([=]( + InstallingPackageView::AsyncOperation_t const& /* sender */, + winrt::Microsoft::Management::Deployment::InstallProgress const& progress) + { + UpdateUIProgress(progress, *this); + }); + } + + double InstallingPackageView::Progress() + { + return m_progress; + } + + void InstallingPackageView::Progress(double value) + { + if (m_progress != value) + { + m_progress = value; + m_propertyChanged(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs{ L"Progress" }); + } + } + + hstring InstallingPackageView::StatusText() + { + return m_text; + } + + void InstallingPackageView::StatusText(hstring const& value) + { + m_text = value; + } + + winrt::Windows::UI::Core::CoreDispatcher InstallingPackageView::Dispatcher() + { + return m_dispatcher; + } + + void InstallingPackageView::Dispatcher(winrt::Windows::UI::Core::CoreDispatcher const& value) + { + m_dispatcher = value; + } + + winrt::event_token InstallingPackageView::PropertyChanged(Windows::UI::Xaml::Data::PropertyChangedEventHandler const& handler) + { + return m_propertyChanged.add(handler); + } + + void InstallingPackageView::PropertyChanged(winrt::event_token const& token) + { + m_propertyChanged.remove(token); + } +} diff --git a/tools/SampleWinGetUWPCaller/AppInstallerCaller/InstallingPackageView.h b/tools/SampleWinGetUWPCaller/AppInstallerCaller/InstallingPackageView.h @@ -0,0 +1,40 @@ +#pragma once +#include "InstallingPackageView.g.h" + +namespace winrt::AppInstallerCaller::implementation +{ + struct InstallingPackageView : InstallingPackageViewT<InstallingPackageView> + { + using AsyncOperation_t = winrt::Windows::Foundation::IAsyncOperationWithProgress<winrt::Microsoft::Management::Deployment::InstallResult, winrt::Microsoft::Management::Deployment::InstallProgress>; + + InstallingPackageView() = default; + + winrt::Microsoft::Management::Deployment::CatalogPackage Package(); + void Package(winrt::Microsoft::Management::Deployment::CatalogPackage const& value); + AsyncOperation_t AsyncOperation(); + void AsyncOperation(AsyncOperation_t const& value); + double Progress(); + void Progress(double value); + hstring StatusText(); + void StatusText(hstring const& value); + winrt::Windows::UI::Core::CoreDispatcher Dispatcher(); + void Dispatcher(winrt::Windows::UI::Core::CoreDispatcher const& value); + winrt::event_token PropertyChanged(Windows::UI::Xaml::Data::PropertyChangedEventHandler const& value); + void PropertyChanged(winrt::event_token const& token); + + private: + winrt::Microsoft::Management::Deployment::CatalogPackage m_package{ nullptr }; + AsyncOperation_t m_asyncOperation{ nullptr }; + double m_progress = 0; + hstring m_text; + winrt::Windows::UI::Core::CoreDispatcher m_dispatcher{ nullptr }; + winrt::event<Windows::UI::Xaml::Data::PropertyChangedEventHandler> m_propertyChanged; + }; +} + +namespace winrt::AppInstallerCaller::factory_implementation +{ + struct InstallingPackageView : InstallingPackageViewT<InstallingPackageView, implementation::InstallingPackageView> + { + }; +} diff --git a/tools/SampleWinGetUWPCaller/AppInstallerCaller/MainPage.cpp b/tools/SampleWinGetUWPCaller/AppInstallerCaller/MainPage.cpp @@ -0,0 +1,550 @@ +#include "pch.h" +#include "MainPage.h" +#include "MainPage.g.cpp" + +#include <wrl.h> +#include <winrt/Microsoft.Management.Deployment.h> +#include <winrt/Windows.UI.Core.h> + +using namespace Microsoft::WRL; +using namespace std::chrono_literals; +using namespace winrt::Microsoft::Management::Deployment; + +namespace winrt +{ + using namespace Windows::UI::Xaml; + using namespace Windows::Foundation; + using namespace Windows::Foundation::Collections; +} + +// CLSIDs for WinGet package +const CLSID CLSID_PackageManager = { 0xC53A4F16, 0x787E, 0x42A4, 0xB3, 0x04, 0x29, 0xEF, 0xFB, 0x4B, 0xF5, 0x97 }; //C53A4F16-787E-42A4-B304-29EFFB4BF597 +const CLSID CLSID_InstallOptions = { 0x1095f097, 0xEB96, 0x453B, 0xB4, 0xE6, 0x16, 0x13, 0x63, 0x7F, 0x3B, 0x14 }; //1095F097-EB96-453B-B4E6-1613637F3B14 +const CLSID CLSID_FindPackagesOptions = { 0x572DED96, 0x9C60, 0x4526, { 0x8F, 0x92, 0xEE, 0x7D, 0x91, 0xD3, 0x8C, 0x1A } }; //572DED96-9C60-4526-8F92-EE7D91D38C1A +const CLSID CLSID_PackageMatchFilter = { 0xD02C9DAF, 0x99DC, 0x429C, { 0xB5, 0x03, 0x4E, 0x50, 0x4E, 0x4A, 0xB0, 0x00 } }; //D02C9DAF-99DC-429C-B503-4E504E4AB000 +const CLSID CLSID_CreateCompositePackageCatalogOptions = { 0x526534B8, 0x7E46, 0x47C8, { 0x84, 0x16, 0xB1, 0x68, 0x5C, 0x32, 0x7D, 0x37 } }; //526534B8-7E46-47C8-8416-B1685C327D37 + +// CLSIDs for WinGetDev package +const CLSID CLSID_PackageManager2 = { 0x74CB3139, 0xB7C5, 0x4B9E, { 0x93, 0x88, 0xE6, 0x61, 0x6D, 0xEA, 0x28, 0x8C } }; //74CB3139-B7C5-4B9E-9388-E6616DEA288C +const CLSID CLSID_InstallOptions2 = { 0x44FE0580, 0x62F7, 0x44D4, 0x9E, 0x91, 0xAA, 0x96, 0x14, 0xAB, 0x3E, 0x86 }; //44FE0580-62F7-44D4-9E91-AA9614AB3E86 +const CLSID CLSID_FindPackagesOptions2 = { 0x1BD8FF3A, 0xEC50, 0x4F69, { 0xAE, 0xEE, 0xDF, 0x4C, 0x9D, 0x3B, 0xAA, 0x96 } }; //1BD8FF3A-EC50-4F69-AEEE-DF4C9D3BAA96 +const CLSID CLSID_PackageMatchFilter2 = { 0x3F85B9F4, 0x487A, 0x4C48, { 0x90, 0x35, 0x29, 0x03, 0xF8, 0xA6, 0xD9, 0xE8 } }; //3F85B9F4-487A-4C48-9035-2903F8A6D9E8 +const CLSID CLSID_CreateCompositePackageCatalogOptions2 = { 0xEE160901, 0xB317, 0x4EA7, { 0x9C, 0xC6, 0x53, 0x55, 0xC6, 0xD7, 0xD8, 0xA7 } }; //EE160901-B317-4EA7-9CC6-5355C6D7D8A7 + +namespace winrt::AppInstallerCaller::implementation +{ + MainPage::MainPage() + { + InitializeComponent(); + m_packageCatalogs = winrt::single_threaded_observable_vector<PackageCatalogReference>(); + m_installedPackages = winrt::single_threaded_observable_vector<CatalogPackage>(); + m_installingPackageViews = winrt::single_threaded_observable_vector<winrt::AppInstallerCaller::InstallingPackageView>(); + } + + PackageManager MainPage::CreatePackageManager() { + if (m_useDev) + { + return winrt::create_instance<PackageManager>(CLSID_PackageManager2, CLSCTX_ALL); + } + return winrt::create_instance<PackageManager>(CLSID_PackageManager, CLSCTX_ALL); + } + InstallOptions MainPage::CreateInstallOptions() { + if (m_useDev) + { + return winrt::create_instance<InstallOptions>(CLSID_InstallOptions2, CLSCTX_ALL); + } + return winrt::create_instance<InstallOptions>(CLSID_InstallOptions, CLSCTX_ALL); + } + FindPackagesOptions MainPage::CreateFindPackagesOptions() { + if (m_useDev) + { + return winrt::create_instance<FindPackagesOptions>(CLSID_FindPackagesOptions2, CLSCTX_ALL); + } + return winrt::create_instance<FindPackagesOptions>(CLSID_FindPackagesOptions, CLSCTX_ALL); + } + CreateCompositePackageCatalogOptions MainPage::CreateCreateCompositePackageCatalogOptions() { + if (m_useDev) + { + return winrt::create_instance<CreateCompositePackageCatalogOptions>(CLSID_CreateCompositePackageCatalogOptions2, CLSCTX_ALL); + } + return winrt::create_instance<CreateCompositePackageCatalogOptions>(CLSID_CreateCompositePackageCatalogOptions, CLSCTX_ALL); + } + PackageMatchFilter MainPage::CreatePackageMatchFilter() { + if (m_useDev) + { + return winrt::create_instance<PackageMatchFilter>(CLSID_PackageMatchFilter2, CLSCTX_ALL); + } + return winrt::create_instance<PackageMatchFilter>(CLSID_PackageMatchFilter, CLSCTX_ALL); + } + + IAsyncOperation<PackageCatalog> MainPage::FindSourceAsync(std::wstring packageSource) + { + PackageManager packageManager = CreatePackageManager(); + PackageCatalogReference catalogRef{ packageManager.GetPackageCatalogByName(packageSource) }; + if (catalogRef) + { + ConnectResult connectResult{ co_await catalogRef.ConnectAsync() }; + // PackageCatalog will be null if connectResult.ErrorCode() is a failure + PackageCatalog catalog = connectResult.PackageCatalog(); + co_return catalog; + } + } + + IAsyncOperation<FindPackagesResult> MainPage::TryFindPackageInCatalogAsync(PackageCatalog catalog, std::wstring packageId) + { + FindPackagesOptions findPackagesOptions = CreateFindPackagesOptions(); + PackageMatchFilter filter = CreatePackageMatchFilter(); + filter.Field(PackageMatchField::Id); + filter.Option(PackageFieldMatchOption::Equals); + filter.Value(packageId); + findPackagesOptions.Filters().Append(filter); + return catalog.FindPackagesAsync(findPackagesOptions); + } + IAsyncOperation<CatalogPackage> MainPage::FindPackageInCatalogAsync(PackageCatalog catalog, std::wstring packageId) + { + FindPackagesOptions findPackagesOptions = CreateFindPackagesOptions(); + PackageMatchFilter filter = CreatePackageMatchFilter(); + filter.Field(PackageMatchField::Id); + filter.Option(PackageFieldMatchOption::Equals); + filter.Value(packageId); + findPackagesOptions.Filters().Append(filter); + FindPackagesResult findPackagesResult{ co_await catalog.FindPackagesAsync(findPackagesOptions) }; + + winrt::IVectorView<MatchResult> matches = findPackagesResult.Matches(); + if (matches.Size() == 0) + { + co_return nullptr; + } + co_return matches.GetAt(0).CatalogPackage(); + } + + IAsyncOperationWithProgress<InstallResult, InstallProgress> MainPage::InstallPackage(CatalogPackage package) + { + PackageManager packageManager = CreatePackageManager(); + InstallOptions installOptions = CreateInstallOptions(); + + // Passing PackageInstallScope::User causes the install to fail if there's no installer that supports that. + installOptions.PackageInstallScope(PackageInstallScope::Any); + installOptions.PackageInstallMode(PackageInstallMode::Silent); + + return packageManager.InstallPackageAsync(package, installOptions); + } + + IAsyncAction UpdateUIProgress( + InstallProgress progress, + winrt::Windows::UI::Xaml::Controls::ProgressBar progressBar, + winrt::Windows::UI::Xaml::Controls::TextBlock statusText) + { + co_await winrt::resume_foreground(progressBar.Dispatcher()); + progressBar.Value(progress.DownloadProgress*100); + + std::wstring downloadText{ L"Downloading. " }; + switch (progress.State) + { + case PackageInstallProgressState::Queued: + statusText.Text(L"Queued"); + break; + case PackageInstallProgressState::Downloading: + downloadText += std::to_wstring(progress.BytesDownloaded) + L" bytes of " + std::to_wstring(progress.BytesRequired); + statusText.Text(downloadText); + break; + case PackageInstallProgressState::Installing: + statusText.Text(L"Installing"); + progressBar.IsIndeterminate(true); + break; + case PackageInstallProgressState::PostInstall: + statusText.Text(L"Finishing install"); + break; + case PackageInstallProgressState::Finished: + statusText.Text(L"Finished install."); + progressBar.IsIndeterminate(false); + break; + default: + statusText.Text(L""); + } + } + + // This method is called from a background thread. + IAsyncAction UpdateUIForInstall( + IAsyncOperationWithProgress<InstallResult, InstallProgress> installPackageOperation, + winrt::Windows::UI::Xaml::Controls::Button installButton, + winrt::Windows::UI::Xaml::Controls::Button cancelButton, + winrt::Windows::UI::Xaml::Controls::ProgressBar progressBar, + winrt::Windows::UI::Xaml::Controls::TextBlock statusText) + { + installPackageOperation.Progress([=]( + IAsyncOperationWithProgress<InstallResult, InstallProgress> const& /* sender */, + InstallProgress const& progress) + { + UpdateUIProgress(progress, progressBar, statusText).get(); + }); + + + winrt::hresult installOperationHr = S_OK; + std::wstring errorMessage{ L"Unknown Error" }; + InstallResult installResult{ nullptr }; + try + { + installResult = co_await installPackageOperation; + } + catch (hresult_canceled const&) + { + errorMessage = L"Cancelled"; + OutputDebugString(L"Operation was cancelled"); + } + catch (...) + { + // Operation failed + // Example: HRESULT_FROM_WIN32(ERROR_DISK_FULL). + installOperationHr = winrt::to_hresult(); + // Example: "There is not enough space on the disk." + errorMessage = winrt::to_message(); + OutputDebugString(L"Operation failed"); + } + + // Switch back to ui thread context. + co_await winrt::resume_foreground(progressBar.Dispatcher()); + + cancelButton.IsEnabled(false); + installButton.IsEnabled(true); + progressBar.IsIndeterminate(false); + + if (installPackageOperation.Status() == AsyncStatus::Canceled) + { + installButton.Content(box_value(L"Retry")); + statusText.Text(L"Install cancelled."); + } + if (installPackageOperation.Status() == AsyncStatus::Error || installResult == nullptr) + { + installButton.Content(box_value(L"Retry")); + statusText.Text(errorMessage); + } + else if (installResult.RebootRequired()) + { + installButton.Content(box_value(L"Install")); + statusText.Text(L"Reboot to finish installation."); + } + else if (installResult.Status() == InstallResultStatus::Ok) + { + installButton.Content(box_value(L"Install")); + statusText.Text(L"Finished."); + } + else + { + installButton.Content(box_value(L"Install")); + statusText.Text(L"Install failed."); + } + } + + IAsyncAction MainPage::GetSources(winrt::Windows::UI::Xaml::Controls::Button button) + { + co_await winrt::resume_background(); + + PackageManager packageManager = CreatePackageManager(); + auto catalogs{ packageManager.GetPackageCatalogs() }; + auto catalog{ packageManager.GetPredefinedPackageCatalog(PredefinedPackageCatalog::MicrosoftStore) }; + co_await winrt::resume_foreground(button.Dispatcher()); + m_packageCatalogs.Clear(); + for (uint32_t i = 0; i < catalogs.Size(); i++) + { + m_packageCatalogs.Append(catalogs.GetAt(i)); + } + m_packageCatalogs.Append(catalog); + + co_return; + } + + IAsyncAction MainPage::GetInstalledPackages(winrt::Windows::UI::Xaml::Controls::Button button) + { + int32_t selectedIndex = catalogsListBox().SelectedIndex(); + co_await winrt::resume_background(); + + PackageManager packageManager = CreatePackageManager(); + + PackageCatalogReference installedSearchCatalogRef{ nullptr }; + + if (selectedIndex < 0) + { + installedSearchCatalogRef = packageManager.GetLocalPackageCatalog(LocalPackageCatalog::InstalledPackages); + } + else + { + PackageCatalogReference selectedRemoteCatalogRef = m_packageCatalogs.GetAt(selectedIndex); + CreateCompositePackageCatalogOptions createCompositePackageCatalogOptions = CreateCreateCompositePackageCatalogOptions(); + createCompositePackageCatalogOptions.Catalogs().Append(selectedRemoteCatalogRef); + + createCompositePackageCatalogOptions.CompositeSearchBehavior(CompositeSearchBehavior::LocalCatalogs); + installedSearchCatalogRef = packageManager.CreateCompositePackageCatalog(createCompositePackageCatalogOptions); + } + + ConnectResult connectResult{ co_await installedSearchCatalogRef.ConnectAsync() }; + PackageCatalog installedCatalog = connectResult.PackageCatalog(); + if (!installedCatalog) + { + // Connect Error. + co_return; + } + + FindPackagesOptions findPackagesOptions = CreateFindPackagesOptions(); + + FindPackagesResult findResult{ TryFindPackageInCatalogAsync(installedCatalog, m_installAppId).get() }; + auto matches = findResult.Matches(); + + co_await winrt::resume_foreground(button.Dispatcher()); + m_installedPackages.Clear(); + for (uint32_t i = 0; i < matches.Size(); ++i) + { + // Filter to only packages that match the selectedCatalogRef + auto version = matches.GetAt(i).CatalogPackage().DefaultInstallVersion(); + if (selectedIndex < 0 || (version && version.PackageCatalog().Info().Id() == m_packageCatalogs.GetAt(selectedIndex).Info().Id())) + { + m_installedPackages.Append(matches.GetAt(i).CatalogPackage()); + } + } + + co_return; + } + IAsyncAction MainPage::GetInstallingPackages(winrt::Windows::UI::Xaml::Controls::Button button) + { + int32_t selectedIndex = catalogsListBox().SelectedIndex(); + co_await winrt::resume_background(); + + PackageManager packageManager = CreatePackageManager(); + + PackageCatalogReference installingSearchCatalogRef{ nullptr }; + + if (selectedIndex < 0) + { + // Installing package querying is only really useful if you know what Catalog you're interested in. + co_return; + } + + installingSearchCatalogRef = packageManager.GetLocalPackageCatalog(LocalPackageCatalog::InstallingPackages); + + PackageCatalogReference selectedRemoteCatalogRef = m_packageCatalogs.GetAt(selectedIndex); + ConnectResult remoteConnectResult{ co_await selectedRemoteCatalogRef.ConnectAsync() }; + PackageCatalog selectedRemoteCatalog = remoteConnectResult.PackageCatalog(); + if (!selectedRemoteCatalog) + { + co_return; + } + + ConnectResult connectResult{ co_await installingSearchCatalogRef.ConnectAsync() }; + PackageCatalog installingCatalog = connectResult.PackageCatalog(); + if (!installingCatalog) + { + co_return; + } + + FindPackagesOptions findPackagesOptions = CreateFindPackagesOptions(); + + FindPackagesResult findResult{ TryFindPackageInCatalogAsync(selectedRemoteCatalog, m_installAppId).get() }; + auto matches = findResult.Matches(); + + co_await winrt::resume_foreground(button.Dispatcher()); + + m_installingPackageViews.Clear(); + for (uint32_t i = 0; i < matches.Size(); ++i) + { + winrt::AppInstallerCaller::InstallingPackageView installingView; + installingView.Package(matches.GetAt(i).CatalogPackage()); + auto installOperation = packageManager.GetInstallProgress(installingView.Package(), selectedRemoteCatalog.Info()); + if (installOperation) + { + installingView.Dispatcher(button.Dispatcher()); + installingView.AsyncOperation(installOperation); + m_installingPackageViews.Append(installingView); + } + } + + co_return; + } + + IAsyncAction MainPage::StartInstall( + winrt::Windows::UI::Xaml::Controls::Button installButton, + winrt::Windows::UI::Xaml::Controls::Button cancelButton, + winrt::Windows::UI::Xaml::Controls::ProgressBar progressBar, + winrt::Windows::UI::Xaml::Controls::TextBlock statusText) + { + installButton.IsEnabled(false); + cancelButton.IsEnabled(true); + int32_t selectedIndex = catalogsListBox().SelectedIndex(); + + co_await winrt::resume_background(); + + if (selectedIndex < 0) + { + co_await winrt::resume_foreground(installButton.Dispatcher()); + installButton.IsEnabled(false); + statusText.Text(L"No catalog selected to install."); + co_return; + } + + // Get the remote catalog + PackageCatalogReference selectedRemoteCatalogRef = m_packageCatalogs.GetAt(selectedIndex); + ConnectResult remoteConnectResult{ co_await selectedRemoteCatalogRef.ConnectAsync() }; + PackageCatalog selectedRemoteCatalog = remoteConnectResult.PackageCatalog(); + if (!selectedRemoteCatalog) + { + co_await winrt::resume_foreground(progressBar.Dispatcher()); + statusText.Text(L"Connecting to catalog failed."); + co_return; + } + FindPackagesResult findPackagesResult{ TryFindPackageInCatalogAsync(selectedRemoteCatalog, m_installAppId).get() }; + winrt::IVectorView<MatchResult> matches = findPackagesResult.Matches(); + if (matches.Size() > 0) + { + m_installPackageOperation = InstallPackage(matches.GetAt(0).CatalogPackage()); + UpdateUIForInstall(m_installPackageOperation, installButton, cancelButton, progressBar, statusText); + } + } + + IAsyncAction MainPage::FindPackage( + winrt::Windows::UI::Xaml::Controls::Button button, + winrt::Windows::UI::Xaml::Controls::ProgressBar progressBar, + winrt::Windows::UI::Xaml::Controls::TextBlock statusText) + { + int32_t selectedIndex = catalogsListBox().SelectedIndex(); + if (selectedIndex < 0) + { + co_await winrt::resume_foreground(button.Dispatcher()); + button.IsEnabled(false); + statusText.Text(L"No catalog selected to search."); + co_return; + } + + co_await winrt::resume_background(); + + // Get the remote catalog + PackageCatalogReference selectedRemoteCatalogRef = m_packageCatalogs.GetAt(selectedIndex); + // Create the composite catalog + CreateCompositePackageCatalogOptions createCompositePackageCatalogOptions = CreateCreateCompositePackageCatalogOptions(); + createCompositePackageCatalogOptions.Catalogs().Append(selectedRemoteCatalogRef); + PackageManager packageManager = CreatePackageManager(); + PackageCatalogReference catalogRef{ packageManager.CreateCompositePackageCatalog(createCompositePackageCatalogOptions) }; + ConnectResult connectResult{ co_await catalogRef.ConnectAsync() }; + PackageCatalog compositeCatalog = connectResult.PackageCatalog(); + if (!compositeCatalog) + { + co_await winrt::resume_foreground(button.Dispatcher()); + button.IsEnabled(false); + statusText.Text(L"Failed to Connect to Catalog."); + co_return; + } + // Do the search. + FindPackagesResult findPackagesResult{ TryFindPackageInCatalogAsync(compositeCatalog, m_installAppId).get() }; + + winrt::IVectorView<MatchResult> matches = findPackagesResult.Matches(); + if (matches.Size() > 0) + { + auto version = matches.GetAt(0).CatalogPackage().InstalledVersion(); + if (version != nullptr) + { + co_await winrt::resume_foreground(button.Dispatcher()); + button.IsEnabled(false); + statusText.Text(version.ProductCodes().GetAt(0)); + } + else + { + co_await winrt::resume_foreground(button.Dispatcher()); + button.IsEnabled(true); + statusText.Text(L"Found the package to install."); + } + } + else + { + co_await winrt::resume_foreground(button.Dispatcher()); + button.IsEnabled(false); + statusText.Text(L"Did not find package"); + } + co_return; + } + + IAsyncOperation<CatalogPackage> MainPage::FindPackageAsync() + { + co_await winrt::resume_background(); + + PackageManager packageManager = CreatePackageManager(); + PackageCatalogReference catalogRef{ packageManager.GetPredefinedPackageCatalog(PredefinedPackageCatalog::OpenWindowsCatalog) }; + PackageCatalog catalog = catalogRef.ConnectAsync().get().PackageCatalog(); + if (!catalog) + { + //Connect error. + co_return nullptr; + } + co_return FindPackageInCatalogAsync(catalog, m_installAppId).get(); + } + + void MainPage::SearchButtonClickHandler(IInspectable const&, RoutedEventArgs const&) + { + m_installAppId = catalogIdTextBox().Text(); + installButton().IsEnabled(false); + cancelButton().IsEnabled(false); + installStatusText().Text(L"Looking for package."); + FindPackage(installButton(), installProgressBar(), installStatusText()); + } + void MainPage::InstallButtonClickHandler(IInspectable const&, RoutedEventArgs const&) + { + if (m_installPackageOperation == nullptr || m_installPackageOperation.Status() != AsyncStatus::Started) + { + StartInstall(installButton(), cancelButton(), installProgressBar(), installStatusText()); + } + } + + void MainPage::CancelButtonClickHandler(IInspectable const&, RoutedEventArgs const&) + { + if (m_installPackageOperation && m_installPackageOperation.Status() == AsyncStatus::Started) + { + m_installPackageOperation.Cancel(); + } + } + void MainPage::RefreshButtonClickHandler(IInspectable const&, RoutedEventArgs const&) + { + GetInstalledPackages(installButton()); + } + void MainPage::ClearInstalledButtonClickHandler(IInspectable const&, RoutedEventArgs const&) + { + m_installedPackages.Clear(); + } + void MainPage::InstallingRefreshButtonClickHandler(IInspectable const&, RoutedEventArgs const&) + { + GetInstallingPackages(installButton()); + } + void MainPage::ClearInstallingButtonClickHandler(IInspectable const&, RoutedEventArgs const&) + { + m_installingPackageViews.Clear(); + } + IAsyncAction MainPage::StartServer() + { + co_await winrt::resume_background(); + PackageManager packageManager = CreatePackageManager(); + } + void MainPage::StartServerButtonClickHandler(IInspectable const&, RoutedEventArgs const&) + { + StartServer(); + } + void MainPage::ToggleDevButtonClicked(IInspectable const&, RoutedEventArgs const&) + { + if (toggleDevButton().IsChecked()) + { + m_useDev = toggleDevButton().IsChecked().Value(); + } + } + void MainPage::FindSourcesButtonClickHandler(IInspectable const&, RoutedEventArgs const&) + { + GetSources(installButton()); + } + + Windows::Foundation::Collections::IObservableVector<Microsoft::Management::Deployment::PackageCatalogReference> MainPage::PackageCatalogs() + { + return m_packageCatalogs; + } + Windows::Foundation::Collections::IObservableVector<Microsoft::Management::Deployment::CatalogPackage> MainPage::InstalledApps() + { + return m_installedPackages; + } + Windows::Foundation::Collections::IObservableVector<winrt::AppInstallerCaller::InstallingPackageView> MainPage::InstallingPackages() + { + return m_installingPackageViews; + } +} diff --git a/tools/SampleWinGetUWPCaller/AppInstallerCaller/MainPage.h b/tools/SampleWinGetUWPCaller/AppInstallerCaller/MainPage.h @@ -0,0 +1,80 @@ +#pragma once + +#include "InstallingPackageView.h" +#include <winrt\Microsoft.Management.Deployment.h> + +#include "MainPage.g.h" +namespace Deployment = winrt::Microsoft::Management::Deployment; + +namespace winrt::AppInstallerCaller::implementation +{ + struct MainPage : MainPageT<MainPage> + { + MainPage(); + Windows::Foundation::Collections::IObservableVector<Deployment::PackageCatalogReference> PackageCatalogs(); + Windows::Foundation::Collections::IObservableVector<Deployment::CatalogPackage> InstalledApps(); + Windows::Foundation::Collections::IObservableVector<winrt::AppInstallerCaller::InstallingPackageView> InstallingPackages(); + + void InitializeUI(); + void ToggleDevButtonClicked(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& args); + void FindSourcesButtonClickHandler(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& args); + void StartServerButtonClickHandler(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& args); + void InstallButtonClickHandler(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& args); + void CancelButtonClickHandler(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& args); + void SearchButtonClickHandler(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& args); + void RefreshButtonClickHandler(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& args); + void ClearInstalledButtonClickHandler(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& args); + void InstallingRefreshButtonClickHandler(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& args); + void ClearInstallingButtonClickHandler(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& args); + + Windows::Foundation::IAsyncAction GetSources(winrt::Windows::UI::Xaml::Controls::Button button); + Windows::Foundation::IAsyncAction GetInstalledPackages(winrt::Windows::UI::Xaml::Controls::Button button); + Windows::Foundation::IAsyncAction GetInstallingPackages(winrt::Windows::UI::Xaml::Controls::Button button); + + Windows::Foundation::IAsyncAction InitializeInstallUI( + std::wstring installAppId, + winrt::Windows::UI::Xaml::Controls::Button installButton, + winrt::Windows::UI::Xaml::Controls::Button cancelButton, + winrt::Windows::UI::Xaml::Controls::ProgressBar progressBar, + winrt::Windows::UI::Xaml::Controls::TextBlock statusText); + Windows::Foundation::IAsyncAction StartInstall( + winrt::Windows::UI::Xaml::Controls::Button installButton, + winrt::Windows::UI::Xaml::Controls::Button cancelButton, + winrt::Windows::UI::Xaml::Controls::ProgressBar progressBar, + winrt::Windows::UI::Xaml::Controls::TextBlock statusText); + Windows::Foundation::IAsyncAction FindPackage( + winrt::Windows::UI::Xaml::Controls::Button button, + winrt::Windows::UI::Xaml::Controls::ProgressBar progressBar, + winrt::Windows::UI::Xaml::Controls::TextBlock statusText); + Windows::Foundation::IAsyncOperation<Deployment::CatalogPackage> FindPackageAsync(); + + private: + Deployment::PackageManager CreatePackageManager(); + Deployment::InstallOptions CreateInstallOptions(); + Deployment::FindPackagesOptions CreateFindPackagesOptions(); + Deployment::CreateCompositePackageCatalogOptions CreateCreateCompositePackageCatalogOptions(); + Deployment::PackageMatchFilter CreatePackageMatchFilter(); + + Windows::Foundation::IAsyncOperation<Deployment::FindPackagesResult> TryFindPackageInCatalogAsync(Deployment::PackageCatalog catalog, std::wstring packageId); + Windows::Foundation::IAsyncOperation<Deployment::CatalogPackage> FindPackageInCatalogAsync(Deployment::PackageCatalog catalog, std::wstring packageId); + Windows::Foundation::IAsyncOperationWithProgress<Deployment::InstallResult, Deployment::InstallProgress> InstallPackage(Deployment::CatalogPackage package); + Windows::Foundation::IAsyncOperation<Deployment::PackageCatalog> FindSourceAsync(std::wstring packageSource); + Windows::Foundation::IAsyncAction StartServer(); + + Windows::Foundation::Collections::IObservableVector<Deployment::PackageCatalogReference> m_packageCatalogs; + Windows::Foundation::Collections::IObservableVector<Deployment::CatalogPackage> m_installedPackages; + Windows::Foundation::Collections::IObservableVector<winrt::AppInstallerCaller::InstallingPackageView> m_installingPackageViews; + Windows::Foundation::IAsyncOperationWithProgress<Deployment::InstallResult, Deployment::InstallProgress> m_installPackageOperation; + std::wstring m_installAppId; + Deployment::PackageManager m_packageManager{ nullptr }; + bool m_useDev = false; + + }; +} + +namespace winrt::AppInstallerCaller::factory_implementation +{ + struct MainPage : MainPageT<MainPage, implementation::MainPage> + { + }; +} diff --git a/tools/SampleWinGetUWPCaller/AppInstallerCaller/MainPage.idl b/tools/SampleWinGetUWPCaller/AppInstallerCaller/MainPage.idl @@ -0,0 +1,28 @@ +namespace AppInstallerCaller +{ + [default_interface] + runtimeclass InstallingPackageView : Windows.UI.Xaml.Data.INotifyPropertyChanged + { + InstallingPackageView(); + Microsoft.Management.Deployment.CatalogPackage Package; + Windows.Foundation.IAsyncOperationWithProgress<Microsoft.Management.Deployment.InstallResult, Microsoft.Management.Deployment.InstallProgress> AsyncOperation; + Double Progress; + String StatusText; + Windows.UI.Core.CoreDispatcher Dispatcher; + } + + [default_interface] + runtimeclass MainPage : Windows.UI.Xaml.Controls.Page + { + MainPage(); + Windows.Foundation.Collections.IObservableVector<Microsoft.Management.Deployment.PackageCatalogReference> PackageCatalogs{ get; }; + Windows.Foundation.Collections.IObservableVector<Microsoft.Management.Deployment.CatalogPackage> InstalledApps{ get; }; + Windows.Foundation.Collections.IObservableVector<InstallingPackageView> InstallingPackages{ get; }; + } + + declare + { + interface Windows.Foundation.Collections.IVector<InstallingPackageView>; + interface Windows.Foundation.Collections.IVectorView<InstallingPackageView>; + } +} diff --git a/tools/SampleWinGetUWPCaller/AppInstallerCaller/MainPage.xaml b/tools/SampleWinGetUWPCaller/AppInstallerCaller/MainPage.xaml @@ -0,0 +1,69 @@ +<Page + x:Class="AppInstallerCaller.MainPage" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:local="using:AppInstallerCaller" + xmlns:deployment="using:Microsoft.Management.Deployment" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + mc:Ignorable="d"> + + <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="12"> + <StackPanel HorizontalAlignment="Center" VerticalAlignment="Top"> + <TextBlock Margin="0 12 0 0">Select catalogs to search</TextBlock> + <ToggleButton x:Name="toggleDevButton" Click="ToggleDevButtonClicked" HorizontalAlignment="Center" Margin="12">Use WinGetDev</ToggleButton> + <Button x:Name="findSourcesButton" Click="FindSourcesButtonClickHandler" HorizontalAlignment="Center" Margin="12">Find Catalogs.</Button> + <ListBox x:Name="catalogsListBox" ItemsSource="{x:Bind PackageCatalogs}" SelectionMode="Multiple" MaxWidth="300" MinHeight="50"> + <ItemsControl.ItemTemplate> + <DataTemplate x:DataType="deployment:PackageCatalogReference"> + <TextBlock Text="{x:Bind Info.Name, Mode=OneWay}"/> + </DataTemplate> + </ItemsControl.ItemTemplate> + </ListBox> + </StackPanel> + <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"> + <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="12"> + <TextBox x:Name="catalogIdTextBox" Header="Find an app to install:" PlaceholderText="App Id"></TextBox> + <Button x:Name="searchButton" Click="SearchButtonClickHandler" VerticalAlignment="Bottom">🔍</Button> + </StackPanel> + <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center"> + <Button x:Name="installButton" Click="InstallButtonClickHandler" IsEnabled="False">Install</Button> + <Button x:Name="cancelButton" Click="CancelButtonClickHandler" Margin="12 0 0 0" IsEnabled="False">Cancel</Button> + </StackPanel> + <ProgressBar x:Name="installProgressBar" Value="0" Maximum="100" Width="200px" Margin="12" ></ProgressBar> + <TextBlock x:Name="installStatusText" Text="" HorizontalAlignment="Center"></TextBlock> + </StackPanel> + <StackPanel HorizontalAlignment="Center" VerticalAlignment="Top"> + <StackPanel Orientation="Horizontal" > + <TextBlock Margin="0 12 0 0">Installed apps</TextBlock> + <Button x:Name="refreshButton" Click="RefreshButtonClickHandler" Margin="12 0 0 0" IsEnabled="True">Refresh</Button> + <Button x:Name="clearInstalledButton" Click="ClearInstalledButtonClickHandler" Margin="12 0 0 0" IsEnabled="True">Clear</Button> + </StackPanel> + <ListBox x:Name="installedListBox" ItemsSource="{x:Bind InstalledApps}" SelectionMode="Multiple" MaxWidth="300" MaxHeight="600" MinHeight="200" ScrollViewer.VerticalScrollBarVisibility="Visible"> + <ItemsControl.ItemTemplate> + <DataTemplate x:DataType="deployment:CatalogPackage"> + <TextBlock Text="{x:Bind Name, Mode=OneWay}"/> + </DataTemplate> + </ItemsControl.ItemTemplate> + </ListBox> + </StackPanel> + <StackPanel HorizontalAlignment="Center" VerticalAlignment="Top"> + <StackPanel Orientation="Horizontal" > + <TextBlock Margin="0 12 0 0">Installing apps</TextBlock> + <Button x:Name="installingRefreshButton" Click="InstallingRefreshButtonClickHandler" Margin="12 0 0 0" IsEnabled="True">Refresh</Button> + <Button x:Name="installingClearInstalledButton" Click="ClearInstallingButtonClickHandler" Margin="12 0 0 0" IsEnabled="True">Clear</Button> + </StackPanel> + <ListBox x:Name="installingListBox" ItemsSource="{x:Bind InstallingPackages}" SelectionMode="Multiple" MaxWidth="300" MaxHeight="600" MinHeight="200" ScrollViewer.VerticalScrollBarVisibility="Visible"> + <ItemsControl.ItemTemplate> + <DataTemplate x:DataType="local:InstallingPackageView"> + <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"> + <TextBlock Text="{x:Bind Package.Id, Mode=OneWay}"/> + <ProgressBar Value="{x:Bind Progress, Mode=OneWay}" Maximum="100" Width="200px" Margin="12" ></ProgressBar> + <TextBlock Text="{x:Bind StatusText, Mode=OneWay}" HorizontalAlignment="Center"></TextBlock> + </StackPanel> + </DataTemplate> + </ItemsControl.ItemTemplate> + </ListBox> + </StackPanel> + </StackPanel> +</Page> diff --git a/tools/SampleWinGetUWPCaller/AppInstallerCaller/Package.appxmanifest b/tools/SampleWinGetUWPCaller/AppInstallerCaller/Package.appxmanifest @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="utf-8"?> +<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" IgnorableNamespaces="uap mp"> + <Identity Name="SampleWinGetCaller" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" Version="1.0.0.0" /> + <mp:PhoneIdentity PhoneProductId="8b5526fe-0870-42b7-bde0-da8c4c7ea1aa" PhonePublisherId="00000000-0000-0000-0000-000000000000" /> + <Properties> + <DisplayName>Sample WinGet Caller</DisplayName> + <PublisherDisplayName>Microsoft Corporation</PublisherDisplayName> + <Logo>Assets\StoreLogo.png</Logo> + </Properties> + <Dependencies> + <TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" /> + </Dependencies> + <Resources> + <Resource Language="x-generate" /> + </Resources> + <Applications> + <Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="Sample WinGet Caller"> + <uap:VisualElements DisplayName="SampleWinGetCaller" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" BackgroundColor="transparent" Description="Sample WinGet UWP caller"> + <uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png"></uap:DefaultTile> + </uap:VisualElements> + </Application> + </Applications> + <Capabilities> + <Capability Name="internetClient" /> + </Capabilities> +</Package>+ \ No newline at end of file diff --git a/tools/SampleWinGetUWPCaller/AppInstallerCaller/PropertySheet.props b/tools/SampleWinGetUWPCaller/AppInstallerCaller/PropertySheet.props @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ImportGroup Label="PropertySheets" /> + <PropertyGroup Label="UserMacros" /> + <!-- + To customize common C++/WinRT project properties: + * right-click the project node + * expand the Common Properties item + * select the C++/WinRT property page + + For more advanced scenarios, and complete documentation, please see: + https://github.com/Microsoft/cppwinrt/tree/master/nuget + --> + <PropertyGroup /> + <ItemDefinitionGroup /> +</Project>+ \ No newline at end of file diff --git a/tools/SampleWinGetUWPCaller/AppInstallerCaller/packages.config b/tools/SampleWinGetUWPCaller/AppInstallerCaller/packages.config @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="Microsoft.Windows.CppWinRT" version="2.0.210503.1" targetFramework="native" /> +</packages>+ \ No newline at end of file diff --git a/tools/SampleWinGetUWPCaller/AppInstallerCaller/pch.cpp b/tools/SampleWinGetUWPCaller/AppInstallerCaller/pch.cpp @@ -0,0 +1 @@ +#include "pch.h" diff --git a/tools/SampleWinGetUWPCaller/AppInstallerCaller/pch.h b/tools/SampleWinGetUWPCaller/AppInstallerCaller/pch.h @@ -0,0 +1,14 @@ +#pragma once +#include <windows.h> +#include <unknwn.h> +#include <hstring.h> +#include <winrt/Windows.Foundation.h> +#include <winrt/Windows.Foundation.Collections.h> +#include <winrt/Windows.ApplicationModel.Activation.h> +#include <winrt/Windows.UI.Xaml.h> +#include <winrt/Windows.UI.Xaml.Controls.h> +#include <winrt/Windows.UI.Xaml.Controls.Primitives.h> +#include <winrt/Windows.UI.Xaml.Data.h> +#include <winrt/Windows.UI.Xaml.Interop.h> +#include <winrt/Windows.UI.Xaml.Markup.h> +#include <winrt/Windows.UI.Xaml.Navigation.h>