コード例 #1
0
        // 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();
            }
        }
コード例 #2
0
 public static void NotifyBox(string msg, Color color, int durationInMilliseconds = 3000)
 {
     try
     {
         OsuMethods.osuNotificationMethod.Invoke(null, new object[] { msg, color, durationInMilliseconds, null });
     }
     catch (Exception e)
     {
         Bancho2.MessageBox(e.ToString() + e.GetType().ToString());
     }
 }
コード例 #3
0
 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();
     }
 }
コード例 #4
0
        private static void OnDownloadCompleted(object sender, AsyncCompletedEventArgs e)
        {
            try
            {
                lock (downloadLock)
                {
                    isDownloading = false;
                }

                if (e.Error != null)
                {
                    OsuNotifications.NotifyBoxError($"Failed to download beatmap due to an error.");
                    return;
                }

                OsuNotifications.NotifyBoxSuccess($"Download completed!");
                Process.Start(Path.Combine(Bancho2.osuPath, "osu!.exe"), Path.Combine(Bancho2.osuPath, "download.osz"));
            }
            catch (Exception ex)
            {
                new Thread(() => Bancho2.MessageBox(ex.ToString())).Start();
            }
        }