@@ -166,6 +166,19 @@ public async Task<IStorageHistory> CopyItemsAsync(IList<IStorageItemWithPath> so
166
166
var lockingProcess = await WhoIsLockingAsync ( failedSources . Select ( x => x . HResult == HResult . COPYENGINE_E_SHARING_VIOLATION_SRC ? x . Source : x . Destination ) ) ;
167
167
await DialogDisplayHelper . ShowDialogAsync ( "FileInUseDeleteDialog/Title" . GetLocalized ( ) , lockingProcess != null ? string . Join ( Environment . NewLine , lockingProcess . Select ( x => $ "Name: { x . Name } , PID: { x . Pid } ") ) : "" ) ;
168
168
}
169
+ else if ( copyResult . Items . Any ( x => HResult . Convert ( x . HResult ) == FileSystemStatusCode . NameTooLong ) )
170
+ {
171
+ // Retry with StorageFile API
172
+ return await filesystemOperations . CopyItemsAsync ( source , destination , collisions , progress , errorCode , cancellationToken ) ;
173
+ }
174
+ else if ( copyResult . Items . Any ( x => HResult . Convert ( x . HResult ) == FileSystemStatusCode . NotFound ) )
175
+ {
176
+ await DialogDisplayHelper . ShowDialogAsync ( "FileNotFoundDialog/Title" . GetLocalized ( ) , "FileNotFoundDialog/Text" . GetLocalized ( ) ) ;
177
+ }
178
+ else if ( copyResult . Items . Any ( x => HResult . Convert ( x . HResult ) == FileSystemStatusCode . AlreadyExists ) )
179
+ {
180
+ await DialogDisplayHelper . ShowDialogAsync ( "ItemAlreadyExistsDialogTitle" . GetLocalized ( ) , "ItemAlreadyExistsDialogContent" . GetLocalized ( ) ) ;
181
+ }
169
182
errorCode ? . Report ( HResult . Convert ( copyResult . Items . FirstOrDefault ( x => ! x . Succeeded ) ? . HResult ) ) ;
170
183
return null ;
171
184
}
@@ -254,6 +267,19 @@ public async Task<IStorageHistory> CopyItemsAsync(IList<IStorageItemWithPath> so
254
267
return await CreateAsync ( source , errorCode , cancellationToken ) ;
255
268
}
256
269
}
270
+ else if ( createResult . Items . Any ( x => HResult . Convert ( x . HResult ) == FileSystemStatusCode . NameTooLong ) )
271
+ {
272
+ // Retry with StorageFile API
273
+ return await filesystemOperations . CreateAsync ( source , errorCode , cancellationToken ) ;
274
+ }
275
+ else if ( createResult . Items . Any ( x => HResult . Convert ( x . HResult ) == FileSystemStatusCode . NotFound ) )
276
+ {
277
+ await DialogDisplayHelper . ShowDialogAsync ( "FileNotFoundDialog/Title" . GetLocalized ( ) , "FileNotFoundDialog/Text" . GetLocalized ( ) ) ;
278
+ }
279
+ else if ( createResult . Items . Any ( x => HResult . Convert ( x . HResult ) == FileSystemStatusCode . AlreadyExists ) )
280
+ {
281
+ await DialogDisplayHelper . ShowDialogAsync ( "ItemAlreadyExistsDialogTitle" . GetLocalized ( ) , "ItemAlreadyExistsDialogContent" . GetLocalized ( ) ) ;
282
+ }
257
283
errorCode ? . Report ( HResult . Convert ( createResult . Items . FirstOrDefault ( x => ! x . Succeeded ) ? . HResult ) ) ;
258
284
return ( null , null ) ;
259
285
}
@@ -397,6 +423,10 @@ public async Task<IStorageHistory> DeleteItemsAsync(IList<IStorageItemWithPath>
397
423
var lockingProcess = await WhoIsLockingAsync ( failedSources . Select ( x => x . HResult == HResult . COPYENGINE_E_SHARING_VIOLATION_SRC ? x . Source : x . Destination ) ) ;
398
424
await DialogDisplayHelper . ShowDialogAsync ( "FileInUseDeleteDialog/Title" . GetLocalized ( ) , lockingProcess != null ? string . Join ( Environment . NewLine , lockingProcess . Select ( x => $ "Name: { x . Name } , PID: { x . Pid } ") ) : "" ) ;
399
425
}
426
+ else if ( deleteResult . Items . Any ( x => HResult . Convert ( x . HResult ) == FileSystemStatusCode . NotFound ) )
427
+ {
428
+ await DialogDisplayHelper . ShowDialogAsync ( "FileNotFoundDialog/Title" . GetLocalized ( ) , "FileNotFoundDialog/Text" . GetLocalized ( ) ) ;
429
+ }
400
430
errorCode ? . Report ( HResult . Convert ( deleteResult . Items . FirstOrDefault ( x => ! x . Succeeded ) ? . HResult ) ) ;
401
431
return null ;
402
432
}
@@ -515,13 +545,32 @@ public async Task<IStorageHistory> MoveItemsAsync(IList<IStorageItemWithPath> so
515
545
return await MoveItemsAsync ( source , destination , collisions , progress , errorCode , cancellationToken ) ;
516
546
}
517
547
}
548
+ else if ( source . Zip ( destination , ( src , dest ) => ( src , dest ) ) . FirstOrDefault ( x => x . src . ItemType == FilesystemItemType . Directory && PathNormalization . GetParentDir ( x . dest ) . IsSubPathOf ( x . src . Path ) ) is ( IStorageItemWithPath , string ) subtree )
549
+ {
550
+ var destName = subtree . dest . Split ( Path . DirectorySeparatorChar , StringSplitOptions . RemoveEmptyEntries ) . Last ( ) ;
551
+ var srcName = subtree . src . Path . Split ( Path . DirectorySeparatorChar , StringSplitOptions . RemoveEmptyEntries ) . Last ( ) ;
552
+ await DialogDisplayHelper . ShowDialogAsync ( "ErrorDialogThisActionCannotBeDone" . GetLocalized ( ) , $ "{ "ErrorDialogTheDestinationFolder" . GetLocalized ( ) } ({ destName } ) { "ErrorDialogIsASubfolder" . GetLocalized ( ) } ({ srcName } )") ;
553
+ }
518
554
else if ( moveResult . Items . Any ( x => HResult . Convert ( x . HResult ) == FileSystemStatusCode . InUse ) )
519
555
{
520
556
// TODO: proper dialog, retry
521
557
var failedSources = moveResult . Items . Where ( x => HResult . Convert ( x . HResult ) == FileSystemStatusCode . InUse ) ;
522
558
var lockingProcess = await WhoIsLockingAsync ( failedSources . Select ( x => x . HResult == HResult . COPYENGINE_E_SHARING_VIOLATION_SRC ? x . Source : x . Destination ) ) ;
523
559
await DialogDisplayHelper . ShowDialogAsync ( "FileInUseDeleteDialog/Title" . GetLocalized ( ) , lockingProcess != null ? string . Join ( Environment . NewLine , lockingProcess . Select ( x => $ "Name: { x . Name } , PID: { x . Pid } ") ) : "" ) ;
524
560
}
561
+ else if ( moveResult . Items . Any ( x => HResult . Convert ( x . HResult ) == FileSystemStatusCode . NameTooLong ) )
562
+ {
563
+ // Retry with StorageFile API
564
+ return await filesystemOperations . MoveItemsAsync ( source , destination , collisions , progress , errorCode , cancellationToken ) ;
565
+ }
566
+ else if ( moveResult . Items . Any ( x => HResult . Convert ( x . HResult ) == FileSystemStatusCode . NotFound ) )
567
+ {
568
+ await DialogDisplayHelper . ShowDialogAsync ( "FileNotFoundDialog/Title" . GetLocalized ( ) , "FileNotFoundDialog/Text" . GetLocalized ( ) ) ;
569
+ }
570
+ else if ( moveResult . Items . Any ( x => HResult . Convert ( x . HResult ) == FileSystemStatusCode . AlreadyExists ) )
571
+ {
572
+ await DialogDisplayHelper . ShowDialogAsync ( "ItemAlreadyExistsDialogTitle" . GetLocalized ( ) , "ItemAlreadyExistsDialogContent" . GetLocalized ( ) ) ;
573
+ }
525
574
errorCode ? . Report ( HResult . Convert ( moveResult . Items . FirstOrDefault ( x => ! x . Succeeded ) ? . HResult ) ) ;
526
575
return null ;
527
576
}
@@ -586,6 +635,19 @@ public async Task<IStorageHistory> RenameAsync(IStorageItemWithPath source, stri
586
635
var lockingProcess = await WhoIsLockingAsync ( failedSources . Select ( x => x . HResult == HResult . COPYENGINE_E_SHARING_VIOLATION_SRC ? x . Source : x . Destination ) ) ;
587
636
await DialogDisplayHelper . ShowDialogAsync ( "FileInUseDeleteDialog/Title" . GetLocalized ( ) , lockingProcess != null ? string . Join ( Environment . NewLine , lockingProcess . Select ( x => $ "Name: { x . Name } , PID: { x . Pid } ") ) : "" ) ;
588
637
}
638
+ else if ( renameResult . Items . Any ( x => HResult . Convert ( x . HResult ) == FileSystemStatusCode . NameTooLong ) )
639
+ {
640
+ // Retry with StorageFile API
641
+ return await filesystemOperations . RenameAsync ( source , newName , collision , errorCode , cancellationToken ) ;
642
+ }
643
+ else if ( renameResult . Items . Any ( x => HResult . Convert ( x . HResult ) == FileSystemStatusCode . NotFound ) )
644
+ {
645
+ await DialogDisplayHelper . ShowDialogAsync ( "RenameError/ItemDeleted/Title" . GetLocalized ( ) , "RenameError/ItemDeleted/Text" . GetLocalized ( ) ) ;
646
+ }
647
+ else if ( renameResult . Items . Any ( x => HResult . Convert ( x . HResult ) == FileSystemStatusCode . AlreadyExists ) )
648
+ {
649
+ await DialogDisplayHelper . ShowDialogAsync ( "ItemAlreadyExistsDialogTitle" . GetLocalized ( ) , "ItemAlreadyExistsDialogContent" . GetLocalized ( ) ) ;
650
+ }
589
651
errorCode ? . Report ( HResult . Convert ( renameResult . Items . FirstOrDefault ( x => ! x . Succeeded ) ? . HResult ) ) ;
590
652
return null ;
591
653
}
@@ -681,6 +743,19 @@ public async Task<IStorageHistory> RestoreItemsFromTrashAsync(IList<IStorageItem
681
743
var lockingProcess = await WhoIsLockingAsync ( failedSources . Select ( x => x . HResult == HResult . COPYENGINE_E_SHARING_VIOLATION_SRC ? x . Source : x . Destination ) ) ;
682
744
await DialogDisplayHelper . ShowDialogAsync ( "FileInUseDeleteDialog/Title" . GetLocalized ( ) , lockingProcess != null ? string . Join ( Environment . NewLine , lockingProcess . Select ( x => $ "Name: { x . Name } , PID: { x . Pid } ") ) : "" ) ;
683
745
}
746
+ else if ( moveResult . Items . Any ( x => HResult . Convert ( x . HResult ) == FileSystemStatusCode . NameTooLong ) )
747
+ {
748
+ // Retry with StorageFile API
749
+ return await filesystemOperations . RestoreItemsFromTrashAsync ( source , destination , progress , errorCode , cancellationToken ) ;
750
+ }
751
+ else if ( moveResult . Items . Any ( x => HResult . Convert ( x . HResult ) == FileSystemStatusCode . NotFound ) )
752
+ {
753
+ await DialogDisplayHelper . ShowDialogAsync ( "FileNotFoundDialog/Title" . GetLocalized ( ) , "FileNotFoundDialog/Text" . GetLocalized ( ) ) ;
754
+ }
755
+ else if ( moveResult . Items . Any ( x => HResult . Convert ( x . HResult ) == FileSystemStatusCode . AlreadyExists ) )
756
+ {
757
+ await DialogDisplayHelper . ShowDialogAsync ( "ItemAlreadyExistsDialogTitle" . GetLocalized ( ) , "ItemAlreadyExistsDialogContent" . GetLocalized ( ) ) ;
758
+ }
684
759
errorCode ? . Report ( HResult . Convert ( moveResult . Items . FirstOrDefault ( x => ! x . Succeeded ) ? . HResult ) ) ;
685
760
return null ;
686
761
}
@@ -795,7 +870,6 @@ private struct HResult
795
870
//public const int COPYENGINE_E_SAME_FILE = -2144927741;
796
871
//public const int COPYENGINE_E_DEST_SAME_TREE = -2144927734;
797
872
//public const int COPYENGINE_E_DEST_SUBTREE = -2144927735;
798
- //public const int COPYENGINE_E_DIFF_DIR = -2144927740;
799
873
800
874
public static FileSystemStatusCode Convert ( int ? hres )
801
875
{
0 commit comments