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)}"); }
public static async Task <string> DownloadAsset(string link, string folder, string fileName = null, string displayName = null, bool showNotification = true, bool beatsaver = false, bool preferContentDisposition = false) { if (string.IsNullOrEmpty(BeatSaberPath)) { ModAssistant.Utils.SendNotify((string)Application.Current.FindResource("OneClick:InstallDirNotFound")); } try { var parentDir = Path.Combine(BeatSaberPath, folder); Directory.CreateDirectory(parentDir); if (string.IsNullOrEmpty(fileName)) { fileName = new Uri(link).Segments.Last(); } if (beatsaver) { fileName = WebUtility.UrlDecode(Path.Combine(parentDir, fileName)); await BeatSaver.Download(link, fileName); } else { fileName = await ModAssistant.Utils.Download(link, parentDir, fileName, preferContentDisposition); } if (string.IsNullOrEmpty(displayName)) { displayName = Path.GetFileNameWithoutExtension(fileName); } if (showNotification) { SetMessage(string.Format((string)Application.Current.FindResource("OneClick:InstalledAsset"), displayName)); } return(fileName); } catch { SetMessage((string)Application.Current.FindResource("OneClick:AssetInstallFailed")); App.CloseWindowOnFinish = false; return(null); } }