/// <summary> /// Return whether the client is outdated or not /// </summary> private static bool Outdated() { while (webClient.IsBusy) { Thread.Sleep(100); } try { Log.Write("Checking for updates..."); List<Files.RemoteFile> remoteFiles = new List<Files.RemoteFile>(); XmlDocument XML = new XmlDocument(); XML.Load(Host + "info.xml"); XmlNodeList Updater = XML.GetElementsByTagName("Updater"); XmlNodeList Info = ((XmlElement)Updater[0]).GetElementsByTagName("FileInfo"); XmlNodeList CacheInfo = ((XmlElement)Info[0]).GetElementsByTagName("File"); foreach (XmlElement File in CacheInfo) { remoteFiles.Add(new Files.RemoteFile(File.GetAttribute("name"), File.GetAttribute("md5"), File.GetAttribute("sha1"))); } Log.Write("Remote updater information obtained."); Log.Write("Current version: 1337 - Newest version: 1337"); List<Files.LocalFile> localFiles = new List<Files.LocalFile>(); foreach (Files.RemoteFile file in remoteFiles) { if (!File.Exists(Environment.CurrentDirectory + @"\" + file.Filename)) { outdatedFiles.Add(file.Filename); continue; } string path = Environment.CurrentDirectory + @"\" + file.Filename; string MD5Hash; string SHA1Hash; Hash.GetHash(path, out MD5Hash, out SHA1Hash); Files.LocalFile localFile = new Files.LocalFile(file.Filename, MD5Hash, SHA1Hash); localFiles.Add(localFile); if ((localFile.MD5Hash == file.MD5Hash) && (localFile.SHA1Hash == file.SHA1Hash)) { localFile.correctHash = true; } else { localFile.correctHash = false; } } foreach (Files.LocalFile file in localFiles.FindAll(x => x.correctHash == false)) { outdatedFiles.Add(file.Filename); } if (outdatedFiles.Count > 1) Log.Write(outdatedFiles.Count + " files need update."); if (outdatedFiles.Count == 1) Log.Write(outdatedFiles.Count + " file needs update."); if (outdatedFiles.Count == 0) { return false; } else { return true; } } catch (Exception) { Log.Write("ERROR: Could not retrieve outdated files. Press any key to exit."); Console.ReadKey(); Environment.Exit(0x1); return false; } }
/// <summary> /// Return whether the client is outdated or not /// </summary> private static bool Outdated() { while (webClient.IsBusy) { Thread.Sleep(100); } try { Log.Write("Checking for updates..."); List <Files.RemoteFile> remoteFiles = new List <Files.RemoteFile>(); XmlDocument XML = new XmlDocument(); XML.Load(Host + "info.xml"); XmlNodeList Updater = XML.GetElementsByTagName("Updater"); XmlNodeList Info = ((XmlElement)Updater[0]).GetElementsByTagName("FileInfo"); XmlNodeList CacheInfo = ((XmlElement)Info[0]).GetElementsByTagName("File"); foreach (XmlElement File in CacheInfo) { remoteFiles.Add(new Files.RemoteFile(File.GetAttribute("name"), File.GetAttribute("md5"), File.GetAttribute("sha1"))); } Log.Write("Remote updater information obtained."); Log.Write("Current version: 1337 - Newest version: 1337"); List <Files.LocalFile> localFiles = new List <Files.LocalFile>(); foreach (Files.RemoteFile file in remoteFiles) { if (!File.Exists(Environment.CurrentDirectory + @"\" + file.Filename)) { outdatedFiles.Add(file.Filename); continue; } string path = Environment.CurrentDirectory + @"\" + file.Filename; string MD5Hash; string SHA1Hash; Hash.GetHash(path, out MD5Hash, out SHA1Hash); Files.LocalFile localFile = new Files.LocalFile(file.Filename, MD5Hash, SHA1Hash); localFiles.Add(localFile); if ((localFile.MD5Hash == file.MD5Hash) && (localFile.SHA1Hash == file.SHA1Hash)) { localFile.correctHash = true; } else { localFile.correctHash = false; } } foreach (Files.LocalFile file in localFiles.FindAll(x => x.correctHash == false)) { outdatedFiles.Add(file.Filename); } if (outdatedFiles.Count > 1) { Log.Write(outdatedFiles.Count + " files need update."); } if (outdatedFiles.Count == 1) { Log.Write(outdatedFiles.Count + " file needs update."); } if (outdatedFiles.Count == 0) { return(false); } else { return(true); } } catch (Exception) { Log.Write("ERROR: Could not retrieve outdated files. Press any key to exit."); Console.ReadKey(); Environment.Exit(0x1); return(false); } }