public static async void TryDownloadSong(string levelId, TaskCompletionSource <BeatmapLevelsModel.GetBeatmapLevelResult> tcs, CancellationToken cancellationToken, BeatmapLevelsModel beatmapLevelsModel) { try { IPreviewBeatmapLevel beatmap = await Downloader.DownloadSong(levelId, cancellationToken); if (beatmap is CustomPreviewBeatmapLevel customLevel) { Plugin.Log?.Debug($"Download was successful."); IBeatmapLevel beatmapLevel = await CustomLevelLoader(ref beatmapLevelsModel).LoadCustomBeatmapLevelAsync(customLevel, cancellationToken); UIHelper.RefreshUI(); tcs.TrySetResult(new BeatmapLevelsModel.GetBeatmapLevelResult(false, beatmapLevel)); } else { Plugin.Log?.Error($"beatmap:{beatmap?.GetType().Name} is not an CustomPreviewBeatmapLevel"); } } catch (OperationCanceledException) { Plugin.Log?.Debug($"Download was canceled."); tcs.TrySetCanceled(cancellationToken); return; } catch (Exception ex) { Plugin.Log?.Error($"Error downloading beatmap '{levelId}': {ex.Message}"); Plugin.Log?.Debug(ex); } tcs.TrySetResult(new BeatmapLevelsModel.GetBeatmapLevelResult(true, null)); Plugin.Log?.Debug($"Download was unsuccessful."); }
public static async Task TryDownloadSong(string levelId, CancellationToken cancellationToken, Action <bool> callback) { try { IPreviewBeatmapLevel?beatmap = await DownloadSong(levelId, cancellationToken); if (beatmap is CustomPreviewBeatmapLevel customLevel) { Plugin.Log?.Debug($"Download was successful."); callback(true); return; } else { Plugin.Log?.Error($"beatmap:{beatmap?.GetType().Name} is not a CustomPreviewBeatmapLevel"); } } catch (OperationCanceledException) { Plugin.Log?.Debug($"Download was canceled."); callback(false); return; } catch (Exception ex) { Plugin.Log?.Error($"Error downloading beatmap '{levelId}': {ex.Message}"); Plugin.Log?.Debug(ex); } Plugin.Log?.Debug($"Download was unsuccessful."); callback(false); }
private static async Task <IPreviewBeatmapLevel?> TryDownloadSongInternal(string levelId, CancellationToken cancellationToken) { Plugin.DebugLog($"TryDownloadSongInternal: {levelId}"); try { string?hash = Utils.LevelIdToHash(levelId); if (hash == null) { Plugin.Log?.Error($"Cannot parse a hash from level id '{levelId}'."); return(null); } IPreviewBeatmapLevel?beatmap = await DownloadSong(hash, cancellationToken); if (beatmap is CustomPreviewBeatmapLevel customLevel) { Plugin.Log?.Debug($"Download was successful."); return(beatmap); } else { Plugin.Log?.Error($"beatmap:{beatmap?.GetType().Name} is not a CustomPreviewBeatmapLevel"); } } catch (OperationCanceledException) { Plugin.Log?.Debug($"Download was canceled."); return(null); } catch (Exception ex) { Plugin.Log?.Error($"Error downloading beatmap '{levelId}': {ex.Message}"); Plugin.Log?.Debug(ex); } finally { CurrentDownloads.TryRemove(levelId, out _); } Plugin.Log?.Debug($"Download was unsuccessful."); return(null); }
public static bool IsDlcSong(IPreviewBeatmapLevel level) { return(level.GetType() == typeof(PreviewBeatmapLevelSO)); }