Skip to content

Commit e2f6805

Browse files
committed
Added file already existing error code
1 parent accc4e1 commit e2f6805

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

Files/Filesystem/StorageFileHelpers/FilesystemResult.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ public enum FilesystemErrorCode
1717
ERROR_NOTFOUND = 4,
1818
ERROR_INUSE = 8,
1919
ERROR_NAMETOOLONG = 16,
20-
ERROR_NOTAFOLDER = 32,
21-
ERROR_NOTAFILE = 64
20+
ERROR_ALREADYEXIST = 32,
21+
ERROR_NOTAFOLDER = 64,
22+
ERROR_NOTAFILE = 128
2223
}
2324

2425
public static class FilesystemErrorCodeExtensions
@@ -86,6 +87,10 @@ private static FilesystemErrorCode GetErrorCode(Exception ex, Type T = null)
8687
return (T == typeof(StorageFolder) || T == typeof(StorageFolderWithPath)) ?
8788
FilesystemErrorCode.ERROR_NOTAFOLDER : FilesystemErrorCode.ERROR_NOTAFILE;
8889
}
90+
else if ((uint)ex.HResult == 0x800700B7)
91+
{
92+
return FilesystemErrorCode.ERROR_ALREADYEXIST;
93+
}
8994
else if ((uint)ex.HResult == 0x800700A1 // The specified path is invalid (usually an mtp device was disconnected)
9095
|| (uint)ex.HResult == 0x8007016A // The cloud file provider is not running
9196
|| (uint)ex.HResult == 0x8000000A) // The data necessary to complete this operation is not yet available)

Files/Interacts/Interaction.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ public async Task<bool> RenameFileItem(ListedItem item, string oldName, string n
796796
renamed = await AssociatedInstance.FilesystemViewModel.GetFileFromPathAsync(item.ItemPath)
797797
.OnSuccess(t => t.RenameAsync(newName, NameCollisionOption.FailIfExists).AsTask());
798798
}
799-
if (renamed.ErrorCode == FilesystemErrorCode.ERROR_UNAUTHORIZED)
799+
if (renamed == FilesystemErrorCode.ERROR_UNAUTHORIZED)
800800
{
801801
// Try again with MoveFileFromApp
802802
if (!NativeDirectoryChangesHelper.MoveFileFromApp(item.ItemPath, Path.Combine(Path.GetDirectoryName(item.ItemPath), newName)))
@@ -805,24 +805,24 @@ public async Task<bool> RenameFileItem(ListedItem item, string oldName, string n
805805
return false;
806806
}
807807
}
808-
else if (renamed.ErrorCode == FilesystemErrorCode.ERROR_NOTAFILE || renamed.ErrorCode == FilesystemErrorCode.ERROR_NOTAFOLDER)
808+
else if (renamed == FilesystemErrorCode.ERROR_NOTAFILE || renamed == FilesystemErrorCode.ERROR_NOTAFOLDER)
809809
{
810810
await DialogDisplayHelper.ShowDialog("RenameError.NameInvalid.Title".GetLocalized(), "RenameError.NameInvalid.Text".GetLocalized());
811811
}
812-
else if (renamed.ErrorCode == FilesystemErrorCode.ERROR_NAMETOOLONG)
812+
else if (renamed == FilesystemErrorCode.ERROR_NAMETOOLONG)
813813
{
814814
await DialogDisplayHelper.ShowDialog("RenameError.TooLong.Title".GetLocalized(), "RenameError.TooLong.Text".GetLocalized());
815815
}
816-
else if (renamed.ErrorCode == FilesystemErrorCode.ERROR_INUSE)
816+
else if (renamed == FilesystemErrorCode.ERROR_INUSE)
817817
{
818818
// TODO: proper dialog, retry
819819
await DialogDisplayHelper.ShowDialog("FileInUseDeleteDialog/Title".GetLocalized(), "");
820820
}
821-
else if (renamed.ErrorCode == FilesystemErrorCode.ERROR_NOTFOUND)
821+
else if (renamed == FilesystemErrorCode.ERROR_NOTFOUND)
822822
{
823823
await DialogDisplayHelper.ShowDialog("RenameError.ItemDeleted.Title".GetLocalized(), "RenameError.ItemDeleted.Text".GetLocalized());
824824
}
825-
else if (!renamed)
825+
else if (renamed == FilesystemErrorCode.ERROR_ALREADYEXIST)
826826
{
827827
var ItemAlreadyExistsDialog = new ContentDialog()
828828
{
@@ -913,7 +913,7 @@ await AssociatedInstance.FilesystemViewModel.GetFileFromPathAsync(iFilePath)
913913
{
914914
await DialogDisplayHelper.ShowDialog("FileNotFoundDialog/Title".GetLocalized(), "FileNotFoundDialog/Text".GetLocalized());
915915
}
916-
else
916+
else if (restored.HasFlag(FilesystemErrorCode.ERROR_ALREADYEXIST))
917917
{
918918
await DialogDisplayHelper.ShowDialog("ItemAlreadyExistsDialogTitle".GetLocalized(), "ItemAlreadyExistsDialogContent".GetLocalized());
919919
}

0 commit comments

Comments
 (0)