mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-07 09:28:03 +08:00
Fix for File Not Found exception while indexing invalid Package App (#4971)
* Catching file not found exception * removed unnecessary header files * Added a string.empty check for installed location * reusing package wrapper instead of package installing event args
This commit is contained in:
parent
74412766fa
commit
f59abe23c3
@ -72,5 +72,23 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
Assert.AreEqual(applications.Length, 1);
|
||||
Assert.IsTrue(applications.FindAll(x => x.Name == "PackagedApp").Length > 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PowerToysRun_ShouldNotAddInvalidApp_WhenIndexingUWPApplications()
|
||||
{
|
||||
// Arrange
|
||||
PackageWrapper invalidPackagedApp = new PackageWrapper();
|
||||
Main._settings = new Settings();
|
||||
List<IPackage> packages = new List<IPackage>() {invalidPackagedApp };
|
||||
var mock = new Mock<IPackageManager>();
|
||||
mock.Setup(x => x.FindPackagesForCurrentUser()).Returns(packages);
|
||||
UWP.PackageManagerWrapper = mock.Object;
|
||||
|
||||
// Act
|
||||
var applications = UWP.All();
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(applications.Length, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,24 @@
|
||||
using Package = Windows.ApplicationModel.Package;
|
||||
using Microsoft.Plugin.Program.Logger;
|
||||
using System.IO;
|
||||
using Package = Windows.ApplicationModel.Package;
|
||||
|
||||
namespace Microsoft.Plugin.Program.Programs
|
||||
{
|
||||
public class PackageWrapper : IPackage
|
||||
{
|
||||
public string Name { get; }
|
||||
public string Name { get; } = string.Empty;
|
||||
|
||||
public string FullName { get; }
|
||||
public string FullName { get; } = string.Empty;
|
||||
|
||||
public string FamilyName { get; }
|
||||
public string FamilyName { get; } = string.Empty;
|
||||
|
||||
public bool IsFramework { get; }
|
||||
public bool IsFramework { get; } = false;
|
||||
|
||||
public bool IsDevelopmentMode { get; }
|
||||
public bool IsDevelopmentMode { get; } = false;
|
||||
|
||||
public string InstalledLocation { get; }
|
||||
public string InstalledLocation { get; } = string.Empty;
|
||||
|
||||
public PackageWrapper() { }
|
||||
|
||||
public PackageWrapper(string Name, string FullName, string FamilyName, bool IsFramework, bool IsDevelopmentMode, string InstalledLocation)
|
||||
{
|
||||
@ -28,7 +32,9 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
|
||||
public static PackageWrapper GetWrapperFromPackage(Package package)
|
||||
{
|
||||
return new PackageWrapper(
|
||||
try
|
||||
{
|
||||
return new PackageWrapper(
|
||||
package.Id.Name,
|
||||
package.Id.FullName,
|
||||
package.Id.FamilyName,
|
||||
@ -36,6 +42,12 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
package.IsDevelopmentMode,
|
||||
package.InstalledLocation.Path
|
||||
);
|
||||
}
|
||||
catch(FileNotFoundException ex)
|
||||
{
|
||||
ProgramLogger.LogException($"PackageWrapper", "GetWrapperFromPackage","package.InstalledLocation.Path",$"File Not Found for package {package.Id.Name}", ex);
|
||||
return new PackageWrapper();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,11 +35,14 @@ namespace Microsoft.Plugin.Program.Storage
|
||||
try
|
||||
{
|
||||
var packageWrapper = PackageWrapper.GetWrapperFromPackage(args.Package);
|
||||
var uwp = new UWP(packageWrapper);
|
||||
uwp.InitializeAppInfo(args.Package.InstalledLocation.Path);
|
||||
foreach (var app in uwp.Apps)
|
||||
if(!string.IsNullOrEmpty(packageWrapper.InstalledLocation))
|
||||
{
|
||||
Add(app);
|
||||
var uwp = new UWP(packageWrapper);
|
||||
uwp.InitializeAppInfo(packageWrapper.InstalledLocation);
|
||||
foreach (var app in uwp.Apps)
|
||||
{
|
||||
Add(app);
|
||||
}
|
||||
}
|
||||
}
|
||||
//InitializeAppInfo will throw if there is no AppxManifest.xml for the package.
|
||||
|
Loading…
Reference in New Issue
Block a user