Skip to content

Commit 494c71b

Browse files
committed
Detect Unindexed Directory on Thumbnail Load
1 parent 2a4d0c5 commit 494c71b

File tree

2 files changed

+43
-27
lines changed

2 files changed

+43
-27
lines changed

Files/App.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public App()
9494
DetectCustomLocations();
9595
PopulatePinnedSidebarItems();
9696
DetectWSLDistros();
97-
//QuickLookIntegration(); <--- Prevent Crash
97+
//QuickLookIntegration(); <--- Temporarily Prevent Crash
9898
LoadTerminalApps();
9999
}
100100

Files/Filesystem/ItemViewModel.cs

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -583,30 +583,42 @@ public async void RapidAddItemsToCollectionAsync(string path)
583583
var fetchOperation = Task.Run(async () =>
584584
{
585585
_rootFolder = await StorageFolder.GetFolderFromPathAsync(path);
586-
QueryOptions options = new QueryOptions()
587-
{
588-
IndexerOption = IndexerOption.OnlyUseIndexerAndOptimizeForIndexedProperties,
589-
FolderDepth = FolderDepth.Shallow
590-
};
591-
var query = _rootFolder.CreateItemQueryWithOptions(options);
592-
options.SetPropertyPrefetch(PropertyPrefetchOptions.None, null);
593-
options.SetThumbnailPrefetch(ThumbnailMode.ListView, 40, ThumbnailOptions.ReturnOnlyIfCached);
594-
FileInformationFactory thumbnailFactory = new FileInformationFactory(query, ThumbnailMode.ListView, 40, ThumbnailOptions.ReturnOnlyIfCached, false);
595586

596-
var singlePurposedFiles = await thumbnailFactory.GetFilesAsync();
597-
partialFiles = new System.Collections.ObjectModel.ObservableCollection<PartialStorageItem>();
598-
foreach (FileInformation info in singlePurposedFiles)
587+
QueryOptions options = new QueryOptions();
588+
if (await _rootFolder.GetIndexedStateAsync() == IndexedState.FullyIndexed)
599589
{
600-
partialFiles.Add(new PartialStorageItem() { RelativeId = info.FolderRelativeId, Thumbnail = await info.GetThumbnailAsync(ThumbnailMode.ListView, 40, ThumbnailOptions.ReturnOnlyIfCached), ItemName = info.Name, ContentType = info.DisplayType });
590+
options.IndexerOption = IndexerOption.OnlyUseIndexerAndOptimizeForIndexedProperties;
601591
}
602-
603-
var singlePurposedFolders = await thumbnailFactory.GetFoldersAsync();
604-
partialFolders = new System.Collections.ObjectModel.ObservableCollection<PartialStorageItem>();
605-
foreach (FolderInformation info in singlePurposedFolders)
592+
else
606593
{
607-
partialFolders.Add(new PartialStorageItem() { RelativeId = info.FolderRelativeId, ItemName = info.Name, ContentType = null, Thumbnail = null });
594+
options.IndexerOption = IndexerOption.UseIndexerWhenAvailable;
608595
}
596+
options.FolderDepth = FolderDepth.Shallow;
609597

598+
options.SetPropertyPrefetch(PropertyPrefetchOptions.None, null);
599+
options.SetThumbnailPrefetch(ThumbnailMode.ListView, 40, ThumbnailOptions.ReturnOnlyIfCached);
600+
var query = _rootFolder.CreateItemQueryWithOptions(options);
601+
var thumbnails = await query.GetItemsAsync(0, 250);
602+
uint index = 0;
603+
partialFiles = new ObservableCollection<PartialStorageItem>();
604+
partialFolders = new ObservableCollection<PartialStorageItem>();
605+
606+
while (thumbnails.Count > 0)
607+
{
608+
foreach (IStorageItem item in thumbnails)
609+
{
610+
if (item.IsOfType(StorageItemTypes.Folder))
611+
{
612+
partialFolders.Add(new PartialStorageItem() { RelativeId = ((StorageFolder)item).FolderRelativeId, ItemName = item.Name, ContentType = null, Thumbnail = null });
613+
}
614+
else
615+
{
616+
partialFiles.Add(new PartialStorageItem() { RelativeId = ((StorageFile)item).FolderRelativeId, Thumbnail = await ((StorageFile)item).GetThumbnailAsync(ThumbnailMode.ListView, 40, ThumbnailOptions.ReturnOnlyIfCached), ItemName = item.Name, ContentType = ((StorageFile)item).DisplayType });
617+
}
618+
}
619+
index += 250;
620+
thumbnails = await query.GetItemsAsync(index, 250);
621+
}
610622

611623
});
612624

@@ -624,16 +636,20 @@ public async void RapidAddItemsToCollectionAsync(string path)
624636
{
625637
do
626638
{
627-
if (((FileAttributes)findData.dwFileAttributes & FileAttributes.Directory) != FileAttributes.Directory)
639+
if (((FileAttributes)findData.dwFileAttributes & FileAttributes.Hidden) != FileAttributes.Hidden && ((FileAttributes)findData.dwFileAttributes & FileAttributes.System) != FileAttributes.System)
628640
{
629-
AddFile(findData, path, null);
630-
++count;
631-
}
632-
else if(((FileAttributes)findData.dwFileAttributes & FileAttributes.Directory) == FileAttributes.Directory)
633-
{
634-
AddFolder(findData, path, null);
635-
++count;
641+
if (((FileAttributes)findData.dwFileAttributes & FileAttributes.Directory) != FileAttributes.Directory)
642+
{
643+
AddFile(findData, path, null);
644+
++count;
645+
}
646+
else if (((FileAttributes)findData.dwFileAttributes & FileAttributes.Directory) == FileAttributes.Directory)
647+
{
648+
AddFolder(findData, path, null);
649+
++count;
650+
}
636651
}
652+
637653
} while (FindNextFile(hFile, out findData));
638654

639655
FindClose(hFile);

0 commit comments

Comments
 (0)