Exemple #1
0
        public static async Task DownloadFrom(string file)
        {
            CreatePlaylistsFolder();

            if (Path.Combine(BeatSaberPath, PlaylistsFolder) != Path.GetDirectoryName(file))
            {
                string destination = Path.Combine(BeatSaberPath, PlaylistsFolder, Path.GetFileName(file));
                File.Copy(file, destination, true);
            }

            int Errors  = 0;
            int Minimum = 0;
            int Value   = 0;

            Playlist playlist = JsonSerializer.Deserialize <Playlist>(File.ReadAllText(file));
            int      Maximum  = playlist.songs.Length;

            foreach (Playlist.Song song in playlist.songs)
            {
                API.BeatSaver.BeatSaverMap response = new BeatSaver.BeatSaverMap();
                if (!string.IsNullOrEmpty(song.hash))
                {
                    response = await BeatSaver.GetFromHash(song.hash, false);
                }
                else if (!string.IsNullOrEmpty(song.key))
                {
                    response = await BeatSaver.GetFromKey(song.key, false);
                }
                Value++;

                if (response.Success)
                {
                    Utils.SetMessage($"{string.Format((string)Application.Current.FindResource("Options:InstallingPlaylist"), TextProgress(Minimum, Maximum, Value))} {response.Name}");
                }
                else
                {
                    Utils.SetMessage($"{string.Format((string)Application.Current.FindResource("Options:FailedPlaylistSong"), song.songName)}");
                    ModAssistant.Utils.Log($"Failed installing BeatSaver map: {song.songName} | {song.key} | {song.hash} | ({response?.response?.ratelimit?.Remaining})");
                    App.CloseWindowOnFinish = false;
                    await Task.Delay(3 * 1000);

                    Errors++;
                }
            }
            Utils.SetMessage($"{string.Format((string)Application.Current.FindResource("Options:FinishedPlaylist"), Errors, playlist.playlistTitle)}");
        }