Skip to content

Commit

Permalink
Fix: Fixed crash that would occur at the start of a file operation if…
Browse files Browse the repository at this point in the history
… Explorer wasn't running (#13670)
  • Loading branch information
hishitetsu authored Nov 6, 2023
1 parent f3a72e1 commit 83fd839
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 9 additions & 1 deletion src/Files.App/Utils/Shell/Win32API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,15 @@ public static Task<bool> MountVhdDisk(string vhdPath)
public static Shell32.ITaskbarList4? CreateTaskbarObject()
{
var taskbar2 = new Shell32.ITaskbarList2();
taskbar2.HrInit();
try
{
taskbar2.HrInit();
}
catch (NotImplementedException)
{
// explorer.exe is not running as a shell
return null;
}

return taskbar2 as Shell32.ITaskbarList4;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -947,14 +947,14 @@ public class OperationWithProgress
public bool Canceled { get; set; }
}

private readonly Shell32.ITaskbarList4 taskbar;
private readonly Shell32.ITaskbarList4? taskbar;
private readonly ConcurrentDictionary<string, OperationWithProgress> operations;

public HWND OwnerWindow { get; set; }

public ProgressHandler()
{
taskbar = Win32API.CreateTaskbarObject()!;
taskbar = Win32API.CreateTaskbarObject();
operations = new ConcurrentDictionary<string, OperationWithProgress>();
operationsCompletedEvent = new ManualResetEvent(true);
}
Expand Down Expand Up @@ -1034,7 +1034,8 @@ protected override void Dispose(bool disposing)
if (disposing)
{
operationsCompletedEvent?.Dispose();
Marshal.ReleaseComObject(taskbar);
if (taskbar is not null)
Marshal.ReleaseComObject(taskbar);
}
}
}
Expand Down

0 comments on commit 83fd839

Please sign in to comment.