public async Task EnumerateDrivesAsync() { var cloudProviderController = new CloudProviderController(); var cloudProviders = await cloudProviderController.DetectInstalledCloudProvidersAsync(); foreach (var provider in cloudProviders) { Logger.Info($"Adding cloud provider \"{provider.Name}\" mapped to {provider.SyncFolder}"); var cloudProviderItem = new DriveItem() { Text = provider.Name, Path = provider.SyncFolder, Type = DriveType.CloudDrive, }; await CoreApplication.MainView.CoreWindow.DispatcherQueue.EnqueueAsync(async() => { cloudProviderItem.Icon = await(await FileThumbnailHelper.LoadIconWithoutOverlayAsync(provider.SyncFolder, 24)).ToBitmapAsync(); }); lock (drivesList) { if (!drivesList.Any(x => x.Path == cloudProviderItem.Path)) { drivesList.Add(cloudProviderItem); } } } await RefreshUI(); }
private async void ReloadLibraryItems() { ItemsAdded.BeginBulkOperation(); var toRemove = ItemsAdded.Where(i => i.IsLibrary).ToList(); foreach (var item in toRemove) { ItemsAdded.Remove(item); } foreach (var lib in App.LibraryManager.Libraries) { var iconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(lib.Path, 48u); ItemsAdded.Add(new LibraryCardItem { Icon = iconData != null ? await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => iconData.ToBitmapAsync()) : null, Text = lib.Text, Path = lib.Path, SelectCommand = LibraryCardClicked, AutomationProperties = lib.Text, Library = lib, }); } ItemsAdded.EndBulkOperation(); }
public async override void GetSpecialProperties() { ViewModel.IsReadOnly = NativeFileOperationsHelper.HasFileAttribute(Library.ItemPath, System.IO.FileAttributes.ReadOnly); ViewModel.IsHidden = NativeFileOperationsHelper.HasFileAttribute(Library.ItemPath, System.IO.FileAttributes.Hidden); var fileIconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Library.ItemPath, 80); if (fileIconData != null) { ViewModel.IconData = fileIconData; ViewModel.LoadCustomIcon = false; ViewModel.LoadFileIcon = true; } BaseStorageFile libraryFile = await AppInstance.FilesystemViewModel.GetFileFromPathAsync(Library.ItemPath); if (libraryFile != null) { ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings; string returnformat = Enum.Parse <TimeStyle>(localSettings.Values[Constants.LocalSettings.DateTimeFormat].ToString()) == TimeStyle.Application ? "D" : "g"; ViewModel.ItemCreatedTimestamp = libraryFile.DateCreated.GetFriendlyDateFromFormat(returnformat); if (libraryFile.Properties != null) { GetOtherProperties(libraryFile.Properties); } } var storageFolders = new List <BaseStorageFolder>(); if (Library.Folders != null) { try { foreach (var path in Library.Folders) { BaseStorageFolder folder = await AppInstance.FilesystemViewModel.GetFolderFromPathAsync(path); if (!string.IsNullOrEmpty(folder.Path)) { storageFolders.Add(folder); } } } catch (Exception ex) { App.Logger.Warn(ex, ex.Message); } } if (storageFolders.Count > 0) { ViewModel.ContainsFilesOrFolders = true; ViewModel.LocationsCount = storageFolders.Count; GetLibrarySize(storageFolders, TokenSource.Token); } else { ViewModel.FilesAndFoldersCountString = "LibraryNoLocations/Text".GetLocalized(); } }
public async Task LoadLibraryIcon() { IconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Path, 24u); if (IconData != null) { Icon = await IconData.ToBitmapAsync(); } }
private async Task LoadItemThumbnail() { var iconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Item.ItemPath, 400); if (iconData != null) { FileImage = await iconData.ToBitmapAsync(); } }
private async void LoadLibraryIcon(LibraryLocationItem lib) { lib.IconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(lib.Path, 24u); if (lib.IconData != null) { lib.Icon = await lib.IconData.ToBitmapAsync(); } }
/// <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 SyncSideBarItemsUI() { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { await SidebarControl.SideBarItemsSemaphore.WaitAsync(); try { var section = SidebarControl.SideBarItems.FirstOrDefault(x => x.Text == "SidebarNetworkDrives".GetLocalized()) as LocationItem; if (UserSettingsService.AppearanceSettingsService.ShowNetworkDrivesSection && section == null) { section = new LocationItem() { Text = "SidebarNetworkDrives".GetLocalized(), Section = SectionType.Network, SelectsOnInvoked = false, Icon = await UIHelpers.GetIconResource(Constants.ImageRes.NetworkDrives), ChildItems = new BulkConcurrentObservableCollection <INavigationControlItem>() }; var index = (SidebarControl.SideBarItems.Any(item => item.Section == SectionType.Favorites) ? 1 : 0) + (SidebarControl.SideBarItems.Any(item => item.Section == SectionType.Library) ? 1 : 0) + (SidebarControl.SideBarItems.Any(item => item.Section == SectionType.Drives) ? 1 : 0) + (SidebarControl.SideBarItems.Any(item => item.Section == SectionType.CloudDrives) ? 1 : 0); // After cloud section SidebarControl.SideBarItems.BeginBulkOperation(); SidebarControl.SideBarItems.Insert(Math.Min(index, SidebarControl.SideBarItems.Count), section); SidebarControl.SideBarItems.EndBulkOperation(); } if (section != null) { foreach (var drive in Drives.ToList() .OrderByDescending(o => string.Equals(o.Text, "Network".GetLocalized(), StringComparison.OrdinalIgnoreCase)) .ThenBy(o => o.Text)) { if (!string.IsNullOrEmpty(drive.DeviceID)) { drive.IconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(drive.DeviceID, 24); } if (drive.IconData == null) { var resource = await UIHelpers.GetIconResourceInfo(Constants.ImageRes.Folder); drive.IconData = resource?.IconDataBytes; } drive.Icon = await drive.IconData.ToBitmapAsync(); if (!section.ChildItems.Contains(drive)) { section.ChildItems.Add(drive); } } } } finally { SidebarControl.SideBarItemsSemaphore.Release(); } }); }
/// <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)); } }
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 }); } }
private async Task GetItemsAddedIcon() { foreach (var item in ItemsAdded) { var iconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(item.Path, 48u); if (iconData != null) { item.Icon = await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => iconData.ToBitmapAsync()); } item.SelectCommand = LibraryCardClicked; item.AutomationProperties = item.Text; } }
public async override void GetSpecialProperties() { ViewModel.ItemAttributesVisibility = Visibility.Collapsed; var item = await FilesystemTasks.Wrap(() => DrivesManager.GetRootFromPathAsync(Drive.Path)); StorageFolder diskRoot = await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFolderFromPathAsync(Drive.Path, item)); if (ViewModel.LoadFileIcon) { if (diskRoot != null) { using var thumbnail = await diskRoot.GetThumbnailAsync(ThumbnailMode.SingleItem, 80, ThumbnailOptions.UseCurrentScale); ViewModel.IconData = await thumbnail.ToByteArrayAsync(); } else { var fileIconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Drive.Path, 80); ViewModel.IconData = fileIconData; } } if (diskRoot == null) { ViewModel.LastSeparatorVisibility = Visibility.Collapsed; 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 = Visibility.Collapsed; App.Logger.Warn(e, e.Message); } }
/// <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>()); }
/// <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>()); }
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); } }
/// <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.LoadIconWithoutOverlayAsync(Item.ItemPath, 400); if (iconData != null) { Item.FileImage = await iconData.ToBitmapAsync(); } else { using var icon = await Item.ItemFile.GetThumbnailAsync(ThumbnailMode.SingleItem, 400); Item.FileImage ??= new Windows.UI.Xaml.Media.Imaging.BitmapImage(); await Item.FileImage.SetSourceAsync(icon); } return(new List <FileProperty>()); }
public async Task <List <FilesystemOperationItemViewModel> > ToItems(Action updatePrimaryButtonEnabled, Action optionGenerateNewName, Action optionReplaceExisting, Action optionSkip) { List <FilesystemOperationItemViewModel> items = new List <FilesystemOperationItemViewModel>(); List <FilesystemItemsOperationItemModel> nonConflictingItems = IncomingItems.Except(ConflictingItems).ToList(); // Add conflicting items first foreach (var item in ConflictingItems) { var iconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(item.SourcePath, 64u); items.Add(new FilesystemOperationItemViewModel(updatePrimaryButtonEnabled, optionGenerateNewName, optionReplaceExisting, optionSkip) { IsConflict = true, ItemIcon = iconData != null ? await iconData.ToBitmapAsync() : null, SourcePath = item.SourcePath, DestinationPath = item.DestinationPath, DisplayFileName = item.DisplayFileName, ConflictResolveOption = FileNameConflictResolveOptionType.GenerateNewName, ItemOperation = item.OperationType, ActionTaken = false }); } // Then add non-conflicting items foreach (var item in nonConflictingItems) { var iconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(item.SourcePath, 64u); items.Add(new FilesystemOperationItemViewModel(updatePrimaryButtonEnabled, optionGenerateNewName, optionReplaceExisting, optionSkip) { IsConflict = false, ItemIcon = iconData != null ? await iconData.ToBitmapAsync() : null, SourcePath = item.SourcePath, DestinationPath = item.DestinationPath, DisplayFileName = item.DisplayFileName, ConflictResolveOption = FileNameConflictResolveOptionType.NotAConflict, ItemOperation = item.OperationType, ActionTaken = true }); } return(items); }
public async override void GetSpecialProperties() { base.GetSpecialProperties(); ViewModel.IsHidden = NativeFileOperationsHelper.HasFileAttribute( Item.ItemPath, System.IO.FileAttributes.Hidden); var fileIconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Item.ItemPath, 80); if (fileIconData != null) { ViewModel.IconData = fileIconData; ViewModel.LoadFolderGlyph = false; ViewModel.LoadFileIcon = true; } if (Item.IsShortcutItem) { ViewModel.ItemSizeVisibility = Visibility.Visible; ViewModel.ItemSize = $"{ByteSize.FromBytes(Item.FileSizeBytes).ToBinaryString().ConvertSizeAbbreviation()} ({ByteSize.FromBytes(Item.FileSizeBytes).Bytes:#,##0} {"ItemSizeBytes".GetLocalized()})"; ViewModel.ItemCreatedTimestamp = Item.ItemDateCreated; ViewModel.ItemAccessedTimestamp = Item.ItemDateAccessed; if (Item.IsLinkItem || string.IsNullOrWhiteSpace(((ShortcutItem)Item).TargetPath)) { // Can't show any other property return; } } StorageFolder storageFolder; try { storageFolder = await AppInstance.FilesystemViewModel.GetFolderFromPathAsync((Item as ShortcutItem)?.TargetPath ?? Item.ItemPath); } catch (Exception ex) { App.Logger.Warn(ex, ex.Message); // Could not access folder, can't show any other property return; } if (storageFolder != null) { ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings; string returnformat = Enum.Parse <TimeStyle>(localSettings.Values[Constants.LocalSettings.DateTimeFormat].ToString()) == TimeStyle.Application ? "D" : "g"; ViewModel.ItemCreatedTimestamp = storageFolder.DateCreated.GetFriendlyDateFromFormat(returnformat); GetOtherProperties(storageFolder.Properties); GetFolderSize(storageFolder, TokenSource.Token); } else if (Item.ItemPath.Equals(App.AppSettings.RecycleBinPath, StringComparison.OrdinalIgnoreCase)) { // GetFolderFromPathAsync cannot access recyclebin folder if (AppInstance.ServiceConnection != null) { var value = new ValueSet(); value.Add("Arguments", "RecycleBin"); value.Add("action", "Query"); // Send request to fulltrust process to get recyclebin properties var(status, response) = await AppInstance.ServiceConnection.SendMessageForResponseAsync(value); if (status == Windows.ApplicationModel.AppService.AppServiceResponseStatus.Success) { if (response.TryGetValue("BinSize", out var binSize)) { ViewModel.ItemSizeBytes = (long)binSize; ViewModel.ItemSize = ByteSize.FromBytes((long)binSize).ToString(); ViewModel.ItemSizeVisibility = Visibility.Visible; } else { ViewModel.ItemSizeVisibility = Visibility.Collapsed; } if (response.TryGetValue("NumItems", out var numItems)) { ViewModel.FilesCount = (int)(long)numItems; SetItemsCountString(); ViewModel.FilesAndFoldersCountVisibility = Visibility.Visible; } else { ViewModel.FilesAndFoldersCountVisibility = Visibility.Collapsed; } ViewModel.ItemCreatedTimestampVisibiity = Visibility.Collapsed; ViewModel.ItemAccessedTimestampVisibility = Visibility.Collapsed; ViewModel.ItemModifiedTimestampVisibility = Visibility.Collapsed; ViewModel.ItemFileOwnerVisibility = Visibility.Collapsed; ViewModel.LastSeparatorVisibility = Visibility.Collapsed; } } } }
/// <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)); if (res || (FilesystemResult)FolderHelpers.CheckFolderAccessWithWin32(path)) { var lastItem = favoriteSection.ChildItems.LastOrDefault(x => x.ItemType == NavigationControlItemType.Location && !x.Path.Equals(App.AppSettings.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) { using var thumbnail = await res.Result.GetThumbnailAsync( Windows.Storage.FileProperties.ThumbnailMode.ListView, 24, Windows.Storage.FileProperties.ThumbnailOptions.ResizeThumbnail); if (thumbnail != null) { locationItem.IconData = await thumbnail.ToByteArrayAsync(); await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async() => { locationItem.Icon = await locationItem.IconData.ToBitmapAsync(); }); } else { using var thumbnailFallback = await res.Result.GetThumbnailAsync( Windows.Storage.FileProperties.ThumbnailMode.SingleItem, 24, Windows.Storage.FileProperties.ThumbnailOptions.ResizeThumbnail); if (thumbnailFallback != null) { locationItem.IconData = await thumbnailFallback.ToByteArrayAsync(); await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async() => { locationItem.Icon = await locationItem.IconData.ToBitmapAsync(); }); } } } else { locationItem.IconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(path, 24u); if (locationItem.IconData != null) { locationItem.Icon = await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => locationItem.IconData.ToBitmapAsync()); } } if (!favoriteSection.ChildItems.Contains(locationItem)) { favoriteSection.ChildItems.Insert(insertIndex, locationItem); } } else { Debug.WriteLine($"Pinned item was invalid and will be removed from the file lines list soon: {res.ErrorCode}"); RemoveItem(path); } }
public override async void GetSpecialProperties() { base.GetSpecialProperties(); ViewModel.IsReadOnly = NativeFileOperationsHelper.HasFileAttribute( Item.ItemPath, System.IO.FileAttributes.ReadOnly); ViewModel.IsHidden = NativeFileOperationsHelper.HasFileAttribute( Item.ItemPath, System.IO.FileAttributes.Hidden); ViewModel.ItemSizeVisibility = Visibility.Visible; ViewModel.ItemSize = $"{ByteSize.FromBytes(Item.FileSizeBytes).ToBinaryString().ConvertSizeAbbreviation()} ({ByteSize.FromBytes(Item.FileSizeBytes).Bytes:#,##0} {"ItemSizeBytes".GetLocalized()})"; var fileIconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Item.ItemPath, 80); if (fileIconData != null) { ViewModel.IconData = fileIconData; ViewModel.LoadUnknownTypeGlyph = false; ViewModel.LoadFileIcon = true; } if (Item.IsShortcutItem) { ViewModel.ItemCreatedTimestamp = Item.ItemDateCreated; ViewModel.ItemAccessedTimestamp = Item.ItemDateAccessed; ViewModel.LoadLinkIcon = Item.LoadWebShortcutGlyph; if (Item.IsLinkItem || string.IsNullOrWhiteSpace(((ShortcutItem)Item).TargetPath)) { // Can't show any other property return; } } StorageFile file = await AppInstance.FilesystemViewModel.GetFileFromPathAsync((Item as ShortcutItem)?.TargetPath ?? Item.ItemPath); if (file == null) { // Could not access file, can't show any other property return; } if (Item.IsShortcutItem) { // Can't show any other property return; } GetOtherProperties(file.Properties); // Get file MD5 hash var hashAlgTypeName = HashAlgorithmNames.Md5; ViewModel.ItemMD5HashProgressVisibility = Visibility.Visible; ViewModel.ItemMD5HashVisibility = Visibility.Visible; try { ViewModel.ItemMD5Hash = await GetHashForFileAsync(Item, hashAlgTypeName, TokenSource.Token, hashProgress, AppInstance); } catch (Exception ex) { App.Logger.Warn(ex, ex.Message); ViewModel.ItemMD5HashCalcError = true; } }