Annotation of cleanflash/CleanFlashCommon/UpdateChecker.cs, revision 1.1.1.1

1.1       root        1: using System;
                      2: using System.Linq;
                      3: using System.Text;
                      4: using System.Net;
                      5: using System.Runtime.Serialization.Json;
                      6: using System.Xml;
                      7: using System.Xml.Linq;
                      8: 
                      9: namespace CleanFlashCommon {
                     10:     public class Version {
                     11:         private string name;
                     12:         private string version;
                     13:         private string url;
                     14: 
                     15:         public Version(string name, string version, string url) {
                     16:             this.name = name;
                     17:             this.version = version;
                     18:             this.url = url;
                     19:         }
                     20: 
                     21:         public string GetName() {
                     22:             return name;
                     23:         }
                     24: 
                     25:         public string GetVersion() {
                     26:             return version;
                     27:         }
                     28: 
                     29:         public string GetUrl() {
                     30:             return url;
                     31:         }
                     32:     }
                     33: 
                     34:     public class UpdateChecker {
                     35:         private static readonly string FLASH_VERSION = "34.0.0.192";
                     36:         private static readonly string VERSION = "v34.0.0.192";
                     37:         private static readonly string AUTHOR = "cleanflash";
                     38:         private static readonly string REPO = "installer";
                     39:         private static readonly string USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36";
                     40: 
                     41:         public static string GetAPILink() {
                     42:             return "https://api.github.com/repos/" + AUTHOR + "/" + REPO + "/releases/latest";
                     43:         }
                     44: 
                     45:         public static string GetFlashVersion() {
                     46:             return FLASH_VERSION;
                     47:         }
                     48: 
                     49:         public static string GetCurrentVersion() {
                     50:             return VERSION;
                     51:         }
                     52: 
                     53:         private static Version GetLatestVersionUnsafe() {
                     54:             using (WebClient client = new WebClient()) {
                     55:                 client.Headers.Add("user-agent", USER_AGENT);
                     56: 
                     57:                 string release = client.DownloadString(GetAPILink());
                     58:                 XmlDictionaryReader jsonReader = JsonReaderWriterFactory.CreateJsonReader(Encoding.UTF8.GetBytes(release), new XmlDictionaryReaderQuotas());
                     59:                 XElement root = XElement.Load(jsonReader);
                     60: 
                     61:                 string name = root.Descendants("name").FirstOrDefault().Value;
                     62:                 string tag = root.Descendants("tag_name").FirstOrDefault().Value;
                     63:                 string url = root.Descendants("html_url").FirstOrDefault().Value;
                     64: 
                     65:                 if (!url.StartsWith("https://")) {
                     66:                     // This is a suspicious URL... We shouldn't trust it.
                     67:                     return null;
                     68:                 }
                     69: 
                     70:                 return new Version(name, tag, url);
                     71:             }
                     72:         }
                     73: 
                     74:         public static Version GetLatestVersion() {
                     75:             try {
                     76:                 return GetLatestVersionUnsafe();
                     77:             } catch (Exception e) {
                     78:                 Console.WriteLine(e);
                     79:                 return null;
                     80:             }
                     81:         }
                     82:     }
                     83: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.