private void firmwdownload(string firm, string reg) { string cd = Path.GetDirectoryName(Application.ExecutablePath); if(reg == null || reg.Length != 1 || !yls.regions.ContainsKey(reg[0])) { MessageBox.Show("Invalid region! Valid regions are:\r\n" + String.Join(", ", yls.regions.Keys.ToArray()), "Invalid region", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //better be safe'n'paranoid if(yls == null) if(File.Exists(cd + "\\titlelist.csv")) yls = YLS.Import(cd + "\\titlelist.csv"); else { MessageBox.Show("Can't read title list, file doesn't exist.", "File not found", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } WebClient titlelist = new WebClient(); Directory.CreateDirectory(cd + "\\" + t_titleid.Text); YLS_Sysver sys = new YLS_Sysver(); sys.label = firm; foreach(YLS_Title t in yls.regions[reg[0]]) { YLS_Titlever optimal = null; foreach(YLS_Titlever tv in t.ver) { if(tv.sysver == sys) { optimal = tv; break; } if(tv.sysver < sys && (optimal == null || tv.sysver > optimal.sysver)) optimal = tv; } if(optimal == null) continue; singledownload(t.id.ToString("X16"), optimal.version.ToString()); Application.DoEvents(); } log("\r\n" + DateTime.Now + " Firmware Download complete!"); notifyIcon1.BalloonTipText = "Firmware download complete!"; notifyIcon1.ShowBalloonTip(1); }
private void materialFlatButton1_Click(object sender, EventArgs e) { b_download.Enabled = false; cancel = false; t_log.Clear(); if (working) { cancel = true; sd.stahp(); b_download.Text = "BEGIN DOWNLOAD"; b_download.Enabled = true; return; } t_titleid.Text = t_titleid.Text.Trim(); Match match = Regex.Match(t_titleid.Text, @"(\d+)\.(\d+)(\.(\d+))?(-(\d+))?([a-zA-Z])+"); if (match.Success) { if (yls == null) { log("Checking title database, please wait..."); String csvname = sysarr[selsys] + ".csv"; if (sd.syncDown(ninupdate + sysarr[selsys], csvname)) { yls = YLS.Import(csvname); } else { if (File.Exists(csvname)) { MessageBox.Show("Can't update titlelist! The current (possibly older) titlelist will be used instead.", "Can't update titlelist", MessageBoxButtons.OK, MessageBoxIcon.Error); yls = YLS.Import("titlelist.csv"); } else { MessageBox.Show("Can't acquire the title list!\r\n" + "You can still download titles, but firmware downloading is not possible, thus the downloading will be aborted.", "Can't update titlelist", MessageBoxButtons.OK, MessageBoxIcon.Error); b_download.Enabled = true; return; } } } YLS_Sysver firmw = new YLS_Sysver() { label = (match.Groups[1] + "." + match.Groups[2] + "." + (match.Groups[4].Success ? match.Groups[4].ToString() : "9") + "-" + (match.Groups[6].Success ? match.Groups[6].ToString() : "999")) }; String region = match.Groups[7].ToString().ToUpper(); t_titleid.Text = firmw + region; t_titleid.Update(); log("Downloading Firmware: " + firmw + region); b_download.Enabled = true; working = true; b_download.Text = "CANCEL"; firmwdownload(firmw, region[0]); working = false; b_download.Text = "BEGIN DOWNLOAD"; return; } match = Regex.Match(t_titleid.Text, @"(0-9a-fA-F]{16})([\s_]*v?(\d+))?"); if (match.Success) { ulong title = Convert.ToUInt64(match.Groups[1].ToString(), 16); int version = int.Parse(match.Groups[3].ToString()); b_download.Enabled = true; working = true; b_download.Text = "CANCEL"; singledownload(title, version); working = false; b_download.Text = "BEGIN DOWNLOAD"; return; } else { MessageBox.Show("Your input didn't match as a firmware version, nor as a title ID.\r\n" + "Please see the little question mark above the textbox for more help.", "Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Error); } b_download.Enabled = true; }
private void firmwdownload(YLS_Sysver sys, char region) { if (!yls.regions.ContainsKey(region)) { StringBuilder sb = new StringBuilder(); foreach (char chr in yls.regions.Keys) { sb.Append(chr); sb.Append(", "); } if (sb.Length > 2) { sb.Remove(sb.Length - 3, 2); } MessageBox.Show("Invalid region! Valid regions are:\r\n" + sb.ToString(), "Invalid region", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Directory.CreateDirectory(sys.label + region); sd.op.setProgValue(1); sd.op.setProgMax(yls.regions[region].Count); Boolean showerror = true; int errorn = 0; foreach (YLS_Title t in yls.regions[region]) { sd.op.setProgValue(sd.op.getProgValue() + 1); YLS_Titlever optimal = null; foreach (YLS_Titlever tv in t.ver) { if (tv.sysver == sys) { optimal = tv; break; } if (tv.sysver < sys && (optimal == null || tv.sysver > optimal.sysver)) { optimal = tv; } } if (optimal == null) { continue; } if (!singledownload(t.id, optimal.version) && !cancel) { errorn++; if (!showerror || check_noerr.Checked) { continue; } if (sd.ex != null) { MessageBox.Show(printstack(sd.ex), "Exception dump", MessageBoxButtons.OK, MessageBoxIcon.Error); } DialogResult dr = MessageBox.Show("Do you want to dismiss further errors?", "Error", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); switch (dr) { case System.Windows.Forms.DialogResult.Yes: showerror = false; break; case System.Windows.Forms.DialogResult.No: continue; default: return; } } if (cancel) { return; } } log("Firmware downloading finished with " + (errorn == 0 ? "no" : errorn.ToString()) + " error" + (errorn == 1 ? "" : "s")); if (!check_noerr.Checked) { MessageBox.Show("Firmware downloading finished with " + errorn + " error" + (errorn == 1 ? "" : "s") + (errorn == 0 ? ". Yay! ^^" : " :("), "Download completed", MessageBoxButtons.OK, (errorn == 0) ? MessageBoxIcon.Information : MessageBoxIcon.Error); } sd.op.setProgValue(0); sd.op.setSubValue(0); sd.op.setProgMax(1); sd.op.setSubMax(1); if (_3DNUS_Material_Edition.Properties.Settings.Default.dev_auto_dump_log == "1") { if (_3DNUS_Material_Edition.Properties.Settings.Default.dev_dump_info == "1") { if (!File.Exists("LOG_DUMP.log")) { File.Delete(cd + "LOG_DUMP.log"); } File.WriteAllText(cd + "\\LOG_DUMP_" + DateTime.Now.ToString("M_d_yyyy_HH_mm_ss", CultureInfo.InvariantCulture) + ".log", "--Log Dump Start--" + "\r\n" + "\r\nSystemOS: " + Environment.OSVersion.VersionString + "\r\n" + "\r\nProgram Version: " + Application.ProductVersion + "\r\n" + "\r\nDebug State: " + "Unknown" + "\r\n" + "\r\nTime Dumped: " + DateTime.Now + "\r\n" + "\r\n---------------------------------------" + "\r\n" + t_log.Text); t_log.Text += "\r\n\r\nThe Log was Dumped Sucessfully!"; } else { if (!File.Exists("LOG_DUMP.log")) { File.Delete(cd + "LOG_DUMP.log"); } File.WriteAllText(cd + "\\LOG_DUMP_" + DateTime.Now.ToString("M_d_yyyy_HH_mm_ss", CultureInfo.InvariantCulture) + ".log", t_log.Text); t_log.Text += "\r\n\r\nThe Log was Dumped Sucessfully!"; } } }