Esempio n. 1
0
        private void btnUploadFirmware_Click(object sender, EventArgs e)
        {
            if (IsLoading)
            {
                return;
            }

            //if (MessageBox.Show("This feature is experimental.\nYou use it at your own risk\n\nAre you sure you want to upload firmware to the radio?","Warning", MessageBoxButtons.YesNo)==DialogResult.Yes)
            {
                Action <object> action = (object obj) =>
                {
                    IsLoading = true;
                    FirmwareLoader.UploadFirmare(_filename, this);
                    IsLoading = false;
                };
                try
                {
                    Task t1 = new Task(action, "LoaderUSB");
                    t1.Start();
                }
                catch (Exception)
                {
                    IsLoading = false;
                }
            }
        }
Esempio n. 2
0
        private void downloadFileCompletedCallback(object sender, AsyncCompletedEventArgs ev)
        {
            this.progressBarDwnl.Visible = false;
            this.progressBarDwnl.Value   = 0;

            if (ev.Cancelled)
            {
                MessageBox.Show("Download has been canceled.", "Timeout", MessageBoxButtons.OK, MessageBoxIcon.Error);

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

                SetLoadingState(false);
                IsLoading = false;
                return;
            }

            // Now flash the downloaded firmware
            Action <object> action = (object obj) =>
            {
                IsLoading = true;
                SetLoadingState(true);
                FirmwareLoader.UploadFirmare(tempFile, this);
                SetLoadingState(false);
                IsLoading = false;
                // Cleanup
                if (File.Exists(tempFile))
                {
                    File.Delete(tempFile);
                }
            };

            try
            {
                Task t1 = new Task(action, "LoaderUSB");
                t1.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                SetLoadingState(false);
                IsLoading = false;
                // Cleanup
                if (File.Exists(tempFile))
                {
                    File.Delete(tempFile);
                }
            }
        }
Esempio n. 3
0
        private void btnUploadFirmware_Click(object sender, EventArgs e)
        {
            if (IsLoading)
            {
                return;
            }

            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter           = "firmware files|*.sgl";
            openFileDialog.InitialDirectory = IniFileUtils.getProfileStringWithDefault("Setup", "LastFirmwareLocation", null);

            if (openFileDialog.ShowDialog() == DialogResult.OK && openFileDialog.FileName != null)
            {
                IniFileUtils.WriteProfileString("Setup", "LastFirmwareLocation", Path.GetDirectoryName(openFileDialog.FileName));

                this.lblMessage.Text = "";

                Action <object> action = (object obj) =>
                {
                    IsLoading = true;
                    SetLoadingState(true);
                    FirmwareLoader.UploadFirmare(openFileDialog.FileName, this);
                    SetLoadingState(false);
                    IsLoading = false;
                };
                try
                {
                    Task t1 = new Task(action, "LoaderUSB");
                    t1.Start();
                }
                catch (Exception)
                {
                    IsLoading = false;
                    SetLoadingState(false);
                }
            }
        }
Esempio n. 4
0
        private void downloadFileCompletedCallback(object sender, AsyncCompletedEventArgs ev)
        {
            this.progressBarDwnl.Visible = false;
            this.progressBarDwnl.Value   = 0;

            // Now flash the downloaded firmware
            Action <object> action = (object obj) =>
            {
                IsLoading = true;
                SetLoadingState(true);
                FirmwareLoader.UploadFirmare(tempFile, this);
                SetLoadingState(false);
                IsLoading = false;
                Console.WriteLine("IsLoading=false");
                // Cleanup
                if (File.Exists(tempFile))
                {
                    File.Delete(tempFile);
                }
            };

            try
            {
                Task t1 = new Task(action, "LoaderUSB");
                t1.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                SetLoadingState(false);
                IsLoading = false;
                // Cleanup
                if (File.Exists(tempFile))
                {
                    File.Delete(tempFile);
                }
            }
        }
Esempio n. 5
0
        private void downloadStringCompletedCallback(object sender, DownloadStringCompletedEventArgs ev)
        {
            if (ev.Cancelled)
            {
                MessageBox.Show(StringsDict["DownloadCancelled"], StringsDict["Timeout"], MessageBoxButtons.OK, MessageBoxIcon.Error);

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

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

            String result = ev.Result;

            this.progressBarDwnl.Visible = false;

            FirmwareLoaderReleasesList flrl = new FirmwareLoaderReleasesList(result);

            if (DialogResult.Cancel != flrl.ShowDialog())
            {
                if (_saveDownloadedFile)
                {
                    SaveFileDialog saveFileDialog = new SaveFileDialog();
                    saveFileDialog.Filter           = "firmware files|*.sgl";
                    saveFileDialog.InitialDirectory = IniFileUtils.getProfileStringWithDefault("Setup", "LastFirmwareLocation", null);
                    saveFileDialog.FileName         = FirmwareLoader.getModelSaveFileString(FirmwareLoader.outputType) + "_" + flrl.SelectedVersion + ".sgl";

                    if (saveFileDialog.ShowDialog() == DialogResult.OK && saveFileDialog.FileName != null)
                    {
                        tempFile = saveFileDialog.FileName;
                    }
                    else
                    {
                        MessageBox.Show(StringsDict["No_file_location_specified"]);
                        SetLoadingState(false);
                        IsLoading = false;
                        return;
                    }
                }
                else
                {
                    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(flrl.SelectedURL), tempFile);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(StringsDict["Error"] + ": " + ex.Message, StringsDict["Error"], MessageBoxButtons.OK, MessageBoxIcon.Error);

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

                    SetLoadingState(false);
                    this.progressBarDwnl.Visible = false;
                    return;
                }
            }
            else
            {
                SetLoadingState(false);
            }
            return;
        }
Esempio n. 6
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);
            }
        }
Esempio n. 7
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);
            }
        }