private void backgroundWorkerProcess_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e) { if (e.Result is List <Title> titles) { reloadData(); ArrayOfTitle history = new ArrayOfTitle { description = DateTime.Now.ToString("dd MMMM yyyy HH:mm:ss"), title = titles.ToList(), }; Common.History.Default.Titles.Add(history); if (Common.History.Default.Titles.Count > Common.HISTORY_SIZE) { Common.History.Default.Titles.RemoveRange(0, Common.History.Default.Titles.Count - Common.HISTORY_SIZE); } Common.History.Default.Save(); foreach (ToolStripMenuItem item in historyToolStripMenuItem.DropDownItems) { item.Checked = false; } ToolStripMenuItem menuItem = new ToolStripMenuItem { Name = String.Format("history{0}ToolStripMenuItem", Common.History.Default.Titles.Count - 1), Text = String.Format("{0} ({1} files)", history.description, history.title.Count), CheckOnClick = true, }; menuItem.Click += new System.EventHandler(this.historyToolStripMenuItem_Click); menuItem.Checked = true; historyToolStripMenuItem.DropDownItems.Add(menuItem); while (historyToolStripMenuItem.DropDownItems.Count > Common.HISTORY_SIZE) { historyToolStripMenuItem.DropDownItems.RemoveAt(0); } toolStripStatusLabel.Text = String.Format("{0} files", titles.Count); progressDialog.StopProgressDialog(); Activate(); } else if (e.Result is string error) { progressDialog.StopProgressDialog(); MessageBox.Show(String.Format("{0}.", error), Application.ProductName); } }
public static List <Title> processHistory(int index = -1) { ArrayOfTitle history = index != -1 ? Common.History.Default.Titles.ElementAtOrDefault(index) : Common.History.Default.Titles.LastOrDefault(); List <Title> titles = history?.title?.ToList() ?? new List <Title>(); foreach (var title in titles) { string titleID = title.type == TitleType.AddOnContent ? title.titleID : title.baseTitleID ?? ""; if (latestVersions.TryGetValue(titleID, out uint version)) { if (title.version > version) { latestVersions[titleID] = title.version; } } else { latestVersions.Add(titleID, title.version); } } return(titles); }
private void updateVersionListToolStripMenuItem_Click(object sender, EventArgs e) { progressDialog = (IProgressDialog) new ProgressDialog(); progressDialog.StartProgressDialog(Handle, "Downloading version list"); progressDialog.SetLine(2, String.Format("Downloading from {0}", Common.HAC_VERSIONLIST_URI), true, IntPtr.Zero); if (Process.updateVersionList()) { uint count = 0; foreach (var title in titles) { if (title.type == TitleType.Application || title.type == TitleType.Patch) { if (Process.versionList.TryGetValue(title.baseTitleID, out uint version)) { if (title.latestVersion == unchecked ((uint)-1) || version > title.latestVersion) { title.latestVersion = version; count++; } } } } if (count != 0) { reloadData(); ArrayOfTitle history = new ArrayOfTitle { description = DateTime.Now.ToString("dd MMMM yyyy HH:mm:ss"), title = titles.ToList(), }; Common.History.Default.Titles.Add(history); if (Common.History.Default.Titles.Count > Common.HISTORY_SIZE) { Common.History.Default.Titles.RemoveRange(0, Common.History.Default.Titles.Count - Common.HISTORY_SIZE); } Common.History.Default.Save(); while (historyToolStripMenuItem.DropDownItems.Count > Common.HISTORY_SIZE) { historyToolStripMenuItem.DropDownItems.RemoveAt(0); } } Process.log?.WriteLine("\n{0} titles have updated version", count); progressDialog.StopProgressDialog(); Activate(); MessageBox.Show(String.Format("{0} titles have updated version", count), Application.ProductName); } else { progressDialog.StopProgressDialog(); Activate(); MessageBox.Show("Failed to download version list", Application.ProductName); } }