예제 #1
0
        private void RandomButtom_Click(object sender, EventArgs e)
        {
            SongImg.Image   = null;
            SelectedBeatmap = 0;
            RandomNumber    = BM.Rng();

            string temp = BM.DownloadJson(ApiCode, RandomNumber);

            JsonText = JsonConvert.DeserializeObject <List <Beatmap> >(temp);

            ChangeMainText();

            string result     = Path.GetTempPath() + "OsuDesktopTmp\\" + RandomNumber + ".jpg";
            string BeatmapImg = "https://assets.ppy.sh/beatmaps/" + RandomNumber + "/covers/cover.jpg";

            using (WebClient wc = new WebClient())
            {
                try
                {
                    wc.DownloadFile(new Uri(BeatmapImg), result);
                }
                catch (WebException)
                {
                    SongImg.Image = SongImg.ErrorImage;
                }
                finally
                {
                    if (SongImg.Image != SongImg.ErrorImage)
                    {
                        SongImg.Image = Bitmap.FromFile(result);
                    }
                }
            }

            BM.CreateTempFolder();
        }