コード例 #1
0
        private void LoadLastData()
        {
            //Maximale Bytezahl berechnen
            long gesbyte = 0;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                gesbyte += Convert.ToInt64(dt.Rows[i].ItemArray[3].ToString());
            }

            //Einträge in der DataTable nach Size sortieren
            DataView v = dt.DefaultView;

            v.Sort = "Size DESC";

            //ListView füllen
            ImageList img = new ImageList();

            img.ColorDepth          = ColorDepth.Depth32Bit;
            img.ImageSize           = new Size(16, 16);
            lvinhalt.SmallImageList = img;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                long         size = Convert.ToInt64(v[i].Row.ItemArray[3].ToString());
                ListViewItem lvi  = new ListViewItem(v[i].Row.ItemArray[0].ToString());
                lvi.SubItems.Add(v[i].Row.ItemArray[2].ToString());
                lvi.SubItems.Add(ExtraFunctions.GetFileSizeKB(Convert.ToDouble(size)));

                //Grafik einblenden
                if (v[i].Row.ItemArray[1].ToString() == "Folder")
                {
                    img.Images.Add(FilesystemIcons.GetSmallIcon(DirectoryFunctions.CorrectPath(dirpath)));
                }
                else
                {
                    FileInfo f = new FileInfo(DirectoryFunctions.CorrectPath(dirpath) + v[i].Row.ItemArray[0].ToString());
                    try
                    {
                        if (f.Extension == ".lnk")
                        {
                            img.Images.Add(FilesystemIcons.GetSmallIcon(FileFunctions.GetShortcutPath(f.FullName)));
                        }
                        else
                        {
                            img.Images.Add(FilesystemIcons.GetSmallIcon(f.FullName));
                        }
                    }
                    catch
                    {
                        img.Images.Add(FilesystemIcons.GetIconByExtension_x16(f.Extension));
                    }
                }
                lvi.ImageIndex = img.Images.Count - 1;
                lvi.SubItems.Add(Math.Round(Convert.ToDouble(size * 100 / gesbyte), 2).ToString() + "%");

                lvinhalt.Items.Add(lvi);
            }

            lbsize.Text = ExtraFunctions.UnitChange(Convert.ToDouble(gesbyte));
            tabPage2.Controls.RemoveAt(0);
        }
コード例 #2
0
        private void ShowPathContent()
        {
            //ListView leeren
            lvfs.Items.Clear();

            //Wenn der Pfad leer ist, sollen die Drives angezeigt werden. Wenn aber ein Pfad enthalten ist
            //soll der Inhalt des Pfades (Ordner) angezeigt werden
            if (_aktpfad == "")
            {
                smlist.Images.Clear();

                //Nun werden alle Drives geladen und angezeigt
                foreach (DriveInfo drive in DriveInfo.GetDrives())
                {
                    //Icon ermitteln
                    smlist.Images.Add(FilesystemIcons.GetSmallIcon(string.Concat(drive.Name.Substring(0, 2) + @"\")));
                    //Jetzt muss geschaut werden, ob der Drive aktiv ist oder nicht und danach entschieden werden
                    if (drive.IsReady)
                    {
                        ListViewItem lvi = new ListViewItem(string.Concat(drive.Name.Substring(0, 2), " ", DriveFunctions.GetVolumeLabel(Convert.ToChar(drive.Name.Substring(0, 1)))), smlist.Images.Count - 1);
                        lvi.SubItems.Add(""); //Dummy
                        //Der Typ wird anhand des DriveType angegeben. Bei Size kommt der maximale Speicherplatz
                        if (drive.DriveType == DriveType.Fixed)
                        {
                            lvi.SubItems.Add(DriveFunctions.DRIVE_VOLUMELABEL_STD_HDD);
                        }
                        else if (drive.DriveType == DriveType.CDRom)
                        {
                            lvi.SubItems.Add(DriveFunctions.DRIVE_VOLUMELABEL_STD_OPT);
                        }
                        else if (drive.DriveType == DriveType.Removable)
                        {
                            lvi.SubItems.Add(DriveFunctions.DRIVE_VOLUMELABEL_STD_EXT);
                        }
                        else if (drive.DriveType == DriveType.Network)
                        {
                            lvi.SubItems.Add(DriveFunctions.DRIVE_VOLUMELABEL_STD_NET);
                        }
                        else
                        {
                            lvi.SubItems.Add("Unbekannter Laufwerkstyp");
                        }

                        lvi.SubItems.Add(ExtraFunctions.UnitChange(drive.TotalSize));
                        lvfs.Items.Add(lvi);
                    }
                    else
                    {
                        ListViewItem lvi = new ListViewItem(string.Concat(drive.Name.Substring(0, 2), @"\"), smlist.Images.Count - 1);
                        lvi.SubItems.Add(""); //Dummy
                        //Der Typ wird anhand des DriveType angegeben. Bei Size kommt der maximale Speicherplatz
                        if (drive.DriveType == DriveType.Fixed)
                        {
                            lvi.SubItems.Add(DriveFunctions.DRIVE_VOLUMELABEL_STD_HDD);
                        }
                        else if (drive.DriveType == DriveType.CDRom)
                        {
                            lvi.SubItems.Add(DriveFunctions.DRIVE_VOLUMELABEL_STD_OPT);
                        }
                        else if (drive.DriveType == DriveType.Removable)
                        {
                            lvi.SubItems.Add(DriveFunctions.DRIVE_VOLUMELABEL_STD_EXT);
                        }
                        else if (drive.DriveType == DriveType.Network)
                        {
                            lvi.SubItems.Add(DriveFunctions.DRIVE_VOLUMELABEL_STD_NET);
                        }
                        else
                        {
                            lvi.SubItems.Add("Unbekannter Laufwerkstyp");
                        }
                        lvfs.Items.Add(lvi);
                    }
                }
            }
            else
            {
                DirectoryInfo dirinfo = new DirectoryInfo(_aktpfad);
                smlist.Images.Clear();
                smlist.Images.Add(FilesystemIcons.ICON_FILE_16x);

                //Zuerst kommen die Directories
                foreach (DirectoryInfo d in dirinfo.GetDirectories())
                {
                    try
                    {
                        smlist.Images.Add(FilesystemIcons.GetSmallIcon(d.FullName));
                    }
                    catch                                                      //Wenn das Icon über GetSmallIcon nicht genommen wird
                    {
                        smlist.Images.Add(FilesystemIcons.ICON_DIRECTORY_16x); //Ersatzicon
                    }
                    ListViewItem lvi = new ListViewItem(d.Name, smlist.Images.Count - 1);
                    lvi.SubItems.Add(d.LastWriteTime.ToString());
                    lvi.SubItems.Add(Extra.StringResource.GetStringResourceFromFile("@shell32.dll,-10152").ToString());
                    lvfs.Items.Add(lvi);
                }

                //Jetzt kommen die Files. Hier kann man denselben Code wie in ExplorerPlusFileView verwenden
                //Nun wird die Liste gefüllt
                foreach (FileInfo file in dirinfo.GetFiles())
                {
                    //Anhand der Erweiterung schauen, ob es eine Verknüpfung ist oder nicht
                    try
                    {
                        try
                        {
                            if (file.Extension == ".lnk")
                            {
                                smlist.Images.Add(FilesystemIcons.GetSmallIcon(FileFunctions.GetShortcutPath(file.FullName)));
                            }
                            else
                            {
                                smlist.Images.Add(FilesystemIcons.GetSmallIcon(file.FullName));
                            }
                        }
                        catch
                        {
                            smlist.Images.Add(FilesystemIcons.GetIconByExtension_x16(file.Extension));
                        }
                        ListViewItem lvi = new ListViewItem(file.Name, smlist.Images.Count - 1);
                        lvi.SubItems.Add(file.LastWriteTime.ToString());
                        lvi.SubItems.Add(FileFunctions.GetFileTypeDescription(file.Extension));

                        //Wenn die dateigröße unter 1024 Bytes ist, soll stattdessen 1 KB ausgegeben werden
                        if (file.Length < 1024)
                        {
                            lvi.SubItems.Add("1 KB");
                        }
                        else
                        {
                            lvi.SubItems.Add(ExtraFunctions.GetFileSizeKB(Convert.ToDouble(file.Length)));
                        }
                        lvfs.Items.Add(lvi);
                    }
                    catch (UnauthorizedAccessException)
                    { //Geht nicht, da kein Zugriff
                    }
                    catch
                    {
                        ListViewItem lvi = new ListViewItem(file.Name, 0);
                        lvi.SubItems.Add(file.LastWriteTime.ToString());
                        lvi.SubItems.Add(FileFunctions.GetFileTypeDescription(file.Extension));

                        //Wenn die dateigröße unter 1024 Bytes ist, soll stattdessen 1 KB ausgegeben werden
                        if (file.Length < 1024)
                        {
                            lvi.SubItems.Add("1 KB");
                        }
                        else
                        {
                            lvi.SubItems.Add(ExtraFunctions.GetFileSizeKB(Convert.ToDouble(file.Length)));
                        }
                        lvfs.Items.Add(lvi);
                    }
                }
            }
            cbrecentpaths.Text = _aktpfad;
        }
コード例 #3
0
        private void ShowPathContent()
        {
            //ListView leeren
            lvfiles.Items.Clear();

            //ImageListen vorbereiten. Es werden jeweils 2 erstellt, einmal für die SmallIcons und
            //einmal für die LargeIcons
            ImageList sil = new ImageList();
            ImageList lil = new ImageList();

            sil.ColorDepth = ColorDepth.Depth32Bit;
            sil.ImageSize  = new Size(16, 16);
            lil.ColorDepth = ColorDepth.Depth32Bit;
            lil.ImageSize  = new Size(48, 48);
            sil.Images.Add(FilesystemIcons.ICON_FILE_16x);
            lil.Images.Add(FilesystemIcons.ICON_FILE_32x);
            lvfiles.SmallImageList = sil;
            lvfiles.LargeImageList = lil;

            //Wenn der Pfad leer ist, sollen die Drives angezeigt werden. Wenn aber ein Pfad enthalten ist
            //soll der Inhalt des Pfades (Ordner) angezeigt werden
            if (_selectedpath == "")
            {
                //View hier

                //Nun werden alle Drives geladen und angezeigt
                foreach (DriveInfo drive in DriveInfo.GetDrives())
                {
                    //Icon ermitteln
                    sil.Images.Add(FilesystemIcons.GetSmallIcon(string.Concat(drive.Name.Substring(0, 2) + @"\")));
                    lil.Images.Add(FilesystemIcons.GetLargeIcon(string.Concat(drive.Name.Substring(0, 2) + @"\")));
                    //Jetzt muss geschaut werden, ob der Drive aktiv ist oder nicht und danach entschieden werden
                    if (drive.IsReady)
                    {
                        ListViewItem lvi = new ListViewItem(string.Concat(drive.Name.Substring(0, 2), " ", DriveFunctions.GetVolumeLabel(Convert.ToChar(drive.Name.Substring(0, 1)))), sil.Images.Count - 1);
                        lvi.SubItems.Add(""); //Dummy
                        //Der Typ wird anhand des DriveType angegeben. Bei Size kommt der maximale Speicherplatz
                        if (drive.DriveType == DriveType.Fixed)
                        {
                            //Wenn es eine SSD ist, soll das auch so angegeben werden
                            if (DriveFunctions.IsSSD(Convert.ToChar(drive.Name.Substring(0, 1))))
                            {
                                lvi.SubItems.Add(DriveFunctions.DRIVE_VOLUMELABEL_STD_SSD_DESC);
                            }
                            else
                            {
                                lvi.SubItems.Add(DriveFunctions.DRIVE_VOLUMELABEL_STD_HDD_DESC);
                            }
                        }
                        else if (drive.DriveType == DriveType.CDRom)
                        {
                            lvi.SubItems.Add(DriveFunctions.DRIVE_VOLUMELABEL_STD_OPT);
                        }
                        else if (drive.DriveType == DriveType.Removable)
                        {
                            lvi.SubItems.Add(DriveFunctions.DRIVE_VOLUMELABEL_STD_EXT);
                        }
                        else if (drive.DriveType == DriveType.Network)
                        {
                            lvi.SubItems.Add(DriveFunctions.DRIVE_VOLUMELABEL_STD_NET);
                        }
                        else
                        {
                            lvi.SubItems.Add("Unbekannter Laufwerkstyp");
                        }

                        lvi.SubItems.Add(ExtraFunctions.UnitChange(drive.TotalSize));


                        lvi.SubItems.Add(getView(drive.Name).ToString());
                        lvfiles.Items.Add(lvi);
                    }
                    else
                    {
                        ListViewItem lvi = new ListViewItem(string.Concat(drive.Name.Substring(0, 2), @"\"), sil.Images.Count - 1);
                        lvi.SubItems.Add(""); //Dummy
                        //Der Typ wird anhand des DriveType angegeben. Bei Size kommt der maximale Speicherplatz
                        if (drive.DriveType == DriveType.Fixed)
                        {
                            lvi.SubItems.Add(DriveFunctions.DRIVE_VOLUMELABEL_STD_HDD);
                        }
                        else if (drive.DriveType == DriveType.CDRom)
                        {
                            lvi.SubItems.Add(DriveFunctions.DRIVE_VOLUMELABEL_STD_OPT);
                        }
                        else if (drive.DriveType == DriveType.Removable)
                        {
                            lvi.SubItems.Add(DriveFunctions.DRIVE_VOLUMELABEL_STD_EXT);
                        }
                        else if (drive.DriveType == DriveType.Network)
                        {
                            lvi.SubItems.Add(DriveFunctions.DRIVE_VOLUMELABEL_STD_NET);
                        }
                        else
                        {
                            lvi.SubItems.Add("Unbekannter Laufwerkstyp");
                        }
                        lvi.SubItems.Add(getView(drive.Name).ToString());
                        lvfiles.Items.Add(lvi);
                    }
                }
            }
            else
            {
                //hier implemintiere mich meine code


                DirectoryInfo dirinfo = new DirectoryInfo(_selectedpath);

                if (_selectedpath == @"C:\" || _selectedpath == @"D:\")
                {
                    setView(_selectedpath);
                }
                else if (_selectedpath.EndsWith(@"\"))
                {
                    setView(_selectedpath.Substring(0, _selectedpath.Length - 1));
                }
                else
                {
                    setView(_selectedpath);
                }
                //Zuerst kommen die Directories
                foreach (DirectoryInfo d in dirinfo.GetDirectories())
                {
                    try
                    {
                        sil.Images.Add(FilesystemIcons.GetSmallIcon(d.FullName));
                        lil.Images.Add(FilesystemIcons.GetLargeIcon(d.FullName));
                    }
                    catch                                                   //Wenn das Icon über GetSmallIcon nicht genommen wird
                    {
                        sil.Images.Add(FilesystemIcons.ICON_DIRECTORY_16x); //Ersatzicon
                        lil.Images.Add(FilesystemIcons.ICON_DIRECTORY_32x); //Ersatzicon
                    }
                    ListViewItem lvi = new ListViewItem(d.Name, sil.Images.Count - 1);
                    lvi.SubItems.Add(d.LastWriteTime.ToString());
                    lvi.SubItems.Add(Extra.StringResource.GetStringResourceFromFile("@shell32.dll,-10152").ToString());
                    lvi.SubItems.Add("");
                    lvi.SubItems.Add(getView(d.FullName).ToString());
                    lvfiles.Items.Add(lvi);
                }

                //Jetzt kommen die Files. Hier kann man denselben Code wie in ExplorerPlusFileView verwenden
                //Nun wird die Liste gefüllt
                foreach (FileInfo file in dirinfo.GetFiles())
                {
                    //Anhand der Erweiterung schauen, ob es eine Verknüpfung ist oder nicht
                    try
                    {
                        try
                        {
                            if (file.Extension == ".lnk")
                            {
                                sil.Images.Add(FilesystemIcons.GetSmallIcon(FileFunctions.GetShortcutPath(file.FullName)));
                                lil.Images.Add(FilesystemIcons.GetLargeIcon(FileFunctions.GetShortcutPath(file.FullName)));
                            }
                            else
                            {
                                sil.Images.Add(FilesystemIcons.GetSmallIcon(file.FullName));
                                lil.Images.Add(FilesystemIcons.GetLargeIcon(file.FullName));
                            }
                        }
                        catch
                        {
                            sil.Images.Add(FilesystemIcons.GetIconByExtension_x16(file.Extension));
                            lil.Images.Add(FilesystemIcons.GetIconByExtension_x32(file.Extension));
                        }
                        ListViewItem lvi = new ListViewItem(file.Name, sil.Images.Count - 1);
                        lvi.SubItems.Add(file.LastWriteTime.ToString());
                        lvi.SubItems.Add(FileFunctions.GetFileTypeDescription(file.Extension));

                        //Wenn die dateigröße unter 1024 Bytes ist, soll stattdessen 1 KB ausgegeben werden
                        if (file.Length < 1024)
                        {
                            lvi.SubItems.Add("1 KB");
                        }
                        else
                        {
                            lvi.SubItems.Add(ExtraFunctions.GetFileSizeKB(Convert.ToDouble(file.Length)));
                        }

                        lvi.SubItems.Add(getView(file.FullName).ToString());
                        lvfiles.Items.Add(lvi);
                    }
                    catch (UnauthorizedAccessException)
                    { //Geht nicht, da kein Zugriff
                    }
                    catch
                    {
                        ListViewItem lvi = new ListViewItem(file.Name, 0);
                        lvi.SubItems.Add(file.LastWriteTime.ToString());
                        lvi.SubItems.Add(FileFunctions.GetFileTypeDescription(file.Extension));

                        //Wenn die dateigröße unter 1024 Bytes ist, soll stattdessen 1 KB ausgegeben werden
                        if (file.Length < 1024)
                        {
                            lvi.SubItems.Add("1 KB");
                        }
                        else
                        {
                            lvi.SubItems.Add(ExtraFunctions.GetFileSizeKB(Convert.ToDouble(file.Length)));
                        }
                        lvi.SubItems.Add(getView(file.FullName).ToString());
                        lvfiles.Items.Add(lvi);
                    }
                }
            }

            LoadedPath?.Invoke(_selectedpath);
        }