Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.IO;
- using System.Text.RegularExpressions;
- using System.Net;
- namespace MD5Checker
- {
- public partial class Form1 : Form
- {
- static string filePath;
- string file = string.Empty, md5 = string.Empty;
- bool readFile = false;
- bool readMd5 = false;
- bool justRunned;
- string[] lines;
- Dictionary<string, string> files;
- StreamReader streamReader;
- Label[,] labels;
- public Form1()
- {
- InitializeComponent();
- systemChooser.Items.Add("Windows XP Proffesional");
- systemChooser.Items.Add("Windows XP Home");
- systemChooser.Items.Add("Windows 7 Home x86");
- systemChooser.Items.Add("Windows 7 Professional x86");
- systemChooser.Items.Add("Windows 7 Ultimate x86");
- systemChooser.Items.Add("Windows 7 Home x64");
- systemChooser.Items.Add("Windows 7 Professional x64");
- systemChooser.Items.Add("Windows 7 Ultimate x64");
- }
- private void formLoad(object sender, EventArgs e)
- {
- string singleLine;
- files = new Dictionary<string, string>();
- //gdy odpalimy program automatycznie wczytuje xp prof
- if (string.IsNullOrEmpty(filePath))
- {
- filePath = "Windows XP Proffesional.set";
- justRunned = true;
- }
- #region Czytanie zawartosci pliku
- try
- {
- streamReader = new StreamReader("Content/" + filePath);
- }
- catch
- {
- MessageBox.Show(filePath + " is missing!",
- "File error",
- MessageBoxButtons.OK,
- MessageBoxIcon.Error,
- MessageBoxDefaultButton.Button1);
- Application.Exit();
- }
- while ((singleLine = streamReader.ReadLine()) != null)
- {
- if(singleLine.Contains("[") && singleLine.Contains("]"))
- {
- readFile = true;
- }
- //czytamy nazwe pliku
- if (readFile)
- {
- file = singleLine;
- readFile = false;
- readMd5 = true;
- }
- //czytamy hash MD5
- else if (readMd5)
- {
- md5 = singleLine;
- }
- //gdy oba zostały wyszukane dodaje je do słownika
- if (!string.IsNullOrEmpty(md5) && !string.IsNullOrEmpty(file))
- {
- file = file.Replace("[", "");
- file = file.Replace("]", "");
- file = file.Trim();
- md5 = md5.Trim();
- files.Add(file, md5);
- md5 = string.Empty;
- file = string.Empty;
- readFile = false;
- readMd5 = false;
- }
- }
- #endregion
- //tworzy tablice labelow w zaleznosci od ilości plików w *.set
- labels = new Label[files.Count, 2];
- int x = 0;
- foreach (KeyValuePair<string, string> pair in files)
- {
- Point point = new Point(10, 30);
- point.Y += 15 * (x + 1);
- labels[x, 0] = new Label();
- labels[x, 0].Text = pair.Key + ":";
- labels[x, 0].Location = point;
- labels[x, 0].Size = new Size(80, 13);
- point.X += 80;
- labels[x, 1] = new Label();
- labels[x, 1].Text = pair.Value;
- labels[x, 1].Location = point;
- labels[x, 1].Size = new Size(220, 13);
- this.Controls.Add(labels[x, 0]);
- this.Controls.Add(labels[x, 1]);
- x++;
- }
- //gdy odpalimy program to ustawia text z comboboxa na xp proffesional
- if (justRunned)
- {
- systemChooser.Text = filePath.Replace(".set", "");
- justRunned = false;
- }
- }
- private void checkButton_Click(object sender, EventArgs e)
- {
- Regex r = new Regex("\\n");
- int i = 0;
- foreach (KeyValuePair<string, string> pair in files)
- {
- labels[i, 1].ForeColor = Color.Black;
- labels[i, 1].BackColor = Color.FromArgb(240, 240, 240);
- i++;
- }
- //manualne czytanie
- if (manualButton.Checked)
- {
- if (string.IsNullOrEmpty(inputBox.Text))
- {
- MessageBox.Show("Input is empty!",
- "ERROR",
- MessageBoxButtons.OK,
- MessageBoxIcon.Error,
- MessageBoxDefaultButton.Button1);
- return;
- }
- lines = r.Split(inputBox.Text);
- }
- //czytanie zawartosci z url
- else if (internetButton.Checked)
- {
- if (string.IsNullOrEmpty(internetBox.Text))
- {
- MessageBox.Show("Input is empty!!",
- "ERROR",
- MessageBoxButtons.OK,
- MessageBoxIcon.Error,
- MessageBoxDefaultButton.Button1);
- return;
- }
- try
- {
- downloadingLabel.Text = "Downloading...";
- string url = internetBox.Text;
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
- Application.DoEvents();
- HttpWebResponse response = (HttpWebResponse)request.GetResponse();
- StreamReader sr = new StreamReader(response.GetResponseStream());
- Application.DoEvents();
- string tempString = sr.ReadToEnd();
- lines = r.Split(tempString);
- sr.Close();
- }
- catch
- {
- MessageBox.Show("Problem with internet connection or wrong URL!",
- "ERROR",
- MessageBoxButtons.OK,
- MessageBoxIcon.Exclamation,
- MessageBoxDefaultButton.Button1);
- downloadingLabel.Text = "";
- return;
- }
- }
- downloadingLabel.Text = "";
- bool checkMd5 = false;
- i = 0;
- foreach (KeyValuePair<string, string> pair in files)
- {
- foreach (string l in lines)
- {
- if (l.Contains(pair.Key))
- {
- checkMd5 = true;
- continue;
- }
- if (checkMd5)
- {
- if (l.Contains(pair.Value))
- {
- labels[i, 1].BackColor = Color.Green;
- labels[i, 1].ForeColor = Color.White;
- }
- else
- {
- labels[i, 1].BackColor = Color.Red;
- labels[i, 1].ForeColor = Color.White;
- }
- checkMd5 = false;
- break;
- }
- }
- i++;
- }
- i=0;
- foreach (KeyValuePair<string, string> pair in files)
- {
- if (labels[i, 1].ForeColor != Color.White)
- labels[i, 1].ForeColor = Color.FromArgb(200, 200, 200);
- i++;
- }
- }
- private void manualButton_CheckedChanged(object sender, EventArgs e)
- {
- if (manualButton.Checked)
- {
- inputBox.Enabled = true;
- internetBox.Enabled = false;
- }
- else if (internetButton.Checked)
- {
- inputBox.Enabled = false;
- internetBox.Enabled = true;
- }
- }
- private void systemChooser_SelectedIndexChanged(object sender, EventArgs e)
- {
- filePath = systemChooser.Text + ".set";
- foreach (Label l in labels)
- {
- this.Controls.Remove(l);
- }
- formLoad(sender, e);
- }
- private void inputBox_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.Control & e.KeyCode == Keys.A)
- inputBox.SelectAll();
- }
- private void internetBox_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.Control & e.KeyCode == Keys.A)
- internetBox.SelectAll();
- }
- }
- }
Add Comment
Please, Sign In to add comment