public override async void GetSpecialProperties() { ViewModel.ItemSizeVisibility = Visibility.Visible; ViewModel.ItemSize = ByteSize.FromBytes(Item.FileSizeBytes).ToBinaryString().ConvertSizeAbbreviation() + " (" + ByteSize.FromBytes(Item.FileSizeBytes).Bytes.ToString("#,##0") + " " + ResourceController.GetTranslation("ItemSizeBytes") + ")"; if (Item.IsShortcutItem) { ViewModel.ItemCreatedTimestamp = Item.ItemDateCreated; ViewModel.ItemAccessedTimestamp = Item.ItemDateAccessed; ViewModel.LoadLinkIcon = Item.IsLinkItem; if (Item.IsLinkItem || string.IsNullOrWhiteSpace(((ShortcutItem)Item).TargetPath)) { // Can't show any other property return; } } var file = await ItemViewModel.GetFileFromPathAsync((Item as ShortcutItem)?.TargetPath ?? Item.ItemPath); using (var Thumbnail = await file.GetThumbnailAsync(ThumbnailMode.SingleItem, 80, ThumbnailOptions.UseCurrentScale)) { BitmapImage icon = new BitmapImage(); if (Thumbnail != null) { ViewModel.FileIconSource = icon; await icon.SetSourceAsync(Thumbnail); ViewModel.LoadUnknownTypeGlyph = false; ViewModel.LoadFileIcon = true; } } if (Item.IsShortcutItem) { // Can't show any other property return; } ViewModel.ItemCreatedTimestamp = ListedItem.GetFriendlyDate(file.DateCreated); GetOtherProperties(file.Properties); // Get file MD5 hash var hashAlgTypeName = HashAlgorithmNames.Md5; ViewModel.ItemMD5HashProgressVisibility = Visibility.Visible; ViewModel.ItemMD5HashVisibility = Visibility.Visible; try { ViewModel.ItemMD5Hash = await App.CurrentInstance.InteractionOperations .GetHashForFile(Item, hashAlgTypeName, TokenSource.Token, ProgressBar); } catch (Exception ex) { NLog.LogManager.GetCurrentClassLogger().Error(ex, ex.Message); ViewModel.ItemMD5HashCalcError = true; } }
private async void Properties_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e) { // Collect AppWindow-specific info propWindow = Interaction.AppWindows[this.UIContext]; if (App.CurrentInstance.ContentPage.IsItemSelected) { var selectedItem = App.CurrentInstance.ContentPage.SelectedItem; IStorageItem selectedStorageItem; try { selectedStorageItem = await StorageFolder.GetFolderFromPathAsync(selectedItem.ItemPath); } catch (Exception) { // Not a folder, so attempt to get as StorageFile selectedStorageItem = await StorageFile.GetFileFromPathAsync(selectedItem.ItemPath); var hashAlgTypeName = HashAlgorithmNames.Md5; ItemProperties.ItemMD5Hash = await App.CurrentInstance.InteractionOperations.GetHashForFile(selectedItem, hashAlgTypeName); // get file hash } ItemProperties.ItemName = selectedItem.ItemName; ItemProperties.ItemType = selectedItem.ItemType; ItemProperties.ItemPath = selectedItem.ItemPath; ItemProperties.ItemSize = selectedItem.FileSize; ItemProperties.LoadFileIcon = selectedItem.LoadFileIcon; ItemProperties.LoadFolderGlyph = selectedItem.LoadFolderGlyph; ItemProperties.LoadUnknownTypeGlyph = selectedItem.LoadUnknownTypeGlyph; ItemProperties.ItemModifiedTimestamp = selectedItem.ItemDateModified; ItemProperties.ItemCreatedTimestamp = ListedItem.GetFriendlyDate(selectedStorageItem.DateCreated); if (!App.CurrentInstance.ContentPage.SelectedItem.LoadFolderGlyph) { var thumbnail = await(await StorageFile.GetFileFromPathAsync(App.CurrentInstance.ContentPage.SelectedItem.ItemPath)).GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.SingleItem, 40, Windows.Storage.FileProperties.ThumbnailOptions.ResizeThumbnail); var bitmap = new BitmapImage(); await bitmap.SetSourceAsync(thumbnail); ItemProperties.FileIconSource = bitmap; } } else { var parentDirectory = App.CurrentInstance.ViewModel.CurrentFolder; var parentDirectoryStorageItem = await StorageFolder.GetFolderFromPathAsync(parentDirectory.ItemPath); ItemProperties.ItemName = parentDirectory.ItemName; ItemProperties.ItemType = parentDirectory.ItemType; ItemProperties.ItemPath = parentDirectory.ItemPath; ItemProperties.ItemSize = parentDirectory.FileSize; ItemProperties.LoadFileIcon = false; ItemProperties.LoadFolderGlyph = true; ItemProperties.LoadUnknownTypeGlyph = false; ItemProperties.ItemModifiedTimestamp = parentDirectory.ItemDateModified; ItemProperties.ItemCreatedTimestamp = ListedItem.GetFriendlyDate(parentDirectoryStorageItem.DateCreated); } }
private async void Properties_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e) { // Collect AppWindow-specific info propWindow = Interaction.AppWindows[this.UIContext]; if (App.CurrentInstance.ContentPage.IsItemSelected) { var selectedItem = App.CurrentInstance.ContentPage.SelectedItem; IStorageItem selectedStorageItem; try { selectedStorageItem = await StorageFolder.GetFolderFromPathAsync(selectedItem.FilePath); } catch (Exception) { // Not a folder, so attempt to get as StorageFile selectedStorageItem = await StorageFile.GetFileFromPathAsync(selectedItem.FilePath); } itemProperties.ItemName = selectedItem.FileName; itemProperties.ItemType = selectedItem.FileType; itemProperties.ItemPath = selectedItem.FilePath; itemProperties.ItemSize = selectedItem.FileSize; itemProperties.LoadFileIcon = selectedItem.FileIconVis == Windows.UI.Xaml.Visibility.Visible ? true : false; itemProperties.LoadFolderGlyph = selectedItem.FolderImg == Windows.UI.Xaml.Visibility.Visible ? true : false; itemProperties.LoadUnknownTypeGlyph = selectedItem.EmptyImgVis == Windows.UI.Xaml.Visibility.Visible ? true : false; itemProperties.ItemModifiedTimestamp = selectedItem.FileDate; itemProperties.ItemCreatedTimestamp = ListedItem.GetFriendlyDate(selectedStorageItem.DateCreated); if (App.CurrentInstance.ContentPage.SelectedItem.FolderImg != Windows.UI.Xaml.Visibility.Visible) { var thumbnail = await(await StorageFile.GetFileFromPathAsync(App.CurrentInstance.ContentPage.SelectedItem.FilePath)).GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.SingleItem, 40, Windows.Storage.FileProperties.ThumbnailOptions.ResizeThumbnail); var bitmap = new BitmapImage(); await bitmap.SetSourceAsync(thumbnail); itemProperties.FileIconSource = bitmap; } } else { var parentDirectory = App.CurrentInstance.ViewModel.currentFolder; var parentDirectoryStorageItem = await StorageFolder.GetFolderFromPathAsync(parentDirectory.FilePath); itemProperties.ItemName = parentDirectory.FileName; itemProperties.ItemType = parentDirectory.FileType; itemProperties.ItemPath = parentDirectory.FilePath; itemProperties.ItemSize = parentDirectory.FileSize; itemProperties.LoadFileIcon = false; itemProperties.LoadFolderGlyph = true; itemProperties.LoadUnknownTypeGlyph = false; itemProperties.ItemModifiedTimestamp = parentDirectory.FileDate; itemProperties.ItemCreatedTimestamp = ListedItem.GetFriendlyDate(parentDirectoryStorageItem.DateCreated); } }
public async void GetOtherPropeties(StorageItemContentProperties properties) { string dateAccessedProperty = "System.DateAccessed"; string fileOwnerProperty = "System.FileOwner"; List <string> propertiesName = new List <string>(); propertiesName.Add(dateAccessedProperty); propertiesName.Add(fileOwnerProperty); IDictionary <string, object> extraProperties = await properties.RetrievePropertiesAsync(propertiesName); ViewModel.ItemAccessedTimestamp = ListedItem.GetFriendlyDate((DateTimeOffset)extraProperties[dateAccessedProperty]); ViewModel.ItemFileOwner = extraProperties[fileOwnerProperty].ToString(); }
public async Task GetPropertiesAsync(CancellationTokenSource _tokenSource) { if (ViewModel.Item.PrimaryItemAttribute == StorageItemTypes.File) { var file = await StorageFile.GetFileFromPathAsync(ViewModel.Item.ItemPath); ViewModel.ItemCreatedTimestamp = ListedItem.GetFriendlyDate(file.DateCreated); GetOtherPropeties(file.Properties); ViewModel.ItemsSize = ByteSizeLib.ByteSize.FromBytes(ViewModel.Item.FileSizeBytes).ToBinaryString().ConvertSizeAbbreviation() + " (" + ByteSizeLib.ByteSize.FromBytes(ViewModel.Item.FileSizeBytes).Bytes.ToString("#,##0") + " " + ResourceController.GetTranslation("ItemSizeBytes") + ")"; // Get file MD5 hash var hashAlgTypeName = HashAlgorithmNames.Md5; ViewModel.ItemMD5HashProgressVisibility = Visibility.Visible; ViewModel.ItemMD5HashVisibility = Visibility.Visible; try { ViewModel.ItemMD5Hash = await App.CurrentInstance.InteractionOperations.GetHashForFile(ViewModel.Item, hashAlgTypeName, _tokenSource.Token, ItemMD5HashProgress); } catch (Exception ex) { NLog.LogManager.GetCurrentClassLogger().Error(ex, ex.Message); ViewModel.ItemMD5HashCalcError = true; } } else if (ViewModel.Item.PrimaryItemAttribute == StorageItemTypes.Folder) { StorageFolder storageFolder = null; if (App.CurrentInstance.ContentPage.IsItemSelected) { storageFolder = await StorageFolder.GetFolderFromPathAsync(ViewModel.Item.ItemPath); } else { var parentDirectory = App.CurrentInstance.FilesystemViewModel.CurrentFolder; if (parentDirectory.ItemPath.StartsWith(AppSettings.RecycleBinPath)) { // GetFolderFromPathAsync cannot access recyclebin folder // Currently a fake timestamp is used } else { storageFolder = await StorageFolder.GetFolderFromPathAsync(parentDirectory.ItemPath); } } ViewModel.ItemCreatedTimestamp = ListedItem.GetFriendlyDate(storageFolder.DateCreated); GetOtherPropeties(storageFolder.Properties); GetFolderSize(storageFolder, _tokenSource.Token); } }
private async void GetFolderProperties(CancellationTokenSource _tokenSource) { StorageFolder storageFolder = null; if (App.CurrentInstance.ContentPage.IsItemSelected) { storageFolder = await StorageFolder.GetFolderFromPathAsync(ViewModel.Item.ItemPath); ViewModel.ItemCreatedTimestamp = ListedItem.GetFriendlyDate(storageFolder.DateCreated); GetOtherPropeties(storageFolder.Properties); GetFolderSize(storageFolder, _tokenSource.Token); } else { var parentDirectory = App.CurrentInstance.FilesystemViewModel.CurrentFolder; if (parentDirectory.ItemPath.StartsWith(AppSettings.RecycleBinPath)) { // GetFolderFromPathAsync cannot access recyclebin folder if (App.Connection != null) { var value = new ValueSet(); value.Add("Arguments", "RecycleBin"); value.Add("action", "Query"); // Send request to fulltrust process to get recyclebin properties var response = await App.Connection.SendMessageAsync(value); if (response.Status == Windows.ApplicationModel.AppService.AppServiceResponseStatus.Success) { ViewModel.ItemCreatedTimestamp = ListedItem.GetFriendlyDate(DateTime.FromBinary((long)response.Message["DateCreated"])); ViewModel.ItemSizeBytes = (long)response.Message["BinSize"]; ViewModel.ItemSize = ByteSize.FromBytes((long)response.Message["BinSize"]).ToString(); ViewModel.FilesCount = (int)(long)response.Message["NumItems"]; SetItemsCountString(); ViewModel.ItemAccessedTimestamp = ListedItem.GetFriendlyDate(DateTime.FromBinary((long)response.Message["DateAccessed"])); ViewModel.ItemFileOwnerVisibility = Visibility.Collapsed; ViewModel.ItemSizeVisibility = Visibility.Visible; } } } else { storageFolder = await StorageFolder.GetFolderFromPathAsync(parentDirectory.ItemPath); ViewModel.ItemCreatedTimestamp = ListedItem.GetFriendlyDate(storageFolder.DateCreated); GetOtherPropeties(storageFolder.Properties); GetFolderSize(storageFolder, _tokenSource.Token); } } }
public async void GetOtherProperties(StorageItemContentProperties properties) { string dateAccessedProperty = "System.DateAccessed"; string fileOwnerProperty = "System.FileOwner"; List <string> propertiesName = new List <string>(); propertiesName.Add(dateAccessedProperty); propertiesName.Add(fileOwnerProperty); IDictionary <string, object> extraProperties = await properties.RetrievePropertiesAsync(propertiesName); // Cannot get date and owner in MTP devices ViewModel.ItemAccessedTimestamp = ListedItem.GetFriendlyDate((DateTimeOffset)(extraProperties[dateAccessedProperty] ?? DateTimeOffset.Now)); if (App.AppSettings.ShowFileOwner) { // Cannot get date and owner in MTP devices ViewModel.ItemFileOwner = extraProperties[fileOwnerProperty]?.ToString(); } }
private async void GetFileProperties(CancellationTokenSource _tokenSource) { var file = await StorageFile.GetFileFromPathAsync(ViewModel.Item.ItemPath); ViewModel.ItemCreatedTimestamp = ListedItem.GetFriendlyDate(file.DateCreated); GetOtherPropeties(file.Properties); ViewModel.ItemSizeVisibility = Visibility.Visible; ViewModel.ItemSize = ByteSize.FromBytes(ViewModel.Item.FileSizeBytes).ToBinaryString().ConvertSizeAbbreviation() + " (" + ByteSize.FromBytes(ViewModel.Item.FileSizeBytes).Bytes.ToString("#,##0") + " " + ResourceController.GetTranslation("ItemSizeBytes") + ")"; using (var Thumbnail = await file.GetThumbnailAsync(ThumbnailMode.SingleItem, 80, ThumbnailOptions.UseCurrentScale)) { BitmapImage icon = new BitmapImage(); if (Thumbnail != null) { ViewModel.FileIconSource = icon; await icon.SetSourceAsync(Thumbnail); ViewModel.LoadUnknownTypeGlyph = false; ViewModel.LoadFileIcon = true; } } // Get file MD5 hash var hashAlgTypeName = HashAlgorithmNames.Md5; ViewModel.ItemMD5HashProgressVisibility = Visibility.Visible; ViewModel.ItemMD5HashVisibility = Visibility.Visible; try { ViewModel.ItemMD5Hash = await App.CurrentInstance.InteractionOperations .GetHashForFile(ViewModel.Item, hashAlgTypeName, _tokenSource.Token, ItemMD5HashProgress); } catch (Exception ex) { NLog.LogManager.GetCurrentClassLogger().Error(ex, ex.Message); ViewModel.ItemMD5HashCalcError = true; } }
private async void Properties_Loaded(object sender, RoutedEventArgs e) { if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8)) { // Collect AppWindow-specific info propWindow = Interaction.AppWindows[UIContext]; // Set properties window titleBar style _TitleBar = propWindow.TitleBar; _TitleBar.ButtonBackgroundColor = Colors.Transparent; _TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent; App.AppSettings.UpdateThemeElements.Execute(null); } if (App.CurrentInstance.ContentPage.IsItemSelected) { var selectedItem = App.CurrentInstance.ContentPage.SelectedItem; IStorageItem selectedStorageItem = null; if (selectedItem.PrimaryItemAttribute == StorageItemTypes.File) { selectedStorageItem = await StorageFile.GetFileFromPathAsync(selectedItem.ItemPath); ItemProperties.ItemSize = selectedItem.FileSize; } else if (selectedItem.PrimaryItemAttribute == StorageItemTypes.Folder) { var storageFolder = await StorageFolder.GetFolderFromPathAsync(selectedItem.ItemPath); selectedStorageItem = storageFolder; GetFolderSize(storageFolder); } ItemProperties.ItemName = selectedItem.ItemName; ItemProperties.ItemType = selectedItem.ItemType; ItemProperties.ItemPath = selectedItem.ItemPath; ItemProperties.LoadFileIcon = selectedItem.LoadFileIcon; ItemProperties.LoadFolderGlyph = selectedItem.LoadFolderGlyph; ItemProperties.LoadUnknownTypeGlyph = selectedItem.LoadUnknownTypeGlyph; ItemProperties.ItemModifiedTimestamp = selectedItem.ItemDateModified; ItemProperties.ItemCreatedTimestamp = ListedItem.GetFriendlyDate(selectedStorageItem.DateCreated); if (!App.CurrentInstance.ContentPage.SelectedItem.LoadFolderGlyph) { var thumbnail = await(await StorageFile.GetFileFromPathAsync(App.CurrentInstance.ContentPage.SelectedItem.ItemPath)).GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.SingleItem, 80, Windows.Storage.FileProperties.ThumbnailOptions.ResizeThumbnail); var bitmap = new BitmapImage(); await bitmap.SetSourceAsync(thumbnail); ItemProperties.FileIconSource = bitmap; } if (selectedItem.PrimaryItemAttribute == StorageItemTypes.File) { // Get file MD5 hash var hashAlgTypeName = HashAlgorithmNames.Md5; ItemProperties.ItemMD5HashProgressVisibility = Visibility.Visible; ItemProperties.ItemMD5Hash = await App.CurrentInstance.InteractionOperations.GetHashForFile(selectedItem, hashAlgTypeName); ItemProperties.ItemMD5HashProgressVisibility = Visibility.Collapsed; ItemProperties.ItemMD5HashVisibility = Visibility.Visible; } else if (selectedItem.PrimaryItemAttribute == StorageItemTypes.Folder) { ItemProperties.ItemMD5HashVisibility = Visibility.Collapsed; ItemProperties.ItemMD5HashProgressVisibility = Visibility.Collapsed; } } else { var parentDirectory = App.CurrentInstance.ViewModel.CurrentFolder; if (parentDirectory.ItemPath.StartsWith(App.AppSettings.RecycleBinPath)) { // GetFolderFromPathAsync cannot access recyclebin folder // Currently a fake timestamp is used ItemProperties.ItemCreatedTimestamp = ListedItem.GetFriendlyDate(parentDirectory.ItemDateModifiedReal); ItemProperties.ItemSize = parentDirectory.FileSize; } else { var parentDirectoryStorageItem = await StorageFolder.GetFolderFromPathAsync(parentDirectory.ItemPath); ItemProperties.ItemCreatedTimestamp = ListedItem.GetFriendlyDate(parentDirectoryStorageItem.DateCreated); } ItemProperties.ItemName = parentDirectory.ItemName; ItemProperties.ItemType = parentDirectory.ItemType; ItemProperties.ItemPath = parentDirectory.ItemPath; ItemProperties.LoadFileIcon = false; ItemProperties.LoadFolderGlyph = true; ItemProperties.LoadUnknownTypeGlyph = false; ItemProperties.ItemModifiedTimestamp = parentDirectory.ItemDateModified; ItemProperties.ItemMD5HashVisibility = Visibility.Collapsed; ItemProperties.ItemMD5HashProgressVisibility = Visibility.Collapsed; } }
public async override void GetSpecialProperties() { StorageFolder storageFolder; if (App.CurrentInstance.ContentPage.IsItemSelected) { storageFolder = await ItemViewModel.GetFolderFromPathAsync(Item.ItemPath); ViewModel.ItemCreatedTimestamp = ListedItem.GetFriendlyDate(storageFolder.DateCreated); GetOtherProperties(storageFolder.Properties); GetFolderSize(storageFolder, TokenSource.Token); } else { var parentDirectory = App.CurrentInstance.FilesystemViewModel.CurrentFolder; if (parentDirectory.ItemPath.StartsWith(App.AppSettings.RecycleBinPath)) { // GetFolderFromPathAsync cannot access recyclebin folder if (App.Connection != null) { var value = new ValueSet(); value.Add("Arguments", "RecycleBin"); value.Add("action", "Query"); // Send request to fulltrust process to get recyclebin properties var response = await App.Connection.SendMessageAsync(value); if (response.Status == Windows.ApplicationModel.AppService.AppServiceResponseStatus.Success) { if (response.Message.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.Message.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; } } } else { storageFolder = await ItemViewModel.GetFolderFromPathAsync(parentDirectory.ItemPath); ViewModel.ItemCreatedTimestamp = ListedItem.GetFriendlyDate(storageFolder.DateCreated); GetOtherProperties(storageFolder.Properties); GetFolderSize(storageFolder, TokenSource.Token); } } }