コード例 #1
0
ファイル: Form1.cs プロジェクト: chrisquirk/vdu
        private void concentricRingTree1_SelectedNodeChanged()
        {
            if (concentricRingTree1.SelectedNode == null)
            {
                textBox2.Text = "";
                return;
            }
            if (lastNode == concentricRingTree1.SelectedNode)
            {
                return;
            }
            lastNode = concentricRingTree1.SelectedNode;

            List <ListViewItem> lfi;

            if (d.TryGetValue(concentricRingTree1.SelectedNode.Label.ToLower(), out lfi))
            {
                listView1.Items.Clear();
                listView1.Items.AddRange(lfi.ToArray());
            }

            textBox2.Text = string.Format("{0,10} {1,10} {2}",
                                          SizeString(concentricRingTree1.SelectedNode.Value),
                                          SizeString(concentricRingTree1.SelectedNode.TotalValue),
                                          concentricRingTree1.SelectedNode.Label);
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: chrisquirk/vdu
        private ConcentricRingTree.Node CreateNodeTree(string dir, ConcentricRingTree.Node parent)
        {
            lock (UpdatedLock)
            {
                m_currentDir  = dir;
                m_rootUpdated = true;
            }
            var node = new ConcentricRingTree.Node();

            node.Label    = dir;
            node.Value    = 0;
            node.Children = new List <ConcentricRingTree.Node>();
            if (!m_threadAlive)
            {
                return(node);
            }
            List <ListViewItem> llvi = new List <ListViewItem>();
            var zdir = new ZlpDirectoryInfo(dir);
            Tuple <DateTime, List <ListViewItem>, long> cachedInfo;
            var  items    = new List <ListViewItem>();
            long totalLen = 0;

            if (_cache.TryGetValue(dir, out cachedInfo) && zdir.LastWriteTime == cachedInfo.Item1)
            {
                foreach (var lvi in cachedInfo.Item2)
                {
                    items.Add(lvi);
                }
                totalLen = cachedInfo.Item3;
            }
            else
            {
                foreach (var zfile in zdir.GetFiles())
                {
                    var lvi = new ListViewItem(new string[] {
                        zfile.Name,
                        zfile.LastWriteTime.ToShortDateString() + " " + zfile.LastWriteTime.ToShortTimeString(),
                        zfile.Extension,
                        SizeString(zfile.Length)
                    });
                    lvi.Tag = zfile.Length;
                    llvi.Add(lvi);
                    totalLen += zfile.Length;
                    items.Add(lvi);
                    if (!m_threadAlive)
                    {
                        return(node);
                    }
                }
                items.Sort((a, b) => (Math.Sign(((long)b.Tag) - (long)a.Tag)));
                _cache[dir] = Tuple.Create(zdir.LastWriteTime, llvi, totalLen);
            }
            node.Value += totalLen;
            lock (UpdatedLock)
                if (parent != null)
                {
                    parent.AddChild(node);
                }
                else
                {
                    rootNode = node;
                }
            lock (UpdatedLock)
                m_rootUpdated = true;
            d[dir.ToLower()] = items;
            foreach (var zsubdir in zdir.GetDirectories())
            {
                try
                {
                    CreateNodeTree(zsubdir.FullName, node);
                }
                catch (UnauthorizedAccessException)
                { }
            }
            lock (UpdatedLock)
                m_rootUpdated = true;
            return(node);
        }