public override void RequestSubDirs(TreeViewFolderBrowserHelper helper, TreeNodePath parent, TreeViewCancelEventArgs e)
 {
     if (!parent.IsSpecialFolder)
     {
         return;
     }
     //
     Shell32.FolderItem folderItem = ((Shell32.FolderItem)parent.Tag);
     //
     if (_shell.Shell.NameSpace(Shell32.ShellSpecialFolderConstants.ssfDRIVES).Title == folderItem.Name)
     {
         FillMyComputer(folderItem, parent.Nodes, helper);
     }
     else
     {
         foreach (Shell32.FolderItem fi in ((Shell32.Folder)folderItem.GetFolder).Items())
         {
             if (!_showAllShellObjects && !fi.IsFileSystem || !fi.IsFolder)
             {
                 continue;
             }
             //
             TreeNodePath node = CreateTreeNode(helper, fi.Name, fi.Path, IsFolderWithChilds(fi), false, true);
             node.Tag = fi;
             parent.Nodes.Add(node);
         }
     }
 }
 protected virtual void AttachSystemImageList(TreeViewFolderBrowserHelper helper)
 {
     if (_checkboxMode != helper.TreeView.CheckboxBehaviorMode)
     {
         // checkboxes recreate the control internal
         if (this._systemImageList != null)
         {
             RootKit.Win32.SystemImageListHelper.SetTreeViewImageList(helper.TreeView, _systemImageList, false);
         }
     }
     _checkboxMode = helper.TreeView.CheckboxBehaviorMode;
 }
        /// <summary>
        /// Creates a new node and assigns a icon
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="text"></param>
        /// <param name="path"></param>
        /// <param name="addDummyNode"></param>
        /// <param name="forceChecked"></param>
        /// <returns></returns>
        protected virtual TreeNodePath CreateTreeNode(TreeViewFolderBrowserHelper helper, string text, string path, bool addDummyNode, bool forceChecked, bool isSpecialFolder)
        {
            TreeNodePath node = helper.CreateTreeNode(text, path, addDummyNode, forceChecked, isSpecialFolder);

            try
            {
                SetIcon(helper.TreeView, node);
            }
            catch
            {
                node.ImageIndex         = -1;
                node.SelectedImageIndex = -1;
            }
            return(node);
        }
 /// <summary>
 /// Required designer variable.
 /// </summary>
 public TreeViewFolderBrowser()
 {
     InitializeComponent();
     // initalize a new helper instance for this tree view.
     _helper = new TreeViewFolderBrowserHelper(this);
     //
     this.ContextMenu        = new ContextMenu();
     this.ContextMenu.Popup += new EventHandler(OnContextMenu_Popup);
     //
     this._driveTypes          = DriveTypes.NoRootDirectory | DriveTypes.RemovableDisk | DriveTypes.LocalDisk | DriveTypes.NetworkDrive | DriveTypes.CompactDisc | DriveTypes.RAMDisk;
     this.RootFolder           = Environment.SpecialFolder.MyComputer;
     this.CheckboxBehaviorMode = CheckboxBehaviorMode.SingleChecked;
     // init bold font
     boldFont_ = new Font(this.Font, FontStyle.Bold);
 }
        public override void RequestRoot(TreeViewFolderBrowserHelper helper)
        {
            _helper = helper;
            AttachSystemImageList(helper);
            //
            // setup up root node collection
            switch (helper.TreeView.RootFolder)
            {
            case Environment.SpecialFolder.Desktop:
                Shell32.Folder2 desktopFolder = (Shell32.Folder2)_shell.GetDesktop();
                // create root node <Desktop>
                TreeNodePath desktopNode = CreateTreeNode(helper, desktopFolder.Title, desktopFolder.Self.Path, false, false, true);
                helper.TreeView.Nodes.Add(desktopNode);
                desktopNode.Tag = desktopFolder;
                //
                Shell32.Folder2 myComputer = (Shell32.Folder2)_shell.Shell.NameSpace(Shell32.ShellSpecialFolderConstants.ssfDRIVES);
                foreach (Shell32.FolderItem fi in desktopFolder.Items())
                {
                    if (!fi.IsFolder)
                    {
                        continue;
                    }
                    //
                    TreeNodePath node = CreateTreeNode(helper, fi.Name, fi.Path, true, false, true);
                    node.Tag = fi;
                    desktopNode.Nodes.Add(node);
                    //
                    if (_shell.Shell.NameSpace(Shell32.ShellSpecialFolderConstants.ssfDRIVES).Title == fi.Name)
                    {
                        _rootCollection = node.Nodes;
                    }
                }
                break;

            case Environment.SpecialFolder.MyComputer:
                this.FillMyComputer(((Shell32.Folder2)_shell.Shell.NameSpace(Shell32.ShellSpecialFolderConstants.ssfDRIVES)).Self, helper.TreeView.Nodes, helper);
                break;

            default:
                // create root node with specified SpecialFolder
                Shell32.Folder2 root     = (Shell32.Folder3)_shell.Shell.NameSpace(helper.TreeView.RootFolder);
                TreeNodePath    rootNode = CreateTreeNode(helper, root.Title, root.Self.Path, true, false, true);
                rootNode.Tag = root.Self;
                helper.TreeView.Nodes.Add(rootNode);
                _rootCollection = rootNode.Nodes;
                break;
            }
        }
        public virtual void RequestSubDirs(TreeViewFolderBrowserHelper helper, TreeNodePath parent, TreeViewCancelEventArgs e)
        {
            if (parent.Path == null)
            {
                return;
            }
            //
            DirectoryInfo directory = new DirectoryInfo(parent.Path);

            // check persmission
            new System.Security.Permissions.FileIOPermission(System.Security.Permissions.FileIOPermissionAccess.PathDiscovery, directory.FullName).Demand();

            #region *** Added By Mike / MTH ***
            //
            List <DirectoryInfo> dirList = new List <DirectoryInfo>(directory.GetDirectories());

            dirList.Sort(new Comparison <DirectoryInfo>(delegate(DirectoryInfo a, DirectoryInfo b)
            {
                return(a.Name.CompareTo(b.Name));
            }));

            #endregion

            foreach (DirectoryInfo dir in dirList)
            {
                if ((dir.Attributes & System.IO.FileAttributes.System) == System.IO.FileAttributes.System)
                {
                    continue;
                }
                if ((dir.Attributes & System.IO.FileAttributes.Hidden) == System.IO.FileAttributes.Hidden)
                {
                    continue;
                }
                TreeNodePath newNode = this.CreateTreeNode(helper, dir.Name, dir.FullName, false, ((helper.TreeView.CheckboxBehaviorMode != CheckboxBehaviorMode.None) && (parent.Checked)), false);
                parent.Nodes.Add(newNode);
                //
                try
                {
                    if (dir.GetDirectories().GetLength(0) > 0)
                    {
                        newNode.AddDummyNode();
                    }
                }
                catch { }
            }
        }
 public override void QueryContextMenuItems(TreeViewFolderBrowserHelper helper, TreeNodePath node)
 {
     if (!EnableContextMenu)
     {
         return;
     }
     //
     Shell32.FolderItem fi = node.Tag as Shell32.FolderItem;
     if (fi == null)
     {
         return;
     }
     //
     foreach (Shell32.FolderItemVerb verb in fi.Verbs())
     {
         if (verb.Name.Length == 0)
         {
             continue;
         }
         //
         MenuItemShellVerb item = new MenuItemShellVerb(verb);
         helper.TreeView.ContextMenu.MenuItems.Add(item);
     }
 }
        public virtual System.Windows.Forms.TreeNodeCollection RequestDriveCollection(TreeViewFolderBrowserHelper helper)
        {
            switch (helper.TreeView.RootFolder)
            {
            case Environment.SpecialFolder.Desktop:
                return(helper.TreeView.Nodes[0].Nodes[1].Nodes);

            default:
                return(helper.TreeView.Nodes);
            }
        }
 public virtual void QueryContextMenuItems(TreeViewFolderBrowserHelper helper, TreeNodePath node)
 {
 }
        public virtual void RequestRoot(TreeViewFolderBrowserHelper helper)
        {
            AttachSystemImageList(helper);
            //
            bool populateDrives = true;
            //
            TreeNodeCollection rootNodeCollection;
            TreeNodeCollection driveRootNodeCollection;

            // setup up root node collection
            switch (helper.TreeView.RootFolder)
            {
            case Environment.SpecialFolder.Desktop:
                // create root node <Desktop>
                TreeNodePath desktopNode = this.CreateTreeNode(helper, Environment.SpecialFolder.Desktop.ToString(), string.Empty, false, false, true);
                helper.TreeView.Nodes.Add(desktopNode);
                rootNodeCollection = helper.TreeView.Nodes[0].Nodes;
                // create child node <Personal>
                string personalDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                rootNodeCollection.Add(this.CreateTreeNode(helper, System.IO.Path.GetFileName(personalDirectory), personalDirectory, true, false, false));
                // create child node <MyComuter>
                TreeNodePath myComputerNode = this.CreateTreeNode(helper, Environment.SpecialFolder.MyComputer.ToString(), string.Empty, false, false, true);
                rootNodeCollection.Add(myComputerNode);
                driveRootNodeCollection = myComputerNode.Nodes;
                break;

            case Environment.SpecialFolder.MyComputer:
                rootNodeCollection      = helper.TreeView.Nodes;
                driveRootNodeCollection = rootNodeCollection;
                break;

            default:
                rootNodeCollection      = helper.TreeView.Nodes;
                driveRootNodeCollection = rootNodeCollection;
                // create root node with specified SpecialFolder
                rootNodeCollection.Add(this.CreateTreeNode(helper, System.IO.Path.GetFileName(Environment.GetFolderPath(helper.TreeView.RootFolder)), Environment.GetFolderPath(helper.TreeView.RootFolder), true, false, false));
                populateDrives = false;
                break;
            }
            if (populateDrives)
            {
                // populate local machine drives
                foreach (ROOT.CIMV2.Win32.Logicaldisk logicalDisk in ROOT.CIMV2.Win32.Logicaldisk.GetInstances(null, GetWMIQueryStatement(helper.TreeView)))
                {
                    try
                    {
                        string name = string.Empty;
                        string path = logicalDisk.Name + "\\";
                        name = logicalDisk.Description;
                        //
                        name += (name != string.Empty) ? " (" + path + ")" : path;
                        // add node to root collection
                        driveRootNodeCollection.Add(this.CreateTreeNode(helper, name, path, true, false, false));
                    }
                    catch (Exception doh)
                    {
                        throw doh;
                    }
                }
            }
        }
 protected virtual void FillMyComputer(Shell32.FolderItem folderItem, TreeNodeCollection parentCollection, TreeViewFolderBrowserHelper helper)
 {
     _rootCollection = parentCollection;
     ROOT.CIMV2.Win32.Logicaldisk.LogicaldiskCollection logicalDisks = null;
     // get wmi logical disk's if we have to
     if (helper.TreeView.DriveTypes != DriveTypes.All)
     {
         logicalDisks = ROOT.CIMV2.Win32.Logicaldisk.GetInstances(null, GetWMIQueryStatement(helper.TreeView));
     }
     //
     foreach (Shell32.FolderItem fi in ((Shell32.Folder)folderItem.GetFolder).Items())
     {
         // only File System shell objects ?
         if (!_showAllShellObjects && !fi.IsFileSystem)
         {
             continue;
         }
         // check drive type
         if (fi.IsFileSystem && logicalDisks != null)
         {
             bool skipDrive = true;
             foreach (ROOT.CIMV2.Win32.Logicaldisk lg in logicalDisks)
             {
                 if (lg.Name + "\\" == fi.Path)
                 {
                     skipDrive = false;
                     break;
                 }
             }
             if (skipDrive)
             {
                 continue;
             }
         }
         // create new node
         TreeNodePath node = CreateTreeNode(helper, fi.Name, fi.Path, IsFolderWithChilds(fi), false, true);
         node.Tag = fi;
         parentCollection.Add(node);
     }
 }
 public override TreeNodeCollection RequestDriveCollection(TreeViewFolderBrowserHelper helper)
 {
     return(_rootCollection);
 }