Beispiel #1
0
        // Parcours l'ensemble des fichiers d'un dossier spécifié
        // et mise à jours des informations utiles dans la listeview
        // Révision: 22032020

        private void ParcourirFichier(DirectoryInfo Dossier, Hashing.FctHash Hash, long[] Inter)
        {
            List <FileInfo> Fichiers = new List <FileInfo>();

            try
            {
                Fichiers.AddRange(Dossier.GetFiles());
                //Console.WriteLine("Le nombre de fichier trouvé est {0} dans le dossier {1}", Fichiers.Count, Dossier.FullName);

                for (int IdxFic = 0; IdxFic < Fichiers.Count; IdxFic++)
                {
                    if ((Fichiers[IdxFic].Length > Inter[0]) && (Fichiers[IdxFic].Length < Inter[1]))
                    {
                        ListViewItem Item = new ListViewItem(Fichiers[IdxFic].Name);
                        Item.SubItems.Add(Fichiers[IdxFic].Length.ToString());
                        Item.SubItems.Add(Fichiers[IdxFic].Extension);
                        Item.SubItems.Add(Hash(Fichiers[IdxFic].FullName));
                        Item.SubItems.Add(Fichiers[IdxFic].DirectoryName);
                        // ListView1.Items.Add(Item).BackColor = Colorize(Fichiers[IdxFic].Length);
                        ListView1.Items.Add(Item).BackColor = Color.White;  // pour éviter les surcharges de couleurs
                    }
                }
            }
            catch (Exception e5)
            {
                MessageBox.Show(e5.Message, "Une erreur est survenue dans la fonction ParcourirFichier...");
            }
            Fichiers = null;
        }
Beispiel #2
0
        public Form_RepSrc(string RepertoirParent, Hashing.FctHash Hash, string Str_Hash, long[] Inter)
        {
            InitializeComponent();
            lvwColumnSorter = new ListViewColumnSorter();

            ListView1.Bounds             = new Rectangle(new Point(10, 10), new Size(950, 650)); // xy,xy
            ListView1.View               = View.Details;                                         // afficher les détails
            ListView1.LabelEdit          = true;                                                 // permet d'éditer les items
            ListView1.AllowColumnReorder = true;                                                 // permet déplacer les colonnes
            ListView1.CheckBoxes         = true;                                                 // affiche une case à cocher pour la sélection
            ListView1.FullRowSelect      = true;                                                 // permet de sélectionner l'item et sous-items associé
            ListView1.GridLines          = true;                                                 // affiche le quadrillage
            //       ListView1.Sorting = SortOrder.Ascending;        // effectue un tri croissant
            ListView1.Columns.Add("Nom fichier", -2, HorizontalAlignment.Left);
            ListView1.Columns.Add("Taille fichier", -2, HorizontalAlignment.Left);
            ListView1.Columns.Add("Type fichier", -2, HorizontalAlignment.Left);
            ListView1.Columns.Add("Hash " + Str_Hash, -2, HorizontalAlignment.Left);
            ListView1.Columns.Add("Répertoire", -2, HorizontalAlignment.Left);

            DirectoryInfo DossierParent = null;

            Err = false;
            try
            {
                DossierParent = new DirectoryInfo(RepertoirParent);
            }
            catch (Exception e8)
            {
                Console.WriteLine("Erreur {0}", e8.Message);
                MessageBox.Show(e8.Message, "Une erreur est survenue...", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                Err = true;
            }
            if (!Err)
            {
                ParcourirDossier(DossierParent, Hash, Inter);
                this.Controls.Add(ListView1);
                this.ListView1.ListViewItemSorter = lvwColumnSorter;
                lvwColumnSorter.SortColumn        = 3; // force le tri des empreintes par ordre croissant
                lvwColumnSorter.Order             = SortOrder.Descending;
                this.ListView1.Sort();
            }
            else
            {
                this.Close();
            }
        }
Beispiel #3
0
        // Parcours l'ensemmble des dossier à partir d'un dossier parent
        // Attention à la profondeur des dossiers, appel récursif !
        // Révision: 22032020

        private void ParcourirDossier(DirectoryInfo Dossier, Hashing.FctHash Hash, long[] Inter)
        {
            if (Err != true)
            {
                ParcourirFichier(Dossier, Hash, Inter);
                try
                {
                    DirectoryInfo[] DirInfos = Dossier.GetDirectories();
                    if (DirInfos != null) // présence de sous-répertoire ?
                    {
                        foreach (DirectoryInfo IdxDir in DirInfos)
                        {
                            ParcourirDossier(IdxDir, Hash, Inter);
                        }
                    }
                }
                catch (Exception e6)
                {
                    MessageBox.Show(e6.Message, "Une erreur est survenue dans la fonction ParcourirDossier...");
                }
            }
        }
Beispiel #4
0
        // Gestion du bouton de recherche de doublons
        // rappel: le SHA1 sera validé par défaut
        // Révision: 22042020
        //
        private void Btn_RechercheDoublons_Click(object sender, EventArgs e)
        {
            Hashing.FctHash Hash    = null;         // par défaut pas de fonction déléguée
            string          StrHash = string.Empty; // par défaut vide, désignation de la colonne type de hash

            long[] Inter;

            if (ChkBox_MD5.Checked == true)                             // on fixe la fonction déléguée
            {
                Hash    = new Hashing.FctHash(Hashing.Md5.MD5HashFile); // pointe sur la fonction de hash MD5
                StrHash = "MD5";
            }
            if (ChkBox_SHA1.Checked == true)
            {
                Hash    = new Hashing.FctHash(Hashing.Sha1.SHA1HashFile);   // pointe sur la fonction de hash SHA1
                StrHash = "SHA1";
            }
            if (ChkBox_256.Checked == true)
            {
                Hash    = new Hashing.FctHash(Hashing.Sha256.SHA256HashFile); // pointe sur la fonction de hash SHA256
                StrHash = "SHA256";
            }
            if (ChkBox_384.Checked == true)
            {
                Hash    = new Hashing.FctHash(Hashing.Sha384.SHA384HashFile); // pointe sur la fonction de hash SHA384
                StrHash = "SHA384";
            }
            if (ChkBox_512.Checked == true)
            {
                Hash    = new Hashing.FctHash(Hashing.Sha512.SHA512HashFile); // pointe sur la fonction de hash SHA512
                StrHash = "SHA512";
            }

            if ((Tbx_RepSrc.Text == Tbx_RepDel.Text) && Tbx_RepSrc.Text != "")
            {
                Tbx_MessageEtat.Text = "Le répertoire à analyser ne peut être identique au dossier de corbeille";
                Tbx_MessageEtat.Refresh();
                Btn_RechercheDoublons.Enabled = true;
                return;
            }

            Inter = ParseTailleMinMax();  // calcul valeur interval d'étude

            if (Tbx_RepSrc.Text != "" && Tbx_RepDel.Text != "")
            {
                Tbx_MessageEtat.Text = "Calcul des empreintes en cours, veuillez patienter...";
                Tbx_MessageEtat.Refresh();
                Btn_RechercheDoublons.Enabled = false;
                FormDossierSrc = new Form_RepSrc(Tbx_RepSrc.Text, Hash, StrHash, Inter);
                if (FormDossierSrc.Err != true)
                {
                    FormDossierSrc.Show();
                    if (ChkBox_RapportDonnees.Checked == true)
                    {
                        FormDossierSrc.ExportRapportDonnees(); // la fonction est public définit dans FormRepSrc
                    }
                    Tbx_MessageEtat.Text = "Veuillez vérifier les fichiers ...";
                    Tbx_MessageEtat.Refresh();
                }
                else
                {
                    Tbx_MessageEtat.Text = "Erreur détecter !, Veuillez vérifier les dossiers...";
                    Tbx_MessageEtat.Refresh();
                }
            }
            else
            {
                Tbx_MessageEtat.Text = "Veuillez référencer les champs ci-dessus !!";
                Tbx_MessageEtat.Refresh();
                Btn_RechercheDoublons.Enabled = true;
            }

            // si présence d'item (fichier) dans FormDossierSrc
            if (FormDossierSrc != null)
            {
                FormDossierSrc.ChercheDoublons(ChkBox_CocheDoublons.Checked);
            }
        }