예제 #1
0
        private async Task AddItemToRecentListAsync(IStorageItem item, AccessListEntry entry)
        {
            BitmapImage      ItemImage;
            string           ItemPath;
            string           ItemName;
            StorageItemTypes ItemType;
            bool             ItemFolderImgVis;
            bool             ItemEmptyImgVis;
            bool             ItemFileIconVis;

            if (item.IsOfType(StorageItemTypes.File))
            {
                // Try to read the file to check if still exists
                // This is only needed to remove files opened from a disconnected android/MTP phone
                if (string.IsNullOrEmpty(item.Path)) // This indicates that the file was open from an MTP device
                {
                    using (var inputStream = await item.AsBaseStorageFile().OpenReadAsync())
                        using (var classicStream = inputStream.AsStreamForRead())
                            using (var streamReader = new StreamReader(classicStream))
                            {
                                // NB: this might trigger the download of the file from OneDrive
                                streamReader.Peek();
                            }
                }

                ItemName  = item.Name;
                ItemPath  = string.IsNullOrEmpty(item.Path) ? entry.Metadata : item.Path;
                ItemType  = StorageItemTypes.File;
                ItemImage = new BitmapImage();
                BaseStorageFile file = item.AsBaseStorageFile();
                using var thumbnail = await file.GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.ListView, 24, Windows.Storage.FileProperties.ThumbnailOptions.UseCurrentScale);

                if (thumbnail == null)
                {
                    ItemEmptyImgVis = true;
                }
                else
                {
                    await ItemImage.SetSourceAsync(thumbnail);

                    ItemEmptyImgVis = false;
                }
                ItemFolderImgVis = false;
                ItemFileIconVis  = true;
                recentItemsCollection.Add(new RecentItem()
                {
                    RecentPath  = ItemPath,
                    Name        = ItemName,
                    Type        = ItemType,
                    FolderImg   = ItemFolderImgVis,
                    EmptyImgVis = ItemEmptyImgVis,
                    FileImg     = ItemImage,
                    FileIconVis = ItemFileIconVis
                });
            }
        }
예제 #2
0
 public override IAsyncOperation <IDictionary <string, object> > RetrievePropertiesAsync(IEnumerable <string> propertiesToRetrieve)
 {
     return(AsyncInfo.Run <IDictionary <string, object> >(async(cancellationToken) =>
     {
         var props = new Dictionary <string, object>();
         propertiesToRetrieve.ForEach(x => props[x] = null);
         // Fill common poperties
         var ret = item.AsBaseStorageFile()?.GetBasicPropertiesAsync() ?? item.AsBaseStorageFolder()?.GetBasicPropertiesAsync();
         var basicProps = ret != null ? await ret : null;
         props["System.ItemPathDisplay"] = item?.Path;
         props["System.DateCreated"] = basicProps?.ItemDate;
         props["System.DateModified"] = basicProps?.DateModified;
         return props;
     }));
 }
예제 #3
0
        public static async Task <byte[]> LoadIconFromStorageItemAsync(IStorageItem item, uint thumbnailSize, ThumbnailMode thumbnailMode)
        {
            if (item.IsOfType(StorageItemTypes.File))
            {
                using var thumbnail = (StorageItemThumbnail) await FilesystemTasks.Wrap(
                          () => item.AsBaseStorageFile ().GetThumbnailAsync (thumbnailMode, thumbnailSize, ThumbnailOptions.ResizeThumbnail).AsTask());

                if (thumbnail != null)
                {
                    return(await thumbnail.ToByteArrayAsync());
                }
            }
            else if (item.IsOfType(StorageItemTypes.Folder))
            {
                using var thumbnail = (StorageItemThumbnail) await FilesystemTasks.Wrap(
                          () => item.AsBaseStorageFolder ().GetThumbnailAsync (thumbnailMode, thumbnailSize, ThumbnailOptions.ResizeThumbnail).AsTask());

                if (thumbnail != null)
                {
                    return(await thumbnail.ToByteArrayAsync());
                }
            }
            return(null);
        }