private void StackMenu_PreviewMouseMove(object sender, MouseEventArgs e) { if (!inMove && startPoint != null && !ctxOpen) { inMove = true; Point mousePos = e.GetPosition(this); Vector diff = (Point)startPoint - mousePos; if (mousePos.Y <= ActualHeight && ((Point)startPoint).Y <= ActualHeight && e.LeftButton == MouseButtonState.Pressed && (Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance || Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance)) { Menu menu = sender as Menu; ShellFolder selectedDir = menu.DataContext as ShellFolder; try { DragDrop.DoDragDrop(menu, selectedDir, DragDropEffects.Move); } catch { } // reset the stored mouse position startPoint = null; e.Handled = true; } inMove = false; } }
private void StackMenu_Drop(object sender, DragEventArgs e) { Menu dropContainer = sender as Menu; ShellFolder replacedDir = dropContainer.DataContext as ShellFolder; string[] fileNames = e.Data.GetData(DataFormats.FileDrop) as string[]; if (fileNames != null) { foreach (string fileName in fileNames) { if (StacksManager.Instance.AddLocation(fileName)) { int dropIndex = StacksManager.Instance.StackLocations.IndexOf(replacedDir); StacksManager.Instance.StackLocations.Move(StacksManager.Instance.StackLocations.Count - 1, dropIndex); } } } else if (e.Data.GetDataPresent(typeof(ShellFolder))) { ShellFolder dropData = e.Data.GetData(typeof(ShellFolder)) as ShellFolder; int initialIndex = StacksManager.Instance.StackLocations.IndexOf(dropData); int dropIndex = StacksManager.Instance.StackLocations.IndexOf(replacedDir); StacksManager.Instance.StackLocations.Move(initialIndex, dropIndex); } e.Handled = true; }
public static bool Restore(string Path) { try { using (ShellItem SourceItem = new ShellItem(Path)) { string DirectoryName = System.IO.Path.GetDirectoryName(SourceItem.Name); if (!Directory.Exists(DirectoryName)) { _ = Directory.CreateDirectory(DirectoryName); } using (ShellFolder DestItem = new ShellFolder(DirectoryName)) { ShellFileOperations.Move(SourceItem, DestItem, null, ShellFileOperations.OperationFlags.AddUndoRecord | ShellFileOperations.OperationFlags.NoConfirmMkDir | ShellFileOperations.OperationFlags.Silent | ShellFileOperations.OperationFlags.RenameOnCollision); } string ExtraInfoPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Path), System.IO.Path.GetFileName(Path).Replace("$R", "$I")); if (File.Exists(ExtraInfoPath)) { File.Delete(ExtraInfoPath); } } return(true); } catch { return(false); } }
public LocalShellItem(ShellFolder parent, FileInfo info) : base(parent, info) // there is a specific overload for FileInfo { CanCopy = true; CanDelete = true; CanLink = true; CanMove = true; CanPaste = true; CanRename = true; Info = info; var ms = new MemoryPropertyStore(); ms.SetValue(Props.System.PropList.StatusIcons, "prop:" + LocalShellFolder.IconProperty.CanonicalName); ms.SetValue(Props.System.PropList.StatusIconsDisplayFlag, (uint)2); if (info.Name.Contains("error")) { ms.SetValue(LocalShellFolder.IconProperty, IconValue.Error); } else if (info.Name.Contains("warn")) { ms.SetValue(LocalShellFolder.IconProperty, IconValue.Warning); } else { ms.SetValue(LocalShellFolder.IconProperty, IconValue.Ok); } SetPropertyValue(LocalShellFolder.IconUIProperty, ms); }
public SimpleItem(ShellFolder parent, string text) : base(parent, new StringKeyShellItemId(text)) { // this is needed for icon ItemType = IOUtilities.PathGetExtension(text); CanCopy = true; }
public FolderView(ShellFolder location) { isDesktop = location.IsDesktop; path = location.Path; DisplayItems = GetCollectionView(location); }
public FolderTreeView() { DoubleBuffered = true; HideSelection = false; Nodes.Clear(); if (!isDesignMode) { smallimagelist.ImageSize = new Size(16, 16); smallimagelist.TransparentColor = Color.Black; smallimagelist.ColorDepth = ColorDepth.Depth32Bit; this.ImageList = smallimagelist; using (ShellFolder folder = new ShellFolder(Environment.SpecialFolder.MyComputer)) { string key = folder.Pidl.PhysicalPath; if (key == "") { key = folder.Pidl.DisplayName; } TreeNode node = Nodes.Add(key, folder.Pidl.DisplayName); node.Tag = folder.Pidl.Clone(); node.Nodes.Add(""); node.ImageIndex = -1; node.SelectedImageIndex = -1; node.Expand(); SelectedNode = node; } SelectedNode = CurrentNode = Nodes[0]; } }
public void LoadFiles(PIDL pidl, PIDL selectedPIDL) { folderListBox1.IsDesktop = (pidl.DisplayName == "My Computer"); folderListBox1.SelectedPIDL = selectedPIDL; if (lastDisplayName == pidl.DisplayName) { return; } bool showHiddenObjects = false; bool showNonFolders = false; bool sortResults = true; ShellFolder folder; if (pidl.DisplayName == "My Computer") { folder = new ShellFolder(Environment.SpecialFolder.Desktop); } else { folder = new ShellFolder(pidl); } { ArrayList children = folder.GetChildren(showHiddenObjects, showNonFolders, sortResults); { folderListBox1.AddFolders(children); } } folder.Dispose(); lastDisplayName = pidl.DisplayName; }
/// <summary> /// <see cref="ShellFolder"/>から、フォルダーの<c>ViewModel</c>を作成します。 /// </summary> /// <param name="folder"></param> /// <returns></returns> public static ShellFolderViewModel CreateFolder(ShellFolder folder) { Contract.Requires <ArgumentNullException>(folder != null); Contract.Ensures(Contract.Result <ShellFolderViewModel>() != null); return(new ShellFolderViewModel(folder)); }
// context menu on the root folder protected override void MergeContextMenu(ShellFolder folder, IReadOnlyList <ShellItem> items, ShellMenu existingMenu, ShellMenu appendMenu) { if (folder == null) { throw new ArgumentNullException(nameof(folder)); } if (items == null) { throw new ArgumentNullException(nameof(items)); } if (appendMenu == null) { throw new ArgumentNullException(nameof(appendMenu)); } if (items.Count == 0) // 0 means this is called from Explorer's tree view. We don't want to add the menus twice. { return; } var regeditItem = new ShellMenuItem(appendMenu, "Run &Regedit..."); regeditItem.Invoke += (sender, e) => Process.Start("regedit"); appendMenu.Items.Add(regeditItem); appendMenu.Items.Add(new ShellMenuSeparatorItem()); var propertiesItem = new ShellMenuItem(appendMenu, "&Properties..."); propertiesItem.Invoke += (sender, e) => ShowProperties(e.HwndOwner); appendMenu.Items.Add(propertiesItem); }
public VirtualAndPhysicalShellItem(ShellFolder parent, string name) : base(parent, new StringKeyShellItemId(name)) { // this item is virtual, but we give it a file system path (with nothing in there) // so it's half virtual, half physical FileSystemPath = Path.Combine(Path.GetFullPath("Data"), VirtualAndPhysicalShellFolder.PhysicalStorageName, name + ".txt"); }
private ICollectionView GetCollectionView(ShellFolder location) { if (location == null) { return(CollectionViewSource.GetDefaultView(new List <ShellItem>())); } ICollectionView cvs = CollectionViewSource.GetDefaultView(location.Files); if (location.IsFileSystem) { cvs.SortDescriptions.Add(new SortDescription("IsFolder", ListSortDirection.Descending)); } cvs.SortDescriptions.Add(new SortDescription("DisplayName", ListSortDirection.Ascending)); cvs.Filter += IconsSource_Filter; if (cvs is ICollectionViewLiveShaping cvls) { cvls.IsLiveSorting = true; if (location.IsFileSystem) { cvls.LiveSortingProperties.Add("IsFolder"); } cvls.LiveSortingProperties.Add("DisplayName"); } return(cvs); }
// this item is backed by a physical folder public PhysicalFolder(ShellFolder parent, DirectoryInfo info) : base(parent, info) { CanPaste = true; // this enables the "New" menus Attributes |= SFGAO.SFGAO_STORAGEANCESTOR | SFGAO.SFGAO_STORAGE; }
/// <summary> /// Initializes a new instance of the <see cref="OnDemandFolder"/> class. /// We just add the same sync status column. /// </summary> /// <param name="parent">The parent.</param> /// <param name="info">The information.</param> public OnDemandFolder(ShellFolder parent, ShellItemId fileSystemId, string fileSystemPath) : base(parent, fileSystemId, fileSystemPath) { // since this is a FileSystem oriented NSE, we let base properties pass through ReadPropertiesFromShell = true; /// We just add the sync status column. AddColumn(Props.System.StorageProviderUIStatus, SHCOLSTATE.SHCOLSTATE_ONBYDEFAULT); }
public MyShellItem(ShellFolder parent, ShellItemId fileSystemId, string fileSystemPath) : base(parent, fileSystemId, fileSystemPath) { CanDelete = true; CanMove = true; CanCopy = true; //ReadPropertiesFromShell = true; }
internal static void FillCommonData(ShellFolder shell, MetaData data) { if (shell.IsFileSystemObject) { data.Add(new MetaEntry { Name = FileMetaData.ModifiedDate.Name, Value = shell.Properties.GetProperty(SystemProperties.System.DateModified).ValueAsObject }); data.Add(new MetaEntry { Name = FileMetaData.Type.Name, Value = shell.Properties.GetProperty(SystemProperties.System.ItemTypeText).ValueAsObject }); } }
protected override ShellFolder GetFolderAsRoot(ShellItemIdList idl) { if (_root == null) { _root = new RootFolder(Path, idl); } return(_root); }
/// <summary> /// <see cref="ShellFolderEnumerator" />クラスの新しいインスタンスを初期化します。 /// </summary> /// <param name="parentFolder">親フォルダー。</param> /// <param name="options">フォルダー反復処理オプション。 </param> /// <remarks> /// <para> /// <see cref="System.IO.FileNotFoundException" />が発生する場合は、 /// プロジェクトのプロパティ -> ビルドの「32ビットを優先」のチェックを外す。 /// </para> /// </remarks> internal ShellFolderEnumerator(ShellFolder parentFolder, SHCONTF options) { Contract.Requires <ArgumentNullException>(parentFolder != null); this.Parent = parentFolder; this.enumIdList = this.Parent.ShellFolderItem.EnumObjects(options); }
// this item is backed by a physical file public MyShellItem(ShellFolder parent, FileInfo info) : base(parent, info) { CanDelete = true; CanMove = true; CanCopy = true; CanRename = true; }
/// <summary>Initializes a new instance of the <see cref="ShellLibrary"/> class.</summary> /// <param name="libraryName">Name of the library.</param> /// <param name="parent">The parent.</param> /// <param name="overwrite">if set to <c>true</c> [overwrite].</param> public ShellLibrary2(string libraryName, ShellFolder parent, bool overwrite = false) { lib = new IShellLibrary(); name = libraryName; var item = lib.Save(parent.IShellItem, libraryName, overwrite ? LIBRARYSAVEFLAGS.LSF_OVERRIDEEXISTING : LIBRARYSAVEFLAGS.LSF_FAILIFTHERE); Init(item); }
private void DesktopPanel_MouseClick(object sender, MouseEventArgs e) { using (ShellFolder folder = new ShellFolder(desktop)) { ArrayList children = folder.GetChildren(true, true, true); ItemSelectedEvent?.Invoke(this, new ItemSelectedEventArgs((PIDL)children[0])); } }
public PhysicalFolder(ShellFolder parent, ShellItemId fileSystemId, string fileSystemPath) : base(parent, fileSystemId, fileSystemPath) { CanDelete = true; // this enables the "New" menus Attributes |= SFGAO.SFGAO_STORAGEANCESTOR | SFGAO.SFGAO_STORAGE; }
private BitmapSource GetDirectoryIcon(DirectoryInfo directoryInfo) { try { ShellFolder shellFolder = ShellObject.FromParsingName(directoryInfo.FullName) as ShellFolder; return(shellFolder.Thumbnail.BitmapSource); } catch { return(null); } }
public void EnumComputerTest() { using var computer = new ShellFolder(KNOWNFOLDERID.FOLDERID_ComputerFolder); foreach (var si in computer) { TestContext.WriteLine(si.ParsingName); si.Dispose(); } }
public void GetImageTest2() { var f = new ShellFolder(KNOWNFOLDERID.FOLDERID_AppsFolder); foreach (var i in f.EnumerateChildren(FolderItemFilter.NonFolders | FolderItemFilter.Folders)) { Assert.That(() => i.GetImage(new Size(32, 32), ShellItemGetImageOptions.BiggerSizeOk), Throws.Nothing); } }
internal bool RaiseFolderChangingEvent(ShellFolder folder) { Contract.Requires <ArgumentNullException>(folder != null); var args = new FileDialogFolderChangeEventArgs(folder); OnFolderChanging(args); return(!args.Cancel); }
private void MemoryTest() { for (int i = 0; i < 10000; i++) { ShellFolder folder = GetFolder("C:\\Windows"); int p = folder.Files.Count; folder.Dispose(); } }
/// <summary> /// Retrieves an array of ShellItem objects for sub-folders of this shell item. /// </summary> /// <returns>ArrayList of ShellItem objects.</returns> public ArrayList GetSubFolders() { // Make sure we have a folder. if (IsFolder == false) { throw new Exception("Unable to retrieve sub-folders for a non-folder."); } ArrayList arrChildren = new ArrayList(); try { // Get the IEnumIDList interface pointer. ShellAPI.IEnumIDList pEnum = null; uint hRes = ShellFolder.EnumObjects(IntPtr.Zero, ShellAPI.SHCONTF.SHCONTF_FOLDERS, out pEnum); if (hRes != 0) { Marshal.ThrowExceptionForHR((int)hRes); } IntPtr pIDL = IntPtr.Zero; Int32 iGot = 0; // Grab the first enumeration. pEnum.Next(1, out pIDL, out iGot); // Then continue with all the rest. while (!pIDL.Equals(IntPtr.Zero) && iGot == 1) { // Create the new ShellItem object. arrChildren.Add(new ShellItem(m_shRootShell, pIDL, this)); // Free the PIDL and reset counters. Marshal.FreeCoTaskMem(pIDL); pIDL = IntPtr.Zero; iGot = 0; // Grab the next item. pEnum.Next(1, out pIDL, out iGot); } // Free the interface pointer. if (pEnum != null) { Marshal.ReleaseComObject(pEnum); } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message, "Error:", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error ); } return(arrChildren); }
/// <summary> /// Retrieves an array of ShellItem objects for only Test Files (.xml extensions). All others filtered out. /// </summary> /// <returns>ArrayList of ShellItem objects.</returns> public ArrayList GetTestFiles() { ArrayList arrChildren = new ArrayList(); try { // Get the IEnumIDList interface pointer. ShellAPI.IEnumIDList pEnum = null; uint hRes = ShellFolder.EnumObjects(IntPtr.Zero, ShellAPI.SHCONTF.SHCONTF_NONFOLDERS, out pEnum); if (hRes != 0) { Marshal.ThrowExceptionForHR((int)hRes); } IntPtr pIDL = IntPtr.Zero; Int32 iGot = 0; // Grab the first enumeration. pEnum.Next(1, out pIDL, out iGot); // Then continue with all the rest. while (!pIDL.Equals(IntPtr.Zero) && iGot == 1) { // Check first is display name contains XML ShellItem shItem = new ShellItem(m_shRootShell, pIDL, this); if (shItem.DisplayName.Contains(".xml") == false) { // Create the new ShellItem object. arrChildren.Add(shItem); } // Free the PIDL and reset counters. Marshal.FreeCoTaskMem(pIDL); pIDL = IntPtr.Zero; iGot = 0; // Grab the next item. pEnum.Next(1, out pIDL, out iGot); } // Free the interface pointer. if (pEnum != null) { Marshal.ReleaseComObject(pEnum); } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message, "Error:", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error ); } return(arrChildren); }
public ArchiveFolderShellFolder(ShellFolder parent, ArchiveFolderInfo folder) : base(parent, new StringKeyShellItemId(folder.Name)) { CanCopy = true; Folder = folder; AddColumn(Props.System.FileAttributes, SHCOLSTATE.SHCOLSTATE_DEFAULT); AddColumn(Props.System.Comment, SHCOLSTATE.SHCOLSTATE_DEFAULT); AddColumn(Props.System.ZipFolder.Encrypted, SHCOLSTATE.SHCOLSTATE_DEFAULT); AddColumn(Props.System.ZipFolder.CRC32, SHCOLSTATE.SHCOLSTATE_DEFAULT); }
public void Initialize(NamedPipeServerStream connection) { this.connection = connection; // Create shell COM object and get recycle bin folder using var recycler = new ShellFolder(Shell32.KNOWNFOLDERID.FOLDERID_RecycleBinFolder); ApplicationData.Current.LocalSettings.Values["RecycleBin_Title"] = recycler.Name; StartRecycleBinWatcher(); }
public ShellFolderVM(IItemProvider provider, ContainerVM parent, ShellFolder folder) : base(provider, parent, folder.GetDisplayName(DisplayNameType.Default), false) { Folder = folder; Util.FillCommonData(folder, MetaData); }