private void buttonbrowse1_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) textBoxfile1.Text = openFileDialog1.FileName; } private void buttonbrowse2_Click(object sender, EventArgs e) { if (openFileDialog2.ShowDialog() == DialogResult.OK) textBoxfile2.Text = openFileDialog2.FileName; } private void buttoncompute_Click(object sender, EventArgs e) { timer1.Start(); } private void timer1_Tick(object sender, EventArgs e) { textBox3.Text = ""; if (!checkBox1.Checked) { FileInfo f1 = new FileInfo(textBoxfile1.Text); FileInfo f2 = new FileInfo(textBoxfile2.Text); if (f2.Length < f1.Length) { string tmp = textBoxfile1.Text; textBoxfile1.Text = textBoxfile2.Text; textBoxfile2.Text = tmp; } Process p = new Process(); p.StartInfo.FileName = "bsdiff.exe"; p.StartInfo.Arguments = "\"" + textBoxfile1.Text + "\" \"" + textBoxfile2.Text + "\" diff.bin"; p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; p.Start(); p.WaitForExit(); FileInfo fi = new FileInfo("diff.bin"); long lenf3 = f1.Length > f2.Length ? f1.Length : f2.Length; long filen = (fi.Length - 140) > 0 ? (fi.Length - 140) : 0; float diff = (lenf3 - (filen)); textBox3.Text = "\r\nDifference of two files:" + (filen) + " bytes "; float similar = (diff / lenf3) * 100; textBox3.Text += "\r\nPercentage of similarity : " + similar + "%"; timer1.Stop(); } else { var lines = File.ReadAllLines("inputlist.txt"); textBox3.Text += "\r\n\r\nComparing\r\nFile1:" + textBoxfile1.Text+"\r\n----------------------------------\r\n"; foreach (var line in lines) { textBoxfile2.Text = line; FileInfo f1 = new FileInfo(textBoxfile1.Text); FileInfo f2 = new FileInfo(textBoxfile2.Text); string file1 = textBoxfile1.Text; string file2 = textBoxfile2.Text; if (f2.Length < f1.Length) { string tmp = file1; file1 = file2; file2 = tmp; } f1 = new FileInfo(file1); f2 = new FileInfo(file2); Process p = new Process(); p.StartInfo.FileName = "bsdiff.exe"; p.StartInfo.Arguments = "\"" + file1 + "\" \"" + file2 + "\" diff.bin"; p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; p.Start(); p.WaitForExit(); FileInfo fi = new FileInfo("diff.bin"); long lenf3 = f1.Length > f2.Length ? f1.Length : f2.Length; long filen = (fi.Length - 140)>0?(fi.Length - 140):0; float diff = (lenf3 - (filen)); textBox3.Text += "\r\n\r\n" + file1+","+file2; textBox3.Text += "\r\nDifference of two files:" + (filen) + " bytes "; float similar = (diff / lenf3) * 100; textBox3.Text += "\r\nPercentage of similarity : " + similar + "%"; } timer1.Stop(); } } private void MainForm_Load(object sender, EventArgs e) { } private void checkBox1_CheckedChanged(object sender, EventArgs e) { groupBox1.Visible = !checkBox1.Checked; } private void textBox3_TextChanged(object sender, EventArgs e) { }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)