Exemple #1
0
        public static string getJSON(string url)
        {
            if (!Properties.Settings.Default.jsonSupport)
            {
                return(null);
            }

            try {
                using (WebClient wc = new WebClient()) {
                    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                    wc.Headers.Add("User-Agent: " + Program.UserAgent);
                    string json  = wc.DownloadString(url);
                    byte[] bytes = Encoding.ASCII.GetBytes(json);
                    using (var stream = new MemoryStream(bytes)) {
                        var quotas     = new XmlDictionaryReaderQuotas();
                        var jsonReader = JsonReaderWriterFactory.CreateJsonReader(stream, quotas);
                        var xml        = XDocument.Load(jsonReader);
                        stream.Flush();
                        stream.Close();
                        return(xml.ToString());
                    }
                }
            }
            catch (WebException WebE) {
                Debug.Print(WebE.ToString());
                ErrorLog.reportWebError(WebE, url);
                return(null);

                throw WebE;
            }
            catch (Exception ex) {
                Debug.Print(ex.ToString());
                ErrorLog.reportError(ex);
                return(null);

                throw ex;
            }
        }
Exemple #2
0
        public static bool downloadNewVersion(decimal cloudVersion)
        {
            if (!Properties.Settings.Default.jsonSupport)
            {
                return(false);
            }

            try {
                using (WebClient wc = new WebClient()) {
                    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                    wc.Headers.Add("User-Agent: " + Program.UserAgent);
                    wc.DownloadFile("https://github.com/murrty/youtube-dl-gui/releases/download/" + (cloudVersion) + "/youtube-dl-gui.exe", Environment.CurrentDirectory + "\\youtube-dl-gui.exe.part");
                    return(true);
                }
            }
            catch (WebException webe) {
                ErrorLog.reportWebError(webe, "https://github.com/murrty/youtube-dl-gui/releases/download/this-is-the-detected-updated-version/youtube-dl-gui.exe");
                return(false);
            }
            catch (Exception ex) {
                ErrorLog.reportError(ex);
                return(false);
            }
        }