示例#1
0
        private void btnDownloadFirmware_Click(object sender, EventArgs e)
        {
            Uri uri = new Uri("https://api.github.com/repos/rogerclarkmelbourne/opengd77/releases");//https://github.com/rogerclarkmelbourne/OpenGD77/releases");

            if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift)
            {
                _saveDownloadedFile = true;
            }
            else
            {
                _saveDownloadedFile = false;
            }

            this.lblMessage.Text = "";
            wc = new WebClientAsync(40);
            wc.Headers.Add(HttpRequestHeader.Accept, "application/json");
            wc.Headers.Add(HttpRequestHeader.ContentType, "application/json");
            wc.Headers.Add(HttpRequestHeader.UserAgent, "request");

            ServicePointManager.Expect100Continue = true;
            // If you have .Net 4.5
            //ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
            // otherwise
            ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;

            this.progressBarDwnl.Value = 0;

            wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(downloadProgressChangedCallback);
            wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(downloadStringCompletedCallback);
            wc.DownloadFileCompleted   += new AsyncCompletedEventHandler(downloadFileCompletedCallback);

            this.progressBarDwnl.Visible = true;
            SetLoadingState(true);

            // Retrieve release webpage
            try
            {
                Application.DoEvents();
                wc.DownloadStringAsync(uri);
            }
            catch (WebException ex)
            {
                MessageBox.Show(StringsDict["Error"] + ": " + ex.Message, StringsDict["Error"], MessageBoxButtons.OK, MessageBoxIcon.Error);
                SetLoadingState(false);
                this.progressBarDwnl.Visible = false;
                return;
            }
        }
示例#2
0
        private void btnDownloadFirmware_Click(object sender, EventArgs e)
        {
            Uri uri = new Uri("https://github.com/rogerclarkmelbourne/OpenGD77/releases");

            this.lblMessage.Text = "";
            wc = new WebClientAsync(40);

            ServicePointManager.Expect100Continue = true;
            // If you have .Net 4.5
            //ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
            // otherwise
            ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;

            this.progressBarDwnl.Value = 0;

            wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(downloadProgressChangedCallback);
            wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(downloadStringCompletedCallback);
            wc.DownloadFileCompleted   += new AsyncCompletedEventHandler(downloadFileCompletedCallback);

            this.progressBarDwnl.Visible = true;
            SetLoadingState(true);

            // Retrieve release webpage
            try
            {
                Application.DoEvents();
                wc.DownloadStringAsync(uri);
            }
            catch (WebException ex)
            {
                MessageBox.Show("Error: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                SetLoadingState(false);
                this.progressBarDwnl.Visible = false;
                return;
            }
        }