/// <summary>Does the work in the managing <see cref="BackgroundWorker"/>. /// <para/>Iterates through each selected <see cref="Beatmap"/> and manages them, using <see cref="ManageBeatmap(Beatmap, DirectoryInfo, Bitmap[], ref HashSet{string}, bool, bool)"/> and returning the current progress between maps.</summary> /// <param name="Sender">The source of the event.</param> /// <param name="E">The <see cref="DoWorkEventArgs"/> instance containing the event data.</param> void BW_DoWork(object Sender, DoWorkEventArgs E) { BackgroundWorker Worker = (BackgroundWorker)Sender; (bool Specific, bool Resize, bool Backup, bool UseResources, FileInfo SingleBackgroundPath, DirectoryInfo BackgroundsFolderPath) = ((bool, bool, bool, bool, FileInfo, DirectoryInfo))E.Argument; Bitmap[] Backgrounds = Array.Empty <Bitmap>(); if (Specific) { if (SingleBackgroundPath != null && SingleBackgroundPath.Exists) { Backgrounds = new[] { new Bitmap(SingleBackgroundPath.FullName) }; } } else { if (!UseResources && BackgroundsFolderPath != null) { Backgrounds = BackgroundsFolderPath.GetFiles("*.png", "*.jpg", "*.jpeg", "*.bmp").Select(File => new Bitmap(File.FullName, true)).ToArray(); LogWindow.Log($"Found: {Backgrounds.Length} Files"); //return; } } List <object> Dirs = new List <object>(); Dispatcher.Invoke(() => { if (Backgrounds.Length == 0) { Backgrounds = BRP.GetActiveBackgrounds().ToArray(); } BWProgress.IsIndeterminate = false; Dirs = IndivListView.ListProperty; }, DispatcherPriority.Normal); HashSet <string> ManagedMedia = new HashSet <string>(); float DirCount = Dirs.Count; int FinishedDirs = 0; int FinishedSets = 0; long FinishedMaps = 0; foreach (object DirObject in Dirs) { DirectoryInfo Dir = (DirectoryInfo)DirObject; //LogWindow.Log($"Managing {Dir.FullName}"); try { foreach (Beatmap Beatmap in Dir.GetFiles("*.osu", SearchOption.TopDirectoryOnly).Select(FoundBeatmap => Beatmap.GetBeatmap(FoundBeatmap.ReadAllLines(), false, false, false, false, true, //We only care about background events, since those are the only things that will be affected. Note: To ensure rankings are still valid, ONLY EDIT EXTERNAL FILES; DO NOT EDIT THE .osu BEATMAP!!! false, false))) { //LogWindow.Log($"\tGot Beatmap: {Beatmap}"); try { ManageBeatmap(Beatmap, Dir, Backgrounds, ref ManagedMedia, Resize, Backup); } catch (Exception Ex) { Dispatcher.Invoke(() => ExceptionWindow.Catch(Ex), DispatcherPriority.Normal); } FinishedMaps++; if (E.Cancel) { E.Result = new WorkerResults(FinishedSets, FinishedMaps); return; } } FinishedSets++; if (E.Cancel) { E.Result = new WorkerResults(FinishedSets, FinishedMaps); return; } } catch (Exception Ex) { Dispatcher.Invoke(() => ExceptionWindow.Catch(Ex), DispatcherPriority.Normal); } Worker.ReportProgress((FinishedDirs / DirCount * 100.0f).CeilToWhole()); FinishedDirs++; } Worker.ReportProgress(100); E.Result = new WorkerResults(FinishedSets, FinishedMaps); }