@@ -40,7 +40,7 @@ public class ItemViewModel : INotifyPropertyChanged
40
40
public ListedItem currentFolder { get => _rootFolderItem ; }
41
41
public CollectionViewSource viewSource ;
42
42
public UniversalPath Universal { get ; } = new UniversalPath ( ) ;
43
- private ObservableCollection < ListedItem > _filesAndFolders ;
43
+ public ObservableCollection < ListedItem > _filesAndFolders ;
44
44
private StorageFolderQueryResult _folderQueryResult ;
45
45
public StorageFileQueryResult _fileQueryResult ;
46
46
private CancellationTokenSource _cancellationTokenSource ;
@@ -578,31 +578,38 @@ public async void RapidAddItemsToCollectionAsync(string path)
578
578
Universal . path = App . OneDrivePath ;
579
579
break ;
580
580
}
581
-
582
- _rootFolder = await StorageFolder . GetFolderFromPathAsync ( path ) ;
583
- QueryOptions options = new QueryOptions ( )
584
- {
585
- IndexerOption = IndexerOption . OnlyUseIndexerAndOptimizeForIndexedProperties ,
586
- FolderDepth = FolderDepth . Shallow
587
- } ;
588
- var query = _rootFolder . CreateFileQueryWithOptions ( options ) ;
589
- options . SetPropertyPrefetch ( PropertyPrefetchOptions . None , null ) ;
590
- options . SetThumbnailPrefetch ( ThumbnailMode . ListView , 40 , ThumbnailOptions . ReturnOnlyIfCached ) ;
591
- FileInformationFactory thumbnailFactory = new FileInformationFactory ( query , ThumbnailMode . ListView , 40 , ThumbnailOptions . ReturnOnlyIfCached , false ) ;
592
-
593
- var singlePurposedFiles = await thumbnailFactory . GetFilesAsync ( ) ;
594
- ObservableCollection < PartialStorageItem > partialFiles = new System . Collections . ObjectModel . ObservableCollection < PartialStorageItem > ( ) ;
595
- foreach ( FileInformation info in singlePurposedFiles )
581
+ ObservableCollection < PartialStorageItem > partialFiles = null ;
582
+ ObservableCollection < PartialStorageItem > partialFolders = null ;
583
+ var fetchOperation = Task . Run ( async ( ) =>
596
584
{
597
- partialFiles . Add ( new PartialStorageItem ( ) { RelativeId = info . FolderRelativeId , Thumbnail = info . Thumbnail , ItemName = info . Name , ContentType = info . DisplayType } ) ;
598
- }
585
+ _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 ) ;
595
+
596
+ var singlePurposedFiles = await thumbnailFactory . GetFilesAsync ( ) ;
597
+ partialFiles = new System . Collections . ObjectModel . ObservableCollection < PartialStorageItem > ( ) ;
598
+ foreach ( FileInformation info in singlePurposedFiles )
599
+ {
600
+ partialFiles . Add ( new PartialStorageItem ( ) { RelativeId = info . FolderRelativeId , Thumbnail = await info . GetThumbnailAsync ( ThumbnailMode . ListView , 40 , ThumbnailOptions . ReturnOnlyIfCached ) , ItemName = info . Name , ContentType = info . DisplayType } ) ;
601
+ }
602
+
603
+ var singlePurposedFolders = await thumbnailFactory . GetFoldersAsync ( ) ;
604
+ partialFolders = new System . Collections . ObjectModel . ObservableCollection < PartialStorageItem > ( ) ;
605
+ foreach ( FolderInformation info in singlePurposedFolders )
606
+ {
607
+ partialFolders . Add ( new PartialStorageItem ( ) { RelativeId = info . FolderRelativeId , ItemName = info . Name , ContentType = null , Thumbnail = null } ) ;
608
+ }
609
+
610
+
611
+ } ) ;
599
612
600
- var singlePurposedFolders = await thumbnailFactory . GetFoldersAsync ( ) ;
601
- ObservableCollection < PartialStorageItem > partialFolders = new System . Collections . ObjectModel . ObservableCollection < PartialStorageItem > ( ) ;
602
- foreach ( FolderInformation info in singlePurposedFolders )
603
- {
604
- partialFolders . Add ( new PartialStorageItem ( ) { RelativeId = info . FolderRelativeId , ItemName = info . Name , ContentType = null , Thumbnail = null } ) ;
605
- }
606
613
607
614
WIN32_FIND_DATA findData ;
608
615
FINDEX_INFO_LEVELS findInfoLevel = FINDEX_INFO_LEVELS . FindExInfoStandard ;
@@ -619,19 +626,60 @@ public async void RapidAddItemsToCollectionAsync(string path)
619
626
{
620
627
if ( ( ( FileAttributes ) findData . dwFileAttributes & FileAttributes . Directory ) != FileAttributes . Directory )
621
628
{
622
- AddFile ( findData , path , partialFiles . FirstOrDefault ( x => x . ItemName == findData . cFileName ) ) ;
629
+ AddFile ( findData , path , null ) ;
623
630
++ count ;
624
631
}
625
632
else if ( ( ( FileAttributes ) findData . dwFileAttributes & FileAttributes . Directory ) == FileAttributes . Directory )
626
633
{
627
- AddFolder ( findData , path , partialFolders . FirstOrDefault ( x => x . ItemName == findData . cFileName ) ) ;
634
+ AddFolder ( findData , path , null ) ;
628
635
++ count ;
629
636
}
630
637
} while ( FindNextFile ( hFile , out findData ) ) ;
631
638
632
639
FindClose ( hFile ) ;
633
640
}
634
-
641
+ var populateFetchedProperties = await fetchOperation . ContinueWith ( async ( i ) =>
642
+ {
643
+ await CoreApplication . MainView . CoreWindow . Dispatcher . RunAsync ( CoreDispatcherPriority . Normal , async ( ) =>
644
+ {
645
+ BitmapImage icon = null ;
646
+ var itemsCopy = FilesAndFolders . ToList ( ) ;
647
+ foreach ( ListedItem item in itemsCopy )
648
+ {
649
+ if ( item . FileType != "Folder" )
650
+ {
651
+ icon = new BitmapImage ( ) ;
652
+ var matchingItem = _filesAndFolders . FirstOrDefault ( x => x == item ) ;
653
+ var matchingStorageItem = partialFiles . FirstOrDefault ( x => x . ItemName == matchingItem . FileName ) ;
654
+ if ( matchingItem != null && matchingStorageItem != null )
655
+ {
656
+ matchingItem . FileType = matchingStorageItem . ContentType ;
657
+ matchingItem . FolderRelativeId = matchingStorageItem . RelativeId ;
658
+ if ( matchingStorageItem . Thumbnail != null )
659
+ {
660
+ icon . DecodePixelWidth = 40 ;
661
+ icon . DecodePixelHeight = 40 ;
662
+ await icon . SetSourceAsync ( matchingStorageItem . Thumbnail . CloneStream ( ) ) ;
663
+ matchingItem . FileImg = icon ;
664
+ matchingItem . EmptyImgVis = Visibility . Collapsed ;
665
+ matchingItem . FileIconVis = Visibility . Visible ;
666
+ }
667
+ }
668
+ }
669
+ else
670
+ {
671
+ var matchingItem = _filesAndFolders . FirstOrDefault ( x => x == item ) ;
672
+ var matchingStorageItem = partialFolders . FirstOrDefault ( x => x . ItemName == matchingItem . FileName ) ;
673
+ if ( matchingItem != null && matchingStorageItem != null )
674
+ {
675
+ matchingItem . FolderRelativeId = matchingStorageItem . RelativeId ;
676
+ }
677
+ }
678
+ }
679
+ } ) ;
680
+
681
+ } ) ;
682
+
635
683
636
684
if ( FilesAndFolders . Count == 0 )
637
685
{
0 commit comments