Skip to content

Commit

Permalink
Fix: Fixed issue where online-only files deleted before confirmation (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
hishitetsu authored Feb 17, 2023
1 parent 607eb50 commit aaeb7b0
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/Files.App/Helpers/FileOperationsHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ namespace Files.App.Helpers
{
public class FileOperationsHelpers
{
private static readonly Ole32.PROPERTYKEY PKEY_FilePlaceholderStatus = new Ole32.PROPERTYKEY(new Guid("B2F9B9D6-FEC4-4DD5-94D7-8957488C807B"), 2);
private const uint PS_CLOUDFILE_PLACEHOLDER = 8;

private static ProgressHandler? progressHandler; // Warning: must be initialized from a MTA thread

public static Task SetClipboard(string[] filesToCopy, DataPackageOperation operation)
Expand Down Expand Up @@ -119,14 +122,29 @@ public static Task SetClipboard(string[] filesToCopy, DataPackageOperation opera
op.Options |= ShellFileOperations.OperationFlags.RecycleOnDelete;

var shellOperationResult = new ShellOperationResult();
var tryDelete = false;

for (var i = 0; i < fileToDeletePath.Length; i++)
{
if (!SafetyExtensions.IgnoreExceptions(() =>
{
using var shi = new ShellItem(fileToDeletePath[i]);
var file = SafetyExtensions.IgnoreExceptions(() => GetFirstFile(shi)) ?? shi;
op.QueueDeleteOperation(file);
if (file.Properties.GetProperty<uint>(PKEY_FilePlaceholderStatus) == PS_CLOUDFILE_PLACEHOLDER)
{
// Online only files cannot be tried for deletion, so they are treated as to be permanently deleted.
shellOperationResult.Items.Add(new ShellOperationItemResult()
{
Succeeded = false,
Source = fileToDeletePath[i],
HResult = HRESULT.COPYENGINE_E_RECYCLE_BIN_NOT_FOUND
});
}
else
{
op.QueueDeleteOperation(file);
tryDelete = true;
}
}))
{
shellOperationResult.Items.Add(new ShellOperationItemResult()
Expand All @@ -138,6 +156,9 @@ public static Task SetClipboard(string[] filesToCopy, DataPackageOperation opera
}
}

if (!tryDelete)
return (true, shellOperationResult);

var deleteTcs = new TaskCompletionSource<bool>();
op.PreDeleteItem += [DebuggerHidden] (s, e) =>
{
Expand Down

0 comments on commit aaeb7b0

Please sign in to comment.