private void backgroundWorkerProcess_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; titles.Clear(); if (e.Argument is ValueTuple<Worker, string[]> argumentFile) { if (argumentFile.Item1 == Worker.File && argumentFile.Item2 is string[] files) { List<string> filenames = files.ToList(); filenames.Sort(); Process.log?.WriteLine("{0} files selected", filenames.Count); worker.ReportProgress(-1, String.Format("Opening {0} files", filenames.Count)); int count = filenames.Count, index = 0; foreach (var filename in filenames) { if (worker.CancellationPending) break; worker.ReportProgress(100 * index++ / count, filename); Title title = Process.processFile(filename); if (title != null) { titles.Add(title); } } if (!worker.CancellationPending) { worker.ReportProgress(100, ""); } Process.log?.WriteLine("\n{0} titles processed", titles.Count); } } else if (e.Argument is ValueTuple<Worker, string> argumentPath) { if (argumentPath.Item1 == Worker.Directory && argumentPath.Item2 is string path) { List<string> filenames = Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories) .Where(filename => filename.ToLower().EndsWith(".xci") || filename.ToLower().EndsWith(".nsp") || filename.ToLower().EndsWith(".nro")).ToList(); filenames.Sort(); Process.log?.WriteLine("{0} files selected", filenames.Count); worker.ReportProgress(-1, String.Format("Opening {0} files from directory {1}", filenames.Count, path)); int count = filenames.Count, index = 0; foreach (var filename in filenames) { if (worker.CancellationPending) break; worker.ReportProgress(100 * index++ / count, filename); Title title = Process.processFile(filename); if (title != null) { titles.Add(title); } } if (!worker.CancellationPending) { worker.ReportProgress(100, ""); } Process.log?.WriteLine("\n{0} titles processed", titles.Count); } else if (argumentPath.Item1 == Worker.SDCard && argumentPath.Item2 is string pathSd) { List<FsTitle> fsTitles = Process.processSd(pathSd); if (fsTitles != null) { int count = fsTitles.Count, index = 0; foreach (var fsTitle in fsTitles) { if (worker.CancellationPending) break; worker.ReportProgress(100 * index++ / count, fsTitle.MainNca?.Filename); Title title = Process.processTitle(fsTitle); if (title != null) { titles.Add(title); } } if (!worker.CancellationPending) { worker.ReportProgress(100, ""); } Process.log?.WriteLine("\n{0} titles processed", titles.Count); } else { worker.ReportProgress(0, ""); string error = "SD card \"Contents\" directory could not be found"; Process.log?.WriteLine(error); e.Result = error; return; } } } e.Result = titles; }