diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Program.UnitTests/Storage/Win32ProgramRepositoryTest.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Program.UnitTests/Storage/Win32ProgramRepositoryTest.cs index 9a27a70715..de251dbc29 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Program.UnitTests/Storage/Win32ProgramRepositoryTest.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Program.UnitTests/Storage/Win32ProgramRepositoryTest.cs @@ -349,7 +349,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage Win32Program olditem = new Win32Program { Name = "oldpath", - ExecutableName = path, + ExecutableName = oldpath, FullPath = fullPath, }; diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Storage/Win32ProgramRepository.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Storage/Win32ProgramRepository.cs index da5c27ef89..e29f67ef2c 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Storage/Win32ProgramRepository.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Storage/Win32ProgramRepository.cs @@ -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)