Skip to content

Commit 5dc5e76

Browse files
authored
Fixed crash when moving files (#1354)
1 parent c48eda4 commit 5dc5e76

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

Files/Interacts/Interaction.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ public async Task PasteItems(DataPackageView packageView, string destinationPath
10551055
StatusBanner.StatusBannerOperation.Paste);
10561056
}
10571057

1058-
await Task.Run((Func<Task>)(async () =>
1058+
await Task.Run(async () =>
10591059
{
10601060
foreach (IStorageItem item in itemsToPaste)
10611061
{
@@ -1147,15 +1147,24 @@ await ItemViewModel.GetFolderFromPathAsync(destinationPath),
11471147
{
11481148
try
11491149
{
1150+
if (string.IsNullOrEmpty(item.Path))
1151+
{
1152+
// Can't move (only copy) files from MTP devices because:
1153+
// StorageItems returned in DataPackageView are read-only
1154+
// The item.Path property will be empty and there's no way of retrieving a new StorageItem with R/W access
1155+
continue;
1156+
}
11501157
if (item.IsOfType(StorageItemTypes.File))
11511158
{
1152-
StorageFile file = (StorageFile)item;
1153-
await file.DeleteAsync();
1159+
// If we reached this we are not in an MTP device, using StorageFile.* is ok here
1160+
StorageFile file = await StorageFile.GetFileFromPathAsync(item.Path);
1161+
await file.DeleteAsync(StorageDeleteOption.PermanentDelete);
11541162
}
11551163
else if (item.IsOfType(StorageItemTypes.Folder))
11561164
{
1157-
StorageFolder folder = (StorageFolder)item;
1158-
await folder.DeleteAsync();
1165+
// If we reached this we are not in an MTP device, using StorageFolder.* is ok here
1166+
StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(item.Path);
1167+
await folder.DeleteAsync(StorageDeleteOption.PermanentDelete);
11591168
}
11601169
}
11611170
catch (FileNotFoundException)
@@ -1166,7 +1175,7 @@ await ItemViewModel.GetFolderFromPathAsync(destinationPath),
11661175
ListedItem listedItem = CurrentInstance.FilesystemViewModel.FilesAndFolders.FirstOrDefault(listedItem => listedItem.ItemPath.Equals(item.Path, StringComparison.OrdinalIgnoreCase));
11671176
}
11681177
}
1169-
}));
1178+
});
11701179

11711180
if (destinationPath == CurrentInstance.FilesystemViewModel.WorkingDirectory)
11721181
{

0 commit comments

Comments
 (0)