示例#1
0
        public async Task <ImageModel?> GetImageModelFromPathAsync(string filePath, uint thumbnailSize = 64)
        {
            ImageModel?imageModel = null;

            if (await FileThumbnailHelper.LoadIconFromPathAsync(filePath, thumbnailSize, ThumbnailMode.ListView) is byte[] imageBuffer)
            {
                imageModel = await GetImageModelFromDataAsync(imageBuffer);
            }

            return(imageModel);
        }
示例#2
0
        public async override void GetSpecialProperties()
        {
            ViewModel.IsHidden = NativeFileOperationsHelper.HasFileAttribute(
                Item.ItemPath, System.IO.FileAttributes.Hidden);

            var fileIconData = await FileThumbnailHelper.LoadIconFromPathAsync(Item.ItemPath, 80, Windows.Storage.FileProperties.ThumbnailMode.SingleItem);

            if (fileIconData != null)
            {
                ViewModel.IconData        = fileIconData;
                ViewModel.LoadFolderGlyph = false;
                ViewModel.LoadFileIcon    = true;
            }

            if (Item.IsShortcutItem)
            {
                ViewModel.ItemSizeVisibility    = true;
                ViewModel.ItemSize              = Item.FileSizeBytes.ToLongSizeString();
                ViewModel.ItemCreatedTimestamp  = Item.ItemDateCreated;
                ViewModel.ItemAccessedTimestamp = Item.ItemDateAccessed;
                if (Item.IsLinkItem || string.IsNullOrWhiteSpace(((ShortcutItem)Item).TargetPath))
                {
                    // Can't show any other property
                    return;
                }
            }

            string            folderPath = (Item as ShortcutItem)?.TargetPath ?? Item.ItemPath;
            BaseStorageFolder storageFolder;

            try
            {
                storageFolder = await AppInstance.FilesystemViewModel.GetFolderFromPathAsync(folderPath);
            }
            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);
                if (storageFolder.Properties != null)
                {
                    GetOtherProperties(storageFolder.Properties);
                }
                GetFolderSize(storageFolder.Path, TokenSource.Token);
            }
            else if (Item.ItemPath.Equals(CommonPaths.RecycleBinPath, StringComparison.OrdinalIgnoreCase))
            {
                // GetFolderFromPathAsync cannot access recyclebin folder
                var connection = await AppServiceConnectionHelper.Instance;
                if (connection != 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 connection.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 = true;
                        }
                        else
                        {
                            ViewModel.ItemSizeVisibility = false;
                        }
                        if (response.TryGetValue("NumItems", out var numItems))
                        {
                            ViewModel.FilesCount = (int)(long)numItems;
                            SetItemsCountString();
                            ViewModel.FilesAndFoldersCountVisibility = true;
                        }
                        else
                        {
                            ViewModel.FilesAndFoldersCountVisibility = false;
                        }
                        ViewModel.ItemCreatedTimestampVisibiity   = false;
                        ViewModel.ItemAccessedTimestampVisibility = false;
                        ViewModel.ItemModifiedTimestampVisibility = false;
                        ViewModel.LastSeparatorVisibility         = false;
                    }
                }
            }
            else
            {
                GetFolderSize(folderPath, TokenSource.Token);
            }
        }
示例#3
0
        public override async void 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.LoadIconFromPathAsync(Item.ItemPath, 80, Windows.Storage.FileProperties.ThumbnailMode.SingleItem);

            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;
                }
            }

            BaseStorageFile 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;
            }

            if (file.Properties != null)
            {
                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;
            }
        }