public static async Task <bool> TryRenewOsuCookies() { try // try renew { System.Net.CookieContainer _cookies = await Osu.LoginAndGetCookie(SettingManager.Get("officialOsuUsername"), SettingManager.Get("officialOsuPassword")); SettingManager.Set("officialOsuCookies", await CookieStoreSerializer.SerializeCookies(_cookies)); Osu.Cookies = _cookies; return(true); } catch (Osu.InvalidPasswordException) { MessageBoxResult fallback = MessageBox.Show("It seems like your osu! login password has changed. Press yes to fallback the session to Bloodcat for now and you can go update your password, or press no to permanently use Bloodcat. You will have to retry the download again either way.", "NexDirect - Download Error", MessageBoxButton.YesNo, MessageBoxImage.Error); if (fallback == MessageBoxResult.Yes) { // just fallback SettingManager.Set("useOfficialOsu", false, true); SettingManager.Set("fallbackActualOsu", true, true); return(false); } else { // disable perma SettingManager.Set("useOfficialOsu", false); SettingManager.Set("officialOsuCookies", null); SettingManager.Set("officialOsuUsername", ""); SettingManager.Set("officialOsuPassword", ""); return(false); } } }
public static async Task TestCookies() { System.Net.CookieContainer cookies = null; try { cookies = await CookieStoreSerializer.DeserializeCookies(SettingManager.Get("officialOsuCookies")); } catch { // Corrupted cookie store, deleting corruption SettingManager.Set("officialOsuCookies", null); cookies = new System.Net.CookieContainer(); } try { await Osu.CheckPassedLoginCookieElseUseNew(cookies, SettingManager.Get("officialOsuUsername"), SettingManager.Get("officialOsuPassword")); // store to parent & just persist them incase something new changed SettingManager.Set("officialOsuCookies", await CookieStoreSerializer.SerializeCookies(Osu.Cookies)); return; } catch (Osu.InvalidPasswordException) { MessageBoxResult cookiePrompt = MessageBox.Show("There was an error logging in to your account. Maybe you have changed your password, etc... to update that click NO and visit settings.\nClick YES to retry connection, click NO to fall back to Bloodcat for this session.", "NexDirect - Error", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (cookiePrompt == MessageBoxResult.Yes) { await TestCookies(); return; } SettingManager.Set("useOfficialOsu", false, true); SettingManager.Set("fallbackActualOsu", true, true); return; } catch (Exception ex) { MessageBox.Show("There was an error connecting to osu! servers, falling back to Bloodcat for this session...\n\n" + ex.ToString()); SettingManager.Set("useOfficialOsu", false, true); SettingManager.Set("fallbackActualOsu", true, true); return; } }
private async void loginButton_Click(object sender, EventArgs e) { loginButton.IsEnabled = false; // disable no spam plz try { System.Net.CookieContainer _cookies = await Osu.LoginAndGetCookie(usernameTextBox.Text, passwordPasswordBox.Password); SettingManager.Set("officialOsuCookies", await CookieStoreSerializer.SerializeCookies(_cookies)); SettingManager.Set("useOfficialOsu", true); //SettingManager.Set("fallbackActualOsu", true); SettingManager.Set("officialOsuUsername", usernameTextBox.Text); SettingManager.Set("officialOsuPassword", passwordPasswordBox.Password); _s.officialLoggedInAs.Content = "Currently logged in as: " + usernameTextBox.Text; MessageBox.Show("Logged in to osu! servers and login data saved."); Close(); return; } catch (Osu.InvalidPasswordException) { MessageBox.Show("You have specified an incorrect password. Please try again."); } catch (Exception ex) { MessageBox.Show("There was an error logging in to the osu! servers...\n\n" + ex); } loginButton.IsEnabled = true; }
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()}"); } }