mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-23 16:37:58 +08:00
beecdc8d79
* Moved Logger/Log.cs from Wox.Infrastructure to Wox.Plugin - Installed Logger dependency in Wox.Plugin: NLog.Extensions.Logging - Moved file Log.cs from Wox.Infrastructure/Logger/ to Wox.Plugin/Logger - Moved file Constant.cs from Wox.Infrastructure to Wox.Plugin: This file was moved since Log.cs depends on this class - Copied Wox.Infrastructure.Helper.NonNull to Wox.Plugin.Constant since Constant.cs depends on this method - Replaced all "using Wox.Infrastructure.Logger" to "using Wox.Plugin.Logger" in all files as needed - Replaced Wox.Infrastructure.Constant to Wox.Plugin.Constant in all files as needed * Removed Nlog.Extensions.Logging from Wox.Infrastructure * Added logging and suppressed general exceptions (CA1031: Do not catch general exception types) * Resolved fxcop errors introduced by newly added Log.cs - CA1307: Specify StringComparison for clarity - CA2000: Dispose objects before losing scope - CA1062: Validate arguments of public methods * Replaced Wox.Infrastructure.Logger with Wox.Plugin.Logger
50 lines
1.6 KiB
C#
50 lines
1.6 KiB
C#
// 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.
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Security.Principal;
|
|
using Windows.Management.Deployment;
|
|
using Wox.Plugin.Logger;
|
|
using Package = Windows.ApplicationModel.Package;
|
|
|
|
namespace Microsoft.Plugin.Program.Programs
|
|
{
|
|
public class PackageManagerWrapper : IPackageManager
|
|
{
|
|
private readonly PackageManager _packageManager;
|
|
|
|
public PackageManagerWrapper()
|
|
{
|
|
_packageManager = new PackageManager();
|
|
}
|
|
|
|
[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.")]
|
|
public IEnumerable<IPackage> FindPackagesForCurrentUser()
|
|
{
|
|
List<PackageWrapper> packages = new List<PackageWrapper>();
|
|
var user = WindowsIdentity.GetCurrent().User;
|
|
|
|
if (user != null)
|
|
{
|
|
var id = user.Value;
|
|
var m = _packageManager.FindPackagesForUser(id);
|
|
foreach (Package p in m)
|
|
{
|
|
try
|
|
{
|
|
packages.Add(PackageWrapper.GetWrapperFromPackage(p));
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error(e.Message, GetType());
|
|
}
|
|
}
|
|
}
|
|
|
|
return packages;
|
|
}
|
|
}
|
|
}
|