Пример #1
0
        public void REFRESH1()
        {
            try
            {
                edtFilePath.Text = HerePath;
                if (HerePath == "Home")
                {
                    panContent1.Controls.Clear();
                    int ID = 1;
                    foreach (DriveInfo d in Drives)
                    {
                        if (d.IsReady)
                        {
                            FileItem F = new FileItem("Hardisk");
                            F.ID       = ID;
                            F.PATH     = d.Name;
                            F.isFolder = 1;
                            F.Width    = panContent1.Width - 2;
                            ID++;
                            F.lbText.Text = d.Name;
                            F.lbSize.Text = d.TotalSize / 1000000000 + " Gb";
                            F.F           = this;
                            panContent1.Controls.Add(F);
                        }
                    }

                    FileItem F1 = new FileItem("Desktop");
                    F1.ID = ID;

                    ID++;
                    F1.PATH     = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                    F1.isFolder = 1;
                    F1.Width    = panContent1.Width - 2;
                    ID++;
                    F1.lbText.Text = "Desktop";
                    F1.lbSize.Text = "";
                    F1.F           = this;
                    panContent1.Controls.Add(F1);
                }

                else
                {
                    //Directory search return exception if folder is unacess
                    string[] filePaths = Directory.GetDirectories(HerePath, "*", SearchOption.TopDirectoryOnly);
                    panContent1.Controls.Clear();
                    int ID = 1;
                    for (int i = 0; i < filePaths.Length; ++i)
                    {
                        string   path = filePaths[i];
                        FileInfo info = new FileInfo(path);
                        FileItem F    = new FileItem("Folder");
                        F.ID = ID;
                        ID++;
                        F.PATH        = path;
                        F.Width       = panContent1.Width - 2;
                        F.isFolder    = 1;
                        F.lbText.Text = info.Name.Length > 23 ? info.Name.Substring(0, 20) + "..." : info.Name;
                        F.lbSize.Text = "Folder";
                        F.F           = this;
                        panContent1.Controls.Add(F);
                    }

                    //File
                    filePaths = Directory.GetFiles(HerePath, "*", SearchOption.TopDirectoryOnly);
                    for (int i = 0; i < filePaths.Length; ++i)
                    {
                        string   path = filePaths[i];
                        FileInfo info = new FileInfo(path);
                        FileItem F    = new FileItem(info.Extension.ToLower(), true);
                        F.ID = ID;
                        ID++;
                        F.PATH     = path;
                        F.Width    = panContent1.Width - 2;
                        F.isFolder = 0;

                        //if (info.Extension.ToLower() == ".exe") F.SetSystemIcon(".exe");
                        //if (info.Extension.ToLower() == ".png") F.SetIcon("PNG");
                        //if (info.Extension.ToLower() == ".txt" | info.Extension.ToLower() == ".docx") F.SetIcon("TXT");
                        //if (info.Extension.ToLower() == ".dll") F.SetIcon("DLL");
                        //if (info.Extension.ToLower() == ".ini") F.SetIcon("INI");
                        //if (info.Extension.ToLower() == ".mp3" | info.Extension.ToLower() == ".wav") F.SetIcon("MP3");
                        //if (info.Extension.ToLower() == ".mp4" | info.Extension.ToLower() == ".mkv" | info.Extension.ToLower() == ".flv") F.SetIcon("VIDEO");
                        //if (info.Extension.ToLower() == "") F.SetIcon("NULL");
                        //if (info.Extension.ToLower() == ".bat") F.SetIcon("BAT");
                        //if (info.Extension.ToLower() == ".xls" | info.Extension.ToLower() == ".xlsx") F.SetIcon("EXCEL");

                        F.lbText.Text = info.Name.Length > 23 ? info.Name.Substring(0, 20) + "..." : info.Name;
                        F.lbSize.Text = info.Length / 1024 + " Kb";
                        if (info.Length / 1024 == 0)
                        {
                            F.lbSize.Text      = info.Length + " byte";
                            F.lbSize.ForeColor = Color.Gray;
                        }
                        if (info.Length / 1024 > 1024)
                        {
                            F.lbSize.Text      = DBase.Deci2((decimal)info.Length / 1024 / 1024) + " Mb";
                            F.lbSize.ForeColor = F.lbText.ForeColor = Color.Black;
                        }
                        if (info.Length / 1024 > 1024 * 1024)
                        {
                            F.lbSize.Text      = DBase.Deci2((decimal)info.Length / 1024 / 1024 / 1024) + " Gb";
                            F.lbSize.ForeColor = F.lbText.ForeColor = Color.DarkBlue;
                        }
                        F.F = this;
                        panContent1.Controls.Add(F);
                    }
                }
            }
            catch (Exception ex)
            {
                HerePath = HereLastPath;
            }
        }