[Run] Fix exception (#9068)

This commit is contained in:
Mykhailo Pylyp
2021-01-14 13:17:32 +02:00
committed by GitHub
parent 6ecf8b60b6
commit b1a6964e18
2 changed files with 12 additions and 5 deletions

View File

@@ -349,7 +349,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
Win32Program olditem = new Win32Program
{
Name = "oldpath",
ExecutableName = path,
ExecutableName = oldpath,
FullPath = fullPath,
};

View File

@@ -100,7 +100,7 @@ namespace Microsoft.Plugin.Program.Storage
string extension = Path.GetExtension(newPath);
Win32Program.ApplicationType appType = Win32Program.GetAppTypeFromPath(newPath);
Programs.Win32Program newApp = Programs.Win32Program.GetAppFromPath(newPath);
Programs.Win32Program newApp = Win32Program.GetAppFromPath(newPath);
Programs.Win32Program oldApp = null;
// Once the shortcut application is renamed, the old app does not exist and therefore when we try to get the FullPath we get the lnk path instead of the exe path
@@ -111,7 +111,7 @@ namespace Microsoft.Plugin.Program.Storage
{
if (appType == Win32Program.ApplicationType.ShortcutApplication)
{
oldApp = new Win32Program() { Name = Path.GetFileNameWithoutExtension(e.OldName), ExecutableName = newApp.ExecutableName, FullPath = newApp.FullPath };
oldApp = new Win32Program() { Name = Path.GetFileNameWithoutExtension(e.OldName), ExecutableName = Path.GetFileName(e.OldName), FullPath = newApp.FullPath };
}
else if (appType == Win32Program.ApplicationType.InternetShortcutApplication)
{
@@ -124,13 +124,20 @@ namespace Microsoft.Plugin.Program.Storage
}
catch (Exception ex)
{
Log.Exception($"OnAppRenamed-{extension}Program|{oldPath}|Unable to create program from {oldPath}", ex, GetType());
Log.Exception($"OnAppRenamed-{extension} Program|{e.OldName}|Unable to create program from {oldPath}", ex, GetType());
}
// To remove the old app which has been renamed and to add the new application.
if (oldApp != null)
{
Remove(oldApp);
if (string.IsNullOrWhiteSpace(oldApp.Name) || string.IsNullOrWhiteSpace(oldApp.ExecutableName) || string.IsNullOrWhiteSpace(oldApp.FullPath))
{
Log.Error($"Old app was not initialized properly. OldFullPath: {e.OldFullPath}; OldName: {e.OldName}; FullPath: {e.FullPath}", GetType());
}
else
{
Remove(oldApp);
}
}
if (newApp != null)