public async Task <List <FileSystemStorageItemBase> > GetChildItemsAsync(bool IncludeHiddenItems, ItemFilters Filter = ItemFilters.File | ItemFilters.Folder) { if (WIN_Native_API.CheckLocationAvailability(Path)) { return(WIN_Native_API.GetStorageItems(Path, IncludeHiddenItems, Filter)); } else { LogTracer.Log($"Native API could not enum subitems in path: \"{Path}\", fall back to UWP storage API"); try { if (await GetStorageItemAsync().ConfigureAwait(true) is StorageFolder Folder) { QueryOptions Options = new QueryOptions { FolderDepth = FolderDepth.Shallow, IndexerOption = IndexerOption.UseIndexerWhenAvailable }; Options.SetThumbnailPrefetch(Windows.Storage.FileProperties.ThumbnailMode.ListView, 150, Windows.Storage.FileProperties.ThumbnailOptions.UseCurrentScale); Options.SetPropertyPrefetch(Windows.Storage.FileProperties.PropertyPrefetchOptions.BasicProperties, new string[] { "System.Size", "System.DateModified" }); StorageItemQueryResult Query = Folder.CreateItemQueryWithOptions(Options); uint Count = await Query.GetItemCountAsync(); List <FileSystemStorageItemBase> Result = new List <FileSystemStorageItemBase>(Convert.ToInt32(Count)); for (uint i = 0; i < Count; i += 30) { IReadOnlyList <IStorageItem> CurrentList = await Query.GetItemsAsync(i, 30); foreach (IStorageItem Item in CurrentList.Where((Item) => (Item.IsOfType(StorageItemTypes.Folder) && Filter.HasFlag(ItemFilters.Folder)) || (Item.IsOfType(StorageItemTypes.File) && Filter.HasFlag(ItemFilters.File)))) { if (Item is StorageFolder SubFolder) { Result.Add(new FileSystemStorageFolder(SubFolder, await SubFolder.GetThumbnailBitmapAsync().ConfigureAwait(true), await SubFolder.GetModifiedTimeAsync().ConfigureAwait(true))); } else if (Item is StorageFile SubFile) { Result.Add(new FileSystemStorageFile(SubFile, await SubFile.GetThumbnailBitmapAsync().ConfigureAwait(true), await SubFile.GetSizeRawDataAsync().ConfigureAwait(true), await SubFile.GetModifiedTimeAsync().ConfigureAwait(true))); } } } return(Result); } else { return(new List <FileSystemStorageItemBase>(0)); } } catch { LogTracer.Log($"UWP API could not enum subitems in path: \"{Path}\""); return(new List <FileSystemStorageItemBase>(0)); } } }
public async Task SetStorageQueryResultAsync(StorageItemQueryResult InputQuery) { if (InputQuery == null) { throw new ArgumentNullException(nameof(InputQuery), "Parameter could not be null"); } ItemQuery = InputQuery; MaxNum = await ItemQuery.GetItemCountAsync(); CurrentIndex = MaxNum > 100 ? 100 : MaxNum; if (MaxNum > 100) { HasMoreItems = true; } }
private async void ResetDialog_Loading(FrameworkElement sender, object args) { StorageFolder SecureFolder = await ApplicationData.Current.LocalCacheFolder.CreateFolderAsync("SecureFolder", CreationCollisionOption.OpenIfExists); QueryOptions Options = new QueryOptions { FolderDepth = FolderDepth.Shallow, IndexerOption = IndexerOption.DoNotUseIndexer }; StorageItemQueryResult ItemQuery = SecureFolder.CreateItemQueryWithOptions(Options); uint Count = await ItemQuery.GetItemCountAsync(); if (Count == 0) { ClearSecure.IsEnabled = false; } ClearSecure.Content += $"({Globalization.GetString("Reset_Dialog_TotalFile")}: {Count})"; }
public async IAsyncEnumerable <FileSystemStorageItemBase> SearchAsync(string SearchWord, bool SearchInSubFolders = false, bool IncludeHiddenItem = false, bool IsRegexExpresstion = false, bool IgnoreCase = true, [EnumeratorCancellation] CancellationToken CancelToken = default) { if (WIN_Native_API.CheckLocationAvailability(Path)) { List <FileSystemStorageItemBase> SearchResult = await Task.Run(() => { return(WIN_Native_API.Search(Path, SearchWord, SearchInSubFolders, IncludeHiddenItem, IsRegexExpresstion, IgnoreCase, CancelToken)); }); foreach (FileSystemStorageItemBase Item in SearchResult) { yield return(Item); if (CancelToken.IsCancellationRequested) { yield break; } } } else { if (await GetStorageItemAsync().ConfigureAwait(true) is StorageFolder Folder) { QueryOptions Options = new QueryOptions { FolderDepth = SearchInSubFolders ? FolderDepth.Deep : FolderDepth.Shallow, IndexerOption = IndexerOption.UseIndexerWhenAvailable }; Options.SetThumbnailPrefetch(Windows.Storage.FileProperties.ThumbnailMode.ListView, 150, Windows.Storage.FileProperties.ThumbnailOptions.UseCurrentScale); Options.SetPropertyPrefetch(Windows.Storage.FileProperties.PropertyPrefetchOptions.BasicProperties, new string[] { "System.Size", "System.DateModified" }); if (!IsRegexExpresstion) { Options.ApplicationSearchFilter = $"System.FileName:*{SearchWord}*"; } StorageItemQueryResult Query = Folder.CreateItemQueryWithOptions(Options); uint FileCount = await Query.GetItemCountAsync(); for (uint Index = 0; Index < FileCount && !CancelToken.IsCancellationRequested; Index += 50) { IEnumerable <IStorageItem> Result = IsRegexExpresstion ? (await Query.GetItemsAsync(Index, 50)).Where((Item) => Regex.IsMatch(Item.Name, SearchWord, IgnoreCase ? RegexOptions.IgnoreCase : RegexOptions.None)) : (await Query.GetItemsAsync(Index, 50)).Where((Item) => Item.Name.Contains(SearchWord, IgnoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal)); foreach (IStorageItem Item in Result) { switch (Item) { case StorageFolder SubFolder: { yield return(new FileSystemStorageFolder(SubFolder, await SubFolder.GetThumbnailBitmapAsync().ConfigureAwait(true), await SubFolder.GetModifiedTimeAsync().ConfigureAwait(true))); break; } case StorageFile SubFile: { yield return(new FileSystemStorageFile(SubFile, await SubFile.GetThumbnailBitmapAsync().ConfigureAwait(true), await SubFile.GetSizeRawDataAsync().ConfigureAwait(true), await SubFile.GetModifiedTimeAsync().ConfigureAwait(true))); break; } } if (CancelToken.IsCancellationRequested) { yield break; } } } } } }
public async Task <(uint, uint)> GetFolderAndFileNumAsync(CancellationToken CancelToken = default) { if (WIN_Native_API.CheckLocationAvailability(Path)) { return(await Task.Run(() => { return WIN_Native_API.CalculateFolderAndFileCount(Path, CancelToken); })); } else { try { LogTracer.Log($"Native API could not found the path: \"{Path}\", fall back to UWP storage API"); if (await GetStorageItemAsync().ConfigureAwait(true) is StorageFolder Folder) { QueryOptions Options = new QueryOptions { FolderDepth = FolderDepth.Deep, IndexerOption = IndexerOption.UseIndexerWhenAvailable }; Options.SetPropertyPrefetch(Windows.Storage.FileProperties.PropertyPrefetchOptions.BasicProperties, new string[] { "System.Size" }); StorageItemQueryResult Query = Folder.CreateItemQueryWithOptions(Options); uint ItemCount = await Query.GetItemCountAsync(); uint FolderCount = 0, FileCount = 0; for (uint Index = 0; Index < ItemCount && !CancelToken.IsCancellationRequested; Index += 50) { foreach (IStorageItem Item in await Query.GetItemsAsync(Index, 50)) { if (Item.IsOfType(StorageItemTypes.Folder)) { FolderCount++; } else { FileCount++; } if (CancelToken.IsCancellationRequested) { break; } } } return(FolderCount, FileCount); } else { return(0, 0); } } catch (Exception ex) { LogTracer.Log(ex, $"{nameof(GetFolderAndFileNumAsync)} failed for uwp API"); return(0, 0); } } }