2020-08-13 02:46:11 +08: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-09-18 07:17:02 +08:00
using System ;
2020-07-11 04:43:02 +08:00
using System.Collections.Generic ;
using System.Security.Principal ;
using Windows.Management.Deployment ;
2020-09-18 07:17:02 +08:00
using Wox.Infrastructure.Logger ;
2020-07-11 04:43:02 +08:00
using Package = Windows . ApplicationModel . Package ;
namespace Microsoft.Plugin.Program.Programs
{
public class PackageManagerWrapper : IPackageManager
{
2020-08-15 03:46:23 +08:00
private readonly PackageManager _packageManager ;
2020-07-11 04:43:02 +08:00
public PackageManagerWrapper ( )
{
2020-08-15 03:46:23 +08:00
_packageManager = new PackageManager ( ) ;
2020-07-11 04:43:02 +08:00
}
2020-09-18 07:17:02 +08:00
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "We want to catch all exception to prevent error in a program from affecting loading of program plugin.")]
2020-07-11 04:43:02 +08:00
public IEnumerable < IPackage > FindPackagesForCurrentUser ( )
{
List < PackageWrapper > packages = new List < PackageWrapper > ( ) ;
var user = WindowsIdentity . GetCurrent ( ) . User ;
if ( user ! = null )
{
var id = user . Value ;
2020-08-15 03:46:23 +08:00
var m = _packageManager . FindPackagesForUser ( id ) ;
2020-07-11 04:43:02 +08:00
foreach ( Package p in m )
{
2020-09-18 07:17:02 +08:00
try
{
packages . Add ( PackageWrapper . GetWrapperFromPackage ( p ) ) ;
}
catch ( Exception e )
{
2020-09-24 07:32:06 +08:00
Log . Error ( e . Message , GetType ( ) ) ;
2020-09-18 07:17:02 +08:00
}
2020-07-11 04:43:02 +08:00
}
}
return packages ;
}
}
}