Ejemplo n.º 1
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 fileIconInfo = await AppInstance.FilesystemViewModel.LoadIconOverlayAsync(Item.ItemPath, 80);

            if (fileIconInfo.IconData != null)
            {
                ViewModel.FileIconSource = await fileIconInfo.IconData.ToBitmapAsync();
            }

            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, ProgressBar, AppInstance);
            }
            catch (Exception ex)
            {
                NLog.LogManager.GetCurrentClassLogger().Warn(ex, ex.Message);
                ViewModel.ItemMD5HashCalcError = true;
            }
        }
Ejemplo n.º 2
0
        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();
            }
        }
Ejemplo n.º 3
0
        public override async void GetSpecialProperties()
        {
            if (List.All(x => x.PrimaryItemAttribute == StorageItemTypes.File))
            {
                ViewModel.IsReadOnly = List.All(x => NativeFileOperationsHelper.HasFileAttribute(x.ItemPath, System.IO.FileAttributes.ReadOnly));
            }
            ViewModel.IsHidden = List.All(x => NativeFileOperationsHelper.HasFileAttribute(x.ItemPath, System.IO.FileAttributes.Hidden));

            ViewModel.LastSeparatorVisibility = Visibility.Collapsed;
            ViewModel.ItemSizeVisibility      = Visibility.Visible;

            ViewModel.FilesCount   += List.Where(x => x.PrimaryItemAttribute == StorageItemTypes.File).ToList().Count;
            ViewModel.FoldersCount += List.Where(x => x.PrimaryItemAttribute == StorageItemTypes.Folder).ToList().Count;

            long totalSize   = 0;
            long filesSize   = List.Where(x => x.PrimaryItemAttribute == StorageItemTypes.File).Sum(x => x.FileSizeBytes);
            long foldersSize = 0;

            ViewModel.ItemSizeProgressVisibility = Visibility.Visible;
            foreach (var item in List)
            {
                if (item.PrimaryItemAttribute == StorageItemTypes.Folder)
                {
                    var fileSizeTask = Task.Run(async() =>
                    {
                        var size = await CalculateFolderSizeAsync(item.ItemPath, TokenSource.Token);
                        return(size);
                    });
                    try
                    {
                        foldersSize += await fileSizeTask;
                    }
                    catch (Exception ex)
                    {
                        NLog.LogManager.GetCurrentClassLogger().Error(ex, ex.Message);
                    }
                }
            }
            ViewModel.ItemSizeProgressVisibility = Visibility.Collapsed;

            totalSize          = filesSize + foldersSize;
            ViewModel.ItemSize = ByteSize.FromBytes(totalSize).ToBinaryString().ConvertSizeAbbreviation()
                                 + " (" + ByteSize.FromBytes(totalSize).Bytes.ToString("#,##0") + " " + "ItemSizeBytes".GetLocalized() + ")";
            SetItemsCountString();
        }
Ejemplo n.º 4
0
        public override async void GetSpecialProperties()
        {
            if (List.All(x => x.PrimaryItemAttribute == StorageItemTypes.File))
            {
                ViewModel.IsReadOnly = List.All(x => NativeFileOperationsHelper.HasFileAttribute(x.ItemPath, System.IO.FileAttributes.ReadOnly));
            }
            ViewModel.IsHidden = List.All(x => NativeFileOperationsHelper.HasFileAttribute(x.ItemPath, System.IO.FileAttributes.Hidden));

            ViewModel.LastSeparatorVisibility = false;
            ViewModel.ItemSizeVisibility      = true;

            ViewModel.FilesCount   += List.Where(x => x.PrimaryItemAttribute == StorageItemTypes.File).ToList().Count;
            ViewModel.FoldersCount += List.Where(x => x.PrimaryItemAttribute == StorageItemTypes.Folder).ToList().Count;

            long totalSize   = 0;
            long filesSize   = List.Where(x => x.PrimaryItemAttribute == StorageItemTypes.File).Sum(x => x.FileSizeBytes);
            long foldersSize = 0;

            ViewModel.ItemSizeProgressVisibility = true;
            foreach (var item in List)
            {
                if (item.PrimaryItemAttribute == StorageItemTypes.Folder)
                {
                    var fileSizeTask = Task.Run(async() =>
                    {
                        var size = await CalculateFolderSizeAsync(item.ItemPath, TokenSource.Token);
                        return(size);
                    });
                    try
                    {
                        foldersSize += await fileSizeTask;
                    }
                    catch (Exception ex)
                    {
                        App.Logger.Warn(ex, ex.Message);
                    }
                }
            }
            ViewModel.ItemSizeProgressVisibility = false;

            totalSize          = filesSize + foldersSize;
            ViewModel.ItemSize = totalSize.ToLongSizeString();
            SetItemsCountString();
        }
Ejemplo n.º 5
0
        public static void WriteFileTag(string filePath, string tag)
        {
            var isReadOnly = NativeFileOperationsHelper.HasFileAttribute(filePath, System.IO.FileAttributes.ReadOnly);

            if (isReadOnly) // Unset read-only attribute (#7534)
            {
                NativeFileOperationsHelper.UnsetFileAttribute(filePath, System.IO.FileAttributes.ReadOnly);
            }
            if (tag == null)
            {
                NativeFileOperationsHelper.DeleteFileFromApp($"{filePath}:files");
            }
            else if (ReadFileTag(filePath) != tag)
            {
                NativeFileOperationsHelper.WriteStringToFile($"{filePath}:files", tag);
            }
            if (isReadOnly) // Restore read-only attribute (#7534)
            {
                NativeFileOperationsHelper.SetFileAttribute(filePath, System.IO.FileAttributes.ReadOnly);
            }
        }
Ejemplo n.º 6
0
        public async override void GetSpecialProperties()
        {
            ViewModel.IsHidden = NativeFileOperationsHelper.HasFileAttribute(
                Item.ItemPath, System.IO.FileAttributes.Hidden);

            var fileIconInfo = await AppInstance.FilesystemViewModel.LoadIconOverlayAsync(Item.ItemPath, 80);
            if (fileIconInfo.Icon != null && fileIconInfo.IsCustom)
            {
                ViewModel.FileIconSource = fileIconInfo.Icon;
            }

            if (Item.IsShortcutItem)
            {
                ViewModel.ItemSizeVisibility = Visibility.Visible;
                ViewModel.ItemSize = ByteSize.FromBytes(Item.FileSizeBytes).ToBinaryString().ConvertSizeAbbreviation()
                    + " (" + ByteSize.FromBytes(Item.FileSizeBytes).Bytes.ToString("#,##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)
            {
                NLog.LogManager.GetCurrentClassLogger().Error(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 = ListedItem.GetFriendlyDateFromFormat(storageFolder.DateCreated, 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.FilesystemViewModel.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 AppInstance.FilesystemViewModel.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;
                    }
                }
            }
        }
Ejemplo n.º 7
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.ToString("#,##0") + " " + "ItemSizeBytes".GetLocalized() + ")";

            var fileIconInfo = await AppInstance.FilesystemViewModel.LoadIconOverlayAsync(Item.ItemPath, 80);

            if (fileIconInfo.Icon != null && !Item.IsLinkItem)
            {
                ViewModel.FileIconSource = fileIconInfo.Icon;
            }

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

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

            ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;
            string returnformat = Enum.Parse <TimeStyle>(localSettings.Values[LocalSettings.DateTimeFormat].ToString()) == TimeStyle.Application ? "D" : "g";

            ViewModel.ItemCreatedTimestamp = ListedItem.GetFriendlyDateFromFormat(file.DateCreated, returnformat);
            GetOtherProperties(file.Properties);

            // Get file MD5 hash
            var hashAlgTypeName = HashAlgorithmNames.Md5;

            ViewModel.ItemMD5HashProgressVisibility = Visibility.Visible;
            ViewModel.ItemMD5HashVisibility         = Visibility.Visible;
            try
            {
                ViewModel.ItemMD5Hash = await AppInstance.InteractionOperations
                                        .GetHashForFileAsync(Item, hashAlgTypeName, TokenSource.Token, ProgressBar);
            }
            catch (Exception ex)
            {
                NLog.LogManager.GetCurrentClassLogger().Error(ex, ex.Message);
                ViewModel.ItemMD5HashCalcError = true;
            }
        }
Ejemplo n.º 8
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);
            }
        }
Ejemplo n.º 9
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 = true;
            ViewModel.ItemSize           = Item.FileSizeBytes.ToLongSizeString();

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