internal BeatmapDownloadHandler(MainWindow window, ImporterHolder importerHolder, BeatmapItem_Importer beatmapItemImporter, BeatmapListDownloadManager beatmapListDownloadManager, DownloadMirror mirror) { this.window = window; this.importerHolder = importerHolder; this.beatmapItemImporter = beatmapItemImporter; this.beatmapListDownloadManager = beatmapListDownloadManager; this.mirror = mirror; }
public static async void DownloadBeatmapSet(BeatmapSet set) { // check for already downloading if (DownloadManager.Downloads.Any(b => b.Set.Id == set.Id)) { MessageBox.Show("This beatmap is already being downloaded!"); return; } if (!checkAndPromptIfHaveMap(set)) { return; } // get dl obj BeatmapDownload download; if (!String.IsNullOrEmpty(SettingManager.Get("beatmapMirror"))) { // use mirror download = DownloadMirror.PrepareDownloadSet(set, SettingManager.Get("beatmapMirror")); } else if (!SettingManager.Get("fallbackActualOsu") && SettingManager.Get("useOfficialOsu")) { try { download = await Osu.PrepareDownloadSet(set, SettingManager.Get("novidDownload")); } catch (Osu.IllegalDownloadException) { MessageBoxResult bloodcatAsk = MessageBox.Show("Sorry, this map seems like it has been taken down from the official osu! servers due to a DMCA request to them. Would you like to check if a copy off Bloodcat is available, and if so download it?", "NexDirect - Mirror?", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (bloodcatAsk == MessageBoxResult.No) { return; } BeatmapSet newSet = await Bloodcat.TryResolveSetId(set.Id); if (newSet == null) { MessageBox.Show("Sorry, this map could not be found on Bloodcat. Download has been aborted.", "NexDirect - Could not find beatmap", MessageBoxButton.OK, MessageBoxImage.Error); return; } download = await Bloodcat.PrepareDownloadSet(set); } catch (Osu.CookiesExpiredException) { if (await TryRenewOsuCookies()) { download = await Osu.PrepareDownloadSet(set, SettingManager.Get("novidDownload")); } else { return; } } } else { try { download = await Bloodcat.PrepareDownloadSet(set); } catch (Bloodcat.BloodcatCaptchaException) { MessageBox.Show("It seems like Bloodcat has triggered CAPTCHA. Please click OK to verify and retry download..."); (new Dialogs.Captcha(set)).ShowDialog(); // persist those freshly baked cookies SettingManager.Set("bloodcatCookies", await CookieStoreSerializer.SerializeCookies(Bloodcat.Cookies)); DownloadBeatmapSet(set); // hard retry return; } } if (download == null) { return; } // start dl try { await DownloadManager.DownloadSet(download); if (download.Cancelled) { return; } if (SettingManager.Get("launchOsu") && Process.GetProcessesByName("osu!").Length > 0) { string newPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, download.FileName); File.Move(download.TempPath, newPath); // rename to .osz Process.Start(Path.Combine(SettingManager.Get("osuFolder"), "osu!.exe"), newPath); } else { string path = Path.Combine(mw.osuSongsFolder, download.FileName); if (File.Exists(path)) { File.Delete(path); // overwrite if exist } File.Move(download.TempPath, path); } AudioManager.PlayWavBytes(DownloadCompleteSound, (float)SettingManager.Get("previewVolume")); (new Dialogs.DownloadComplete(set)).Show(); } catch (Exception ex) { MessageBox.Show($"An error has occured whilst downloading {set.Title} ({set.Mapper}).\n\n{ex.ToString()}"); } }