// The backing type of enum is int, and it hasn't been changed in the linktype enum. // passedEnum: Link type // passedInt: ID public static void BeatmapDownloadHandler(int passedEnum, int passedInt) { var letter = GetUrlLetter(passedEnum); if (letter != 'b' && letter != 's') { Process.Start($"https://osu.ppy.sh/forum/t/{letter}/{passedInt}"); return; } try { lock (downloadLock) { if (isDownloading) { return; } isDownloading = true; } new Thread(() => { OsuNotifications.NotifyBoxAlert($"{letter} | {passedInt}"); string data; using (WebClient http = new WebClient()) { data = http.DownloadString(String.Format(OsuUrls.DIRECT_SEARCH_SET, Bancho2.username, Bancho2.password, letter, passedInt)); } var split = data.Split('|'); var setId = split[0].Split('.')[0]; using (WebClient download = new WebClient()) { download.DownloadProgressChanged += OnProgressChanged; download.DownloadFileCompleted += OnDownloadCompleted; download.DownloadFileAsync(new Uri(String.Format(OsuUrls.BEATMAP_DOWNLOAD, setId, Bancho2.username, Bancho2.password)), Path.Combine(Bancho2.osuPath, "download.osz")); } }).Start(); return; } catch (Exception e) { lock (downloadLock) { isDownloading = false; } new Thread(() => Bancho2.MessageBox(e.ToString())).Start(); } }
private static void OnProgressChanged(object sender, DownloadProgressChangedEventArgs e) { try { OsuNotifications.NotifyBoxAlert($"Download {e.ProgressPercentage}% complete", 1000); } catch (Exception ex) { new Thread(() => Bancho2.MessageBox(ex.ToString())).Start(); } }