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; this.progressBar.Visible = false; FirmwareLoaderReleasesList flrl = new FirmwareLoaderReleasesList(result); if (DialogResult.Cancel != flrl.ShowDialog()) { tempFile = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".sgl"; 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(flrl.SelectedURL), 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 { enableUI(true); } }
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); } }