示例#1
0
        private void AddListItemThread(object fullpath)
        {
            progressForm.Visible = true;
            progressForm.SetPosition(Left, Width, Top, Height);
            LogLabel.Text = "加载中...";
            string path = (string)fullpath;

            listView1.Items.Clear();
            try
            {
                ListViewData.Instance.ClearListItemInfo();
                DirectoryInfo   di       = new DirectoryInfo(path);
                DirectoryInfo[] dis      = di.GetDirectories();
                FileInfo[]      fis      = di.GetFiles();
                int             allfiles = dis.Length + fis.Length;
                int             index    = 0;
                foreach (var directoryInfo in dis)
                {
                    string text = string.Format("正在加载{2}  已完成{0}/{1}", index, allfiles, directoryInfo.Name);
                    LogLabel.Text = text;
                    progressForm.ShowText(text);
                    progressForm.ShowProgress(allfiles, index);
                    ListItemInfo listItemInfo = new ListItemInfo {
                        Name = directoryInfo.Name, CrtTm = directoryInfo.CreationTime, ModTm = directoryInfo.LastWriteTime, Type = "文件夹", Size = Util.GetDirectoryLength(directoryInfo.FullName)
                    };
                    AddViewItem(listItemInfo, false);
                    ListViewData.Instance.SetListItemInfo(listItemInfo, InfoType.DIRECTORY);
                    index++;
                    Thread.Sleep(10);
                }
                foreach (var fileInfo in fis)
                {
                    string text = string.Format("正在加载{2}  已完成{0}/{1}", index, allfiles, fileInfo.Name);
                    LogLabel.Text = text;
                    LogLabel.Text = text;
                    progressForm.ShowText(text);
                    progressForm.ShowProgress(allfiles, index);
                    ListItemInfo listItemInfo = new ListItemInfo {
                        Name = fileInfo.Name, CrtTm = fileInfo.CreationTime, ModTm = fileInfo.LastWriteTime, Type = fileInfo.Extension.Replace(".", "").ToUpper() + "文件", Size = Util.FileSize(fileInfo.FullName)
                    };
                    AddViewItem(listItemInfo);
                    ListViewData.Instance.SetListItemInfo(listItemInfo, InfoType.File);
                    index++;
                    Thread.Sleep(10);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            LogLabel.Text        = "加载完成";
            progressForm.Visible = false;
        }
示例#2
0
        public void SetListItemInfo(ListItemInfo listItemInfo, InfoType type)
        {
            switch (type)
            {
            case InfoType.File:
                fileList.Add(listItemInfo);
                break;

            default:
                DirectoryList.Add(listItemInfo);
                break;
            }
        }
示例#3
0
        private void AddViewItem(ListItemInfo listItemInfo, bool isfile = true)
        {
            ListViewItem li = new ListViewItem();

            li.Text = listItemInfo.Name;
            li.SubItems.Add(listItemInfo.CrtTm.ToString("yyyy-MM-dd HH:MM:ss"));
            li.SubItems.Add(listItemInfo.ModTm.ToString("yyyy-MM-dd HH:MM:ss"));
            li.SubItems.Add(listItemInfo.Type);
            long size = listItemInfo.Size;

            li.SubItems.Add(Util.FormatSize(size));
            long largeFile = 1024 * 1024 * 1024;

            if (size > largeFile)
            {
                li.BackColor = Color.Red;
            }
            if (isfile)
            {
                li.ForeColor = Color.Green;
                string extension = Util.GetExtension(listItemInfo.Name);
                if (extension != "")
                {
                    li.ImageIndex = Util.GetFileExtesionIndex(extension);
                }
                else
                {
                    li.ImageIndex = (int)ImageFileType.FILE;
                }
            }
            else
            {
                if (size == 0)
                {
                    li.ForeColor = Color.Blue;
                }
                li.ImageIndex = (int)ImageFileType.DIRECTORY;
            }
            listView1.Items.Add(li);
        }