Esempio n. 1
0
        private void downloadFileCompletedCallback(object sender, AsyncCompletedEventArgs ev)
        {
            this.progressBar.Visible = false;
            this.progressBar.Value   = 0;

            // Now flash the downloaded firmware
            try
            {
                FrmProgress frmProgress = new FrmProgress();
                frmProgress.SetLabel("");
                frmProgress.SetProgressPercentage(0);
                frmProgress.FormBorderStyle = FormBorderStyle.FixedSingle;
                frmProgress.MaximizeBox     = false;
                frmProgress.Show();

                if (FirmwareLoader.UploadFirmware(tempFile, frmProgress) != 0)
                {
                    MessageBox.Show("Error: Unable to upload the firmware to the " + FirmwareLoader.getModelName(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                frmProgress.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

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

            enableUI(true);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            int exitCode = 0;

            /* Testing only
             * args = new string[2];
             * args[0] = "test.bin";
             * args[1] = "GUI";
             */
            if (args.Length == 0)
            {
                FirmwareLoader.outputType = FirmwareLoader.probeModel();

                if ((FirmwareLoader.outputType < FirmwareLoader.OutputType.OutputType_GD77) || (FirmwareLoader.outputType > FirmwareLoader.OutputType.OutputType_DM1801))
                {
                    Console.WriteLine("Unable to detect HT model, using GD-77 as fallback.");
                    FirmwareLoader.outputType = FirmwareLoader.OutputType.OutputType_GD77;
                }
                else
                {
                    Console.WriteLine(String.Format("Detected mode: {0}", FirmwareLoader.getModelName()));
                }

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new MainForm());
            }
            else
            {
                if (args.Contains("--help") || args.Contains("-h") || args.Contains("/h"))
                {
                    //FirmwareLoader.OutputType[] models = new FirmwareLoader.OutputType[] { FirmwareLoader.OutputType.OutputType_GD77, FirmwareLoader.OutputType.OutputType_GD77S, FirmwareLoader.OutputType.OutputType_DM1801 };
                    String[] modelsString =
                    {
                        FirmwareLoader.getModelString(FirmwareLoader.OutputType.OutputType_GD77),
                        FirmwareLoader.getModelString(FirmwareLoader.OutputType.OutputType_GD77S),
                        FirmwareLoader.getModelString(FirmwareLoader.OutputType.OutputType_DM1801)
                    };
                    String allModels = String.Join(" | ", modelsString);

                    Console.WriteLine(String.Format("\nUsage: GD77_FirmwareLoader [GUI] [{0}] [filename]\n\n", allModels));
                    Environment.Exit(exitCode);
                }

                int idxGD77   = Array.IndexOf(args, "GD-77");
                int idxDM1801 = Array.IndexOf(args, "DM-1801");
                int idxGD77S  = Array.IndexOf(args, "GD-77S");

                if (idxGD77 >= 0)
                {
                    FirmwareLoader.outputType = FirmwareLoader.OutputType.OutputType_GD77;
                    args = RemoveArgAt(args, idxGD77);
                }
                else if (idxGD77S >= 0)
                {
                    FirmwareLoader.outputType = FirmwareLoader.OutputType.OutputType_GD77S;
                    args = RemoveArgAt(args, idxGD77S);
                }
                else if (idxDM1801 >= 0)
                {
                    FirmwareLoader.outputType = FirmwareLoader.OutputType.OutputType_DM1801;
                    args = RemoveArgAt(args, idxDM1801);
                }
                else
                {
                    FirmwareLoader.outputType = FirmwareLoader.probeModel();
                    Console.WriteLine(String.Format(" - Detected model: {0}", FirmwareLoader.getModelName()));
                }

                if (args.Length == 0)
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new MainForm());
                }

                int idx = Array.IndexOf(args, "GUI");
                if (idx >= 0)
                {
                    args = RemoveArgAt(args, idx);

                    if (args.Length <= 0)
                    {
                        Console.WriteLine("ERROR: No filename specified.");
                        Environment.Exit(-1);
                    }

                    FrmProgress frmProgress = new FrmProgress();
                    frmProgress.SetLabel("");
                    frmProgress.SetProgressPercentage(0);
                    frmProgress.Show();

                    exitCode = FirmwareLoader.UploadFirmware(args[0], frmProgress);
                    frmProgress.Close();
                }
                else
                {
                    if (args.Length <= 0)
                    {
                        Console.WriteLine("ERROR: No filename specified.");
                        Environment.Exit(-1);
                    }

                    exitCode = FirmwareLoader.UploadFirmware(args[0]);
                }
            }
            //	Console.WriteLine("Usage GD77_FirmwareLoader filename");

            Environment.Exit(exitCode);
        }
Esempio n. 3
0
        private void downloadStringCompletedCallback(object sender, DownloadStringCompletedEventArgs ev)
        {
            String result  = ev.Result;
            String urlBase = "http://github.com";
            String pattern = "";
            String urlFW   = "";

            this.progressBar.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)
            {
                // Extract release version
                // If there is no match the process will go further anyway.
                pattern = @"/R([0-9\.]+)/";

                Match match = Regex.Match(urlFW, pattern, RegexOptions.IgnoreCase);

                if (match.Success)
                {
                    if (MessageBox.Show(String.Format("It will download and install the firmware version {0}.\nPlease confirm.",
                                                      match.Groups[0].Value.Trim('/')), "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    {
                        enableUI(true);
                        return;
                    }
                }

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

                // Download the firmware binary to a temporary file
                try
                {
                    Application.DoEvents();
                    this.progressBar.Value   = 0;
                    this.progressBar.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);
                    }

                    enableUI(true);
                    this.progressBar.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);
                enableUI(true);
            }
        }
Esempio n. 4
0
        private void downloadStringCompletedCallback(object sender, DownloadStringCompletedEventArgs ev)
        {
            if (ev.Cancelled)
            {
                MessageBox.Show("Download has been canceled.", "Timeout", MessageBoxButtons.OK, MessageBoxIcon.Error);

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

                enableUI(true);
                this.progressBar.Visible = false;
                return;
            }

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

            this.progressBar.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 = "It will download and install a firmware.\n\nPlease choose between Stable and Development version.";
                }
                else
                {
                    message = "It will download and install a firmware.\n\nPlease make you choice.";
                }

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

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

                case DialogResult.No:
                    // Devel
                    Console.WriteLine("UNSTABLE");
                    urlFW = develURL;
                    break;

                case DialogResult.Cancel:
                    enableUI(true);
                    return;
                }

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

                // Download the firmware binary to a temporary file
                try
                {
                    Application.DoEvents();
                    this.progressBar.Value   = 0;
                    this.progressBar.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);
                    }

                    enableUI(true);
                    this.progressBar.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);
                enableUI(true);
            }
        }