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 SysSelectRadio_CheckedChanged(object sender, EventArgs e) { WebClient titlelist = new WebClient(); String cd = Path.GetDirectoryName(Application.ExecutablePath); yls = null; RadioButton chk = panel1.Controls.OfType <RadioButton>().FirstOrDefault(ch => ch.Checked); if (chk == null) { return; } switch (chk.Name) { case "radioButton1": titlelist.DownloadFile("http://yls8.mtheall.com/ninupdates/titlelist.php?sys=ktr&csv=1", cd + "\\titlelist.csv"); break; case "radioButton2": case "radioButton3": titlelist.DownloadFile("http://yls8.mtheall.com/ninupdates/titlelist.php?sys=ctr&csv=1", cd + "\\titlelist.csv"); break; default: MessageBox.Show("Well, this shouldn't be happening!\r\nDeveloper! " + "Please update Form1.cs @ SysSelectRadio_CheckedChanged!\r\n\r\nThanks! :D", "Developer error", MessageBoxButtons.OK, MessageBoxIcon.Error); break; } if (File.Exists(cd + "\\titlelist.csv")) { yls = YLS.Import(cd + "\\titlelist.csv"); } }
private void pictureBox1_Click(object sender, EventArgs e) { t_titleid.Text = t_titleid.Text.Trim(); t_version.Text = t_version.Text.Trim(); if (t_titleid.Text.Length == 0 || t_version.Text.Length == 0) { MessageBox.Show("Please enter a Firmware or Title to download;" + "Ex: 8.1.0-23 ---- USA; Or 00000000000 ---- v1024 "); return; } if (c_cia.Checked && !File.Exists("make_cdn_cia.exe")) { MessageBox.Show("Error: make_cdn_cia.exe can't be found in the working directory!\r\n" + "This option will be unavailable while make_cdn_cia.exe is not found", "File not found", MessageBoxButtons.OK, MessageBoxIcon.Error); c_cia.Checked = false; } String cd = Path.GetDirectoryName(Application.ExecutablePath); 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; } } if (t_titleid.Text.Contains(".")) { string firmw = t_titleid.Text; string reg = t_version.Text; Match match = Regex.Match(firmw, @"(\d+)\.(\d+)(\.(\d+))?(-(\d+))?([a-zA-Z])?"); if (!match.Success) { MessageBox.Show("Invalid firmware string format!"); return; } firmw = (match.Groups[1] + "." + match.Groups[2] + "." + (match.Groups[4].Success ? match.Groups[4].ToString() : "0") + "-" + (match.Groups[6].Success ? match.Groups[6].ToString() : "999")); t_titleid.Text = firmw; t_titleid.Update(); switch (reg.ToUpper()) { case "EUR": reg = "E"; break; case "USA": reg = "U"; break; case "JPN": reg = "J"; break; case "TWN": reg = "T"; break; case "CHN": reg = "C"; break; case "KOR": reg = "K"; break; } t_version.Text = reg; t_version.Update(); log(DateTime.Now + " Downloading Firmware: " + firmw + reg); notifyIcon1.BalloonTipText = "Downloading Firmware: " + firmw + reg; notifyIcon1.ShowBalloonTip(1); firmwdownload(firmw, reg); } else { string title = t_titleid.Text; string version = t_version.Text; if (version[0] == 'v') { version = version.Substring(1); t_version.Text = version; t_version.Update(); } singledownload(title, version); } }