@@ -65,7 +65,7 @@ public FilesystemOperations(IShellPage associatedInstance)
65
65
var newEntryInfo = await RegistryHelper . GetNewContextMenuEntryForType ( Path . GetExtension ( source . Path ) ) ;
66
66
if ( newEntryInfo == null )
67
67
{
68
- BaseStorageFolder folder = await associatedInstance . FilesystemViewModel . GetFolderFromPathAsync ( Path . GetDirectoryName ( source . Path ) ) ;
68
+ BaseStorageFolder folder = await associatedInstance . FilesystemViewModel . GetFolderFromPathAsync ( PathNormalization . GetParentDir ( source . Path ) ) ;
69
69
item = await folder . CreateFileAsync ( Path . GetFileName ( source . Path ) ) ;
70
70
}
71
71
else
@@ -78,7 +78,7 @@ public FilesystemOperations(IShellPage associatedInstance)
78
78
79
79
case FilesystemItemType . Directory :
80
80
{
81
- BaseStorageFolder folder = await associatedInstance . FilesystemViewModel . GetFolderFromPathAsync ( Path . GetDirectoryName ( source . Path ) ) ;
81
+ BaseStorageFolder folder = await associatedInstance . FilesystemViewModel . GetFolderFromPathAsync ( PathNormalization . GetParentDir ( source . Path ) ) ;
82
82
item = await folder . CreateFolderAsync ( Path . GetFileName ( source . Path ) ) ;
83
83
84
84
break ;
@@ -145,7 +145,7 @@ await DialogDisplayHelper.ShowDialogAsync(
145
145
if ( source . ItemType == FilesystemItemType . Directory )
146
146
{
147
147
if ( ! string . IsNullOrWhiteSpace ( source . Path ) &&
148
- Path . GetDirectoryName ( destination ) . IsSubPathOf ( source . Path ) ) // We check if user tried to copy anything above the source.ItemPath
148
+ PathNormalization . GetParentDir ( destination ) . IsSubPathOf ( source . Path ) ) // We check if user tried to copy anything above the source.ItemPath
149
149
{
150
150
var destinationName = destination . Split ( Path . DirectorySeparatorChar , StringSplitOptions . RemoveEmptyEntries ) . Last ( ) ;
151
151
var sourceName = source . Path . Split ( Path . DirectorySeparatorChar , StringSplitOptions . RemoveEmptyEntries ) . Last ( ) ;
@@ -171,11 +171,11 @@ await DialogDisplayHelper.ShowDialogAsync(
171
171
}
172
172
return null ;
173
173
}
174
- else if ( ! FtpHelpers . IsFtpPath ( destination ) && ! FtpHelpers . IsFtpPath ( source . Path ) )
174
+ else
175
175
{
176
176
// CopyFileFromApp only works on file not directories
177
177
var fsSourceFolder = await source . ToStorageItemResult ( associatedInstance ) ;
178
- var fsDestinationFolder = await associatedInstance . FilesystemViewModel . GetFolderFromPathAsync ( Path . GetDirectoryName ( destination ) ) ;
178
+ var fsDestinationFolder = await associatedInstance . FilesystemViewModel . GetFolderFromPathAsync ( PathNormalization . GetParentDir ( destination ) ) ;
179
179
var fsResult = ( FilesystemResult ) ( fsSourceFolder . ErrorCode | fsDestinationFolder . ErrorCode ) ;
180
180
181
181
if ( fsResult )
@@ -218,38 +218,16 @@ await DialogDisplayHelper.ShowDialogAsync(
218
218
return null ;
219
219
}
220
220
}
221
- else if ( FtpHelpers . IsFtpPath ( destination ) && ! FtpHelpers . IsFtpPath ( source . Path ) )
222
- {
223
- var fsSourceFolder = await source . ToStorageItemResult ( associatedInstance ) ;
224
- var ftpDestFolder = await new StorageFolderWithPath ( null , destination ) . ToStorageItemResult ( associatedInstance ) ;
225
- var fsCopyResult = await FilesystemTasks . Wrap ( ( ) => CloneDirectoryToFtpAsync ( ( BaseStorageFolder ) fsSourceFolder , ( FtpStorageFolder ) ftpDestFolder . Result , collision . Convert ( ) ) ) ;
226
-
227
- if ( fsCopyResult == FileSystemStatusCode . AlreadyExists )
228
- {
229
- errorCode ? . Report ( FileSystemStatusCode . AlreadyExists ) ;
230
- progress ? . Report ( 100.0f ) ;
231
- return null ;
232
- }
233
-
234
- errorCode ? . Report ( fsCopyResult ? FileSystemStatusCode . Success : FileSystemStatusCode . Generic ) ;
235
- progress ? . Report ( 100.0f ) ;
236
- return null ;
237
- }
238
- else
239
- {
240
- errorCode ? . Report ( FileSystemStatusCode . Generic ) ;
241
- return null ;
242
- }
243
221
}
244
- else if ( source . ItemType == FilesystemItemType . File && ! string . IsNullOrEmpty ( source . Path ) && ! FtpHelpers . IsFtpPath ( destination ) )
222
+ else if ( source . ItemType == FilesystemItemType . File )
245
223
{
246
224
var fsResult = ( FilesystemResult ) await Task . Run ( ( ) => NativeFileOperationsHelper . CopyFileFromApp ( source . Path , destination , true ) ) ;
247
225
248
226
if ( ! fsResult )
249
227
{
250
228
Debug . WriteLine ( System . Runtime . InteropServices . Marshal . GetLastWin32Error ( ) ) ;
251
229
252
- FilesystemResult < BaseStorageFolder > destinationResult = await associatedInstance . FilesystemViewModel . GetFolderFromPathAsync ( Path . GetDirectoryName ( destination ) ) ;
230
+ FilesystemResult < BaseStorageFolder > destinationResult = await associatedInstance . FilesystemViewModel . GetFolderFromPathAsync ( PathNormalization . GetParentDir ( destination ) ) ;
253
231
var sourceResult = await source . ToStorageItemResult ( associatedInstance ) ;
254
232
fsResult = sourceResult . ErrorCode | destinationResult . ErrorCode ;
255
233
@@ -299,67 +277,8 @@ await DialogDisplayHelper.ShowDialogAsync(
299
277
return null ;
300
278
}
301
279
}
302
- else if ( string . IsNullOrEmpty ( source . Path ) && ! FtpHelpers . IsFtpPath ( destination ) )
303
- {
304
- var fsResult = source . Item is BaseStorageFile file ? await FilesystemTasks . Wrap ( async ( ) =>
305
- await file . CopyAsync (
306
- await StorageFileExtensions . DangerousGetFolderFromPathAsync ( Path . GetDirectoryName ( destination ) ) ,
307
- file . Name ,
308
- collision ) ) : new FilesystemResult < BaseStorageFile > ( null , FileSystemStatusCode . Generic ) ;
309
-
310
- if ( ! fsResult )
311
- {
312
- errorCode ? . Report ( fsResult . ErrorCode ) ;
313
- return null ;
314
- }
315
- }
316
- else if ( FtpHelpers . IsFtpPath ( destination ) )
317
- {
318
- using var ftpClient = new FtpClient ( ) ;
319
- ftpClient . Host = FtpHelpers . GetFtpHost ( destination ) ;
320
- ftpClient . Port = FtpHelpers . GetFtpPort ( destination ) ;
321
- ftpClient . Credentials = FtpManager . Credentials . Get ( ftpClient . Host , FtpManager . Anonymous ) ;
322
-
323
- if ( ! await ftpClient . EnsureConnectedAsync ( ) )
324
- {
325
- errorCode ? . Report ( FileSystemStatusCode . Generic ) ;
326
- return null ;
327
- }
328
-
329
- if ( source . Item is BaseStorageFile file )
330
- {
331
- void ReportFtpPorgress ( object sender , FtpProgress p )
332
- {
333
- progress ? . Report ( ( float ) p . Progress ) ;
334
- }
335
-
336
- using var stream = await file . OpenStreamForReadAsync ( ) ;
337
-
338
- var ftpProgress = new Progress < FtpProgress > ( ) ;
339
- ftpProgress . ProgressChanged += ReportFtpPorgress ;
340
-
341
- var result = await ftpClient . UploadAsync ( stream , FtpHelpers . GetFtpPath ( destination ) , collision switch
342
- {
343
- NameCollisionOption . ReplaceExisting => FtpRemoteExists . Overwrite ,
344
- _ => FtpRemoteExists . Skip ,
345
- } , false , ftpProgress , cancellationToken ) ;
346
-
347
- ftpProgress . ProgressChanged -= ReportFtpPorgress ;
348
-
349
- if ( result != FtpStatus . Success )
350
- {
351
- errorCode ? . Report ( FileSystemStatusCode . Generic ) ;
352
- return null ;
353
- }
354
- }
355
- }
356
- else
357
- {
358
- errorCode ? . Report ( FileSystemStatusCode . Generic ) ;
359
- return null ;
360
- }
361
280
362
- if ( Path . GetDirectoryName ( destination ) == associatedInstance . FilesystemViewModel . WorkingDirectory . TrimPath ( ) )
281
+ if ( PathNormalization . GetParentDir ( destination ) == associatedInstance . FilesystemViewModel . WorkingDirectory . TrimPath ( ) )
363
282
{
364
283
await Windows . ApplicationModel . Core . CoreApplication . MainView . DispatcherQueue . EnqueueAsync ( async ( ) =>
365
284
{
@@ -444,7 +363,7 @@ await DialogDisplayHelper.ShowDialogAsync(
444
363
if ( source . ItemType == FilesystemItemType . Directory )
445
364
{
446
365
if ( ! string . IsNullOrWhiteSpace ( source . Path ) &&
447
- Path . GetDirectoryName ( destination ) . IsSubPathOf ( source . Path ) ) // We check if user tried to move anything above the source.ItemPath
366
+ PathNormalization . GetParentDir ( destination ) . IsSubPathOf ( source . Path ) ) // We check if user tried to move anything above the source.ItemPath
448
367
{
449
368
var destinationName = destination . Split ( Path . DirectorySeparatorChar , StringSplitOptions . RemoveEmptyEntries ) . Last ( ) ;
450
369
var sourceName = source . Path . Split ( Path . DirectorySeparatorChar , StringSplitOptions . RemoveEmptyEntries ) . Last ( ) ;
@@ -479,7 +398,7 @@ await DialogDisplayHelper.ShowDialogAsync(
479
398
Debug . WriteLine ( System . Runtime . InteropServices . Marshal . GetLastWin32Error ( ) ) ;
480
399
481
400
var fsSourceFolder = await source . ToStorageItemResult ( associatedInstance ) ;
482
- var fsDestinationFolder = await associatedInstance . FilesystemViewModel . GetFolderFromPathAsync ( Path . GetDirectoryName ( destination ) ) ;
401
+ var fsDestinationFolder = await associatedInstance . FilesystemViewModel . GetFolderFromPathAsync ( PathNormalization . GetParentDir ( destination ) ) ;
483
402
fsResult = fsSourceFolder . ErrorCode | fsDestinationFolder . ErrorCode ;
484
403
485
404
if ( fsResult )
@@ -528,7 +447,7 @@ await DialogDisplayHelper.ShowDialogAsync(
528
447
{
529
448
Debug . WriteLine ( System . Runtime . InteropServices . Marshal . GetLastWin32Error ( ) ) ;
530
449
531
- FilesystemResult < BaseStorageFolder > destinationResult = await associatedInstance . FilesystemViewModel . GetFolderFromPathAsync ( Path . GetDirectoryName ( destination ) ) ;
450
+ FilesystemResult < BaseStorageFolder > destinationResult = await associatedInstance . FilesystemViewModel . GetFolderFromPathAsync ( PathNormalization . GetParentDir ( destination ) ) ;
532
451
var sourceResult = await source . ToStorageItemResult ( associatedInstance ) ;
533
452
fsResult = sourceResult . ErrorCode | destinationResult . ErrorCode ;
534
453
@@ -566,7 +485,7 @@ await DialogDisplayHelper.ShowDialogAsync(
566
485
errorCode ? . Report ( fsResult . ErrorCode ) ;
567
486
}
568
487
569
- if ( Path . GetDirectoryName ( destination ) == associatedInstance . FilesystemViewModel . WorkingDirectory . TrimPath ( ) )
488
+ if ( PathNormalization . GetParentDir ( destination ) == associatedInstance . FilesystemViewModel . WorkingDirectory . TrimPath ( ) )
570
489
{
571
490
await Windows . ApplicationModel . Core . CoreApplication . MainView . DispatcherQueue . EnqueueAsync ( async ( ) =>
572
491
{
@@ -844,7 +763,7 @@ public async Task<IStorageHistory> RestoreFromTrashAsync(IStorageItemWithPath so
844
763
if ( source . ItemType == FilesystemItemType . Directory )
845
764
{
846
765
FilesystemResult < BaseStorageFolder > sourceFolder = await associatedInstance . FilesystemViewModel . GetFolderFromPathAsync ( source . Path ) ;
847
- FilesystemResult < BaseStorageFolder > destinationFolder = await associatedInstance . FilesystemViewModel . GetFolderFromPathAsync ( Path . GetDirectoryName ( destination ) ) ;
766
+ FilesystemResult < BaseStorageFolder > destinationFolder = await associatedInstance . FilesystemViewModel . GetFolderFromPathAsync ( PathNormalization . GetParentDir ( destination ) ) ;
848
767
849
768
fsResult = sourceFolder . ErrorCode | destinationFolder . ErrorCode ;
850
769
errorCode ? . Report ( fsResult ) ;
@@ -860,7 +779,7 @@ public async Task<IStorageHistory> RestoreFromTrashAsync(IStorageItemWithPath so
860
779
else
861
780
{
862
781
FilesystemResult < BaseStorageFile > sourceFile = await associatedInstance . FilesystemViewModel . GetFileFromPathAsync ( source . Path ) ;
863
- FilesystemResult < BaseStorageFolder > destinationFolder = await associatedInstance . FilesystemViewModel . GetFolderFromPathAsync ( Path . GetDirectoryName ( destination ) ) ;
782
+ FilesystemResult < BaseStorageFolder > destinationFolder = await associatedInstance . FilesystemViewModel . GetFolderFromPathAsync ( PathNormalization . GetParentDir ( destination ) ) ;
864
783
865
784
fsResult = sourceFile . ErrorCode | destinationFolder . ErrorCode ;
866
785
errorCode ? . Report ( fsResult ) ;
@@ -935,24 +854,6 @@ private async static Task<BaseStorageFolder> CloneDirectoryAsync(BaseStorageFold
935
854
return createdRoot ;
936
855
}
937
856
938
- private async static Task CloneDirectoryToFtpAsync ( BaseStorageFolder sourceFolder , FtpStorageFolder destinationFolder , CreationCollisionOption collision = CreationCollisionOption . FailIfExists )
939
- {
940
- var result = await FilesystemTasks . Wrap ( async ( ) => await destinationFolder . CreateFolderAsync ( sourceFolder . Name , collision ) ) ;
941
-
942
- if ( result )
943
- {
944
- foreach ( BaseStorageFile fileInSourceDir in await sourceFolder . GetFilesAsync ( ) )
945
- {
946
- await destinationFolder . UploadFileAsync ( fileInSourceDir , fileInSourceDir . Name , NameCollisionOption . FailIfExists ) ;
947
- }
948
-
949
- foreach ( BaseStorageFolder folderinSourceDir in await sourceFolder . GetFoldersAsync ( ) )
950
- {
951
- await CloneDirectoryToFtpAsync ( folderinSourceDir , destinationFolder . CloneWithPath ( $ "{ destinationFolder . Path } /{ sourceFolder . Name } ") ) ;
952
- }
953
- }
954
- }
955
-
956
857
private static async Task < BaseStorageFolder > MoveDirectoryAsync ( BaseStorageFolder sourceFolder , BaseStorageFolder destinationDirectory , string sourceRootName , CreationCollisionOption collision = CreationCollisionOption . FailIfExists , bool deleteSource = false )
957
858
{
958
859
BaseStorageFolder createdRoot = await destinationDirectory . CreateFolderAsync ( sourceRootName , collision ) ;
0 commit comments