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; }
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); } }