Пример #1
0
        /// <summary>
        /// Fill the "My Computer" or "This Pc" collection
        /// </summary>
        /// <param name="folderItem"></param>
        /// <param name="parentCollection"></param>
        /// <param name="helper"></param>
        protected virtual void FillMyComputer(FolderItem folderItem, ObservableCollection <TreeItem> parentCollection,
                                              TreeViewHelper helper)
        {
            log.Trace(">>>");
            _rootCollection = parentCollection;
            Logicaldisk.LogicaldiskCollection logicalDisks = null;

            // get wmi logical disk's if we have to
            if (helper.TreeView.DriveTypes != Enums.DriveTypes.All)
            {
                logicalDisks = Logicaldisk.GetInstances(null, GetWmiQueryStatement(helper.TreeView));
            }

            foreach (FolderItem fi in ((Folder)folderItem.GetFolder).Items())
            {
                log.Trace($"Folder: {fi.Name} | Type: {fi.Type} | IsFolder: {fi.IsFolder} | IsFileSystem: {fi.IsFileSystem}");
                // only File System shell objects ?
                if (!_showAllShellObjects && !fi.IsFileSystem)
                {
                    continue;
                }

                // check drive type
                if (fi.IsFileSystem && logicalDisks != null)
                {
                    bool skipDrive = true;
                    foreach (Logicaldisk lg in logicalDisks)
                    {
                        if (lg.Name + "\\" == fi.Path)
                        {
                            skipDrive = false;
                            break;
                        }
                    }

                    if (skipDrive)
                    {
                        continue;
                    }
                }
                // create new node
                var node = CreateTreeNode(helper, fi.Name, fi.Path, false, fi);
                parentCollection.Add(node);
            }
            log.Trace("<<<");
        }
Пример #2
0
 protected virtual void FillMyComputer(FolderItem folderItem, TreeNodeCollection parentCollection,
                                       TreeViewFolderBrowserHelper helper)
 {
     _rootCollection = parentCollection;
     Logicaldisk.LogicaldiskCollection logicalDisks = null;
     // get wmi logical disk's if we have to
     if (helper.TreeView.DriveTypes != DriveTypes.All)
     {
         logicalDisks = Logicaldisk.GetInstances(null, GetWMIQueryStatement(helper.TreeView));
     }
     //
     foreach (FolderItem fi in ((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 (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);
     }
 }
Пример #3
0
        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 = 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(CreateTreeNode(helper, Path.GetFileName(personalDirectory), personalDirectory, true,
                                                      false, false));
                // create child node <MyComuter>
                TreeNodePath myComputerNode = 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(CreateTreeNode(helper,
                                                      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 (Logicaldisk logicalDisk in 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(CreateTreeNode(helper, name, path, true, false, false));
                    }
                    catch (Exception doh)
                    {
                        throw doh;
                    }
                }
            }
        }