private void checkVersionToolStripMenuItem_Click(object sender, EventArgs e) { string path = ME3Directory.gamePath; if (path != "") { path += "Binaries\\Win32\\MassEffect3.exe"; string hash = MD5Hash.FromFile(path); bool found = false; for (int i = 0; i < Versions.Count(); i++) { if (hash == Versions[i].Key) { RefreshLists(); listBox1.SelectedIndex = i; found = true; MessageBox.Show("Your version is: " + Versions[i].Desc); } } if (!found) { RefreshLists(); listBox1.Items.Add(hash + " : Unknown Version, please report md5"); listBox1.SelectedIndex = Versions.Count(); System.Windows.Forms.Clipboard.SetText(hash); MessageBox.Show("Your version is unknown, please report the md5 string, its in the clipboard now"); } } }
public static Image ReadImage(XElement item, string itemName) { try { string relativePath = item.XPathSelectElement($"{itemName}/relPath").Value; string filename = Path.Combine(Paths.ExecutingDirectory, relativePath.Replace(@"/", "\\")); if (File.Exists(filename)) { string hash = item.XPathSelectElement($"{itemName}/hash").Value; string localHash = MD5Hash.FromFile(filename); if (hash == localHash) { return(Image.FromFile(filename)); } } Uri imageUri = new Uri(item.XPathSelectElement($"{itemName}/url").Value); Downloader.Download(imageUri, filename); return(Image.FromFile(filename)); } catch (Exception e) { OutputConsole.PrintVerbose(e, $"Unable to load image '{itemName}'.", 1); return(null); } }
private List <PatchFile> GetUpdateableFiles() { List <PatchFile> result = new List <PatchFile>(); foreach (var file in PatchFiles) { if (File.Exists(file.LocalDirectory)) { string hash = MD5Hash.FromFile(file.LocalDirectory); if (hash == file.Hash) { continue; } } if (!IsValidSubDirectory(file.LocalDirectory)) { continue; } result.Add(file); } return(result); }
public static void CheckForNewVersion(XDocument document) { XElement launcherExecutable = document.XPathSelectElement("root/launcher/launcherExecutable"); string webHash = XElementExtender.ReadHash(launcherExecutable); string localHash = MD5Hash.FromFile(Paths.ExecutingFile); if (webHash == localHash) { return; } if (MessageBox.Show("There is a new version of this software available. Do you want to download the latest version?", "New Version", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes) { Uri uri = XElementExtender.ReadUri(launcherExecutable); Process.Start(uri.ToString()); } }
private void PatchMinecraftLauncher() { if (!File.Exists(fileInfos.MinecraftLauncherFilename) || fileInfos.MinecraftLauncherHash != MD5Hash.FromFile(fileInfos.MinecraftLauncherFilename)) { Downloader.Download(fileInfos.DefaultMinecraftLauncherFile, fileInfos.MinecraftLauncherFilename); OutputConsole.Print($"[Patching] {fileInfos.MinecraftLauncherFilename}"); } }
private void createPatchToolStripMenuItem_Click(object sender, EventArgs e) { string loc = Path.GetDirectoryName(Application.ExecutablePath); rtb1.Text += "\nCreating patch\n" + "==============\n\nOriginal File:"; string fileorg = ""; string filemod = ""; string filepatch = ""; OpenFileDialog d = new OpenFileDialog(); if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK) { fileorg = d.FileName; } if (fileorg == "") { rtb1.Text += "\nCanceled by user"; return; } rtb1.Text += fileorg + "\nModefied File:"; if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK) { filemod = d.FileName; } if (filemod == "") { rtb1.Text += "\nCanceled by user"; return; } rtb1.Text += filemod + "\nPatch File:"; SaveFileDialog d2 = new SaveFileDialog(); d2.Filter = "*.patch|*.patch"; if (d2.ShowDialog() == System.Windows.Forms.DialogResult.OK) { filepatch = d2.FileName; } if (filepatch == "") { rtb1.Text += "\nCanceled by user"; return; } rtb1.Text += filepatch + "\n\nCreating MD5...\n"; string hashorg = MD5Hash.FromFile(fileorg); rtb1.Text += "Org File: " + hashorg + "\n"; string hashmod = MD5Hash.FromFile(filemod); rtb1.Text += "Mod File: " + hashmod + "\n"; rtb1.Text += "\nCreating Patch...\n"; rtb1.Refresh(); Application.DoEvents(); if (File.Exists(loc + "\\exec\\out.patch")) { File.Delete(loc + "\\exec\\out.patch"); } // RunShell(loc + "\\exec\\bsdiff.exe", "\"" + fileorg + "\" \"" + filemod + "\" out.patch"); PatcherTool.CreatePatch(fileorg, filemod, "out.patch"); if (File.Exists(loc + "\\exec\\out.patch")) { rtb1.Text += "\nCombining Patch with md5...\n"; FileStream fs = new FileStream(filepatch, FileMode.Create, FileAccess.Write); for (int i = 0; i < 32; i++) { fs.WriteByte((byte)hashorg[i]); } for (int i = 0; i < 32; i++) { fs.WriteByte((byte)hashmod[i]); } FileStream fs2 = new FileStream(loc + "\\exec\\out.patch", FileMode.Open, FileAccess.Read); for (int i = 0; i < fs2.Length; i++) { fs.WriteByte((byte)fs2.ReadByte()); } fs2.Close(); fs.Close(); rtb1.Text += "\nDone.\n"; File.Delete(loc + "\\exec\\out.patch"); } else { rtb1.Text += "\nCanceled by user"; return; } }
private void applyPatchToolStripMenuItem_Click(object sender, EventArgs e) { string loc = Path.GetDirectoryName(Application.ExecutablePath); rtb1.Text += "\nApplying patch\n" + "==============\n\nOriginal File:"; string fileorg = ""; string filemod = ""; string filepatch = ""; OpenFileDialog d = new OpenFileDialog(); if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK) { fileorg = d.FileName; } if (fileorg == "") { rtb1.Text += "\nCanceled by user"; return; } rtb1.Text += fileorg + "\nOutput File:"; SaveFileDialog d2 = new SaveFileDialog(); if (d2.ShowDialog() == System.Windows.Forms.DialogResult.OK) { filemod = d2.FileName; } if (filemod == "") { rtb1.Text += "\nCanceled by user"; return; } rtb1.Text += filemod + "\nPatch File:"; d.Filter = "*.patch|*.patch"; if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK) { filepatch = d.FileName; } if (filepatch == "") { rtb1.Text += "\nCanceled by user"; return; } rtb1.Text += filepatch + "\n\nReading MD5...\n"; if (File.Exists(filepatch)) { FileStream fs = new FileStream(filepatch, FileMode.Open, FileAccess.Read); string hashorg = ""; string hashmod = ""; for (int i = 0; i < 32; i++) { hashorg += (char)fs.ReadByte(); } for (int i = 0; i < 32; i++) { hashmod += (char)fs.ReadByte(); } rtb1.Text += "Checksum Org File: " + hashorg + "\n"; rtb1.Text += "Checksum Mod File: " + hashmod + "\n"; string s = MD5Hash.FromFile(fileorg); rtb1.Text += "Actual Org File: " + s; if (s == hashorg) { rtb1.Text += "...OK\n"; } else { rtb1.Text += "...FAIL\n Exiting."; return; } rtb1.Text += "\nLoading Patch..."; FileStream fs2 = new FileStream(loc + "\\exec\\out.patch", FileMode.Create, FileAccess.Write); for (int i = 64; i < fs.Length; i++) { fs2.WriteByte((byte)fs.ReadByte()); } fs2.Close(); fs.Close(); rtb1.Text += "\nApplying Path...\n"; rtb1.Refresh(); Application.DoEvents(); //RunShell(loc + "\\exec\\bspatch", "\"" + fileorg + "\" \"" + filemod + "\" out.patch"); PatcherTool.ApplyPatch(loc + "\\exec\\", fileorg, filemod, "out.patch"); s = MD5Hash.FromFile(filemod); rtb1.Text += "\nFinished. Checking...\nActual Mod File: " + s; if (s == hashmod) { rtb1.Text += "...OK\n"; } else { rtb1.Text += "...FAIL\n Exiting."; return; } rtb1.Text += "\nDone.\n"; File.Delete(loc + "\\exec\\out.patch"); } else { rtb1.Text += "\nCanceled by user"; return; } }