コード例 #1
0
        //private List<FileItem> viewItems = new List<FileItem>();

        private void LoadDir(string path)
        {
            listView1.VirtualListSize = 0;
            Items.Clear();

            //DateTime s = DateTime.Now;
            //{
            //    var dirs = Directory.GetDirectories(path);
            //    var files = Directory.GetFiles(path);

            //    Items.Capacity = dirs.Length + files.Length;
            //    foreach (var f in dirs) {
            //        FileItem item = new FileItem();
            //        FileInfo fi = new FileInfo(System.IO.Path.Combine(path, f));
            //        item.IsFile = false;
            //        item.Name = fi.Name;
            //        Items.Add(item);
            //    }
            //    foreach (var f in files) {
            //        FileItem item = new FileItem();
            //        FileInfo fi = new FileInfo(System.IO.Path.Combine(path, f));
            //        item.IsFile = true;
            //        item.Name = fi.Name;
            //        item.Size = fi.Length;
            //        item.LastWriteTime = fi.LastWriteTime;
            //        Items.Add(item);
            //    }
            //}
            long sum = 0;
            //MaxNameWidth = 0;
            var dirinfo = new DirectoryInfo(path);

            foreach (var item in dirinfo.GetDirectories())
            {
                FileItem fitem = new FileItem();
                fitem.IsFile = false;
                fitem.Name   = item.Name;
                fitem.type   = "/";
                //fitem.NameWidth = GetTextExtend(fitem.Name).width;
                //if (MaxNameWidth < fitem.NameWidth) {
                //    MaxNameWidth = fitem.NameWidth;
                //}
                fitem.LastWriteTime = item.LastWriteTime;
                Items.Add(fitem);
            }
            int dircnt = Items.Count;

            foreach (var item in dirinfo.GetFiles())
            {
                FileItem fitem = new FileItem();
                fitem.IsFile = true;
                fitem.Name   = item.Name;
                fitem.type   = item.Extension;
                //fitem.NameWidth = GetTextExtend(fitem.Name).width;
                //if (MaxNameWidth < fitem.NameWidth) {
                //    MaxNameWidth = fitem.NameWidth;
                //}
                fitem.Size          = item.Length;
                fitem.LastWriteTime = item.LastWriteTime;
                Items.Add(fitem);
                sum += fitem.Size;
            }
            int filecnt = Items.Count - dircnt;

            //toolStripStatusLabel1.Text = (DateTime.Now - s).TotalMilliseconds.ToString();
            toolStripStatusLabel1.Text = string.Format("Objects {0}(Dir {1}, Files {2})", Items.Count.ToString(), dircnt, filecnt);;
            toolStripStatusLabel2.Text = getFileSizeFormat(sum);
            listView1.VirtualListSize  = Items.Count;
        }
コード例 #2
0
ファイル: UserControl1.cs プロジェクト: mohammadul/addondev
        //private List<FileItem> viewItems = new List<FileItem>();
        private void LoadDir(string path)
        {
            listView1.VirtualListSize = 0;
            Items.Clear();

            //DateTime s = DateTime.Now;
            //{
            //    var dirs = Directory.GetDirectories(path);
            //    var files = Directory.GetFiles(path);

            //    Items.Capacity = dirs.Length + files.Length;
            //    foreach (var f in dirs) {
            //        FileItem item = new FileItem();
            //        FileInfo fi = new FileInfo(System.IO.Path.Combine(path, f));
            //        item.IsFile = false;
            //        item.Name = fi.Name;
            //        Items.Add(item);
            //    }
            //    foreach (var f in files) {
            //        FileItem item = new FileItem();
            //        FileInfo fi = new FileInfo(System.IO.Path.Combine(path, f));
            //        item.IsFile = true;
            //        item.Name = fi.Name;
            //        item.Size = fi.Length;
            //        item.LastWriteTime = fi.LastWriteTime;
            //        Items.Add(item);
            //    }
            //}
            long sum = 0;
            //MaxNameWidth = 0;
            var dirinfo = new DirectoryInfo(path);
            foreach (var item in dirinfo.GetDirectories()) {
                FileItem fitem = new FileItem();
                fitem.IsFile = false;
                fitem.Name = item.Name;
                fitem.type = "/";
                //fitem.NameWidth = GetTextExtend(fitem.Name).width;
                //if (MaxNameWidth < fitem.NameWidth) {
                //    MaxNameWidth = fitem.NameWidth;
                //}
                fitem.LastWriteTime = item.LastWriteTime;
                Items.Add(fitem);

            }
            int dircnt = Items.Count;

            foreach (var item in dirinfo.GetFiles()) {
                FileItem fitem = new FileItem();
                fitem.IsFile = true;
                fitem.Name = item.Name;
                fitem.type = item.Extension;
                //fitem.NameWidth = GetTextExtend(fitem.Name).width;
                //if (MaxNameWidth < fitem.NameWidth) {
                //    MaxNameWidth = fitem.NameWidth;
                //}
                fitem.Size = item.Length;
                fitem.LastWriteTime = item.LastWriteTime;
                Items.Add(fitem);
                sum += fitem.Size;
            }
            int filecnt = Items.Count-dircnt;

            //toolStripStatusLabel1.Text = (DateTime.Now - s).TotalMilliseconds.ToString();
            toolStripStatusLabel1.Text = string.Format("Objects {0}(Dir {1}, Files {2})", Items.Count.ToString(), dircnt, filecnt); ;
            toolStripStatusLabel2.Text = getFileSizeFormat(sum);
            listView1.VirtualListSize = Items.Count;
        }
コード例 #3
0
        //FileItem lFileItem = null;

        void fileSystemWatcher1_Changed(object sender, FileSystemEventArgs e)
        {
            switch (e.ChangeType)
            {
            case System.IO.WatcherChangeTypes.Changed: {
                Console.WriteLine("ファイル 「" + e.FullPath + "」が変更されました。");
                if (!ChangedItems.Contains(e.Name))
                {
                    ChangedItems.Add(e.Name);
                    var index = (Items.FindIndex(x => {
                            return(x.Name.Equals(e.Name));
                        }));
                    if (index >= 0)
                    {
                        listView.RedrawItems(index, index, false);
                    }
                }
            }
                //if (File.Exists(e.FullPath)) {
                //    FileItem fi = null;
                //    var info = new FileInfo(e.FullPath);
                //    if (lFileItem != null && lFileItem.Name.Equals(e.Name)) {
                //        fi = lFileItem;
                //    }
                //    else if ((listView1.SelectedIndices.Count > 0 && Items[listView1.SelectedIndices[0]].Name.Equals(e.Name))) {
                //        fi = Items[listView1.SelectedIndices[0]];
                //    }else{
                //        fi = Items.First(x => {
                //            return x.Name.Equals(e.Name);
                //        });
                //    }
                //    if (fi != null) {
                //        fi.Size = info.Length;
                //        fi.LastWriteTime = info.LastWriteTime;
                //        var index = Items.IndexOf(fi);
                //        listView1.RedrawItems(index, index, false);
                //    }
                //    lFileItem = fi;
                //}
                break;

            case System.IO.WatcherChangeTypes.Created: {
                var fitem = new FileItem();
                fitem.Name = e.Name;
                if (File.Exists(e.FullPath))
                {
                    //var info = new FileInfo(e.FullPath);
                    fitem.IsFile = true;
                    fitem.type   = e.Name.Substring(e.Name.IndexOf("."));
                    //fitem.Size = info.Length;
                    //fitem.LastWriteTime = info.LastWriteTime;
                }
                else
                {
                    //var info = new DirectoryInfo(e.FullPath);
                    fitem.IsFile = false;
                    fitem.type   = "/";
                    //fitem.LastWriteTime = info.LastWriteTime;
                }
                //lFileItem = fitem;
                var index = 0;
                if (listView.SelectedIndices.Count == 0)
                {
                    index = listView.TopItem != null ? listView.TopItem.Index : 0;
                }
                else
                {
                    index = listView.SelectedIndices[listView.SelectedIndices.Count - 1];
                }
                index = index == Items.Count ? index : index + 1;
                //Items.Add(fitem);
                Items.Insert(index, fitem);

                if (!ChangedItems.Contains(e.Name))
                {
                    ChangedItems.Add(e.Name);
                    listView.RedrawItems(index, index, false);
                }

                listView1.VirtualListSize = Items.Count;
                //Console.WriteLine("ファイル 「" + e.FullPath + "」がCreatedされました。");
                break;
            }

            case System.IO.WatcherChangeTypes.Deleted: {
                //Console.WriteLine("ファイル 「" + e.FullPath + "」が削除されました。");
                Items.Remove(Items.First(x => {
                        return(x.Name.Equals(e.Name));
                    }));
                listView1.VirtualListSize = Items.Count;
                break;
            }
            }
        }
コード例 #4
0
ファイル: UserControl1.cs プロジェクト: mohammadul/addondev
        //FileItem lFileItem = null;
        void fileSystemWatcher1_Changed(object sender, FileSystemEventArgs e)
        {
            switch (e.ChangeType) {
                case System.IO.WatcherChangeTypes.Changed: {
                        Console.WriteLine("ファイル 「" + e.FullPath + "」が変更されました。");
                        if (!ChangedItems.Contains(e.Name)) {
                            ChangedItems.Add(e.Name);
                            var index = (Items.FindIndex(x => {
                                return x.Name.Equals(e.Name);
                            }));
                            if (index >= 0) {
                                listView.RedrawItems(index, index, false);
                            }
                        }
                    }
                    //if (File.Exists(e.FullPath)) {
                    //    FileItem fi = null;
                    //    var info = new FileInfo(e.FullPath);
                    //    if (lFileItem != null && lFileItem.Name.Equals(e.Name)) {
                    //        fi = lFileItem;
                    //    }
                    //    else if ((listView1.SelectedIndices.Count > 0 && Items[listView1.SelectedIndices[0]].Name.Equals(e.Name))) {
                    //        fi = Items[listView1.SelectedIndices[0]];
                    //    }else{
                    //        fi = Items.First(x => {
                    //            return x.Name.Equals(e.Name);
                    //        });
                    //    }
                    //    if (fi != null) {
                    //        fi.Size = info.Length;
                    //        fi.LastWriteTime = info.LastWriteTime;
                    //        var index = Items.IndexOf(fi);
                    //        listView1.RedrawItems(index, index, false);
                    //    }
                    //    lFileItem = fi;
                    //}
                    break;
                case System.IO.WatcherChangeTypes.Created: {
                        var fitem = new FileItem();
                        fitem.Name = e.Name;
                        if (File.Exists(e.FullPath)) {
                            //var info = new FileInfo(e.FullPath);
                            fitem.IsFile = true;
                            fitem.type = e.Name.Substring(e.Name.IndexOf("."));
                            //fitem.Size = info.Length;
                            //fitem.LastWriteTime = info.LastWriteTime;
                        }
                        else {
                            //var info = new DirectoryInfo(e.FullPath);
                            fitem.IsFile = false;
                            fitem.type = "/";
                            //fitem.LastWriteTime = info.LastWriteTime;
                        }
                        //lFileItem = fitem;
                        var index = 0;
                        if (listView.SelectedIndices.Count == 0) {
                            index = listView.TopItem != null ? listView.TopItem.Index : 0;
                        }
                        else {
                            index = listView.SelectedIndices[listView.SelectedIndices.Count - 1];
                        }
                        index = index == Items.Count ? index : index + 1;
                        //Items.Add(fitem);
                        Items.Insert(index, fitem);

                        if (!ChangedItems.Contains(e.Name)) {
                            ChangedItems.Add(e.Name);
                            listView.RedrawItems(index, index, false);
                        }

                        listView1.VirtualListSize = Items.Count;
                        //Console.WriteLine("ファイル 「" + e.FullPath + "」がCreatedされました。");
                        break;
                    }
                case System.IO.WatcherChangeTypes.Deleted: {
                        //Console.WriteLine("ファイル 「" + e.FullPath + "」が削除されました。");
                        Items.Remove(Items.First(x => {
                            return x.Name.Equals(e.Name);
                        }));
                        listView1.VirtualListSize = Items.Count;
                        break;
                    }
            }
        }