private void btParse_Click(object sender, EventArgs e) { try { this.Email = new Regex(this.tbEmail.Text); this.Fname = new Regex(this.tbFName.Text); this.Lname = new Regex(this.tbLName.Text); this.Address = new Regex(this.tbAddress.Text); this.City = new Regex(this.tbCity.Text); this.State = new Regex(this.tbState.Text); this.Zip = new Regex(this.tbZip.Text); this.Phone = new Regex(this.tbPhone.Text); this.URL = new Regex(this.tbURL.Text); this.Date = new Regex(this.tbDate.Text); this.Sex = new Regex(this.tbSex.Text); this.Country = new Regex(this.tbCountry.Text); this.DoB = new Regex(this.tbDoB.Text); this.OptIn = new Regex(this.tbOptIn.Text); this.Misc = new Regex(this.tbMisc.Text); } catch { MessageBox.Show("Invalid Regex!"); return; } try { SaveFileDialog dialog = new SaveFileDialog(); dialog.Title = "Where do you want to save the new DB?"; dialog.ShowDialog(); FileOut = new StreamWriter(dialog.FileName); this.OutFile = dialog.FileName; } catch { MessageBox.Show("Error Opening File!"); return; } this.lbStatus.Visible = true; try { WorkThread = new Thread(new ThreadStart(Work)); WorkThread.Start(); //Work(); } catch { MessageBox.Show("Aiiie! Failed to run thread!"); Application.Exit(); } } public void Work() { try { this.LineCount = 0; this.Invoke(new UpdateDelegate(updateStatus), 0); for (int i = 0; i < Files.Count; i++) { string file = Files.ElementAt(i); ParseFile(file); updateStatus(i+1); this.Invoke(new UpdateDelegate(updateStatus), i + 1); } this.FileOut.Close(); MessageBox.Show("Completed!\nWrote:" + this.LineCount + " lines\nOutput File:" + this.OutFile); } catch { MessageBox.Show("Aaaiiiieee!Crashed in the work thread which is impossible"); } } private void ParseFile(string file) { try { StreamReader reader = new StreamReader(file); while (!reader.EndOfStream) ParseLine(reader.ReadLine()); reader.Close(); } catch { MessageBox.Show("Aiiie!Failed to read from file!!"); } } private void ParseLine(string line) { string[] values; try { //Massive Time!!!!!!!! if (line.Trim().Length == 0) return; values = line.Split(','); } catch { MessageBox.Show("WTF!? Failed trimming or checking length"); return; } try { if (this.useEmail) if (!this.Email.Match(values[0]).Success) return; if (this.useFName) if (!this.Fname.Match(values[1]).Success) return; if (this.useLName) if (!this.Lname.Match(values[2]).Success) return; if (this.useAddress) if (!this.Address.Match(values[3]).Success) return; if (this.useCity) if (!this.City.Match(values[4]).Success) return; if (this.useState) if (!this.State.Match(values[5]).Success) return; if (this.useZip) if (!this.Zip.Match(values[6]).Success) return; if (this.usePhone) if (!this.Phone.Match(values[7]).Success) return; if (this.useURL) if (!this.URL.Match(values[8]).Success) return; if (this.useDate) if (!this.Date.Match(values[9]).Success) return; if (this.useSex) if (!this.Sex.Match(values[10]).Success) return; if (this.useCountry) if (!this.Country.Match(values[11]).Success) return; if (this.useDoB) if (!this.DoB.Match(values[12]).Success) return; if (this.useOptIn) if (!this.OptIn.Match(values[13]).Success) return; if (this.useMisc) if (!(this.Misc.Match(values[14]).Success || this.Misc.Match(values[15]).Success)) return; } catch { MessageBox.Show("Major Aiiiee! Failed checking regex!"); } //didn't fail any checks! its in! try { FileOut.WriteLine(line); } catch { MessageBox.Show("Error writing to file!"); Application.Exit(); } this.LineCount++; }