private void Updater_Load(object sender, System.EventArgs e) { if (File.Exists("New_unrar.dll")) { File.Copy("New_unrar.dll", "unrar.dll", true); File.Delete("New_unrar.dll"); } closeTimer.Stop(); if (UpdaterMain.UpdateVersion == null) { UpdateStatus("Checking latest version..."); try { HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://razor.uo.cx/version.txt"); req.UserAgent = "Razor Updater"; using (StreamReader reader = new StreamReader(req.GetResponse().GetResponseStream())) { UpdaterMain.UpdateVersion = new Version(reader.ReadToEnd().Trim()); } } catch { UpdateFailed(); return; } } _Downloader = new Downloader(String.Format("https://github.com/msturgill/razor/releases/download/v{0}/Update.rar", UpdaterMain.UpdateVersion.ToString()), "Update.rar", ChangelogRAR, new ProgressChange(OnProgressChange), new ConnectionFailed(OnConnectionFailed), new OperationComplete(OnDownloadComplete), new MessageDownloaded(OnChangelogDownloaded)); UpdateStatus("Downloading changelog..."); _Downloader.Download(); txtChangeLog.Text = "(Fetching Changelog...)"; txtChangeLog.Focus(); txtChangeLog.Select(0, 0); }
private void Updater_Load(object sender, System.EventArgs e) { if (File.Exists("New_unrar.dll")) { File.Copy("New_unrar.dll", "unrar.dll", true); File.Delete("New_unrar.dll"); } closeTimer.Stop(); if (UpdaterMain.UpdateVersion == null) { UpdateStatus("Checking latest version..."); try { HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://razor.uo.cx/version.txt"); req.UserAgent = "Razor Updater"; using (StreamReader reader = new StreamReader(req.GetResponse().GetResponseStream())) { UpdaterMain.UpdateVersion = new Version(reader.ReadToEnd().Trim()); } } catch { UpdateFailed(); return; } } _Downloader = new Downloader( String.Format("https://github.com/msturgill/razor/releases/download/v{0}/Update.rar", UpdaterMain.UpdateVersion.ToString()), "Update.rar", ChangelogRAR, new ProgressChange( OnProgressChange ), new ConnectionFailed( OnConnectionFailed ), new OperationComplete( OnDownloadComplete ), new MessageDownloaded( OnChangelogDownloaded ) ); UpdateStatus( "Downloading changelog..." ); _Downloader.Download(); txtChangeLog.Text = "(Fetching Changelog...)"; txtChangeLog.Focus(); txtChangeLog.Select( 0, 0 ); }
/// <summary> /// Checks for available updates and returns an array of filenames that have updates avaiable. /// </summary> /// <returns>An array of filenames that have updates available</returns> public static UpdateInfo[] UpdatesAvailable() { List <UpdateInfo> ReturnVal = new List <UpdateInfo>(); Downloader dl = new Downloader(); byte[] IndexFile = dl.Download("https://raw.github.com/MrNukealizer/SCII-External-Maphack/Main/UpdaterFileList.txt"); if (IndexFile == null || IndexFile.Length == 0) { return(ReturnVal.ToArray()); } List <string> FileList = Encoding.UTF8.GetString(IndexFile).Replace("\r", "").Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries).ToList(); string CurrentFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + '\\'; FileList.Sort(LineComparer); foreach (string s in FileList) { string[] file = s.Split('|'); if (file.Length < 5) { continue; } bool exists = File.Exists(CurrentFolder + file[0]); if (file[1].Contains('D')) { if (exists) { int NewSize; if (!int.TryParse(file[4], out NewSize)) { NewSize = 0; } ReturnVal.Add(new UpdateInfo(file[0], file[3], "D", -1, NewSize)); } continue; } if (!exists) { int NewSize; if (!int.TryParse(file[4], out NewSize)) { NewSize = -1; } ReturnVal.Add(new UpdateInfo(file[0], file[3], "C", -1, NewSize)); } else { byte[] buffer; using (FileStream fs = new FileStream(CurrentFolder + file[0], FileMode.Open, FileAccess.Read, FileShare.Read)) { buffer = new byte[fs.Length]; fs.Read(buffer, 0, (int)fs.Length); } if (file[1].Contains('V')) { FileVersionInfo version = FileVersionInfo.GetVersionInfo(CurrentFolder + file[0]); if (version.FileVersion != file[2]) { int NewSize; if (!int.TryParse(file[4], out NewSize)) { NewSize = -1; } ReturnVal.Add(new UpdateInfo(file[0], file[3], "R", buffer.Length, NewSize)); } continue; } if (file[1].Contains('L')) { if (ReturnVal.Exists(x => x.LocalFile.ToLower() == file[2].ToLower())) { int NewSize; if (!int.TryParse(file[4], out NewSize)) { NewSize = -1; } ReturnVal.Add(new UpdateInfo(file[0], file[3], "R", buffer.Length, NewSize)); } continue; } MD5 md5 = MD5.Create(); byte[] md5Result = md5.ComputeHash(buffer); string md5ResultAsString = string.Empty; foreach (byte b in md5Result) { md5ResultAsString += b.ToString("x2"); } if (md5ResultAsString != file[2].ToLower()) { int NewSize; if (!int.TryParse(file[4], out NewSize)) { NewSize = -1; } ReturnVal.Add(new UpdateInfo(file[0], file[3], "R", buffer.Length, NewSize)); } } } return(ReturnVal.ToArray()); }
/// <summary> /// Checks for available updates and returns an array of filenames that have updates avaiable. /// </summary> /// <returns>An array of filenames that have updates available</returns> public static UpdateInfo[] UpdatesAvailable() { List <UpdateInfo> ReturnVal = new List <UpdateInfo>(); Downloader dl = new Downloader(); byte[] IndexFile = dl.Download("https://raw.github.com/MrNukealizer/SCII-External-Maphack/Main/UpdaterFileList.txt"); if (IndexFile == null || IndexFile.Length == 0) { return(ReturnVal.ToArray()); } List <string> FileList = Encoding.UTF8.GetString(IndexFile).Replace("\r", "").Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries).ToList(); string CurrentFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + '\\'; FileList.Sort(LineComparer); foreach (string s in FileList) { string[] file = s.Split('|'); if (file.Length < 5) { continue; } bool exists = File.Exists(CurrentFolder + file[0]); if (file[1].Contains('D')) { if (exists) { int NewSize; if (!int.TryParse(file[4], out NewSize)) { NewSize = 0; } ReturnVal.Add(new UpdateInfo(file[0], file[3], "D", -1, NewSize)); } continue; } if (!exists) { int NewSize; if (!int.TryParse(file[4], out NewSize)) { NewSize = -1; } ReturnVal.Add(new UpdateInfo(file[0], file[3], "C", -1, NewSize)); } else { byte[] buffer; using (FileStream fs = new FileStream(CurrentFolder + file[0], FileMode.Open, FileAccess.Read, FileShare.Read)) { buffer = new byte[fs.Length]; fs.Read(buffer, 0, (int)fs.Length); } if (file[1].Contains('V')) { FileVersionInfo version = FileVersionInfo.GetVersionInfo(CurrentFolder + file[0]); if (version.FileVersion != file[2]) { int NewSize; if (!int.TryParse(file[4], out NewSize)) { NewSize = -1; } ReturnVal.Add(new UpdateInfo(file[0], file[3], "R", buffer.Length, NewSize)); } continue; } if (file[1].Contains('L')) { if (ReturnVal.Exists(x => x.LocalFile.ToLower() == file[2].ToLower())) { int NewSize; if (!int.TryParse(file[4], out NewSize)) { NewSize = -1; } ReturnVal.Add(new UpdateInfo(file[0], file[3], "R", buffer.Length, NewSize)); } continue; } MD5 md5 = MD5.Create(); byte[] md5Result = md5.ComputeHash(buffer); string md5ResultAsString = string.Empty; foreach (byte b in md5Result) { md5ResultAsString += b.ToString("x2"); } if (md5ResultAsString != file[2].ToLower()) { if (file[1].Contains('O') && file.Length >= 6) { //TODO: This is a disaster waiting to happen without more error checking, thus the try/catch. try { XDocument _File; using (FileStream fs = new FileStream(CurrentFolder + file[0], FileMode.Open, FileAccess.Read, FileShare.Read)) { _File = XDocument.Load(fs); } XElement _BaseElement = _File.Root; string _Version; if (_BaseElement.HasAttributes && _BaseElement.Attribute("Version") != null) { _Version = _BaseElement.Attribute("Version").Value; } else { _Version = "-1.-1.-1.-1"; } string[] FileVersion = _Version.Split('.', ','); string[] NewVersion = file[5].Split('.', ','); int fv0 = int.Parse(FileVersion[0]); int fv1 = int.Parse(FileVersion[1]); int fv2 = int.Parse(FileVersion[2]); int nv0 = int.Parse(NewVersion[0]); int nv1 = int.Parse(NewVersion[1]); int nv2 = int.Parse(NewVersion[2]); if (fv0 > nv0 || (fv0 == nv0 && (fv1 > nv1 || (fv1 == nv1 && fv2 > nv2)))) { continue; } } catch { } } int NewSize; if (!int.TryParse(file[4], out NewSize)) { NewSize = -1; } ReturnVal.Add(new UpdateInfo(file[0], file[3], "R", buffer.Length, NewSize)); } } } return(ReturnVal.ToArray()); }