2020-08-12 11:46:11 -07:00
|
|
|
|
// Copyright (c) Microsoft Corporation
|
|
|
|
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
|
|
2020-08-14 12:46:23 -07:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
using System.Runtime.InteropServices.ComTypes;
|
2020-08-11 09:08:44 -07:00
|
|
|
|
using static Microsoft.Plugin.Program.Programs.UWP;
|
|
|
|
|
|
|
2020-08-14 12:46:23 -07:00
|
|
|
|
namespace Microsoft.Plugin.Program.Programs
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class AppxPackageHelper
|
|
|
|
|
|
{
|
|
|
|
|
|
// This function returns a list of attributes of applications
|
|
|
|
|
|
public static List<IAppxManifestApplication> GetAppsFromManifest(IStream stream)
|
|
|
|
|
|
{
|
|
|
|
|
|
List<IAppxManifestApplication> apps = new List<IAppxManifestApplication>();
|
|
|
|
|
|
var appxFactory = new AppxFactory();
|
|
|
|
|
|
var reader = ((IAppxFactory)appxFactory).CreateManifestReader(stream);
|
|
|
|
|
|
var manifestApps = reader.GetApplications();
|
2020-08-13 15:31:14 -07:00
|
|
|
|
|
2020-08-14 12:46:23 -07:00
|
|
|
|
while (manifestApps.GetHasCurrent())
|
|
|
|
|
|
{
|
|
|
|
|
|
var manifestApp = manifestApps.GetCurrent();
|
|
|
|
|
|
var hr = manifestApp.GetStringValue("AppListEntry", out var appListEntry);
|
|
|
|
|
|
_ = CheckHRAndReturnOrThrow(hr, appListEntry);
|
|
|
|
|
|
if (appListEntry != "none")
|
|
|
|
|
|
{
|
|
|
|
|
|
apps.Add(manifestApp);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
manifestApps.MoveNext();
|
|
|
|
|
|
}
|
2020-08-13 15:31:14 -07:00
|
|
|
|
|
2020-08-14 12:46:23 -07:00
|
|
|
|
return apps;
|
2020-08-11 09:08:44 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static T CheckHRAndReturnOrThrow<T>(Hresult hr, T result)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (hr != Hresult.Ok)
|
|
|
|
|
|
{
|
|
|
|
|
|
Marshal.ThrowExceptionForHR((int)hr);
|
|
|
|
|
|
}
|
2020-08-13 15:31:14 -07:00
|
|
|
|
|
2020-08-11 09:08:44 -07:00
|
|
|
|
return result;
|
2020-08-14 12:46:23 -07:00
|
|
|
|
}
|
2020-08-11 09:08:44 -07:00
|
|
|
|
}
|
2020-08-14 12:46:23 -07:00
|
|
|
|
}
|