Skip to content

Commit ce47f0b

Browse files
authored
Fix: Fixed issue where renaming a shortcut that had a blank name would cause a crash (#10293)
1 parent 1359aa4 commit ce47f0b

File tree

1 file changed

+19
-24
lines changed

1 file changed

+19
-24
lines changed

src/Files.App/Helpers/UIFilesystemHelpers.cs

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1-
using Files.Shared;
21
using Files.App.Dialogs;
3-
using Files.Shared.Enums;
4-
using Files.Shared.Extensions;
52
using Files.App.Filesystem;
63
using Files.App.Filesystem.StorageItems;
74
using Files.App.Interacts;
85
using Files.App.ViewModels;
96
using Files.App.Extensions;
7+
using Files.Backend.Enums;
8+
using Files.Shared;
9+
using Files.Shared.Enums;
10+
using Files.Shared.Extensions;
11+
using Microsoft.UI.Xaml.Controls;
1012
using System;
1113
using System.Collections.Concurrent;
1214
using System.IO;
1315
using System.Linq;
1416
using System.Threading;
1517
using System.Threading.Tasks;
16-
using Windows.ApplicationModel.AppService;
1718
using Windows.ApplicationModel.DataTransfer;
18-
using Windows.Foundation.Collections;
1919
using Windows.Storage;
20-
using Files.Backend.Enums;
2120
using Windows.System;
22-
using Microsoft.UI.Xaml.Controls;
2321

2422
namespace Files.App.Helpers
2523
{
@@ -255,26 +253,24 @@ public static async Task<bool> RenameFileItemAsync(ListedItem item, string newNa
255253
StringComparison.Ordinal);
256254
newName = $"{ads.MainStreamName}:{newName}";
257255
}
256+
else if (string.IsNullOrEmpty(item.Name))
257+
{
258+
newName = string.Concat(newName, item.FileExtension);
259+
}
258260
else
259261
{
260262
newName = item.ItemNameRaw.Replace(item.Name, newName, StringComparison.Ordinal);
261263
}
264+
262265
if (item.ItemNameRaw == newName || string.IsNullOrEmpty(newName))
263266
{
264267
return true;
265268
}
266269

270+
FilesystemItemType itemType = (item.PrimaryItemAttribute == StorageItemTypes.Folder) ? FilesystemItemType.Directory : FilesystemItemType.File;
271+
267272
ReturnResult renamed = ReturnResult.InProgress;
268-
if (item.PrimaryItemAttribute == StorageItemTypes.Folder)
269-
{
270-
renamed = await associatedInstance.FilesystemHelpers.RenameAsync(StorageHelpers.FromPathAndType(item.ItemPath, FilesystemItemType.Directory),
271-
newName, NameCollisionOption.FailIfExists, true);
272-
}
273-
else
274-
{
275-
renamed = await associatedInstance.FilesystemHelpers.RenameAsync(StorageHelpers.FromPathAndType(item.ItemPath, FilesystemItemType.File),
276-
newName, NameCollisionOption.FailIfExists, true);
277-
}
273+
renamed = await associatedInstance.FilesystemHelpers.RenameAsync(StorageHelpers.FromPathAndType(item.ItemPath, itemType), newName, NameCollisionOption.FailIfExists, true);
278274

279275
if (renamed == ReturnResult.Success)
280276
{
@@ -286,7 +282,7 @@ public static async Task<bool> RenameFileItemAsync(ListedItem item, string newNa
286282

287283
public static async void CreateFileFromDialogResultType(AddItemDialogItemType itemType, ShellNewEntry itemInfo, IShellPage associatedInstance)
288284
{
289-
_ = await CreateFileFromDialogResultTypeForResult(itemType, itemInfo, associatedInstance);
285+
await CreateFileFromDialogResultTypeForResult(itemType, itemInfo, associatedInstance);
290286
}
291287

292288
// WINUI3
@@ -305,12 +301,11 @@ public static async Task<IStorageItem> CreateFileFromDialogResultTypeForResult(A
305301
if (associatedInstance.SlimContentPage != null)
306302
{
307303
currentPath = associatedInstance.FilesystemViewModel.WorkingDirectory;
308-
if (App.LibraryManager.TryGetLibrary(currentPath, out var library))
309-
{
310-
if (!library.IsEmpty && library.Folders.Count == 1) // TODO: handle libraries with multiple folders
311-
{
312-
currentPath = library.Folders.First();
313-
}
304+
if (App.LibraryManager.TryGetLibrary(currentPath, out var library) &&
305+
!library.IsEmpty &&
306+
library.Folders.Count == 1) // TODO: handle libraries with multiple folders
307+
{
308+
currentPath = library.Folders.First();
314309
}
315310
}
316311

0 commit comments

Comments
 (0)