Lets go over what's wrong with this and why no one should use it.
1. Synchronous downloads.
2. Using MD5 hashing instead of a decent algorithm.Code:namespace GLauncher{ class PatchFile{ public bool checkPatchFile(string from){ try{ WebClient PatchFile = new WebClient(); PatchFile.DownloadFile(from+"ZPatch.xml", "ZPatch.xml"); return true; }catch(WebException exeption){ MessageBox.Show(Convert.ToString(exeption)); return false; } } }
3. Sleeping on a main thread.Code:class Hash{ public string GetMD5HashFromFile(string fileName){ FileStream file = new FileStream(fileName, FileMode.Open); MD5 md5 = new MD5CryptoServiceProvider(); byte[] retVal = md5.ComputeHash(file); file.Close(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < retVal.Length; i++){ sb.Append(retVal[i].ToString("x2")); } return sb.ToString(); } }
4. Do I even need to explain this?Code:private void checkPatchFile(){ PatchFile checkPatch = new PatchFile(); if (!checkPatch.checkPatchFile(Convert.ToString(this.PatchLocation))){ this.TransferSpeed.Visible = false; this.Information.Text = "Exiting Gunz Launcher."; this.Information.Refresh(); Thread.Sleep(500); this.Information.Text = "Exiting Gunz Launcher.."; this.Information.Refresh(); Thread.Sleep(500); this.Information.Text = "Exiting Gunz Launcher..."; this.Information.Refresh(); Thread.Sleep(500); Environment.Exit(0); }else{ this.checkFiles(); } }
Code:static bool FilesAreEqual(FileInfo first, FileInfo second){ if (first.Length != second.Length) return false; int iterations = (int)Math.Ceiling((double)first.Length / BYTES_TO_READ); using (FileStream fs1 = first.OpenRead()) using (FileStream fs2 = second.OpenRead()){ byte[] one = new byte[BYTES_TO_READ]; byte[] two = new byte[BYTES_TO_READ]; for (int i = 0; i < iterations; i++){ fs1.Read(one, 0, BYTES_TO_READ); fs2.Read(two, 0, BYTES_TO_READ); if (BitConverter.ToInt64(one, 0) != BitConverter.ToInt64(two, 0)) return false; } } return true; }





