Example #1
0
        public void BasicTest()
        {
            var data   = Encoding.UTF8.GetBytes("Hello World");
            var crc32  = new CRC32HashProvider();
            var result = crc32.ComputeHash(data).ToHexString();

            Assert.Equal("4A17B156", result);
        }
Example #2
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string filePath = "";

            //openFD.InitialDirectory = "C:";
            ofd.Title    = "Open a File";
            ofd.FileName = "";
            ofd.Filter   = "Text Document|*.txt|Rich Text Document|*.rtf|Microsoft Word Document|*.docx|PDF Document|*.pdf|EPUB Files|*.epub";
            string ext;

            if (ofd.ShowDialog() != DialogResult.Cancel)
            {
                filePath = ofd.FileName;
                ext      = Path.GetExtension(filePath);
                FileInfo fInfo = new FileInfo(filePath);

                var    crc32 = new CRC32HashProvider();
                String hash  = String.Empty;

                using (FileStream fs = File.Open(filePath, FileMode.Open))
                    foreach (byte b in crc32.ComputeHash(fs))
                    {
                        hash += b.ToString("x2").ToLower();
                    }

                lbChecksum.Text = hash;

                switch (ext)
                {
                case ".txt":
                    HandleOpenTxt(filePath);
                    break;

                case ".rtf":
                    HandleOpenRtf(filePath);
                    break;

                case ".docx":
                    HandleOpenDoc(filePath);
                    break;

                case ".pdf":
                    HandleOpenPdf(filePath);
                    break;

                case ".epub":
                    HandleOpenEpub(filePath);
                    break;

                default:
                    break;
                }

                metadata = parser.GetAllMetadata();
                foreach (var md in metadata)
                {
                    dataGridView1.Rows.Add(md.Name, md.Value.JoinUsing(", "));
                }

                lbpath.Text               = ofd.FileName;
                fileNameLabel2.Text       = fInfo.Name.ToString();
                fileFormatLabel2.Text     = fInfo.Extension.ToString();
                fileSizeLabel2.Text       = fInfo.Length.ToString();
                creationTimeLabel2.Text   = fInfo.CreationTime.ToString();
                lastAccessTimeLabel2.Text = fInfo.LastAccessTime.ToString();
                lastTimeWriteLabel2.Text  = fInfo.LastWriteTime.ToString();
            }
        }