private void ApplyButton_Click(object sender, EventArgs e) { if (OsuFolderBrowserDialog.SelectedPath == string.Empty) { MessageBox.Show("Please select your osu! folder before applying changes.", "Error", MessageBoxButtons.OK); return; } ApplyButton.Enabled = false; CurrentStatusPanel.BackColor = Color.Yellow; BackgroundWorkerThread.RunWorkerAsync(); }
private void BackgroundWorkerThread_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { string imagePath = $"{OsuConfig.GetValue("BeatmapDirectory")}{Path.DirectorySeparatorChar}bg.jpg"; int beatmapsSkipped = 0; if (BackgroundPreviewPanel.BackgroundImage != null) { BackgroundPreviewPanel.BackgroundImage.Save(imagePath, ImageFormat.Jpeg); } else { var image = new Bitmap(1920, 1080); var filledImage = Graphics.FromImage(image); using (SolidBrush B = new SolidBrush(Color.FromArgb(255, BackgroundPreviewPanel.BackColor))) filledImage.FillRectangle(B, 0, 0, image.Width, image.Height); try { image.Save(imagePath); } catch (Exception) { Console.WriteLine("Error: Could not save solid color bitmap"); } } var beatmaps = new Code.osu.Beatmaps(OsuConfig.GetValue("BeatmapDirectory"), imagePath); while (!beatmaps.ReplacementFinished()) { BackgroundWorkerThread.ReportProgress(beatmaps.GetReplacementProgress(), new Code.osu.BeatmapState() { CurrentBeatmap = beatmaps.GetCurrentBeatmap() }); if (!beatmaps.ReplaceNext(RestoreBeatmapsCheck.Checked)) { beatmapsSkipped++; } } BackgroundWorkerThread.ReportProgress(100, new Code.osu.BeatmapState() { CurrentBeatmap = $"Completed - [{beatmaps.ReplacedBeatmapImages}] succeeded, [{beatmaps.GetSkippedFolders()}] skipped folders, [{beatmaps.BackgroundlessBeatmaps}] without backgrounds" }); }
public Class1(BackgroundWorkerThread worker) { _backgroundWorker = worker; // rest of constructor }