Skip to content

Commit 54db161

Browse files
committed
Temporary commit of incoming PackageInformation setup.
1 parent e52dee4 commit 54db161

5 files changed

Lines changed: 282 additions & 0 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using Windows.ApplicationModel;
2+
using Windows.Foundation;
3+
using Windows.Storage.Streams;
4+
5+
namespace PSADT.WindowsRuntime.Management.Deployment
6+
{
7+
/// <summary>
8+
/// Provides an application's name, description, and logo.
9+
/// </summary>
10+
public sealed class AppDisplayInformation
11+
{
12+
/// <summary>
13+
/// Initializes a new instance of the <see cref="AppDisplayInformation"/> class based on the provided <see cref="AppDisplayInfo"/> object.
14+
/// </summary>
15+
/// <param name="appDisplayInfo">The <see cref="AppDisplayInfo"/> object to wrap.</param>
16+
internal AppDisplayInformation(AppDisplayInfo appDisplayInfo)
17+
{
18+
_appDisplayInfo = appDisplayInfo;
19+
}
20+
21+
/// <summary>
22+
/// Gets the application's description.
23+
/// </summary>
24+
public string Description => _appDisplayInfo.Description;
25+
26+
/// <summary>
27+
/// Gets the application's display name.
28+
/// </summary>
29+
public string DisplayName => _appDisplayInfo.DisplayName;
30+
31+
/// <summary>
32+
/// Gets the application's logo.
33+
/// </summary>
34+
/// <param name="size">The desired size of the logo.</param>
35+
/// <returns>A <see cref="RandomAccessStreamReference"/> representing the application's logo.</returns>
36+
public RandomAccessStreamReference GetLogo(Size size)
37+
{
38+
return _appDisplayInfo.GetLogo(size);
39+
}
40+
41+
/// <summary>
42+
/// The underlying AppDisplayInfo object that this class wraps around.
43+
/// </summary>
44+
private readonly AppDisplayInfo _appDisplayInfo;
45+
}
46+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System.Collections.Generic;
2+
using System.Collections.ObjectModel;
3+
using Windows.ApplicationModel;
4+
5+
namespace PSADT.WindowsRuntime.Management.Deployment
6+
{
7+
/// <summary>
8+
/// Provides information about an application such as its name, logo, package information, ID.
9+
/// </summary>
10+
public sealed class AppInformation
11+
{
12+
/// <summary>
13+
/// Initializes a new instance of the AppInformation class based on the provided AppInfo object.
14+
/// </summary>
15+
/// <param name="appInfo">The AppInfo object to initialize the AppInformation instance with.</param>
16+
internal AppInformation(AppInfo appInfo)
17+
{
18+
_appInfo = appInfo;
19+
}
20+
21+
/// <summary>
22+
/// Gets the app identifier.
23+
/// </summary>
24+
public string Id => _appInfo.Id;
25+
26+
/// <summary>
27+
/// An identifier that uniquely identifies the app's package.
28+
/// </summary>
29+
public string PackageFamilyName => _appInfo.PackageFamilyName;
30+
31+
/// <summary>
32+
/// An enum that represents the execution context for the specified app. Values may be one of Unknown, Host, or Guest. On Desktop devices, this will be Host.
33+
/// </summary>
34+
public AppExecutionContext ExecutionContext => _appInfo.ExecutionContext;
35+
36+
/// <summary>
37+
/// A list of file extensions that the application has been registered to handle. An app can register to handle an extension under the windows.fileTypeAssociation in the application manifest file.
38+
/// </summary>
39+
public IReadOnlyList<string> SupportedFileExtensions => new ReadOnlyCollection<string>(_appInfo.SupportedFileExtensions);
40+
41+
/// <summary>
42+
/// The underlying AppInfo object that this class wraps around.
43+
/// </summary>
44+
private readonly AppInfo _appInfo;
45+
}
46+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using Windows.ApplicationModel.Core;
4+
using Windows.System;
5+
6+
namespace PSADT.WindowsRuntime.Management.Deployment
7+
{
8+
/// <summary>
9+
/// Provides an app's display info such as its display name and description, and a method to launch the app.
10+
/// </summary>
11+
public sealed class AppListEntryInformation
12+
{
13+
/// <summary>
14+
/// Initializes a new instance of the AppListEntryInformation class based on the provided AppListEntry object.
15+
/// </summary>
16+
/// <param name="appListEntry">The AppListEntry object to initialize the AppListEntryInformation instance with.</param>
17+
internal AppListEntryInformation(AppListEntry appListEntry)
18+
{
19+
_appListEntry = appListEntry;
20+
DisplayInfo = new(appListEntry.DisplayInfo);
21+
AppInfo = new(appListEntry.AppInfo);
22+
}
23+
24+
/// <summary>
25+
/// Provides an app's display name, description, and logo.
26+
/// </summary>
27+
public AppDisplayInformation DisplayInfo { get; }
28+
29+
/// <summary>
30+
/// Gets the Application User Model ID (AUMID) for this AppListEntry.
31+
/// </summary>
32+
public string AppUserModelId => _appListEntry.AppUserModelId;
33+
34+
/// <summary>
35+
/// Provides information about an application such as its name, logo, package information, ID.
36+
/// </summary>
37+
public AppInformation AppInfo { get; }
38+
39+
/// <summary>
40+
/// Launch the app associated with this AppListEntryInformation
41+
/// </summary>
42+
/// <returns></returns>
43+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "VSTHRD002:Avoid problematic synchronous waits", Justification = "There's no async in PowerShell.")]
44+
public bool Launch()
45+
{
46+
return LaunchAsync().ConfigureAwait(false).GetAwaiter().GetResult();
47+
}
48+
49+
/// <summary>
50+
/// Launch the app associated with this AppListEntryInformation
51+
/// </summary>
52+
/// <returns>A task that represents the asynchronous operation. The task result contains a boolean value indicating whether the app was successfully launched.</returns>
53+
public Task<bool> LaunchAsync()
54+
{
55+
return _appListEntry.LaunchAsync().AsTask();
56+
}
57+
58+
/// <summary>
59+
/// Launch the app associated with this AppListEntryInformation within the context of a specified user.
60+
/// </summary>
61+
/// <param name="user">The user context in which to launch the app.</param>
62+
/// <returns>A boolean value indicating whether the app was successfully launched.</returns>
63+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "VSTHRD002:Avoid problematic synchronous waits", Justification = "There's no async in PowerShell.")]
64+
public bool LaunchForUser(User user)
65+
{
66+
return LaunchForUserAsync(user).ConfigureAwait(false).GetAwaiter().GetResult();
67+
}
68+
69+
/// <summary>
70+
/// Launch the app associated with this AppListEntryInformation within the context of a specified user.
71+
/// </summary>
72+
/// <param name="user">The user context in which to launch the app.</param>
73+
/// <returns>A task that represents the asynchronous operation. The task result contains a boolean value indicating whether the app was successfully launched.</returns>
74+
public Task<bool> LaunchForUserAsync(User user)
75+
{
76+
return _appListEntry.LaunchForUserAsync(user).AsTask();
77+
}
78+
79+
/// <summary>
80+
/// The underlying AppListEntry object that this class wraps around.
81+
/// </summary>
82+
private readonly AppListEntry _appListEntry;
83+
}
84+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Collections.ObjectModel;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Windows.ApplicationModel;
7+
8+
namespace PSADT.WindowsRuntime.Management.Deployment
9+
{
10+
/// <summary>
11+
/// Provides information about a package.
12+
/// </summary>
13+
public sealed class PackageInformation
14+
{
15+
/// <summary>
16+
///
17+
/// </summary>
18+
/// <param name="package"></param>
19+
internal PackageInformation(Package package)
20+
{
21+
_package = package;
22+
Dependencies = new ReadOnlyCollection<PackageInformation>([.. package.Dependencies.Select(static d => new PackageInformation(d))]);
23+
}
24+
25+
/// <summary>
26+
/// Gets the packages on which the current package depends.
27+
/// </summary>
28+
public IReadOnlyList<PackageInformation> Dependencies { get; }
29+
30+
/// <summary>
31+
/// Gets the package identity of the current package.
32+
/// </summary>
33+
public PackageId Id => _package.Id;
34+
35+
/// <summary>
36+
/// The CheckUpdateAvailabilityAsync method allows developers to check for updates to the main app package listed in the .appinstaller file. It allows the developer to determine if the updates are required due to .appinstaller policy. This method currently only works for applications installed via .appinstaller files.
37+
/// </summary>
38+
/// <returns>A PackageUpdateAvailabilityResult that indicates if an application has an update, and if the update is required.</returns>
39+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "VSTHRD002:Avoid problematic synchronous waits", Justification = "There's no async in PowerShell.")]
40+
public PackageUpdateAvailabilityResult CheckUpdateAvailability()
41+
{
42+
return CheckUpdateAvailabilityAsync().ConfigureAwait(false).GetAwaiter().GetResult();
43+
}
44+
45+
/// <summary>
46+
/// The CheckUpdateAvailabilityAsync method allows developers to check for updates to the main app package listed in the .appinstaller file. It allows the developer to determine if the updates are required due to .appinstaller policy. This method currently only works for applications installed via .appinstaller files.
47+
/// </summary>
48+
/// <returns>A PackageUpdateAvailabilityResult that indicates if an application has an update, and if the update is required.</returns>
49+
public Task<PackageUpdateAvailabilityResult> CheckUpdateAvailabilityAsync()
50+
{
51+
return _package.CheckUpdateAvailabilityAsync().AsTask();
52+
}
53+
54+
/// <summary>
55+
/// The FindRelatedPackages method provides the dependencies and then dependents for a given package as a Package list. The list can be filtered by the type of dependency using the options parameter.
56+
/// </summary>
57+
/// <param name="options">The FindRelatedPackageOptions which defines the search options.</param>
58+
/// <returns>A read-only list of <see cref="PackageInformation"/> objects representing the related packages.</returns>
59+
public IReadOnlyList<PackageInformation> FindRelatedPackages(FindRelatedPackagesOptions options)
60+
{
61+
return new ReadOnlyCollection<PackageInformation>([.. _package.FindRelatedPackages(options).Select(static p => new PackageInformation(p))]);
62+
}
63+
64+
/// <summary>
65+
/// Returns the .appinstaller XML file location. Use this method when you need to retrieve the .appinstaller XML file location for your app. For example, this is useful if your app needs to share a URI to its associated .appinstaller file. You can optionally add arguments to the URI.
66+
/// </summary>
67+
/// <returns>The .appinstaller XML file location.</returns>
68+
public AppInstallerInfo GetAppInstallerInfo()
69+
{
70+
return _package.GetAppInstallerInfo();
71+
}
72+
73+
/// <summary>
74+
/// Enumerates the packaged apps on the device and returns the list synchronously. Only apps included in the current package are returned.
75+
/// </summary>
76+
/// <returns>A list of AppListEntry objects that specify the packaged apps along with their display name, description, and logo.</returns>
77+
public IReadOnlyList<AppListEntryInformation> GetAppListEntries()
78+
{
79+
return new ReadOnlyCollection<AppListEntryInformation>([.. _package.GetAppListEntries().Select(static entry => new AppListEntryInformation(entry))]);
80+
}
81+
82+
/// <summary>
83+
/// Enumerates the packaged apps on the device and returns the list asynchronously. Only apps included in the current package are returned.
84+
/// </summary>
85+
/// <returns>A task that represents the asynchronous operation. The task result contains a list of AppListEntryInformation objects that specify the packaged apps along with their display name, description, and logo.</returns>
86+
public async Task<IReadOnlyList<AppListEntryInformation>> GetAppListEntriesAsync()
87+
{
88+
return new ReadOnlyCollection<AppListEntryInformation>([.. (await _package.GetAppListEntriesAsync().AsTask().ConfigureAwait(false)).Select(static entry => new AppListEntryInformation(entry))]);
89+
}
90+
91+
/// <summary>
92+
/// Gets the underlying <see cref="Package"/> object.
93+
/// </summary>
94+
private readonly Package _package;
95+
}
96+
}

src/PSADT/PSADT.WindowsRuntime/Management/Deployment/PackageManagement.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Threading;
77
using System.Threading.Tasks;
88
using PSADT.Interop;
9+
using Windows.ApplicationModel;
910
using Windows.Management.Deployment;
1011
using Windows.Win32.Storage.Packaging.Appx;
1112
using Windows.Win32.System.Com;
@@ -17,6 +18,15 @@ namespace PSADT.WindowsRuntime.Management.Deployment
1718
/// </summary>
1819
public static class PackageManagement
1920
{
21+
/// <summary>
22+
/// Retrieves a list of all provisioned Appx/Msix packages on the system using the PackageManager API.
23+
/// </summary>
24+
/// <returns>A list of provisioned packages.</returns>
25+
public static IList<Package> GetAppxProvisionedPackages()
26+
{
27+
return new PackageManager().FindProvisionedPackages();
28+
}
29+
2030
/// <summary>
2131
/// Provisions the specified Appx/Msix package for all users on the system by staging the package and then provisioning it using the PackageManager API. Validates the input package URI and checks for the existence of the package file before attempting to stage and provision. Retrieves the package family name from the package manifest to use for provisioning. Throws exceptions if any step of the staging or provisioning process fails, or if the input package URI is invalid or does not point to an existing file.
2232
/// </summary>

0 commit comments

Comments
 (0)