Skip to content

Commit accc4e1

Browse files
committed
Distinguish error code for file/folder
1 parent 0b48a81 commit accc4e1

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

Files/Filesystem/StorageFileHelpers/FilesystemResult.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static explicit operator FilesystemResult(bool res) =>
6161

6262
public static class TaskExtensions
6363
{
64-
private static FilesystemErrorCode GetErrorCode(Exception ex)
64+
private static FilesystemErrorCode GetErrorCode(Exception ex, Type T = null)
6565
{
6666
if (ex is UnauthorizedAccessException)
6767
{
@@ -83,7 +83,8 @@ private static FilesystemErrorCode GetErrorCode(Exception ex)
8383
}
8484
else if (ex is ArgumentException) // Item was invalid
8585
{
86-
return FilesystemErrorCode.ERROR_NOTAFOLDER;
86+
return (T == typeof(StorageFolder) || T == typeof(StorageFolderWithPath)) ?
87+
FilesystemErrorCode.ERROR_NOTAFOLDER : FilesystemErrorCode.ERROR_NOTAFILE;
8788
}
8889
else if ((uint)ex.HResult == 0x800700A1 // The specified path is invalid (usually an mtp device was disconnected)
8990
|| (uint)ex.HResult == 0x8007016A // The cloud file provider is not running
@@ -105,7 +106,7 @@ public async static Task<FilesystemResult<T>> Wrap<T>(this Task<T> wrapped)
105106
}
106107
catch (Exception ex)
107108
{
108-
return new FilesystemResult<T>(default(T), GetErrorCode(ex));
109+
return new FilesystemResult<T>(default(T), GetErrorCode(ex, typeof(T)));
109110
}
110111
}
111112

Files/Interacts/Interaction.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -667,19 +667,13 @@ private async void Manager_DataRequested(DataTransferManager sender, DataRequest
667667
}
668668
else if (item.PrimaryItemAttribute == StorageItemTypes.Folder)
669669
{
670-
StorageFolder folderAsItem = await AssociatedInstance.FilesystemViewModel.GetFolderFromPathAsync(item.ItemPath);
671-
if (folderAsItem != null)
672-
{
673-
items.Add(folderAsItem);
674-
}
670+
await AssociatedInstance.FilesystemViewModel.GetFolderFromPathAsync(item.ItemPath)
671+
.OnSuccess(folderAsItem => items.Add(folderAsItem));
675672
}
676673
else
677674
{
678-
StorageFile fileAsItem = await AssociatedInstance.FilesystemViewModel.GetFileFromPathAsync(item.ItemPath);
679-
if (fileAsItem != null)
680-
{
681-
items.Add(fileAsItem);
682-
}
675+
await AssociatedInstance.FilesystemViewModel.GetFileFromPathAsync(item.ItemPath)
676+
.OnSuccess(fileAsItem => items.Add(fileAsItem));
683677
}
684678
}
685679

0 commit comments

Comments
 (0)