Skip to content

Commit f36aede

Browse files
hecksmosishishitetsu
authored andcommitted
Fix: Fixed NullReferenceException with EnumerateItemsFromStandardFolderAsync (#12335)
1 parent 1042d49 commit f36aede

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/Files.App/ViewModels/ItemViewModel.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public ListedItem CurrentFolder
104104

105105
public string WorkingDirectory { get; private set; }
106106

107-
private StorageFolderWithPath currentStorageFolder;
107+
private StorageFolderWithPath? currentStorageFolder;
108108
private StorageFolderWithPath workingRoot;
109109

110110
public delegate void WorkingDirectoryModifiedEventHandler(object sender, WorkingDirectoryModifiedEventArgs e);
@@ -1400,7 +1400,7 @@ public async Task EnumerateItemsFromSpecialFolderAsync(string path)
14001400
{
14011401
var isFtp = FtpHelpers.IsFtpPath(path);
14021402

1403-
CurrentFolder = new ListedItem(null)
1403+
CurrentFolder = new ListedItem(null!)
14041404
{
14051405
PrimaryItemAttribute = StorageItemTypes.Folder,
14061406
ItemPropertiesInitialized = true,
@@ -1569,22 +1569,22 @@ await DialogDisplayHelper.ShowDialogAsync(
15691569
if (enumFromStorageFolder)
15701570
{
15711571
var basicProps = await rootFolder?.GetBasicPropertiesAsync();
1572-
var currentFolder = library ?? new ListedItem(rootFolder.FolderRelativeId)
1572+
var currentFolder = library ?? new ListedItem(rootFolder?.FolderRelativeId ?? string.Empty)
15731573
{
15741574
PrimaryItemAttribute = StorageItemTypes.Folder,
15751575
ItemPropertiesInitialized = true,
1576-
ItemNameRaw = rootFolder.DisplayName,
1576+
ItemNameRaw = rootFolder?.DisplayName ?? string.Empty,
15771577
ItemDateModifiedReal = basicProps.DateModified,
1578-
ItemType = rootFolder.DisplayType,
1578+
ItemType = rootFolder?.DisplayType ?? string.Empty,
15791579
FileImage = null,
15801580
LoadFileIcon = false,
1581-
ItemPath = string.IsNullOrEmpty(rootFolder.Path) ? currentStorageFolder.Path : rootFolder.Path,
1581+
ItemPath = string.IsNullOrEmpty(rootFolder?.Path) ? currentStorageFolder?.Path ?? string.Empty : rootFolder.Path,
15821582
FileSize = null,
15831583
FileSizeBytes = 0,
15841584
};
15851585

15861586
if (library is null)
1587-
currentFolder.ItemDateCreatedReal = rootFolder.DateCreated;
1587+
currentFolder.ItemDateCreatedReal = rootFolder?.DateCreated ?? DateTimeOffset.Now;
15881588

15891589
CurrentFolder = currentFolder;
15901590
await EnumFromStorageFolderAsync(path, rootFolder, currentStorageFolder, cancellationToken);

0 commit comments

Comments
 (0)