public bool TryGetSize(string path, out ulong size) => provider.TryGetSize(path, out size);
public static async Task <List <ListedItem> > ListEntries( string path, IntPtr hFile, WIN32_FIND_DATA findData, NamedPipeAsAppServiceConnection connection, CancellationToken cancellationToken, int countLimit, Func <List <ListedItem>, Task> intermediateAction, Dictionary <string, BitmapImage> defaultIconPairs = null ) { var sampler = new IntervalSampler(500); var tempList = new List <ListedItem>(); var hasNextFile = false; var count = 0; IUserSettingsService userSettingsService = Ioc.Default.GetService <IUserSettingsService>(); bool showFolderSize = userSettingsService.PreferencesSettingsService.ShowFolderSize; do { var isSystem = ((FileAttributes)findData.dwFileAttributes & FileAttributes.System) == FileAttributes.System; var isHidden = ((FileAttributes)findData.dwFileAttributes & FileAttributes.Hidden) == FileAttributes.Hidden; var startWithDot = findData.cFileName.StartsWith("."); if ((!isHidden || (userSettingsService.PreferencesSettingsService.AreHiddenItemsVisible && (!isSystem || !userSettingsService.PreferencesSettingsService.AreSystemItemsHidden))) && (!startWithDot || userSettingsService.PreferencesSettingsService.ShowDotFiles)) { if (((FileAttributes)findData.dwFileAttributes & FileAttributes.Directory) != FileAttributes.Directory) { var file = await GetFile(findData, path, connection, cancellationToken); if (file != null) { if (defaultIconPairs != null) { if (!string.IsNullOrEmpty(file.FileExtension)) { var lowercaseExtension = file.FileExtension.ToLowerInvariant(); if (defaultIconPairs.ContainsKey(lowercaseExtension)) { file.SetDefaultIcon(defaultIconPairs[lowercaseExtension]); } } } tempList.Add(file); ++count; if (userSettingsService.PreferencesSettingsService.AreAlternateStreamsVisible) { tempList.AddRange(EnumAdsForPath(file.ItemPath, file)); } } } else if (((FileAttributes)findData.dwFileAttributes & FileAttributes.Directory) == FileAttributes.Directory) { if (findData.cFileName != "." && findData.cFileName != "..") { var folder = await GetFolder(findData, path, cancellationToken); if (folder != null) { if (defaultIconPairs?.ContainsKey(string.Empty) ?? false) { // Set folder icon (found by empty extension string) folder.SetDefaultIcon(defaultIconPairs[string.Empty]); } tempList.Add(folder); ++count; if (userSettingsService.PreferencesSettingsService.AreAlternateStreamsVisible) { tempList.AddRange(EnumAdsForPath(folder.ItemPath, folder)); } if (showFolderSize) { if (folderSizeProvider.TryGetSize(folder.ItemPath, out var size)) { folder.FileSizeBytes = (long)size; folder.FileSize = size.ToSizeString(); } _ = folderSizeProvider.UpdateAsync(folder.ItemPath, cancellationToken); } } } } } if (cancellationToken.IsCancellationRequested || count == countLimit) { break; } hasNextFile = FindNextFile(hFile, out findData); if (intermediateAction != null && (count == 32 || sampler.CheckNow())) { await intermediateAction(tempList); // clear the temporary list every time we do an intermediate action tempList.Clear(); } } while (hasNextFile); FindClose(hFile); return(tempList); }