Skip to content

Commit 0e145be

Browse files
authored
Code Quality: Avoid unnecessary shell folder fetching (#15140)
1 parent fb1d003 commit 0e145be

File tree

5 files changed

+8
-7
lines changed

5 files changed

+8
-7
lines changed

src/Files.App/Helpers/Win32/Win32Helper.Shell.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static partial class Win32Helper
1717

1818
private readonly static ShellFolder _controlPanelCategoryView = new("::{26EE0668-A00A-44D7-9371-BEB064C98683}");
1919

20-
public static async Task<(ShellFileItem Folder, List<ShellFileItem> Enumerate)> GetShellFolderAsync(string path, string action, int from, int count, params string[] properties)
20+
public static async Task<(ShellFileItem Folder, List<ShellFileItem> Enumerate)> GetShellFolderAsync(string path, bool getFolder, bool getEnumerate, int from, int count, params string[] properties)
2121
{
2222
if (path.StartsWith("::{", StringComparison.Ordinal))
2323
{
@@ -43,9 +43,10 @@ public static partial class Win32Helper
4343
return (null, flc);
4444
}
4545

46-
folder = ShellFolderExtensions.GetShellFileItem(shellFolder);
46+
if (getFolder)
47+
folder = ShellFolderExtensions.GetShellFileItem(shellFolder);
4748

48-
if (action == "Enumerate")
49+
if (getEnumerate)
4950
{
5051
foreach (var folderItem in shellFolder.Skip(from).Take(count))
5152
{

src/Files.App/Services/QuickAccessService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ internal sealed class QuickAccessService : IQuickAccessService
1212

1313
public async Task<IEnumerable<ShellFileItem>> GetPinnedFoldersAsync()
1414
{
15-
var result = (await Win32Helper.GetShellFolderAsync(guid, "Enumerate", 0, int.MaxValue, "System.Home.IsPinned")).Enumerate
15+
var result = (await Win32Helper.GetShellFolderAsync(guid, false, true, 0, int.MaxValue, "System.Home.IsPinned")).Enumerate
1616
.Where(link => link.IsFolder);
1717
return result;
1818
}

src/Files.App/Utils/RecentItem/RecentItems.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public async Task UpdateRecentFoldersAsync()
109109
/// </summary>
110110
public async Task<List<RecentItem>> ListRecentFilesAsync()
111111
{
112-
return (await Win32Helper.GetShellFolderAsync(QuickAccessGuid, "Enumerate", 0, int.MaxValue)).Enumerate
112+
return (await Win32Helper.GetShellFolderAsync(QuickAccessGuid, false, true, 0, int.MaxValue)).Enumerate
113113
.Where(link => !link.IsFolder)
114114
.Select(link => new RecentItem(link, ShowFileExtensions)).ToList();
115115
}

src/Files.App/Utils/RecycleBin/RecycleBinHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static class RecycleBinHelpers
1919

2020
public static async Task<List<ShellFileItem>> EnumerateRecycleBin()
2121
{
22-
return (await Win32Helper.GetShellFolderAsync(Constants.UserEnvironmentPaths.RecycleBinPath, "Enumerate", 0, int.MaxValue)).Enumerate;
22+
return (await Win32Helper.GetShellFolderAsync(Constants.UserEnvironmentPaths.RecycleBinPath, false, true, 0, int.MaxValue)).Enumerate;
2323
}
2424

2525
public static ulong GetSize()

src/Files.App/Utils/Storage/StorageItems/ShellStorageFolder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public static IAsyncOperation<BaseStorageFolder> FromPathAsync(string path)
108108

109109
protected static async Task<(ShellFileItem Folder, List<ShellFileItem> Items)> GetFolderAndItems(string path, bool enumerate, int startIndex = 0, int maxItemsToRetrieve = int.MaxValue)
110110
{
111-
return await Win32Helper.GetShellFolderAsync(path, enumerate ? "Enumerate" : "Query", startIndex, maxItemsToRetrieve);
111+
return await Win32Helper.GetShellFolderAsync(path, !enumerate, enumerate, startIndex, maxItemsToRetrieve);
112112
}
113113

114114
public override IAsyncOperation<StorageFolder> ToStorageFolderAsync() => throw new NotSupportedException();

0 commit comments

Comments
 (0)