Exemplo n.º 1
0
        private IFileSystemItemModel CreateFileSystemTreeItemModel(IFileSystemItemModel parentFileSystemItem, FileSystemInfo pathInfo)
        {
            IFileSystemItemModel fileSystemTreeElement = parentFileSystemItem.CreateModel();

            fileSystemTreeElement.ParentFileSystemItem = parentFileSystemItem;
            fileSystemTreeElement.Info        = pathInfo;
            fileSystemTreeElement.DisplayName = pathInfo.Name;

            fileSystemTreeElement.IsDirectory = pathInfo is DirectoryInfo;

            fileSystemTreeElement.IsArchive = !fileSystemTreeElement.IsDirectory &&
                                              FileExtractor.FileIsArchive(fileSystemTreeElement.Info as FileInfo);

            fileSystemTreeElement.IsSystem = pathInfo.Attributes.HasFlag(FileAttributes.System);
            fileSystemTreeElement.IsHidden = pathInfo.Attributes.HasFlag(FileAttributes.Hidden);
            fileSystemTreeElement.IsDrive  = pathInfo is DirectoryInfo directoryInfo && directoryInfo.Root.FullName.Equals(
                directoryInfo.FullName,
                StringComparison.OrdinalIgnoreCase);
            return(fileSystemTreeElement);
        }
Exemplo n.º 2
0
        private void CreateChildItems(int remainingFileSystemTreeEnumerationLevelCount, ref List <FileSystemTreeElement> lazyChildren)
        {
            foreach (FileSystemInfo fileSystemTreeChildInfo in (this.ElementInfo as DirectoryInfo).EnumerateFileSystemInfos(
                         "*",
                         SearchOption.TopDirectoryOnly))
            {
                if (fileSystemTreeChildInfo is DirectoryInfo subdirectoryInfo)
                {
                    var childDirectoryElement = new FileSystemTreeElement(this.RootFileSystemTreeElement, this, subdirectoryInfo)
                    {
                        HasLazyChildren = remainingFileSystemTreeEnumerationLevelCount.Equals(0)
                    };

                    Application.Current.Dispatcher.Invoke(
                        () => this.ChildFileSystemTreeElements.Add(childDirectoryElement),
                        DispatcherPriority.Send);

                    if (childDirectoryElement.HasLazyChildren)
                    {
                        lazyChildren.Add(childDirectoryElement);
                    }
                    else
                    {
                        childDirectoryElement.ReadFolderStructure(remainingFileSystemTreeEnumerationLevelCount, ref lazyChildren);
                    }
                }
                else if (fileSystemTreeChildInfo is FileInfo fileInfo)
                {
                    var fileIsArchive    = FileExtractor.FileIsArchive(fileInfo);
                    var childFileElement = new FileSystemTreeElement(this.RootFileSystemTreeElement, this, fileInfo)
                    {
                        IsArchive = fileIsArchive
                    };

                    Application.Current.Dispatcher.Invoke(
                        () => this.ChildFileSystemTreeElements.Add(childFileElement),
                        DispatcherPriority.Send);
                }
            }
        }
Exemplo n.º 3
0
        private void ExecuteViewFile(object sender, ExecutedRoutedEventArgs e)
        {
            if (!(e.OriginalSource is FrameworkElement frameworkElement))
            {
                return;
            }

            if (!(frameworkElement.DataContext is FileSystemTreeElement fileSystemTreeElement) || fileSystemTreeElement.IsDirectory)
            {
                return;
            }

            // If file is a compressed archive, then try to extract to temp folder and open the destination folder ...
            if (FileExtractor.FileIsArchive(fileSystemTreeElement.ElementInfo as FileInfo))
            {
                this.ExplorerViewModel.ExtractArchive(fileSystemTreeElement).ConfigureAwait(true);
                return;
            }

            // ... or just open the document if it's no archive but file
            throw new NotImplementedException();
        }
        private void AddFilePathInfoToExplorerTree([NotNull] FileSystemInfo pathInfo, bool isRootFolderExpanded)
        {
            var fileSystemTreeElement = new FileSystemTreeElement(
                this.VirtualExplorerRootDirectory,
                this.VirtualExplorerRootDirectory,
                pathInfo);

            fileSystemTreeElement.IsArchive = !fileSystemTreeElement.IsDirectory &&
                                              FileExtractor.FileIsArchive(fileSystemTreeElement.ElementInfo as FileInfo);

            fileSystemTreeElement.IsSystemDirectory = DriveInfo.GetDrives().Any((driveInfo) => driveInfo.RootDirectory.FullName.Equals(fileSystemTreeElement.ElementInfo.FullName, StringComparison.OrdinalIgnoreCase));

            if (fileSystemTreeElement.IsDirectory || fileSystemTreeElement.IsArchive)
            {
                List <FileSystemTreeElement> lazyFileSystemElements = fileSystemTreeElement.InitializeWithLazyTreeStructure();

                // Observe top level tree directories 'IsExpanded' to show/ hide drag drop hint accordingly
                ObserveTopLevelDirectoryIsExpanded(fileSystemTreeElement);

                // Observe lazy children
                if (fileSystemTreeElement.IsLazyLoading)
                {
                    ObserveVirtualDirectories(lazyFileSystemElements);
                    fileSystemTreeElement.IsExpanded = isRootFolderExpanded && !fileSystemTreeElement.IsArchive;
                }
            }

            // Validate state including the new item that to this point is still not added to the tree
            UpdateFileSystemElementTreeState(fileSystemTreeElement);

            Application.Current.Dispatcher.Invoke(
                () =>
            {
                FilterFileSystemTree(fileSystemTreeElement);
                this.VirtualExplorerRootDirectory.ChildFileSystemTreeElements.Add(fileSystemTreeElement);
            },
                DispatcherPriority.Send);
        }