public virtual object SelectFileIconSource(IFileSystemItemModel fileSystemItemModel) { switch (fileSystemItemModel) { case IFileSystemItemModel model when model.IsDirectory: return(null); default: { using (var systemIcon = Icon.ExtractAssociatedIcon(fileSystemItemModel.Info.FullName)) { return(new Viewbox() { Child = new Image() { Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon( systemIcon.Handle, System.Windows.Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions()) } }); } } } }
public void PreloadChildTree(IFileSystemItemModel fileSystemItem, int relativeDepth) { if (!(fileSystemItem.Info is DirectoryInfo directoryInfo) || relativeDepth == 0) { return; } if (!fileSystemItem.ChildFileSystemItems.Any()) { try { directoryInfo.EnumerateFileSystemInfos() .Select(fileSystemInfo => CreateFileSystemTreeItemModel(fileSystemItem, fileSystemInfo)) .OrderBy(item => item, fileSystemItem) .ToList() .ForEach( childItem => Application.Current.Dispatcher?.Invoke( () => fileSystemItem.ChildFileSystemItems .Add(childItem), DispatcherPriority.Background)); } catch (UnauthorizedAccessException) { return; } } --relativeDepth; foreach (IFileSystemItemModel childFileSystemItem in fileSystemItem.ChildFileSystemItems) { PreloadChildTree(childFileSystemItem, relativeDepth); } }
public async Task AddFileSystemPathsAsync(IEnumerable <string> newFileSystemItemModels, int preloadDepth) { await Task.Run(() => { SetIsBusy(); foreach (string path in newFileSystemItemModels) { FileSystemInfo newFileSystemInfo; if (File.Exists(path)) { newFileSystemInfo = new FileInfo(path); } else if (Directory.Exists(path)) { newFileSystemInfo = new DirectoryInfo(path); } else { continue; } IFileSystemItemModel fileSystemItemModel = CreateFileSystemTreeItemModel(this.VirtualExplorerRootDirectory, newFileSystemInfo); this.VirtualExplorerRootDirectory.ChildFileSystemItems.Add(fileSystemItemModel); OnFileSystemTreeChanged(); Task.Run(() => PreloadChildTree(fileSystemItemModel, preloadDepth)).ContinueWith(task => ClearIsBusy()); } }).ConfigureAwait(false); }
public virtual ImageSource SelectIconSource(IFileSystemItemModel itemModel, bool isDirectory, string fileSystemItemFullName) { FileAttributeConstants iconType = System.IO.File.Exists(fileSystemItemFullName) ? FileAttributeConstants.FILE_ATTRIBUTE_NORMAL : System.IO.Directory.Exists(fileSystemItemFullName) ? FileAttributeConstants.FILE_ATTRIBUTE_DIRECTORY : FileAttributeConstants.DEFAULT; if (iconType == FileAttributeConstants.DEFAULT || itemModel is SpecialDirectory) { return(null); } return(GetFileSystemItemIcon(fileSystemItemFullName, true, iconType)); }
public void AddFileSystemItemModelToExplorerTree(IFileSystemItemModel fileSystemItemModel, int preloadDepth) { if (fileSystemItemModel.ParentFileSystemItem == null) { fileSystemItemModel.ParentFileSystemItem = this.VirtualExplorerRootDirectory; } this.VirtualExplorerRootDirectory.ChildFileSystemItems.Add(fileSystemItemModel); this.VirtualExplorerRootDirectory.SortChildrenAsync(); OnFileSystemTreeChanged(); Task.Run(() => PreloadChildTree(fileSystemItemModel, preloadDepth)); }
// Uses preorder traversal public static bool TryGetDirectoryElementOf(IFileSystemItemModel currentItemModel, out IFileSystemItemModel directoryItemModel) { directoryItemModel = null; if (currentItemModel.IsDirectory) { directoryItemModel = currentItemModel; return(true); } return(FileSystemItemModel.TryGetDirectoryElementOf(currentItemModel.ParentFileSystemItem, out directoryItemModel)); }
public int CompareTo(IFileSystemItemModel other) { if (ReferenceEquals(this, other)) { return(0); } if (ReferenceEquals(null, other)) { return(1); } return(FileSystemTreeSortComparison(this, other)); }
private void IndexFileSystemItem(IFileSystemItemModel fileSystemItem) { Index.TryAdd(fileSystemItem.Info.FullName.Trim(Path.DirectorySeparatorChar), fileSystemItem); if (fileSystemItem.IsHidden && !fileSystemItem.ParentFileSystemItem.IsHidden) { HiddenIndex.TryAdd(fileSystemItem.Info.FullName.Trim(Path.DirectorySeparatorChar), fileSystemItem); } if (fileSystemItem.IsSystem && !fileSystemItem.ParentFileSystemItem.IsSystem) { SystemIndex.TryAdd(fileSystemItem.Info.FullName.Trim(Path.DirectorySeparatorChar), fileSystemItem); } }
public virtual object SelectOpenedFolderIconSource(IFileSystemItemModel fileSystemItemModel) { switch (fileSystemItemModel) { case IFileSystemItemModel model when model.IsDirectory: { var resourceDictionary = new ResourceDictionary() { Source = new Uri(@"pack://application:,,,/Bionic.FileExplorer;component/Resources/Images/folder_opened.xaml", UriKind.Absolute) }; return(resourceDictionary["FolderOpenedIcon"]); } default: return(null); } }
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); }
private int FileSystemTreeSortComparison(IFileSystemItemModel itemModelA, IFileSystemItemModel itemModelB) { if (itemModelA is SpecialDirectory) { return(-1); } if (itemModelB is SpecialDirectory) { return(1); } //if (itemModelA.IsSystem && itemModelA.IsDirectory && !itemModelB.IsSystem && !itemModelB.IsDirectory) //{ // return -1; //} //if (!itemModelA.IsSystem && !itemModelA.IsDirectory && itemModelB.IsSystem && itemModelB.IsDirectory) //{ // return 1; //} if (itemModelA.IsDirectory && !itemModelB.IsDirectory) { return(-1); } if (!itemModelA.IsDirectory && itemModelB.IsDirectory) { return(1); } return(itemModelA.DisplayName.CompareTo(itemModelB.DisplayName)); //int fileNameAFirstDotIndex = fileNameAWhithoutExtension.IndexOf(".", StringComparison.OrdinalIgnoreCase); //int fileNameBFirstDotIndex = fileNameBWhithoutExtension.IndexOf(".", StringComparison.OrdinalIgnoreCase); //// Both file names doesn't contain a dot separator (normal case) //if (fileNameAFirstDotIndex.Equals(-1) && fileNameBFirstDotIndex.Equals(-1)) //{ // return CompareAlphabetically(itemModelA.Info.Name, itemModelB.Info.Name); //} //if (fileNameAFirstDotIndex.Equals(-1) || fileNameBFirstDotIndex.Equals(-1)) //{ // return CompareAlphabetically(fileNameAWhithoutExtension, fileNameBWhithoutExtension); //} //// If both names contain a dot prefix separator --> compare prefixes //// File without this separator have precedence over those that contain one (on matching prefix) //string prefixFileNameA = fileNameAWhithoutExtension.Substring(0, fileNameAFirstDotIndex); //string prefixFileNameB = fileNameBWhithoutExtension.Substring(0, fileNameBFirstDotIndex); //int prefixCompareResult = CompareAlphabetically(prefixFileNameA, prefixFileNameB); //// Prefixes are equal --> compare suffix //if (prefixCompareResult.Equals(0)) //{ // string suffixFileNameA = fileNameAWhithoutExtension.Substring(fileNameAFirstDotIndex + 1); // string suffixFileNameB = fileNameBWhithoutExtension.Substring(fileNameBFirstDotIndex + 1); // // Suffix is numeric // if ( // int.TryParse( // suffixFileNameA, // NumberStyles.Integer | NumberStyles.Number, // NumberFormatInfo.InvariantInfo, // out int numberA) // && int.TryParse( // suffixFileNameB, // NumberStyles.Integer | NumberStyles.Number, // NumberFormatInfo.InvariantInfo, // out int numberB)) // { // return numberA.CompareTo(numberB); // } // return CompareAlphabetically(itemModelA.Info.Name, itemModelB.Info.Name); //} //return prefixCompareResult; }
public int Compare(IFileSystemItemModel x, IFileSystemItemModel y) => FileSystemTreeSortComparison(x, y);
public void RemoveFileSystemItemModelToExplorerTree(IFileSystemItemModel fileSystemItemModel) { this.VirtualExplorerRootDirectory.ChildFileSystemItems.Remove(fileSystemItemModel); OnFileSystemTreeChanged(); }
private void AddNewFileSystemInfo(IFileSystemItemModel fileSystemItem, IDirectory parentFolderItem) { parentFolderItem.ChildFileSystemItems.Add(fileSystemItem); IndexFileSystemItem(fileSystemItem); }
private void RemoveFileSystemItemFromIndex(IFileSystemItemModel fileSystemItem) { Index.Remove(fileSystemItem.Info.FullName); HiddenIndex.Remove(fileSystemItem.Info.FullName); SystemIndex.Remove(fileSystemItem.Info.FullName); }