Skip to content

Commit

Permalink
[Run] Fix exception (#9068)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykhailopylyp committed Jan 14, 2021
1 parent 6ecf8b6 commit b1a6964
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public void Win32ProgramRepositoryMustCallOnAppRenamedForLnkAppsWhenRenamedEvent
Win32Program olditem = new Win32Program
{
Name = "oldpath",
ExecutableName = path,
ExecutableName = oldpath,
FullPath = fullPath,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private void OnAppRenamed(object sender, RenamedEventArgs e)

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
Expand All @@ -111,7 +111,7 @@ private void OnAppRenamed(object sender, RenamedEventArgs e)
{
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)
{
Expand All @@ -124,13 +124,20 @@ private void OnAppRenamed(object sender, RenamedEventArgs e)
}
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)
Expand Down

0 comments on commit b1a6964

Please sign in to comment.