diff --git a/src/Files.App/Filesystem/FilesystemOperations/ShellFilesystemOperations.cs b/src/Files.App/Filesystem/FilesystemOperations/ShellFilesystemOperations.cs index 84cd787b4ce9..dd562cf3bd99 100644 --- a/src/Files.App/Filesystem/FilesystemOperations/ShellFilesystemOperations.cs +++ b/src/Files.App/Filesystem/FilesystemOperations/ShellFilesystemOperations.cs @@ -92,7 +92,7 @@ public async Task CopyItemsAsync(IList so var copyResult = new ShellOperationResult(); if (sourceRename.Any()) { - var resultItem = await FileOperationsHelpers.CopyItemAsync(sourceRename.Select(s => s.Path).ToArray(), destinationRename.ToArray(), false, NativeWinApiHelper.CoreWindowHandle.ToInt64(), operationID); + var resultItem = await FileOperationsHelpers.CopyItemAsync(sourceRename.Select(s => s.Path).ToArray(), destinationRename.ToArray(), false, NativeWinApiHelper.CoreWindowHandle.ToInt64(), operationID, progress); result &= (FilesystemResult)resultItem.Item1; @@ -100,7 +100,7 @@ public async Task CopyItemsAsync(IList so } if (sourceReplace.Any()) { - var resultItem = await FileOperationsHelpers.CopyItemAsync(sourceReplace.Select(s => s.Path).ToArray(), destinationReplace.ToArray(), true, NativeWinApiHelper.CoreWindowHandle.ToInt64(), operationID); + var resultItem = await FileOperationsHelpers.CopyItemAsync(sourceReplace.Select(s => s.Path).ToArray(), destinationReplace.ToArray(), true, NativeWinApiHelper.CoreWindowHandle.ToInt64(), operationID, progress); result &= (FilesystemResult)resultItem.Item1; @@ -330,7 +330,7 @@ public async Task DeleteItemsAsync(IList var operationID = Guid.NewGuid().ToString(); using var r = cancellationToken.Register(CancelOperation, operationID, false); - var (success, deleteResult) = await FileOperationsHelpers.DeleteItemAsync(deleleFilePaths.ToArray(), permanently, NativeWinApiHelper.CoreWindowHandle.ToInt64(), operationID); + var (success, deleteResult) = await FileOperationsHelpers.DeleteItemAsync(deleleFilePaths.ToArray(), permanently, NativeWinApiHelper.CoreWindowHandle.ToInt64(), operationID, progress); var result = (FilesystemResult)success; var shellOpResult = deleteResult; @@ -442,14 +442,14 @@ public async Task MoveItemsAsync(IList so var moveResult = new ShellOperationResult(); if (sourceRename.Any()) { - var (status, response) = await FileOperationsHelpers.MoveItemAsync(sourceRename.Select(s => s.Path).ToArray(), destinationRename.ToArray(), false, NativeWinApiHelper.CoreWindowHandle.ToInt64(), operationID); + var (status, response) = await FileOperationsHelpers.MoveItemAsync(sourceRename.Select(s => s.Path).ToArray(), destinationRename.ToArray(), false, NativeWinApiHelper.CoreWindowHandle.ToInt64(), operationID, progress); result &= (FilesystemResult)status; moveResult.Items.AddRange(response?.Final ?? Enumerable.Empty()); } if (sourceReplace.Any()) { - var (status, response) = await FileOperationsHelpers.MoveItemAsync(sourceReplace.Select(s => s.Path).ToArray(), destinationReplace.ToArray(), true, NativeWinApiHelper.CoreWindowHandle.ToInt64(), operationID); + var (status, response) = await FileOperationsHelpers.MoveItemAsync(sourceReplace.Select(s => s.Path).ToArray(), destinationReplace.ToArray(), true, NativeWinApiHelper.CoreWindowHandle.ToInt64(), operationID, progress); result &= (FilesystemResult)status; moveResult.Items.AddRange(response?.Final ?? Enumerable.Empty()); @@ -643,7 +643,7 @@ public async Task RestoreItemsFromTrashAsync(IList s.Path).ToArray(), destination.ToArray(), false, NativeWinApiHelper.CoreWindowHandle.ToInt64(), operationID); + var (status, response) = await FileOperationsHelpers.MoveItemAsync(source.Select(s => s.Path).ToArray(), destination.ToArray(), false, NativeWinApiHelper.CoreWindowHandle.ToInt64(), operationID, progress); var result = (FilesystemResult)status; moveResult.Items.AddRange(response?.Final ?? Enumerable.Empty()); @@ -718,19 +718,6 @@ await sourceMatch.Select(x => x.src).ToListAsync(), } } - private void OnProgressUpdated(object sender, Dictionary message, string currentOperation, IProgress progress) - { - if (message.ContainsKey("OperationID")) - { - var operationID = message["OperationID"].GetString(); - if (operationID == currentOperation) - { - var value = message["Progress"].GetInt64(); - progress?.Report(value); - } - } - } - private async void CancelOperation(object operationID) => FileOperationsHelpers.TryCancelOperation((string)operationID); diff --git a/src/Files.App/Helpers/FileOperationsHelpers.cs b/src/Files.App/Helpers/FileOperationsHelpers.cs index 66fb76950611..e9ef44e670ee 100644 --- a/src/Files.App/Helpers/FileOperationsHelpers.cs +++ b/src/Files.App/Helpers/FileOperationsHelpers.cs @@ -220,7 +220,7 @@ public static Task DragDropAsync(string dropPath) }); } - public static Task<(bool, ShellOperationResult)> DeleteItemAsync(string[] fileToDeletePath, bool permanently, long ownerHwnd, string operationID = "") + public static Task<(bool, ShellOperationResult)> DeleteItemAsync(string[] fileToDeletePath, bool permanently, long ownerHwnd, string operationID = "", IProgress? progress = default) { operationID = string.IsNullOrEmpty(operationID) ? Guid.NewGuid().ToString() : operationID; @@ -285,6 +285,7 @@ public static Task DragDropAsync(string dropPath) { throw new Win32Exception(unchecked((int)0x80004005)); // E_FAIL, stops operation } + progress?.Report(e.ProgressPercentage); progressHandler.UpdateOperation(operationID, e.ProgressPercentage); }; @@ -362,7 +363,7 @@ public static Task DragDropAsync(string dropPath) }); } - public static Task<(bool, ShellOperationResult)> MoveItemAsync(string[] fileToMovePath, string[] moveDestination, bool overwriteOnMove, long ownerHwnd, string operationID = "") + public static Task<(bool, ShellOperationResult)> MoveItemAsync(string[] fileToMovePath, string[] moveDestination, bool overwriteOnMove, long ownerHwnd, string operationID = "", IProgress? progress = default) { operationID = string.IsNullOrEmpty(operationID) ? Guid.NewGuid().ToString() : operationID; @@ -419,6 +420,7 @@ public static Task DragDropAsync(string dropPath) { throw new Win32Exception(unchecked((int)0x80004005)); // E_FAIL, stops operation } + progress?.Report(e.ProgressPercentage); progressHandler.UpdateOperation(operationID, e.ProgressPercentage); }; @@ -437,7 +439,7 @@ public static Task DragDropAsync(string dropPath) }); } - public static Task<(bool, ShellOperationResult)> CopyItemAsync(string[] fileToCopyPath, string[] copyDestination, bool overwriteOnCopy, long ownerHwnd, string operationID = "") + public static Task<(bool, ShellOperationResult)> CopyItemAsync(string[] fileToCopyPath, string[] copyDestination, bool overwriteOnCopy, long ownerHwnd, string operationID = "", IProgress? progress = default) { operationID = string.IsNullOrEmpty(operationID) ? Guid.NewGuid().ToString() : operationID; @@ -495,6 +497,7 @@ public static Task DragDropAsync(string dropPath) { throw new Win32Exception(unchecked((int)0x80004005)); // E_FAIL, stops operation } + progress?.Report(e.ProgressPercentage); progressHandler.UpdateOperation(operationID, e.ProgressPercentage); };