@@ -77,20 +77,12 @@ await Win32API.StartSTATask(() =>
77
77
var operation = ( DataPackageOperation ) ( long ) message [ "operation" ] ;
78
78
var fileList = new System . Collections . Specialized . StringCollection ( ) ;
79
79
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 ) ;
94
86
return true ;
95
87
} ) ;
96
88
break ;
@@ -233,7 +225,8 @@ await Win32API.StartSTATask(() =>
233
225
if ( ! Extensions . IgnoreExceptions ( ( ) =>
234
226
{
235
227
using var shi = new ShellItem ( fileToDeletePath [ i ] ) ;
236
- op . QueueDeleteOperation ( shi ) ;
228
+ var file = Extensions . IgnoreExceptions ( ( ) => GetFirstFile ( shi ) ) ?? shi ;
229
+ op . QueueDeleteOperation ( file ) ;
237
230
} ) )
238
231
{
239
232
shellOperationResult . Items . Add ( new ShellOperationItemResult ( )
@@ -821,6 +814,28 @@ await Win32API.StartSTATask(() =>
821
814
}
822
815
}
823
816
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
+
824
839
public void WaitForCompletion ( )
825
840
{
826
841
progressHandler . WaitForCompletion ( ) ;
0 commit comments