Esempio n. 1
0
        private void MoveUp(TreeNode node)
        {
            TreeNode n   = node;
            TreeNode nn  = n.Parent;
            TreeNode nnn = nn.Parent;
            SizeNode s   = (SizeNode)n.Tag;
            SizeNode ss  = (SizeNode)nn.Tag;
            SizeNode sss = (SizeNode)nnn.Tag;

            s.PrefixName(ss);
            if (ss.FolderInfo != null)
            {
                nodeMap.Remove(ss.FolderInfo);
            }
            ss.RemoveChild(s);
            nn.Nodes.Remove(n);
            if (nn.Nodes.Count == 0)
            {
                nnn.Nodes.Remove(nn);
            }
            nnn.Nodes.Add(n);
            SortNodes(sss, nnn);
            updateTreeNode(n, s);
            updateTreeNode(nn, ss);
        }
Esempio n. 2
0
 private void tree_BeforeExpand(object sender, TreeViewCancelEventArgs e)
 {
     if (e.Node.Tag != null)
     {
         SizeNode sn = (SizeNode)e.Node.Tag;
         if (sn.FolderInfo != null)
         {
             FolderInfo fi = sn.FolderInfo;
             if (fi != null)
             {
                 if (fi.State == ScanState.QUEUED || fi.State == ScanState.EXPANDQUEUED)
                 {
                     if (fi.State == ScanState.QUEUED)
                     {
                         fqueue.MoveToFront(fi);
                     }
                     fi.State = ScanState.EXPANDQUEUED;
                     e.Cancel = true;
                     return;
                 }
                 if (!sn.ChildrenVisible)
                 {
                     FillInChildren(sn, e.Node);
                 }
             }
         }
     }
 }
Esempio n. 3
0
        private void updateTreeNode(TreeNode tn, SizeNode sn)
        {
            tn.ContextMenuStrip = treeMenuStrip;
            sn.treeNode         = tn;
            tn.Tag = sn;
            string iconName = sn.IconName;

            if (!treeIcons.Images.ContainsKey(iconName))
            {
                treeIcons.Images.Add(iconName, sn.Icon);
            }
            tn.ImageKey         = iconName;
            tn.SelectedImageKey = iconName;
            string s;

            if (tn.Parent == null)
            {
                s = SizeString(sn, sn, sn);
            }
            else
            {
                s = SizeString(sn, (SizeNode)tn.Parent.Tag, (SizeNode)tree.Nodes[0].Tag);
            }
            tn.Text = PadString(s);
            tn.Text = s + "  " + sn.DisplayName;
        }
Esempio n. 4
0
        private void refreshToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SizeNode sn = (SizeNode)contextMenuNode.Tag;

            contextMenuNode.Nodes.Clear();
            sn.PrepareRefresh(contextMenuNode.IsExpanded);
            contextMenuNode.Collapse();
            updateTreeNode(contextMenuNode, sn);
            FolderInfo f = sn.FolderInfo.Parent;

            while (f != null)
            {
                lock (f)
                {
                    f.State = ScanState.SCANNING;
                }
                if (nodeMap.ContainsKey(f))
                {
                    SizeNode s = nodeMap[f];
                    s.Update();
                    TreeNode t = s.treeNode;
                    updateTreeNode(t, s);
                }
                f = f.Parent;
            }
            BuildChildren(contextMenuNode);
            fqueue.AddFolder(sn.FolderInfo, fqueue.Generation);
        }
Esempio n. 5
0
        private void BuildChildren(TreeNode tn)
        {
            SizeNode        sn      = (SizeNode)tn.Tag;
            List <SizeNode> allKids = new List <SizeNode>();

            if (sn.Directories != null)
            {
                if (filesByExtensionToolStripMenuItem.Checked)
                {
                    allKids.AddRange(sn.FileTypeSummaries);
                }
                else
                {
                    allKids.AddRange(sn.FileSummaries);
                }
                allKids.AddRange(sn.Directories);
            }
            else if (sn.DummyNode != null)
            {
                allKids.Add(sn.DummyNode);
            }
            foreach (SizeNode kid in allKids)
            {
                BuildChild(tn, kid);
            }
            SortNodes(sn, tn);
        }
Esempio n. 6
0
        private void BuildChild(TreeNode tn, SizeNode kid)
        {
            TreeNode child = new TreeNode();

            updateTreeNode(child, kid);
            tn.Nodes.Add(child);
        }
Esempio n. 7
0
 internal void RemoveChild(SizeNode s)
 {
     Unlink();
     directories.Remove(s);
     fileSummaries.Remove(s);
     size.Subtract(s.Size);
 }
Esempio n. 8
0
        private TreeNode BuildTreeNode(SizeNode sn)
        {
            TreeNode tn = new TreeNode();

            updateTreeNode(tn, sn);
            BuildChildren(tn);
            return(tn);
        }
Esempio n. 9
0
        internal void PrefixName(SizeNode parent)
        {
            string prefix = parent.displayName;

            if (prefix.EndsWith("*"))
            {
                prefix = prefix.Substring(0, prefix.Length - 1);
            }
            displayName = prefix + "/" + displayName;
        }
Esempio n. 10
0
 public void LoadChildren()
 {
     if (directories == null && folderInfo != null)
     {
         directories = new List <SizeNode>();
         foreach (FolderInfo child in folderInfo.Children)
         {
             directories.Add(new SizeNode(child));
         }
         dummyNode = null;
     }
 }
Esempio n. 11
0
        private void ScanFolder()
        {
            filesByExtensionToolStripMenuItem.Checked = false;
            filesByExtensionToolStripMenuItem.Enabled = true;
            string     directory = folderBrowser.SelectedPath;
            FolderInfo fi        = new FolderInfo(null, directory, directory, 0);

            fi.State = ScanState.EXPANDQUEUED;
            SizeNode sn = new SizeNode(fi);

            nodeMap[fi] = sn;
            TreeNode tn = BuildTreeNode(sn);

            tree.Nodes.Add(tn);
            fqueue.AddFolder(fi, fqueue.Generation);
        }
Esempio n. 12
0
 public void ExpandFolder(FolderInfo fi)
 {
     if (InvokeRequired)
     {
         try
         {
             Invoke(new FolderDelegate(ExpandFolder), fi);
         }
         catch (ObjectDisposedException) { }
         return;
     }
     lock (this)
     {
         SizeNode sn = nodeMap[fi];
         TreeNode n  = sn.treeNode;
         FillInChildren(sn, n);
         n.Expand();
     }
 }
Esempio n. 13
0
        private void UpdateFolder00(TreeNode n)
        {
            SizeNode sn = (SizeNode)n.Tag;

            sn.Update();
            updateTreeNode(n, sn);
            for (int i = 0; i < n.Nodes.Count; i++)
            {
                TreeNode nn  = n.Nodes[i];
                SizeNode ssn = (SizeNode)nn.Tag;
                if (ssn.DummyNode == ssn && sn.DummyNode == null)
                {
                    n.Nodes.RemoveAt(i);
                }
                else
                {
                    updateTreeNode(nn, ssn);
                }
            }
            SortNodes((SizeNode)n.Tag, n);
        }
Esempio n. 14
0
 private void treeMenuStrip_Opening(object sender, CancelEventArgs e)
 {
     contextMenuNode = tree.GetNodeAt(tree.PointToClient(Cursor.Position));
     if (contextMenuNode == null)
     {
         SetContextMenuCommandsEnabled(false, false, false, 0, false, -1);
     }
     else
     {
         SizeNode sn    = (SizeNode)contextMenuNode.Tag;
         int      depth = 0;
         TreeNode tn    = contextMenuNode;
         while (tn != tree.Nodes[0])
         {
             tn = tn.Parent;
             depth++;
         }
         SetContextMenuCommandsEnabled(sn.Path != null, sn.State == ScanState.DONE,
                                       contextMenuNode == tree.Nodes[0] ? false : ((SizeNode)contextMenuNode.Parent.Tag).State == ScanState.DONE,
                                       1, sn.Path != null && sn.FolderInfo != null, depth);
     }
 }
Esempio n. 15
0
        private void UpdateExtensionView(SizeNode sn, bool showExtensions)
        {
            if (sn.Directories == null)
            {
                return;
            }
            TreeNode tn = sn.treeNode;

            foreach (SizeNode fNode in sn.FileSummaries)
            {
                if (showExtensions)
                {
                    tn.Nodes.Remove(fNode.treeNode);
                    fNode.treeNode = null;
                }
                else
                {
                    BuildChild(tn, fNode);
                }
            }
            foreach (SizeNode ftNode in sn.FileTypeSummaries)
            {
                if (!showExtensions)
                {
                    tn.Nodes.Remove(ftNode.treeNode);
                    ftNode.treeNode = null;
                }
                else
                {
                    BuildChild(tn, ftNode);
                }
            }
            foreach (SizeNode child in sn.Directories)
            {
                UpdateExtensionView(child, showExtensions);
            }
            SortNodes(sn, tn);
        }
Esempio n. 16
0
        private string MakePercent(ulong size, SizeNode sizeRef)
        {
            if (size == 0)
            {
                return("0%");
            }
            if (sizeRef.State != ScanState.DONE)
            {
                return("WAIT");
            }
            ulong refval  = displayValue(sizeRef.Size);
            uint  percent = (uint)(size * 100 / refval);

            if (percent < 0)
            {
                percent = 0;
            }
            if (percent > 100)
            {
                percent = 100;
            }
            return(percent + "%");
        }
Esempio n. 17
0
 private void FillInChildren(SizeNode snParent, TreeNode n)
 {
     if (snParent.ChildrenVisible)
     {
         return;
     }
     this.Cursor = Cursors.WaitCursor;
     snParent.LoadChildren();
     foreach (SizeNode sn in snParent.Directories)
     {
         TreeNode tn = BuildTreeNode(sn);
         nodeMap[sn.FolderInfo] = sn;
         n.Nodes.Add(tn);
         UpdateFolder0(tn);
     }
     foreach (SizeNode sn in filesByExtensionToolStripMenuItem.Checked ? snParent.FileTypeSummaries : snParent.FileSummaries)
     {
         TreeNode tn = BuildTreeNode(sn);
         n.Nodes.Add(tn);
     }
     snParent.Update();
     UpdateFolder0(n);
     this.Cursor = null;
 }
Esempio n. 18
0
        private void SortNodes(SizeNode sn, TreeNode n)
        {
            if (n.Nodes.Count < 2)
            {
                return;
            }
            if (sn.State != ScanState.DONE)
            {
                return;
            }
            int cnt = n.Nodes.Count;

            TreeNode[] l = new TreeNode[cnt];
            for (int i = 0; i < cnt; i++)
            {
                l[i] = n.Nodes[i];
            }
            Array.Sort <TreeNode>(l, new Comparison <TreeNode>(CompareNodes));
            n.Nodes.Clear();
            for (int i = 0; i < cnt; i++)
            {
                n.Nodes.Add(l[i]);
            }
        }
Esempio n. 19
0
 public void LoadChildren()
 {
     if (directories == null && folderInfo != null)
     {
         directories = new List<SizeNode>();
         foreach (FolderInfo child in folderInfo.Children)
         {
             directories.Add(new SizeNode(child));
         }
         dummyNode = null;
     }
 }
Esempio n. 20
0
 internal void PrefixName(SizeNode parent)
 {
     string prefix = parent.displayName;
     if (prefix.EndsWith("*")) prefix = prefix.Substring(0, prefix.Length - 1);
     displayName = prefix + "/" + displayName;
 }
Esempio n. 21
0
 private void FillInChildren(SizeNode snParent, TreeNode n)
 {
     if (snParent.ChildrenVisible)
     {
         return;
     }
     this.Cursor = Cursors.WaitCursor;
     snParent.LoadChildren();
     foreach (SizeNode sn in snParent.Directories)
     {
         TreeNode tn = BuildTreeNode(sn);
         nodeMap[sn.FolderInfo] = sn;
         n.Nodes.Add(tn);
         UpdateFolder0(tn);
     }
     foreach (SizeNode sn in filesByExtensionToolStripMenuItem.Checked ? snParent.FileTypeSummaries : snParent.FileSummaries)
     {
         TreeNode tn = BuildTreeNode(sn);
         n.Nodes.Add(tn);
     }
     snParent.Update();
     UpdateFolder0(n);
     this.Cursor = null;
 }
Esempio n. 22
0
 private void BuildDummyNode()
 {
     dummyNode           = new SizeNode("DummyNodeNeverVisible", null, ScanState.QUEUED, folderInfo.AllFilesSize, fileIcon, null);
     dummyNode.dummyNode = dummyNode; // self-pointer to identify dummy nodes
 }
Esempio n. 23
0
 private void ScanFolder()
 {
     filesByExtensionToolStripMenuItem.Checked = false;
     filesByExtensionToolStripMenuItem.Enabled = true;
     string directory = folderBrowser.SelectedPath;
     FolderInfo fi = new FolderInfo(null, directory, directory, 0);
     fi.State = ScanState.EXPANDQUEUED;
     SizeNode sn = new SizeNode(fi);
     nodeMap[fi] = sn;
     TreeNode tn = BuildTreeNode(sn);
     tree.Nodes.Add(tn);
     fqueue.AddFolder(fi, fqueue.Generation);
 }
Esempio n. 24
0
 private string MakePercent(ulong size, SizeNode sizeRef)
 {
     if (size == 0) return "0%";
     if (sizeRef.State != ScanState.DONE)
     {
         return "WAIT";
     }
     ulong refval = displayValue(sizeRef.Size);
     uint percent = (uint)(size * 100 / refval);
     if (percent < 0) percent = 0;
     if (percent > 100) percent = 100;
     return percent + "%";
 }
Esempio n. 25
0
 private void SortNodes(SizeNode sn, TreeNode n)
 {
     if (n.Nodes.Count < 2) return;
     if (sn.State != ScanState.DONE) return;
     int cnt = n.Nodes.Count;
     TreeNode[] l = new TreeNode[cnt];
     for (int i = 0; i < cnt; i++)
     {
         l[i] = n.Nodes[i];
     }
     Array.Sort<TreeNode>(l, new Comparison<TreeNode>(CompareNodes));
     n.Nodes.Clear();
     for (int i = 0; i < cnt; i++)
     {
         n.Nodes.Add(l[i]);
     }
 }
Esempio n. 26
0
 private string SizeString(SizeNode sn, SizeNode sizeParent, SizeNode sizeRoot)
 {
     FolderSize size = sn.Size;
     ScanState ss = sn.State;
     if (ss == ScanState.QUEUED) return "QUEUED";
     if (ss == ScanState.SCANNING) return "SCAN";
     if (size.fileCount == 0 && size.folderCount == 0 && size.childrenDenied) return "DENIED";
     string den = size.childrenDenied ? "?" : "";
     ulong dsize = displayValue(size);
     if (sizeValue >= SizeValue.ALLCOUNT)
     {
         if (displayMode != DisplayMode.PERCENT && displayMode != DisplayMode.PERCENTPARENT)
         {
             return dsize.ToString(FORMAT) + den;
         }
     }
     switch (displayMode)
     {
         case DisplayMode.KB:
             return RoundDiv(dsize, 1024).ToString(FORMAT) + " kb" + den;
         case DisplayMode.MB:
             return RoundDiv(dsize, 1024 * 1024).ToString(FORMAT) + " MB" + den;
         case DisplayMode.GB:
             return RoundDiv(dsize, 1024 * 1024 * 1024).ToString(FORMAT) + " GB" + den;
         case DisplayMode.MIXED:
             {
                 ulong kb = RoundDiv(dsize, 1024);
                 if (kb < 100 * 1024)
                     return kb.ToString(FORMAT) + " kb" + den;
                 else
                     return (kb / 1024).ToString(FORMAT) + " MB" + den;
             }
         case DisplayMode.PERCENT:
             return MakePercent(dsize, sizeRoot) + den;
         case DisplayMode.PERCENTPARENT:
             return MakePercent(dsize, sizeParent) + den;
         default:
             throw new Exception();
     }
 }
Esempio n. 27
0
 private void UpdateExtensionView(SizeNode sn, bool showExtensions)
 {
     if (sn.Directories == null) return;
     TreeNode tn = sn.treeNode;
     foreach (SizeNode fNode in sn.FileSummaries)
     {
         if (showExtensions)
         {
             tn.Nodes.Remove(fNode.treeNode);
             fNode.treeNode = null;
         }
         else
         {
             BuildChild(tn, fNode);
         }
     }
     foreach (SizeNode ftNode in sn.FileTypeSummaries)
     {
         if (!showExtensions)
         {
             tn.Nodes.Remove(ftNode.treeNode);
             ftNode.treeNode = null;
         }
         else
         {
             BuildChild(tn, ftNode);
         }
     }
     foreach (SizeNode child in sn.Directories)
     {
         UpdateExtensionView(child, showExtensions);
     }
     SortNodes(sn, tn);
 }
Esempio n. 28
0
 private void updateTreeNode(TreeNode tn, SizeNode sn)
 {
     tn.ContextMenuStrip = treeMenuStrip;
     sn.treeNode = tn;
     tn.Tag = sn;
     string iconName = sn.IconName;
     if (!treeIcons.Images.ContainsKey(iconName))
     {
         treeIcons.Images.Add(iconName, sn.Icon);
     }
     tn.ImageKey = iconName;
     tn.SelectedImageKey = iconName;
     string s;
     if (tn.Parent == null)
     {
         s = SizeString(sn, sn, sn);
     }
     else
     {
         s = SizeString(sn, (SizeNode)tn.Parent.Tag, (SizeNode)tree.Nodes[0].Tag);
     }
     tn.Text = PadString(s);
     tn.Text = s + "  " + sn.DisplayName;
 }
Esempio n. 29
0
        private string SizeString(SizeNode sn, SizeNode sizeParent, SizeNode sizeRoot)
        {
            FolderSize size = sn.Size;
            ScanState  ss   = sn.State;

            if (ss == ScanState.QUEUED)
            {
                return("QUEUED");
            }
            if (ss == ScanState.SCANNING)
            {
                return("SCAN");
            }
            if (size.fileCount == 0 && size.folderCount == 0 && size.childrenDenied)
            {
                return("DENIED");
            }
            string den   = size.childrenDenied ? "?" : "";
            ulong  dsize = displayValue(size);

            if (sizeValue >= SizeValue.ALLCOUNT)
            {
                if (displayMode != DisplayMode.PERCENT && displayMode != DisplayMode.PERCENTPARENT)
                {
                    return(dsize.ToString(FORMAT) + den);
                }
            }
            switch (displayMode)
            {
            case DisplayMode.KB:
                return(RoundDiv(dsize, 1024).ToString(FORMAT) + " kb" + den);

            case DisplayMode.MB:
                return(RoundDiv(dsize, 1024 * 1024).ToString(FORMAT) + " MB" + den);

            case DisplayMode.GB:
                return(RoundDiv(dsize, 1024 * 1024 * 1024).ToString(FORMAT) + " GB" + den);

            case DisplayMode.MIXED:
            {
                ulong kb = RoundDiv(dsize, 1024);
                if (kb < 100 * 1024)
                {
                    return(kb.ToString(FORMAT) + " kb" + den);
                }
                else
                {
                    return((kb / 1024).ToString(FORMAT) + " MB" + den);
                }
            }

            case DisplayMode.PERCENT:
                return(MakePercent(dsize, sizeRoot) + den);

            case DisplayMode.PERCENTPARENT:
                return(MakePercent(dsize, sizeParent) + den);

            default:
                throw new Exception();
            }
        }
Esempio n. 30
0
 internal void RemoveChild(SizeNode s)
 {
     Unlink();
     directories.Remove(s);
     fileSummaries.Remove(s);
     size.Subtract(s.Size);
 }
Esempio n. 31
0
 private TreeNode BuildTreeNode(SizeNode sn)
 {
     TreeNode tn = new TreeNode();
     updateTreeNode(tn, sn);
     BuildChildren(tn);
     return tn;
 }
Esempio n. 32
0
 private void BuildDummyNode()
 {
     dummyNode = new SizeNode("DummyNodeNeverVisible", null, ScanState.QUEUED, folderInfo.AllFilesSize, fileIcon, null);
     dummyNode.dummyNode = dummyNode; // self-pointer to identify dummy nodes
 }
Esempio n. 33
0
 private void BuildChild(TreeNode tn, SizeNode kid)
 {
     TreeNode child = new TreeNode();
     updateTreeNode(child, kid);
     tn.Nodes.Add(child);
 }