Beispiel #1
0
        private void downloadStringCompletedCallback(object sender, DownloadStringCompletedEventArgs ev)
        {
            if (ev.Cancelled)
            {
                MessageBox.Show("Download has been canceled.", "Timeout", MessageBoxButtons.OK, MessageBoxIcon.Error);

                SetLoadingState(false);
                this.progressBarDwnl.Visible = false;
                return;
            }
            else if (ev.Error != null)
            {
                MessageBox.Show(ev.Error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                SetLoadingState(false);
                this.progressBarDwnl.Visible = false;
                return;
            }

            String result = ev.Result;
            String urlBase = "http://github.com";
            String urlFW = "";
            String patternR = "", patternD = "";
            String releaseURL = "", develURL = "";

            this.progressBarDwnl.Visible = false;

            // Looking for firmware's URL
            String[] lines = result.Split('\n');

            downloadedGetReleaseAndDevelURLs(lines, ref releaseURL, ref develURL);

            // Is firmware's URL found ?
            if ((releaseURL.Length > 0) || (develURL.Length > 0))
            {
                String   message;
                String[] buttonsLabel = new String[2];

                buttonsLabel[0] = "&Stable ";
                buttonsLabel[1] = "&Unstable ";

                // Extract release version
                patternR = @"/R([0-9\.]+)/";
                patternD = @"/D([0-9\.]+)/";

                Match matchR = Regex.Match(releaseURL, patternR, RegexOptions.IgnoreCase);
                Match matchD = Regex.Match(develURL, patternD, RegexOptions.IgnoreCase);

                if (matchR.Success && (releaseURL.Length > 0))
                {
                    buttonsLabel[0] += matchR.Groups[0].Value.Trim('/').Remove(0, 1);
                }
                else
                {
                    buttonsLabel[0] = "";
                }

                if (matchD.Success && (develURL.Length > 0))
                {
                    buttonsLabel[1] += matchD.Groups[0].Value.Trim('/').Remove(0, 1);
                }
                else
                {
                    buttonsLabel[1] = "";
                }

                if ((releaseURL.Length > 0) && (develURL.Length > 0))
                {
                    message = "Please choose between Stable and Development version to download and install.";
                }
                else
                {
                    message = "It will download and install a firmware.\n\nPlease make you choice.";
                }

                DialogResult res = DialogBox("Select version", message, buttonsLabel[0], buttonsLabel[1]);

                switch (res)
                {
                case DialogResult.Yes:
                    // Stable
                    urlFW = releaseURL;
                    break;

                case DialogResult.No:
                    // Devel
                    urlFW = develURL;
                    break;

                case DialogResult.Cancel:
                    SetLoadingState(false);
                    return;
                }

                tempFile = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".sgl";

                // Download the firmware binary to a temporary file
                try
                {
                    Application.DoEvents();
                    this.progressBarDwnl.Value   = 0;
                    this.progressBarDwnl.Visible = true;
                    wc.DownloadFileAsync(new Uri(urlBase + urlFW), tempFile);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    if (File.Exists(tempFile))
                    {
                        File.Delete(tempFile);
                    }

                    SetLoadingState(false);
                    this.progressBarDwnl.Visible = false;
                    return;
                }
            }
            else
            {
                MessageBox.Show(String.Format("Error: unable to find a firmware for your {0} transceiver.", FirmwareLoader.getModelName()), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                SetLoadingState(false);
            }
        }
Beispiel #2
0
        private void downloadStringCompletedCallback(object sender, DownloadStringCompletedEventArgs ev)
        {
            String result  = ev.Result;
            String urlBase = "http://github.com";
            String pattern = "";
            String urlFW   = "";

            this.progressBarDwnl.Visible = false;

            // Define Regex's patterm, according to current Model selection
            switch (FirmwareLoader.outputType)
            {
            case FirmwareLoader.OutputType.OutputType_GD77:
                pattern = @"/rogerclarkmelbourne/OpenGD77/releases/download/R([0-9\.]+)/OpenGD77\.sgl";
                break;

            case FirmwareLoader.OutputType.OutputType_GD77S:
                pattern = @"/rogerclarkmelbourne/OpenGD77/releases/download/R([0-9\.]+)/OpenGD77S\.sgl";
                break;

            case FirmwareLoader.OutputType.OutputType_DM1801:
                pattern = @"/rogerclarkmelbourne/OpenGD77/releases/download/R([0-9\.]+)/OpenDM1801\.sgl";
                break;

            case FirmwareLoader.OutputType.OutputType_RD5R:
                pattern = @"/rogerclarkmelbourne/OpenGD77/releases/download/R([0-9\.]+)/OpenRD5R\.sgl";
                break;
            }

            // Looking for firmware's URL
            String[] lines = result.Split('\n');
            foreach (String l in lines)
            {
                Match match = Regex.Match(l, pattern, RegexOptions.IgnoreCase);

                if (match.Success)
                {
                    urlFW = match.Groups[0].Value;
                    break;
                }
            }

            // Is firmware's URL found ?
            if (urlFW.Length > 0)
            {
                tempFile = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".sgl";

                // Download the firmware binary to a temporary file
                try
                {
                    Application.DoEvents();
                    this.progressBarDwnl.Value   = 0;
                    this.progressBarDwnl.Visible = true;
                    wc.DownloadFileAsync(new Uri(urlBase + urlFW), tempFile);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    if (File.Exists(tempFile))
                    {
                        File.Delete(tempFile);
                    }

                    SetLoadingState(false);
                    this.progressBarDwnl.Visible = false;
                    return;
                }
            }
            else
            {
                MessageBox.Show(String.Format("Error: unable to find a firmware for your {0} transceiver.", FirmwareLoader.getModelName()), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                SetLoadingState(false);
            }
        }