Skip to content

Commit 239c3d7

Browse files
committed
7/22
1 parent c59731a commit 239c3d7

File tree

4 files changed

+28
-231
lines changed

4 files changed

+28
-231
lines changed

Files/Filesystem/FilesystemOperations/FilesystemOperations.cs

+17-89
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ public FilesystemOperations(IShellPage associatedInstance)
5050

5151
#region IFilesystemOperations
5252

53-
public async Task<(IStorageHistory, IStorageItem)> CreateAsync(IStorageItemWithPath source, IProgress<FileSystemStatusCode> errorCode, CancellationToken cancellationToken)
53+
public async Task<(IStorageHistory, IStorageItem)> CreateAsync(IStorageItem source, IProgress<FileSystemStatusCode> errorCode, CancellationToken cancellationToken)
5454
{
5555
IStorageItem item = null;
5656
try
5757
{
58-
switch (source.ItemType)
58+
switch (source)
5959
{
60-
case FilesystemItemType.File:
60+
case IStorageFile:
6161
{
6262
var newEntryInfo = await RegistryHelper.GetNewContextMenuEntryForType(Path.GetExtension(source.Path));
6363
if (newEntryInfo == null)
@@ -73,20 +73,14 @@ public FilesystemOperations(IShellPage associatedInstance)
7373
break;
7474
}
7575

76-
case FilesystemItemType.Directory:
76+
case IStorageFolder:
7777
{
7878
StorageFolder folder = await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(Path.GetDirectoryName(source.Path));
7979
item = await folder.CreateFolderAsync(Path.GetFileName(source.Path));
8080

8181
break;
8282
}
8383

84-
case FilesystemItemType.Symlink:
85-
{
86-
Debugger.Break();
87-
throw new NotImplementedException();
88-
}
89-
9084
default:
9185
Debugger.Break();
9286
break;
@@ -108,21 +102,6 @@ public async Task<IStorageHistory> CopyAsync(IStorageItem source,
108102
IProgress<float> progress,
109103
IProgress<FileSystemStatusCode> errorCode,
110104
CancellationToken cancellationToken)
111-
{
112-
return await CopyAsync(source.FromStorageItem(),
113-
destination,
114-
collision,
115-
progress,
116-
errorCode,
117-
cancellationToken);
118-
}
119-
120-
public async Task<IStorageHistory> CopyAsync(IStorageItemWithPath source,
121-
string destination,
122-
NameCollisionOption collision,
123-
IProgress<float> progress,
124-
IProgress<FileSystemStatusCode> errorCode,
125-
CancellationToken cancellationToken)
126105
{
127106
if (destination.StartsWith(App.AppSettings.RecycleBinPath))
128107
{
@@ -139,7 +118,7 @@ await DialogDisplayHelper.ShowDialogAsync(
139118
IStorageItem copiedItem = null;
140119
//long itemSize = await FilesystemHelpers.GetItemSize(await source.ToStorageItem(associatedInstance));
141120

142-
if (source.ItemType == FilesystemItemType.Directory)
121+
if (source is IStorageFolder)
143122
{
144123
if (!string.IsNullOrWhiteSpace(source.Path) &&
145124
Path.GetDirectoryName(destination).IsSubPathOf(source.Path)) // We check if user tried to copy anything above the source.ItemPath
@@ -216,7 +195,7 @@ await DialogDisplayHelper.ShowDialogAsync(
216195
}
217196
}
218197
}
219-
else if (source.ItemType == FilesystemItemType.File)
198+
else if (source is IStorageFile)
220199
{
221200
var fsResult = (FilesystemResult)await Task.Run(() => NativeFileOperationsHelper.CopyFileFromApp(source.Path, destination, true));
222201

@@ -291,9 +270,7 @@ await Windows.ApplicationModel.Core.CoreApplication.MainView.DispatcherQueue.Enq
291270
return null; // Cannot undo overwrite operation
292271
}
293272

294-
var pathWithType = copiedItem.FromStorageItem(destination, source.ItemType);
295-
296-
return new StorageHistory(FileOperationType.Copy, source, pathWithType);
273+
return new StorageHistory(FileOperationType.Copy, source, copiedItem);
297274
}
298275

299276
public async Task<IStorageHistory> MoveAsync(IStorageItem source,
@@ -302,21 +279,6 @@ public async Task<IStorageHistory> MoveAsync(IStorageItem source,
302279
IProgress<float> progress,
303280
IProgress<FileSystemStatusCode> errorCode,
304281
CancellationToken cancellationToken)
305-
{
306-
return await MoveAsync(source.FromStorageItem(),
307-
destination,
308-
collision,
309-
progress,
310-
errorCode,
311-
cancellationToken);
312-
}
313-
314-
public async Task<IStorageHistory> MoveAsync(IStorageItemWithPath source,
315-
string destination,
316-
NameCollisionOption collision,
317-
IProgress<float> progress,
318-
IProgress<FileSystemStatusCode> errorCode,
319-
CancellationToken cancellationToken)
320282
{
321283
if (source.Path == destination)
322284
{
@@ -348,7 +310,7 @@ await DialogDisplayHelper.ShowDialogAsync(
348310
IStorageItem movedItem = null;
349311
//long itemSize = await FilesystemHelpers.GetItemSize(await source.ToStorageItem(associatedInstance));
350312

351-
if (source.ItemType == FilesystemItemType.Directory)
313+
if (source is IStorageFolder)
352314
{
353315
if (!string.IsNullOrWhiteSpace(source.Path) &&
354316
Path.GetDirectoryName(destination).IsSubPathOf(source.Path)) // We check if user tried to move anything above the source.ItemPath
@@ -427,7 +389,7 @@ await DialogDisplayHelper.ShowDialogAsync(
427389
errorCode?.Report(fsResult.ErrorCode);
428390
}
429391
}
430-
else if (source.ItemType == FilesystemItemType.File)
392+
else if (source is IStorageFile)
431393
{
432394
var fsResult = (FilesystemResult)await Task.Run(() => NativeFileOperationsHelper.MoveFileFromApp(source.Path, destination));
433395

@@ -496,29 +458,14 @@ await Windows.ApplicationModel.Core.CoreApplication.MainView.DispatcherQueue.Enq
496458
return null; // Cannot undo overwrite operation
497459
}
498460

499-
var pathWithType = movedItem.FromStorageItem(destination, source.ItemType);
500-
501-
return new StorageHistory(FileOperationType.Move, source, pathWithType);
461+
return new StorageHistory(FileOperationType.Move, source, movedItem);
502462
}
503463

504464
public async Task<IStorageHistory> DeleteAsync(IStorageItem source,
505465
IProgress<float> progress,
506466
IProgress<FileSystemStatusCode> errorCode,
507467
bool permanently,
508468
CancellationToken cancellationToken)
509-
{
510-
return await DeleteAsync(source.FromStorageItem(),
511-
progress,
512-
errorCode,
513-
permanently,
514-
cancellationToken);
515-
}
516-
517-
public async Task<IStorageHistory> DeleteAsync(IStorageItemWithPath source,
518-
IProgress<float> progress,
519-
IProgress<FileSystemStatusCode> errorCode,
520-
bool permanently,
521-
CancellationToken cancellationToken)
522469
{
523470
bool deleteFromRecycleBin = recycleBinHelpers.IsPathUnderRecycleBin(source.Path);
524471

@@ -533,12 +480,12 @@ public async Task<IStorageHistory> DeleteAsync(IStorageItemWithPath source,
533480
}
534481
if (!fsResult)
535482
{
536-
if (source.ItemType == FilesystemItemType.File)
483+
if (source is IStorageFile)
537484
{
538485
fsResult = await associatedInstance.FilesystemViewModel.GetFileFromPathAsync(source.Path)
539486
.OnSuccess((t) => t.DeleteAsync(permanently ? StorageDeleteOption.PermanentDelete : StorageDeleteOption.Default).AsTask());
540487
}
541-
else if (source.ItemType == FilesystemItemType.Directory)
488+
else if (source is IStorageFolder)
542489
{
543490
fsResult = await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(source.Path)
544491
.OnSuccess((t) => t.DeleteAsync(permanently ? StorageDeleteOption.PermanentDelete : StorageDeleteOption.Default).AsTask());
@@ -631,15 +578,6 @@ public async Task<IStorageHistory> RenameAsync(IStorageItem source,
631578
NameCollisionOption collision,
632579
IProgress<FileSystemStatusCode> errorCode,
633580
CancellationToken cancellationToken)
634-
{
635-
return await RenameAsync(StorageItemHelpers.FromStorageItem(source), newName, collision, errorCode, cancellationToken);
636-
}
637-
638-
public async Task<IStorageHistory> RenameAsync(IStorageItemWithPath source,
639-
string newName,
640-
NameCollisionOption collision,
641-
IProgress<FileSystemStatusCode> errorCode,
642-
CancellationToken cancellationToken)
643581
{
644582
if (Path.GetFileName(source.Path) == newName && collision == NameCollisionOption.FailIfExists)
645583
{
@@ -668,7 +606,7 @@ public async Task<IStorageHistory> RenameAsync(IStorageItemWithPath source,
668606
if (renamed)
669607
{
670608
errorCode?.Report(FileSystemStatusCode.Success);
671-
return new StorageHistory(FileOperationType.Rename, source, renamed.Result.FromStorageItem());
609+
return new StorageHistory(FileOperationType.Rename, source.CreateEnumerable(), renamed.Result.FromStorageItem());
672610
}
673611
else if (renamed == FileSystemStatusCode.Unauthorized)
674612
{
@@ -747,7 +685,7 @@ public async Task<IStorageHistory> RenameAsync(IStorageItemWithPath source,
747685
return null;
748686
}
749687

750-
public async Task<IStorageHistory> RestoreFromTrashAsync(IStorageItemWithPath source,
688+
public async Task<IStorageHistory> RestoreFromTrashAsync(IStorageItem source,
751689
string destination,
752690
IProgress<float> progress,
753691
IProgress<FileSystemStatusCode> errorCode,
@@ -760,7 +698,7 @@ public async Task<IStorageHistory> RestoreFromTrashAsync(IStorageItemWithPath so
760698

761699
if (!fsResult)
762700
{
763-
if (source.ItemType == FilesystemItemType.Directory)
701+
if (source is IStorageFolder)
764702
{
765703
FilesystemResult<StorageFolder> sourceFolder = await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(source.Path);
766704
FilesystemResult<StorageFolder> destinationFolder = await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(Path.GetDirectoryName(destination));
@@ -953,12 +891,7 @@ public async Task<IStorageHistory> CopyItemsAsync(IEnumerable<IStorageItemWithPa
953891
return null;
954892
}
955893

956-
public async Task<IStorageHistory> MoveItemsAsync(IEnumerable<IStorageItem> source, IEnumerable<string> destination, IEnumerable<FileNameConflictResolveOptionType> collisions, IProgress<float> progress, IProgress<FileSystemStatusCode> errorCode, CancellationToken cancellationToken)
957-
{
958-
return await MoveItemsAsync(source.Select((item) => item.FromStorageItem()).ToList(), destination, collisions, progress, errorCode, cancellationToken);
959-
}
960-
961-
public async Task<IStorageHistory> MoveItemsAsync(IEnumerable<IStorageItemWithPath> source, IEnumerable<string> destination, IEnumerable<FileNameConflictResolveOptionType> collisions, IProgress<float> progress, IProgress<FileSystemStatusCode> errorCode, CancellationToken token)
894+
public async Task<IStorageHistory> MoveItemsAsync(IEnumerable<IStorageItem> source, IEnumerable<string> destination, IEnumerable<FileNameConflictResolveOptionType> collisions, IProgress<float> progress, IProgress<FileSystemStatusCode> errorCode, CancellationToken token)
962895
{
963896
var rawStorageHistory = new List<IStorageHistory>();
964897

@@ -993,12 +926,7 @@ public async Task<IStorageHistory> MoveItemsAsync(IEnumerable<IStorageItemWithPa
993926
return null;
994927
}
995928

996-
public async Task<IStorageHistory> DeleteItemsAsync(IEnumerable<IStorageItem> source, IProgress<float> progress, IProgress<FileSystemStatusCode> errorCode, bool permanently, CancellationToken cancellationToken)
997-
{
998-
return await DeleteItemsAsync(source.Select((item) => item.FromStorageItem()), progress, errorCode, permanently, cancellationToken);
999-
}
1000-
1001-
public async Task<IStorageHistory> DeleteItemsAsync(IEnumerable<IStorageItemWithPath> source, IProgress<float> progress, IProgress<FileSystemStatusCode> errorCode, bool permanently, CancellationToken token)
929+
public async Task<IStorageHistory> DeleteItemsAsync(IEnumerable<IStorageItem> source, IProgress<float> progress, IProgress<FileSystemStatusCode> errorCode, bool permanently, CancellationToken token)
1002930
{
1003931
bool originalPermanently = permanently;
1004932
var rawStorageHistory = new List<IStorageHistory>();

0 commit comments

Comments
 (0)