/// <summary> /// Adds the item (from a path) to the navigation sidebar /// </summary> /// <param name="path">The path which to save</param> /// <returns>Task</returns> public async Task AddItemToSidebarAsync(string path) { var item = await FilesystemTasks.Wrap(() => DrivesManager.GetRootFromPathAsync(path)); var res = await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFolderFromPathAsync(path, item)); var locationItem = new LocationItem { Font = MainViewModel.FontName, Path = path, Section = SectionType.Favorites, MenuOptions = new ContextMenuOptions { IsLocationItem = true, ShowProperties = true, ShowUnpinItem = true, ShowShellItems = true, ShowEmptyRecycleBin = path == CommonPaths.RecycleBinPath, }, IsDefaultLocation = false, Text = res.Result?.DisplayName ?? Path.GetFileName(path.TrimEnd('\\')) }; if (res || (FilesystemResult)FolderHelpers.CheckFolderAccessWithWin32(path)) { locationItem.IsInvalid = false; if (res) { var iconData = await FileThumbnailHelper.LoadIconFromStorageItemAsync(res.Result, 24u, Windows.Storage.FileProperties.ThumbnailMode.ListView); if (iconData == null) { iconData = await FileThumbnailHelper.LoadIconFromStorageItemAsync(res.Result, 24u, Windows.Storage.FileProperties.ThumbnailMode.SingleItem); } locationItem.IconData = iconData; locationItem.Icon = await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => locationItem.IconData.ToBitmapAsync()); } if (locationItem.IconData == null) { locationItem.IconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(path, 24u); if (locationItem.IconData != null) { locationItem.Icon = await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => locationItem.IconData.ToBitmapAsync()); } } } else { locationItem.Icon = await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => UIHelpers.GetIconResource(Constants.ImageRes.Folder)); locationItem.IsInvalid = true; Debug.WriteLine($"Pinned item was invalid {res.ErrorCode}, item: {path}"); } AddLocationItemToSidebar(locationItem); }
private async Task LoadPreviewAndDetailsAsync() { ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings; string returnformat = Enum.Parse <TimeStyle>(localSettings.Values[Constants.LocalSettings.DateTimeFormat].ToString()) == TimeStyle.Application ? "D" : "g"; var rootItem = await FilesystemTasks.Wrap(() => DrivesManager.GetRootFromPathAsync(Item.ItemPath)); Folder = await StorageFileExtensions.DangerousGetFolderFromPathAsync(Item.ItemPath, rootItem); var items = await Folder.GetItemsAsync(); var iconData = await FileThumbnailHelper.LoadIconFromStorageItemAsync(Folder, 400, ThumbnailMode.SingleItem); iconData ??= await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Item.ItemPath, 400); if (iconData != null) { Thumbnail = await iconData.ToBitmapAsync(); } var info = await Folder.GetBasicPropertiesAsync(); Item.FileDetails = new ObservableCollection <FileProperty>() { new FileProperty() { NameResource = "PropertyItemCount", Value = items.Count, }, new FileProperty() { NameResource = "PropertyDateModified", Value = Extensions.DateTimeExtensions.GetFriendlyDateFromFormat(info.DateModified, returnformat, true) }, new FileProperty() { NameResource = "PropertyDateCreated", Value = Extensions.DateTimeExtensions.GetFriendlyDateFromFormat(info.ItemDate, returnformat, true) }, new FileProperty() { NameResource = "PropertyItemPathDisplay", Value = Folder.Path, } }; if (UserSettingsService.PreferencesSettingsService.AreFileTagsEnabled) { Item.FileDetails.Add(new FileProperty() { NameResource = "DetailsViewHeaderFlyout_ShowFileTag/Text", Value = Item.FileTagUI?.TagName }); } }
/// <summary> /// Adds the item do the navigation sidebar /// </summary> /// <param name="path">The path which to save</param> /// <returns>Task</returns> public async Task AddItemToSidebarAsync(string path) { var item = await FilesystemTasks.Wrap(() => DrivesManager.GetRootFromPathAsync(path)); var res = await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFolderFromPathAsync(path, item)); var lastItem = favoriteSection.ChildItems.LastOrDefault(x => x.ItemType == NavigationControlItemType.Location && !x.Path.Equals(CommonPaths.RecycleBinPath)); int insertIndex = lastItem != null?favoriteSection.ChildItems.IndexOf(lastItem) + 1 : 0; var locationItem = new LocationItem { Font = MainViewModel.FontName, Path = path, Section = SectionType.Favorites, IsDefaultLocation = false, Text = res.Result?.DisplayName ?? Path.GetFileName(path.TrimEnd('\\')) }; if (res || (FilesystemResult)FolderHelpers.CheckFolderAccessWithWin32(path)) { locationItem.IsInvalid = false; if (res) { var iconData = await FileThumbnailHelper.LoadIconFromStorageItemAsync(res.Result, 24u, Windows.Storage.FileProperties.ThumbnailMode.ListView); if (iconData == null) { iconData = await FileThumbnailHelper.LoadIconFromStorageItemAsync(res.Result, 24u, Windows.Storage.FileProperties.ThumbnailMode.SingleItem); } locationItem.IconData = iconData; locationItem.Icon = await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => locationItem.IconData.ToBitmapAsync()); } if (locationItem.IconData == null) { locationItem.IconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(path, 24u); if (locationItem.IconData != null) { locationItem.Icon = await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => locationItem.IconData.ToBitmapAsync()); } } } else { locationItem.Icon = await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => UIHelpers.GetIconResource(Constants.ImageRes.Folder)); locationItem.IsInvalid = true; Debug.WriteLine($"Pinned item was invalid {res.ErrorCode}, item: {path}"); } if (!favoriteSection.ChildItems.Any(x => x.Path == locationItem.Path)) { await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => favoriteSection.ChildItems.Insert(insertIndex, locationItem)); } }
/// <summary> /// Override this and place the code to load the file preview here. /// You can return details that may have been obtained while loading the preview (eg. word count). /// This details will be displayed *before* the system file properties. /// If there are none, return an empty list. /// </summary> /// <returns>A list of details</returns> public async virtual Task <List <FileProperty> > LoadPreviewAndDetails() { var iconData = await FileThumbnailHelper.LoadIconFromStorageItemAsync(Item.ItemFile, 400, ThumbnailMode.SingleItem); iconData ??= await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Item.ItemPath, 400); if (iconData != null) { await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async() => FileImage = await iconData.ToBitmapAsync()); } else { FileImage ??= await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => new BitmapImage()); } return(new List <FileProperty>()); }
/// <summary> /// Override this and place the code to load the file preview here. /// You can return details that may have been obtained while loading the preview (eg. word count). /// This details will be displayed *before* the system file properties. /// If there are none, return an empty list. /// </summary> /// <returns>A list of details</returns> public async virtual Task <List <FileProperty> > LoadPreviewAndDetails() { var iconData = await FileThumbnailHelper.LoadIconFromStorageItemAsync(Item.ItemFile, 400, ThumbnailMode.SingleItem); iconData ??= await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Item.ItemPath, 400); if (iconData != null) { FileImage = await iconData.ToBitmapAsync(); } else { FileImage ??= new BitmapImage(); } return(new List <FileProperty>()); }
public async override void GetSpecialProperties() { ViewModel.ItemAttributesVisibility = false; var item = await FilesystemTasks.Wrap(() => DrivesManager.GetRootFromPathAsync(Drive.Path)); BaseStorageFolder diskRoot = await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFolderFromPathAsync(Drive.Path, item)); if (ViewModel.LoadFileIcon) { if (diskRoot != null) { ViewModel.IconData = await FileThumbnailHelper.LoadIconFromStorageItemAsync(diskRoot, 80, ThumbnailMode.SingleItem); } else { ViewModel.IconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Drive.Path, 80); } ViewModel.IconData ??= await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Drive.DeviceID, 80); // For network shortcuts } if (diskRoot == null || diskRoot.Properties == null) { ViewModel.LastSeparatorVisibility = false; return; } try { string freeSpace = "System.FreeSpace"; string capacity = "System.Capacity"; string fileSystem = "System.Volume.FileSystem"; var properties = await diskRoot.Properties.RetrievePropertiesAsync(new[] { freeSpace, capacity, fileSystem }); ViewModel.DriveCapacityValue = (ulong)properties[capacity]; ViewModel.DriveFreeSpaceValue = (ulong)properties[freeSpace]; ViewModel.DriveUsedSpaceValue = ViewModel.DriveCapacityValue - ViewModel.DriveFreeSpaceValue; ViewModel.DriveFileSystem = (string)properties[fileSystem]; } catch (Exception e) { ViewModel.LastSeparatorVisibility = false; App.Logger.Warn(e, e.Message); } }