public async Task CreateFolder(string folderPath) { await Task.Run(() => _fileExplorerCommand.CreateFolder(folderPath)); var parentFolder = Path.GetDirectoryName(folderPath); var entry = new PackedDirectoryEntry { CreationTime = DateTime.Now, HasSubFolder = false, Name = new DirectoryInfo(folderPath).Name, Path = folderPath }; if (parentFolder != null && _cachedEntries.TryGetValue(parentFolder.NormalizePath(), out var entriesInfo)) { entry.Parent = entriesInfo.DirectoryEntry; entriesInfo.DirectoryEntry.HasSubFolder = true; lock (entriesInfo) entriesInfo.Entries.Add(entry); FileExplorerEntryAdded?.Invoke(this, new EntryAddedInfo(entry, entriesInfo.DirectoryEntry.Path)); } else { FileExplorerEntryAdded?.Invoke(this, new EntryAddedInfo(entry, parentFolder)); } }
//http://archives.miloush.net/michkap/archive/2007/01/18/1487464.html public static string GetLabel(this PackedDirectoryEntry directory) { if (directory.LabelId != 0 && !string.IsNullOrEmpty(directory.LabelPath)) { var dllPath = Environment.ExpandEnvironmentVariables(directory.LabelPath); var hMod = NativeMethods.LoadLibraryEx(dllPath, IntPtr.Zero, DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE); if (hMod != IntPtr.Zero) { try { var sb = new StringBuilder(500); if (NativeMethods.LoadString(hMod, directory.LabelId, sb, sb.Capacity) != 0) { return(sb.ToString()); } } finally { NativeMethods.FreeLibrary(hMod); } } } if (!string.IsNullOrEmpty(directory.Label)) { return(directory.Label); } return(directory.Name); }
public DirectoryNodeViewModel(PackedDirectoryEntry packedDirectoryEntry, IFileSystem fileSystem) { Value = packedDirectoryEntry; _fileSystem = fileSystem; var driveDirectoryEntry = packedDirectoryEntry as DriveDirectoryEntry; if (driveDirectoryEntry != null) { IsDrive = true; Size = driveDirectoryEntry.UsedSpace; switch (driveDirectoryEntry.DriveType) { case DriveDirectoryType.Unknown: Description = (string)Application.Current.Resources["Unknown"]; break; case DriveDirectoryType.Removable: Description = (string)Application.Current.Resources["UsbDrive"]; break; case DriveDirectoryType.Fixed: Description = (string)Application.Current.Resources["LocalDisk"]; break; case DriveDirectoryType.Network: Description = (string)Application.Current.Resources["NetworkDrive"]; break; case DriveDirectoryType.CDRom: Description = (string)Application.Current.Resources["CdDrive"]; break; case DriveDirectoryType.Ram: Description = "RAM " + (string)Application.Current.Resources["Drive"]; break; default: Description = (string)Application.Current.Resources["Drive"]; break; } } else { Description = (string)Application.Current.Resources["Directory"]; } Name = packedDirectoryEntry.Name; fileSystem.DirectoryEntriesUpdated += FileSystemOnDirectoryEntriesUpdated; fileSystem.FileExplorerEntryRemoved += FileSystemOnFileExplorerEntryRemoved; fileSystem.FileExplorerEntryRenamed += FileSystemOnFileExplorerEntryRenamed; fileSystem.FileExplorerEntryAdded += FileSystemOnFileExplorerEntryAdded; Commands = new EntryViewModelCommands(this, fileSystem); }
public async void Update(PackedDirectoryEntry directoryEntry) { Value = directoryEntry; OnPropertyChanged(nameof(Value)); if (directoryEntry.HasSubFolder && Entries.All.Count == 0) { await Entries.UnloadAsync(); Entries.SetEntries(UpdateMode.Replace, new DirectoryNodeViewModel[1]); } Name = directoryEntry.Name; }
public DirectoryNodeViewModel(DirectoryTreeViewModel rootTreeViewModel, PackedDirectoryEntry currentEntry, DirectoryNodeViewModel parentModel, IFileSystem fileSystem, Func <IWindowService> getWindow) : this(currentEntry, fileSystem) { _rootModel = rootTreeViewModel; _getWindow = getWindow; Parent = parentModel; Entries = new EntriesHelper <DirectoryNodeViewModel>(LoadEntriesTask); Selection = new TreeSelector <DirectoryNodeViewModel, IFileExplorerEntry>(Value, this, parentModel == null ? rootTreeViewModel.Selection : parentModel.Selection, Entries); _isNodeViewModel = true; if (!Value.HasSubFolder) { Entries.SetEntries(UpdateMode.Update); } }
public DirectoryNodeViewModel(PackedDirectoryEntry packedDirectoryEntry, IFileSystem fileSystem, int orderNumber) : this(packedDirectoryEntry, fileSystem) { _orderName = orderNumber.ToString("0000"); }
private DirectoryNodeViewModel GetViewModel(PackedDirectoryEntry directoryEntry) { return(new DirectoryNodeViewModel(_rootModel, directoryEntry, this, _fileSystem, _getWindow)); }
public BitmapImage GetFolderImage(PackedDirectoryEntry directoryEntry) { return(GetFolderImage(directoryEntry.Name, Math.Abs(directoryEntry.IconId))); }