259 lines
7.8 KiB
C#
259 lines
7.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using System.IO;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace FindDifferences
|
|
{
|
|
public partial class frmFindDifferences : Form
|
|
{
|
|
public frmFindDifferences()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
private void frmFindDifferences_Load(object sender, EventArgs e)
|
|
{
|
|
LoadSettings();
|
|
SetupComboBoxes();
|
|
}
|
|
private void LoadSettings()
|
|
{
|
|
Size = Properties.Settings.Default.Size;
|
|
Resize += new EventHandler(frmFindDifferences_Resize);
|
|
Location = Properties.Settings.Default.Location;
|
|
Move += new EventHandler(frmFindDifferences_Move);
|
|
tbCompare.Text = Properties.Settings.Default.CompareFolder;
|
|
tbCompare.TextChanged += new EventHandler(tbCompare_TextChanged);
|
|
tbPdf.Text = Properties.Settings.Default.PdfFolder;
|
|
tbPdf.TextChanged += new EventHandler(tbPdf_TextChanged);
|
|
splitContainer1.SplitterDistance = Properties.Settings.Default.SplitterDistance;
|
|
splitContainer1.SplitterMoved +=new SplitterEventHandler(splitContainer1_SplitterMoved);
|
|
WindowState = Properties.Settings.Default.WindowState;
|
|
cbShowFirst.Checked = Properties.Settings.Default.ShowFirst;
|
|
cbShowFirst.CheckedChanged += new EventHandler(cbShowFirst_CheckedChanged);
|
|
}
|
|
void cbShowFirst_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
Properties.Settings.Default.ShowFirst = cbShowFirst.Checked;
|
|
SetupDifferences();
|
|
}
|
|
void tbPdf_TextChanged(object sender, EventArgs e)
|
|
{
|
|
Properties.Settings.Default.PdfFolder = tbPdf.Text;
|
|
}
|
|
void tbCompare_TextChanged(object sender, EventArgs e)
|
|
{
|
|
Properties.Settings.Default.CompareFolder = tbCompare.Text;
|
|
SetupComboBoxes();
|
|
}
|
|
void frmFindDifferences_Move(object sender, EventArgs e)
|
|
{
|
|
Properties.Settings.Default.WindowState = WindowState;
|
|
if (WindowState == FormWindowState.Normal)
|
|
Properties.Settings.Default.Location = Location;
|
|
}
|
|
void frmFindDifferences_Resize(object sender, EventArgs e)
|
|
{
|
|
Properties.Settings.Default.WindowState = WindowState;
|
|
if (WindowState == FormWindowState.Normal)
|
|
Properties.Settings.Default.Size = Size;
|
|
}
|
|
private void SetupComboBoxes()
|
|
{
|
|
if (tbCompare.Text != string.Empty)
|
|
LoadComboBoxes();
|
|
else
|
|
DisableComboBoxes();
|
|
}
|
|
private void LoadComboBoxes()
|
|
{
|
|
DirectoryInfo di = new DirectoryInfo(tbCompare.Text);
|
|
if (di.Exists)
|
|
{
|
|
List<string> myFiles1 = new List<string>();
|
|
List<string> myFiles2 = new List<string>();
|
|
foreach (FileInfo myFile in di.GetFiles("*.txt"))
|
|
{
|
|
myFiles1.Add(myFile.Name);
|
|
myFiles2.Add(myFile.Name);
|
|
}
|
|
cmbCompare.SelectedIndexChanged -= new EventHandler(cmbCompare_SelectedIndexChanged);
|
|
cmbWith.SelectedIndexChanged -= new EventHandler(cmbCompare_SelectedIndexChanged);
|
|
cmbCompare.DataSource = myFiles1;
|
|
cmbWith.DataSource = myFiles2;
|
|
cmbCompare.Enabled = true;
|
|
cmbWith.Enabled = true;
|
|
cmbCompare.SelectedIndex = -1;
|
|
cmbWith.SelectedIndex = -1;
|
|
cmbCompare.SelectedIndexChanged += new EventHandler(cmbCompare_SelectedIndexChanged);
|
|
cmbWith.SelectedIndexChanged += new EventHandler(cmbCompare_SelectedIndexChanged);
|
|
}
|
|
else
|
|
DisableComboBoxes();
|
|
}
|
|
void cmbCompare_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
SetupDifferences();
|
|
}
|
|
private void DisableComboBoxes()
|
|
{
|
|
lbDifferences.Enabled = false;
|
|
cmbCompare.Enabled = false;
|
|
cmbWith.Enabled = false;
|
|
}
|
|
private void SetupDifferences()
|
|
{
|
|
if (cmbCompare.Text != string.Empty && cmbWith.Text != string.Empty)
|
|
{
|
|
List<string> compareList = BuildList(cmbCompare.Text);
|
|
List<string> withList = BuildList(cmbWith.Text);
|
|
RemoveMatches(withList, compareList);
|
|
if (cbShowFirst.Checked) RemoveMultiples(withList);
|
|
lbDifferences.Click -= new EventHandler(lbDifferences_Click);
|
|
//lbDifferences.SelectedIndexChanged -= new EventHandler(lbDifferences_SelectedIndexChanged);
|
|
lblDifferences.Text = withList.Count.ToString() + " Differences";
|
|
lbDifferences.DataSource = withList;
|
|
lbDifferences.Enabled = true;
|
|
//lbDifferences.SelectedIndexChanged += new EventHandler(lbDifferences_SelectedIndexChanged);
|
|
lbDifferences.Click += new EventHandler(lbDifferences_Click);
|
|
}
|
|
else
|
|
{
|
|
lbDifferences.DataSource = null;
|
|
lbDifferences.Enabled = false;
|
|
}
|
|
}
|
|
|
|
void lbDifferences_Click(object sender, EventArgs e)
|
|
{
|
|
wb.Navigate("about:blank");
|
|
Clipboard.Clear();
|
|
if (lbDifferences.SelectedValue != null)
|
|
{
|
|
Clipboard.SetText(lbDifferences.SelectedValue.ToString());
|
|
tmr.Enabled = true;
|
|
}
|
|
}
|
|
Regex myRegExpMult = new Regex("'([^']*?)','([^']*)?',([0-9]*,'[^']*?)'");
|
|
private void RemoveMultiples(List<string> withList)
|
|
{
|
|
List<string> multList = new List<string>();
|
|
string last = string.Empty;
|
|
foreach (string str in withList)
|
|
{
|
|
string found = myRegExpMult.Replace(str, "$1.$2");
|
|
if (found == last) multList.Add(str);
|
|
last = found;
|
|
}
|
|
foreach (string str in multList)
|
|
withList.Remove(str);
|
|
}
|
|
void lbDifferences_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
wb.Navigate("about:blank");
|
|
Clipboard.Clear();
|
|
if (lbDifferences.SelectedValue != null)
|
|
{
|
|
Clipboard.SetText(lbDifferences.SelectedValue.ToString());
|
|
tmr.Enabled = true;
|
|
}
|
|
}
|
|
|
|
private void RemoveMatches(List<string> withList, List<string> compareList)
|
|
{
|
|
foreach (string str in compareList)
|
|
if (withList.Contains(str))
|
|
withList.Remove(str);
|
|
}
|
|
|
|
private List<string> BuildList(string fileName)
|
|
{
|
|
List<string> myList = new List<string>();
|
|
FileInfo myFile = new FileInfo(tbCompare.Text + "\\" + fileName);
|
|
using (StreamReader sr = myFile.OpenText())
|
|
{
|
|
while (!sr.EndOfStream)
|
|
{
|
|
string str = sr.ReadLine();
|
|
if(str != string.Empty)
|
|
myList.Add(str);
|
|
}
|
|
sr.Close();
|
|
}
|
|
return myList;
|
|
}
|
|
private string CompareFolder
|
|
{
|
|
get
|
|
{
|
|
if (tbCompare.Text == string.Empty)
|
|
return Environment.GetFolderPath(Environment.SpecialFolder.MyComputer);
|
|
return tbCompare.Text;
|
|
}
|
|
}
|
|
private string PdfFolder
|
|
{
|
|
get
|
|
{
|
|
if (tbPdf.Text == string.Empty)
|
|
return Environment.GetFolderPath(Environment.SpecialFolder.MyComputer);
|
|
return tbPdf.Text;
|
|
}
|
|
}
|
|
private void btnCompare_Click(object sender, EventArgs e)
|
|
{
|
|
fbd.SelectedPath = CompareFolder;
|
|
if (fbd.ShowDialog() == DialogResult.OK)
|
|
tbCompare.Text = fbd.SelectedPath;
|
|
}
|
|
private void btnPdf_Click(object sender, EventArgs e)
|
|
{
|
|
fbd.SelectedPath = PdfFolder;
|
|
if (fbd.ShowDialog() == DialogResult.OK)
|
|
tbPdf.Text = fbd.SelectedPath;
|
|
}
|
|
private void frmFindDifferences_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
Properties.Settings.Default.Save();
|
|
}
|
|
Regex myRegExp = new Regex("'([^']*?)','[^']*?',([0-9]*,'[^']*?)'");
|
|
private void tmr_Tick(object sender, EventArgs e)
|
|
{
|
|
tmr.Enabled = false;
|
|
string url = myRegExp.Replace(lbDifferences.SelectedValue.ToString(), tbPdf.Text + @"\$1.pdf#search=""$2""");
|
|
wb.Navigate(url);
|
|
}
|
|
private void btnClosePdf_Click(object sender, EventArgs e)
|
|
{
|
|
wb.Navigate("about:blank");
|
|
}
|
|
private void btnRefresh_Click(object sender, EventArgs e)
|
|
{
|
|
int indCompare = cmbCompare.SelectedIndex;
|
|
int indWith = cmbWith.SelectedIndex;
|
|
LoadComboBoxes();
|
|
cmbCompare.SelectedIndex = indCompare;
|
|
cmbWith.SelectedIndex = indWith;
|
|
}
|
|
private void splitContainer1_SplitterMoved(object sender, SplitterEventArgs e)
|
|
{
|
|
Properties.Settings.Default.SplitterDistance = splitContainer1.SplitterDistance;
|
|
}
|
|
|
|
private void btnCopy_Click(object sender, EventArgs e)
|
|
{
|
|
Clipboard.Clear();
|
|
StringBuilder sb = new StringBuilder();
|
|
foreach(string str in lbDifferences.DataSource as List<string>)
|
|
{
|
|
sb.Append(str + "\r\n");
|
|
}
|
|
Clipboard.SetText(sb.ToString());
|
|
}
|
|
}
|
|
} |