Skip to content

Commit ba83287

Browse files
authored
Improved performance of the delete confirmation dialog (#8041)
1 parent 14ca745 commit ba83287

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

src/Files.Launcher/MessageHandlers/FileOperationsHandler.cs

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,12 @@ await Win32API.StartSTATask(() =>
7777
var operation = (DataPackageOperation)(long)message["operation"];
7878
var fileList = new System.Collections.Specialized.StringCollection();
7979
fileList.AddRange(fileToCopy.Split('|'));
80-
if (operation == DataPackageOperation.Copy)
81-
{
82-
System.Windows.Forms.Clipboard.SetFileDropList(fileList);
83-
}
84-
else if (operation == DataPackageOperation.Move)
85-
{
86-
byte[] moveEffect = new byte[] { 2, 0, 0, 0 };
87-
MemoryStream dropEffect = new MemoryStream();
88-
dropEffect.Write(moveEffect, 0, moveEffect.Length);
89-
var data = new System.Windows.Forms.DataObject();
90-
data.SetFileDropList(fileList);
91-
data.SetData("Preferred DropEffect", dropEffect);
92-
System.Windows.Forms.Clipboard.SetDataObject(data, true);
93-
}
80+
MemoryStream dropEffect = new MemoryStream(operation == DataPackageOperation.Copy ?
81+
new byte[] { 5, 0, 0, 0 } : new byte[] { 2, 0, 0, 0 });
82+
var data = new System.Windows.Forms.DataObject();
83+
data.SetFileDropList(fileList);
84+
data.SetData("Preferred DropEffect", dropEffect);
85+
System.Windows.Forms.Clipboard.SetDataObject(data, true);
9486
return true;
9587
});
9688
break;
@@ -233,7 +225,8 @@ await Win32API.StartSTATask(() =>
233225
if (!Extensions.IgnoreExceptions(() =>
234226
{
235227
using var shi = new ShellItem(fileToDeletePath[i]);
236-
op.QueueDeleteOperation(shi);
228+
var file = Extensions.IgnoreExceptions(() => GetFirstFile(shi)) ?? shi;
229+
op.QueueDeleteOperation(file);
237230
}))
238231
{
239232
shellOperationResult.Items.Add(new ShellOperationItemResult()
@@ -821,6 +814,28 @@ await Win32API.StartSTATask(() =>
821814
}
822815
}
823816

817+
private ShellItem GetFirstFile(ShellItem shi)
818+
{
819+
if (!shi.IsFolder || shi.Attributes.HasFlag(ShellItemAttribute.Stream))
820+
{
821+
return shi;
822+
}
823+
using var shf = new ShellFolder(shi);
824+
if (shf.FirstOrDefault(x => !x.IsFolder || x.Attributes.HasFlag(ShellItemAttribute.Stream)) is ShellItem item)
825+
{
826+
return item;
827+
}
828+
foreach (var shsfi in shf.Where(x => x.IsFolder && !x.Attributes.HasFlag(ShellItemAttribute.Stream)))
829+
{
830+
using var shsf = new ShellFolder(shsfi);
831+
if (GetFirstFile(shsf) is ShellItem item2)
832+
{
833+
return item2;
834+
}
835+
}
836+
return null;
837+
}
838+
824839
public void WaitForCompletion()
825840
{
826841
progressHandler.WaitForCompletion();

0 commit comments

Comments
 (0)