public static ShellFileItem GetShellFileItem(ShellItem folderItem) { if (folderItem == null) { return(null); } bool isFolder = folderItem.IsFolder && !folderItem.Attributes.HasFlag(ShellItemAttribute.Stream); var parsingPath = folderItem.GetDisplayName(ShellItemDisplayString.DesktopAbsoluteParsing); parsingPath ??= folderItem.FileSystemPath; // True path on disk if (parsingPath == null || !Path.IsPathRooted(parsingPath)) { parsingPath = parsingPath switch { "::{645FF040-5081-101B-9F08-00AA002F954E}" => "Shell:RecycleBinFolder", "::{F02C1A0D-BE21-4350-88B0-7367FC96EF3C}" => "Shell:NetworkPlacesFolder", "::{208D2C60-3AEA-1069-A2D7-08002B30309D}" => "Shell:NetworkPlacesFolder", // Use PIDL as path _ => $@"\\SHELL\{string.Join("\\", folderItem.PIDL.Select(x => x.GetBytes()).Select(x => Convert.ToBase64String(x, 0, x.Length)))}" }; } var fileName = folderItem.Properties.TryGetProperty <string>(Ole32.PROPERTYKEY.System.ItemNameDisplay); fileName ??= Path.GetFileName(folderItem.Name); // Original file name fileName ??= folderItem.GetDisplayName(ShellItemDisplayString.ParentRelativeParsing); var itemNameOrOriginalPath = folderItem.Name ?? fileName; string filePath = string.IsNullOrEmpty(Path.GetDirectoryName(parsingPath)) ? // Null if root parsingPath : Path.Combine(Path.GetDirectoryName(parsingPath), itemNameOrOriginalPath); // In recycle bin "Name" contains original file path + name if (!isFolder && !string.IsNullOrEmpty(parsingPath) && Path.GetExtension(parsingPath) is string realExtension && !string.IsNullOrEmpty(realExtension)) { if (!string.IsNullOrEmpty(fileName) && !fileName.EndsWith(realExtension, StringComparison.OrdinalIgnoreCase)) { fileName = $"{fileName}{realExtension}"; } if (!string.IsNullOrEmpty(filePath) && !filePath.EndsWith(realExtension, StringComparison.OrdinalIgnoreCase)) { filePath = $"{filePath}{realExtension}"; } } var fileTime = folderItem.Properties.TryGetProperty <System.Runtime.InteropServices.ComTypes.FILETIME?>( Ole32.PROPERTYKEY.System.Recycle.DateDeleted); var recycleDate = fileTime?.ToDateTime().ToLocalTime() ?? DateTime.Now; // This is LocalTime fileTime = folderItem.Properties.TryGetProperty <System.Runtime.InteropServices.ComTypes.FILETIME?>( Ole32.PROPERTYKEY.System.DateModified); var modifiedDate = fileTime?.ToDateTime().ToLocalTime() ?? folderItem.FileInfo?.LastWriteTime ?? DateTime.Now; // This is LocalTime fileTime = folderItem.Properties.TryGetProperty <System.Runtime.InteropServices.ComTypes.FILETIME?>( Ole32.PROPERTYKEY.System.DateCreated); var createdDate = fileTime?.ToDateTime().ToLocalTime() ?? folderItem.FileInfo?.CreationTime ?? DateTime.Now; // This is LocalTime var fileSizeBytes = folderItem.Properties.TryGetProperty <ulong?>(Ole32.PROPERTYKEY.System.Size); string fileSize = fileSizeBytes is not null?folderItem.Properties.GetPropertyString(Ole32.PROPERTYKEY.System.Size) : null; var fileType = folderItem.Properties.TryGetProperty <string>(Ole32.PROPERTYKEY.System.ItemTypeText); return(new ShellFileItem(isFolder, parsingPath, fileName, filePath, recycleDate, modifiedDate, createdDate, fileSize, fileSizeBytes ?? 0, fileType)); }
public void GetDisplayNameTest() { using var i = new ShellItem(testDoc); Assert.That(i.GetDisplayName(ShellItemDisplayString.FileSysPath), Is.EqualTo(testDoc).IgnoreCase); foreach (ShellItemDisplayString e in Enum.GetValues(typeof(ShellItemDisplayString))) { Assert.That(() => TestContext.WriteLine($"{e}={i.GetDisplayName(e)}"), Throws.Nothing); } Assert.That(i.GetDisplayName((ShellItemDisplayString)0x8fffffff), Is.EqualTo(i.GetDisplayName(0))); }
public void GetDisplayNameTest() { using (var i = new ShellItem(testDoc)) { foreach (ShellItemDisplayString e in Enum.GetValues(typeof(ShellItemDisplayString))) { Assert.That(() => { var s = i.GetDisplayName(e); Debug.WriteLine($"{e}={s}"); }, Throws.Nothing); } Assert.That(i.GetDisplayName((ShellItemDisplayString)0x8fffffff), Is.EqualTo(i.GetDisplayName(0))); } }
public void LoadData(NavigationLog log) { nav = log; ShellItem obj = log.CurrentLocation; tabTitle.Text = obj.GetDisplayName(SIGDN.NORMALDISPLAY); image1.Source = obj.Thumbnail.BitmapSource; this.ToolTip = obj.ParsingName; }
public static ShellFileItem GetShellFileItem(ShellItem folderItem) { if (folderItem == null) { return(null); } bool isFolder = folderItem.IsFolder && !folderItem.Attributes.HasFlag(ShellItemAttribute.Stream); if (folderItem.Properties == null) { return(new ShellFileItem(isFolder, folderItem.FileSystemPath, Path.GetFileName(folderItem.Name), folderItem.Name, DateTime.Now, DateTime.Now, DateTime.Now, null, 0, null)); } var parsingPath = folderItem.GetDisplayName(ShellItemDisplayString.DesktopAbsoluteParsing); parsingPath ??= folderItem.FileSystemPath; // True path on disk folderItem.Properties.TryGetValue <string>( Ole32.PROPERTYKEY.System.ItemNameDisplay, out var fileName); fileName ??= Path.GetFileName(folderItem.Name); // Original file name string filePath = string.IsNullOrEmpty(Path.GetDirectoryName(parsingPath)) ? // Null if root parsingPath : Path.Combine(Path.GetDirectoryName(parsingPath), folderItem.Name); // In recycle bin "Name" contains original file path + name if (!isFolder && !string.IsNullOrEmpty(parsingPath) && Path.GetExtension(parsingPath) is string realExtension && !string.IsNullOrEmpty(realExtension)) { if (!string.IsNullOrEmpty(fileName) && !fileName.EndsWith(realExtension, StringComparison.OrdinalIgnoreCase)) { fileName = $"{fileName}{realExtension}"; } if (!string.IsNullOrEmpty(filePath) && !filePath.EndsWith(realExtension, StringComparison.OrdinalIgnoreCase)) { filePath = $"{filePath}{realExtension}"; } } folderItem.Properties.TryGetValue <System.Runtime.InteropServices.ComTypes.FILETIME?>( Ole32.PROPERTYKEY.System.Recycle.DateDeleted, out var fileTime); var recycleDate = fileTime?.ToDateTime().ToLocalTime() ?? DateTime.Now; // This is LocalTime folderItem.Properties.TryGetValue <System.Runtime.InteropServices.ComTypes.FILETIME?>( Ole32.PROPERTYKEY.System.DateModified, out fileTime); var modifiedDate = fileTime?.ToDateTime().ToLocalTime() ?? DateTime.Now; // This is LocalTime folderItem.Properties.TryGetValue <System.Runtime.InteropServices.ComTypes.FILETIME?>( Ole32.PROPERTYKEY.System.DateCreated, out fileTime); var createdDate = fileTime?.ToDateTime().ToLocalTime() ?? DateTime.Now; // This is LocalTime string fileSize = folderItem.Properties.TryGetValue <ulong?>( Ole32.PROPERTYKEY.System.Size, out var fileSizeBytes) ? folderItem.Properties.GetPropertyString(Ole32.PROPERTYKEY.System.Size) : null; folderItem.Properties.TryGetValue <string>( Ole32.PROPERTYKEY.System.ItemTypeText, out var fileType); return(new ShellFileItem(isFolder, parsingPath, fileName, filePath, recycleDate, modifiedDate, createdDate, fileSize, fileSizeBytes ?? 0, fileType)); }
public ResizeImage(ShellItem file) { InitializeComponent(); textBlock1.Text = FindResource("txtFilename") + ": " + file.GetDisplayName(SIGDN.NORMALDISPLAY); cvt = new Bitmap(file.ParsingName); textBlock2.Text = FindResource("lblHeightCP") + ": " + cvt.Height.ToString(); textBlock3.Text = FindResource("lblWidthCP") + ": " + cvt.Width.ToString(); spinner1.Value = 100; percsetting = true; textBox1.Text = cvt.Width.ToString(); textBox2.Text = cvt.Height.ToString(); percsetting = false; }
public void LoadDirectory(ShellItem obj) { obj.Thumbnail.FormatOption = ShellThumbnailFormatOption.IconOnly; obj.Thumbnail.CurrentSize = new System.Windows.Size(16, 16); this.PathImage.Source = obj.Thumbnail.BitmapSource; this.pathName.Text = obj.GetDisplayName(SIGDN.NORMALDISPLAY); this.so = obj; path = obj.ParsingName; Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)(() => { if (obj.ParsingName == KnownFolders.Network.ParsingName || obj.ParsingName.StartsWith(@"\\")) { SetChildren(true); grid1.Visibility = System.Windows.Visibility.Visible; MenuBorder.Visibility = System.Windows.Visibility.Visible; } else { try { ShellItem con = obj; List <ShellItem> joe = new List <ShellItem>(); foreach (ShellItem item in con) { if (item.IsFolder == true) { if (item.ParsingName.ToLower().EndsWith(".zip") == false && item.ParsingName.ToLower().EndsWith(".cab") == false) { joe.Add(item); } } } SetChildren(joe.Count > 0); } catch { SetChildren(false); } } })); }
private void EjectDisk(char DriveLetter) { Thread t = new Thread(() => { Thread.Sleep(10); var vdc = new VolumeDeviceClass(); foreach (Volume item in vdc.Devices) { if (GetDriveLetterFromDrivePath(item.LogicalDrive) == DriveLetter) { var veto = item.Eject(false); if (veto != Native.PNP_VETO_TYPE.TypeUnknown) { if (veto == Native.PNP_VETO_TYPE.Ok) { Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => { this.beNotifyIcon.ShowBalloonTip("Information", $"It is safe to remove {item.LogicalDrive}", Hardcodet.Wpf.TaskbarNotification.BalloonIcon.Info); var tabsForRemove = tcMain.Items.OfType<Wpf.Controls.TabItem>().Where(w => { var root = String.Empty; try { root = Path.GetPathRoot(w.ShellObject.ParsingName.ToShellParsingName()); } catch { } return !String.IsNullOrEmpty(root) && (w.ShellObject.IsFileSystem && root.ToLowerInvariant() == $"{DriveLetter}:\\".ToLowerInvariant()); }).ToArray(); foreach (Wpf.Controls.TabItem tab in tabsForRemove) { tcMain.RemoveTabItem(tab); } })); } else { var message = String.Empty; var obj = new ShellItem(item.LogicalDrive); switch (veto) { case Native.PNP_VETO_TYPE.Ok: break; case Native.PNP_VETO_TYPE.TypeUnknown: break; case Native.PNP_VETO_TYPE.LegacyDevice: break; case Native.PNP_VETO_TYPE.PendingClose: break; case Native.PNP_VETO_TYPE.WindowsApp: break; case Native.PNP_VETO_TYPE.WindowsService: break; case Native.PNP_VETO_TYPE.OutstandingOpen: message = $"The device {obj.GetDisplayName(SIGDN.NORMALDISPLAY)} can not be disconnected because is in use!"; break; case Native.PNP_VETO_TYPE.Device: break; case Native.PNP_VETO_TYPE.Driver: break; case Native.PNP_VETO_TYPE.IllegalDeviceRequest: break; case Native.PNP_VETO_TYPE.InsufficientPower: break; case Native.PNP_VETO_TYPE.NonDisableable: message = $"The device {obj.GetDisplayName(SIGDN.NORMALDISPLAY)} does not support disconnecting!"; break; case Native.PNP_VETO_TYPE.LegacyDriver: break; default: break; } Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => this.beNotifyIcon.ShowBalloonTip("Error", message, Hardcodet.Wpf.TaskbarNotification.BalloonIcon.Error))); } } break; } } }); t.SetApartmentState(ApartmentState.STA); t.Start(); }
private void btnPasetShC_Click(object sender, RoutedEventArgs e) { string PathForDrop = _ShellListView.CurrentFolder.ParsingName; foreach (string item in Clipboards.GetFileDropList()) { using (var shortcut = new ShellLink()) { var o = new ShellItem(item); shortcut.Target = item; shortcut.WorkingDirectory = Path.GetDirectoryName(item); shortcut.Description = o.GetDisplayName(SIGDN.NORMALDISPLAY); shortcut.DisplayMode = ShellLink.LinkDisplayMode.edmNormal; shortcut.Save($"{PathForDrop}\\{o.GetDisplayName(SIGDN.NORMALDISPLAY)}.lnk"); AddToLog($"Shortcut created at {PathForDrop}\\{o.GetDisplayName(SIGDN.NORMALDISPLAY)} from source {item}"); } } }
private void miJunctionpoint_Click(object sender, RoutedEventArgs e) { string pathForDrop = _ShellListView.CurrentFolder.ParsingName.Replace(@"\\", @"\"); var files = new string[0]; if (Clipboards.ContainsData("Shell IDList Array")) files = Clipboards.GetDataObject().ToShellItemArray().ToArray().Select(s => new ShellItem(s).ParsingName).ToArray(); else files = Clipboards.GetFileDropList().OfType<string>().ToArray(); foreach (string item in files) { var o = new ShellItem(item); JunctionPointUtils.JunctionPoint.Create($@"{pathForDrop}\{o.GetDisplayName(SIGDN.NORMALDISPLAY)}", o.ParsingName, true); AddToLog($@"Created Junction Point at {pathForDrop}\{o.GetDisplayName(SIGDN.NORMALDISPLAY)} linked to {o.ParsingName}"); } }
public void EnterEditMode() { IsInEditMode = true; elPanel.Visibility = System.Windows.Visibility.Collapsed; elPanel.Focusable = false; if (Undertextbox != null) { Undertextbox.Visibility = System.Windows.Visibility.Visible; //Undertextbox.SelectAll(); } var obj = furthestrightitem.ShellItem; if (obj.ParsingName.StartsWith(":")) { var correctItems = KnownFolders.All.Where(w => obj.ParsingName.Contains(w.ParsingName)).ToArray(); foreach (var item in correctItems) { ShellItem realItem = (ShellItem)item; HistoryCombo.Text = obj.ParsingName.Replace(realItem.ParsingName, realItem.GetDisplayName(SIGDN.NORMALDISPLAY)).Replace(".library-ms", ""); } } else { HistoryCombo.Text = furthestrightitem.ShellItem.ParsingName; } FocusManager.SetIsFocusScope(this, true); }