Skip to content

Commit 671e280

Browse files
committed
Fixed an infinite iteration in the Quick Access folder.
1 parent fa8533d commit 671e280

File tree

4 files changed

+25
-28
lines changed

4 files changed

+25
-28
lines changed

src/Files.App.CsWin32/NativeMethods.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,4 @@ QITIPF_FLAGS
225225
GetKeyboardState
226226
MapVirtualKey
227227
GetKeyboardLayout
228+
S_FALSE

src/Files.App.Storage/Storables/WindowsStorage/WindowsFolder.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,23 @@ public IAsyncEnumerable<IStorableChild> GetItemsAsync(StorableType type = Storab
4444
List<IStorableChild> childItems = [];
4545

4646
IShellItem* pChildShellItem = null;
47-
while (pEnumShellItems.Get()->Next(1, &pChildShellItem).Succeeded && pChildShellItem is not null)
47+
while ((hr = pEnumShellItems.Get()->Next(1, &pChildShellItem)) == HRESULT.S_OK)
4848
{
49-
cancellationToken.ThrowIfCancellationRequested();
49+
bool isFolder = pChildShellItem->GetAttributes(SFGAO_FLAGS.SFGAO_FOLDER, out var dwAttributes).Succeeded && dwAttributes is SFGAO_FLAGS.SFGAO_FOLDER;
5050

51-
bool isFolder = pChildShellItem->GetAttributes(SFGAO_FLAGS.SFGAO_FOLDER, out var returnedAttributes).Succeeded && returnedAttributes == SFGAO_FLAGS.SFGAO_FOLDER;
52-
53-
if (type is StorableType.File && !isFolder)
51+
if (type.HasFlag(StorableType.File) && !isFolder)
5452
{
5553
childItems.Add(new WindowsFile(pChildShellItem));
5654
}
57-
else if (type is StorableType.Folder && isFolder)
55+
else if (type.HasFlag(StorableType.Folder) && isFolder)
5856
{
5957
childItems.Add(new WindowsFolder(pChildShellItem));
6058
}
61-
else
62-
{
63-
continue;
64-
}
6559
}
6660

61+
if (hr.ThrowIfFailedOnDebug().Failed)
62+
return Enumerable.Empty<IStorableChild>().ToAsyncEnumerable();
63+
6764
return childItems.ToAsyncEnumerable();
6865
}
6966
}

src/Files.App.Storage/Storables/WindowsStorage/WindowsStorableHelpers.Shell.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ public unsafe static HRESULT GetPropertyValue<TValue>(this IWindowsStorable stor
3333
}
3434
if (typeof(TValue) == typeof(bool))
3535
{
36-
bool propertyValue = false;
37-
hr = pShellItem2.Get()->GetBool(propertyKey, out var fPropertyValue);
38-
propertyValue = fPropertyValue;
39-
value = Unsafe.As<bool, TValue>(ref propertyValue);
36+
bool fPropertyValue = false;
37+
hr = pShellItem2.Get()->GetBool(&propertyKey, (BOOL*)&fPropertyValue);
38+
value = Unsafe.As<bool, TValue>(ref fPropertyValue);
4039

4140
return hr;
4241
}

src/Files.App/ViewModels/UserControls/Widgets/QuickAccessWidgetViewModel.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,20 @@ public Task RefreshWidgetAsync()
7272

7373
Items.Clear();
7474

75-
//await foreach (IWindowsStorable folder in HomePageContext.HomeFolder.GetQuickAccessFolderAsync(default))
76-
//{
77-
// folder.GetPropertyValue<bool>("System.Home.IsPinned", out var isPinned);
78-
// folder.TryGetShellTooltip(out var tooltip);
79-
80-
// Items.Insert(
81-
// Items.Count,
82-
// new WidgetFolderCardItem(
83-
// folder,
84-
// folder.GetDisplayName(SIGDN.SIGDN_PARENTRELATIVEFORUI),
85-
// isPinned,
86-
// tooltip ?? string.Empty));
87-
//}
88-
});
75+
await foreach (IWindowsStorable folder in HomePageContext.HomeFolder.GetQuickAccessFolderAsync(default))
76+
{
77+
folder.GetPropertyValue<bool>("System.Home.IsPinned", out var isPinned);
78+
folder.TryGetShellTooltip(out var tooltip);
79+
80+
Items.Insert(
81+
Items.Count,
82+
new WidgetFolderCardItem(
83+
folder,
84+
folder.GetDisplayName(SIGDN.SIGDN_PARENTRELATIVEFORUI),
85+
isPinned,
86+
tooltip ?? string.Empty));
87+
}
88+
});
8989
}
9090

9191
public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCardItem item, bool isPinned, bool isFolder = false)

0 commit comments

Comments
 (0)