private static void SetProgress(FirmFinder owner, Progress form, int value, string text = "") { owner.Invoke(new Action(() => { form.SetProgress(value, text); })); }
public Form1() { InitializeComponent(); firmFinder = new FirmFinder(this); ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(delegate { return(true); }); this.FormClosing += delegate { try { proxyserver.Stop(); Environment.Exit(Environment.ExitCode); } catch { } }; try { proxyserver.CertificateManager.CreateRootCertificate(true); proxyserver.CertificateManager.TrustRootCertificate(true); proxyserver.ServerCertificateValidationCallback += Proxyserver_ServerCertificateValidationCallback; proxyserver.BeforeRequest += Proxyserver_BeforeRequest; proxyserver.BeforeResponse += Proxyserver_BeforeResponse; proxyserver.AddEndPoint(endpoint); proxyserver.Start(); } catch (Exception ex) { textBox3.AppendText(ex.StackTrace); //MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } textBox3.ScrollBars = ScrollBars.Both; textBox3.Visible = false; textBox1.TextChanged += delegate { string text = textBox1.Text; int where = text.IndexOf("/full"); if (where != -1) { textBox1.Text = text.Substring(0, ++where); } }; textBox4.TextChanged += delegate { string text = textBox4.Text; int where = text.IndexOf("/full"); if (where != -1) { textBox4.Text = text.Substring(0, ++where); } }; textBox7.TextChanged += delegate { string text = textBox7.Text; int where = text.IndexOf("/full"); if (where != -1) { textBox7.Text = text.Substring(0, ++where); } }; }
public static void GetFirmwareDetails(FirmFinder form, string url, ref RomDetailsClass romDetails, int DetailsKind) { string VersionID = GetVersionID(url); if (DetailsKind == 0 || DetailsKind == 2) { romDetails.ApprovedForInstall = ApprovedForInstallation(VersionID); if (romDetails.ApprovedForInstall) { romDetails.FirmName = StaticFirmName; } } if (DetailsKind == 0) { return; } Progress progress = null; bool Finished = false; Thread thisthread = Thread.CurrentThread; form.Invoke(new Action(() => { progress = new Progress("Getting Package URL"); progress.FormClosing += delegate { if (!Finished) { thisthread.Abort(); } }; progress.Show(form); })); SetProgress(form, progress, 5); string Package = GetPackageURL(url); SetProgress(form, progress, 30, "Initial Request To ZIP"); HTTPStream httpstream = new HTTPStream(Package); ZipInputStream stream = new ZipInputStream(httpstream); SetProgress(form, progress, 40, "Exploring ZIP File..."); int count = 0; while (true) { ZipEntry entry = stream.GetNextEntry(); if (entry != null) { count += 2; if (count > 60) { count = 30; } SetProgress(form, progress, 40 + count, entry.Name); if (entry.Name.Contains("SOFTWARE_VER_LIST.mbn")) { int read = 4096; byte[] buffer = new byte[read]; string content = ""; while ((read = stream.Read(buffer, 0, buffer.Length)) > 0) { content += Encoding.UTF8.GetString(buffer, 0, read); } romDetails.SupportedVersions = content.Split('\n'); break; } else { stream.CloseEntry(); } } else { MessageBox.Show("Seems like I couldn't load the data :(", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); break; } } Finished = true; progress.Close(); }