@@ -87,9 +87,6 @@ private static void Main(string[] args)
8787 librariesWatcher . Renamed += ( object _ , RenamedEventArgs e ) => OnLibraryChanged ( e . ChangeType , e . OldFullPath , e . FullPath ) ;
8888 librariesWatcher . EnableRaisingEvents = true ;
8989
90- // Create cancellation token for drop window
91- cancellation = new CancellationTokenSource ( ) ;
92-
9390 // Connect to app service and wait until the connection gets closed
9491 appServiceExit = new ManualResetEvent ( false ) ;
9592 InitializeAppServiceConnection ( ) ;
@@ -116,8 +113,6 @@ private static void Main(string[] args)
116113 handleTable ? . Dispose ( ) ;
117114 deviceWatcher ? . Dispose ( ) ;
118115 librariesWatcher ? . Dispose ( ) ;
119- cancellation ? . Cancel ( ) ;
120- cancellation ? . Dispose ( ) ;
121116 appServiceExit ? . Dispose ( ) ;
122117 }
123118 }
@@ -157,7 +152,6 @@ private static async void RecycleBinWatcher_Changed(object sender, FileSystemEve
157152
158153 private static NamedPipeServerStream connection ;
159154 private static ManualResetEvent appServiceExit ;
160- private static CancellationTokenSource cancellation ;
161155 private static Win32API . DisposableDictionary handleTable ;
162156 private static IList < FileSystemWatcher > binWatchers ;
163157 private static DeviceWatcher deviceWatcher ;
@@ -872,17 +866,46 @@ await Win32API.StartSTATask(() =>
872866 break ;
873867
874868 case "DragDrop" :
875- cancellation . Cancel ( ) ;
876- cancellation . Dispose ( ) ;
877- cancellation = new CancellationTokenSource ( ) ;
878869 var dropPath = ( string ) message [ "droppath" ] ;
879- var dropText = ( string ) message [ "droptext" ] ;
880- var drops = Win32API . StartSTATask < List < string > > ( ( ) =>
870+ var result2 = await Win32API . StartSTATask ( ( ) =>
881871 {
882- var form = new DragDropForm ( dropPath , dropText , cancellation . Token ) ;
883- System . Windows . Forms . Application . Run ( form ) ;
884- return form . DropTargets ;
872+ var rdo = new RemoteDataObject ( System . Windows . Forms . Clipboard . GetDataObject ( ) ) ;
873+
874+ foreach ( RemoteDataObject . DataPackage package in rdo . GetRemoteData ( ) )
875+ {
876+ try
877+ {
878+ if ( package . ItemType == RemoteDataObject . StorageType . File )
879+ {
880+ string directoryPath = Path . GetDirectoryName ( dropPath ) ;
881+ if ( ! Directory . Exists ( directoryPath ) )
882+ {
883+ Directory . CreateDirectory ( directoryPath ) ;
884+ }
885+
886+ string uniqueName = Win32API . GenerateUniquePath ( Path . Combine ( dropPath , package . Name ) ) ;
887+ using ( FileStream stream = new FileStream ( uniqueName , FileMode . CreateNew ) )
888+ {
889+ package . ContentStream . CopyTo ( stream ) ;
890+ }
891+ }
892+ else
893+ {
894+ string directoryPath = Path . Combine ( dropPath , package . Name ) ;
895+ if ( ! Directory . Exists ( directoryPath ) )
896+ {
897+ Directory . CreateDirectory ( directoryPath ) ;
898+ }
899+ }
900+ }
901+ finally
902+ {
903+ package . Dispose ( ) ;
904+ }
905+ }
906+ return true ;
885907 } ) ;
908+ await Win32API . SendMessageAsync ( connection , new ValueSet ( ) { { "Success" , result2 } } , message . Get ( "RequestID" , ( string ) null ) ) ;
886909 break ;
887910
888911 case "DeleteItem" :
0 commit comments