Exemple #1
0
        private async Task DownloadPlaylistAsync()
        {
            popupModalsController.ShowOkModal(rootTransform, "", CancelButtonPressed, "Cancel");

            UpdateMissingSongs();
            if (MissingSongs == null)
            {
                popupModalsController.OkText       = "Error: The selected playlist cannot be downloaded.";
                popupModalsController.OkButtonText = "Ok";
                return;
            }

            popupModalsController.OkText = string.Format("{0}/{1} songs downloaded", 0, MissingSongs.Count);
            tokenSource.Dispose();
            tokenSource = new CancellationTokenSource();

            preferCustomArchiveURL = true;
            bool shownCustomArchiveWarning = false;

            for (int i = 0; i < MissingSongs.Count; i++)
            {
                if (preferCustomArchiveURL && MissingSongs[i].TryGetCustomData("customArchiveURL", out object outCustomArchiveURL))
                {
                    string customArchiveURL = (string)outCustomArchiveURL;
                    string identifier       = PlaylistLibUtils.GetIdentifierForPlaylistSong(MissingSongs[i]);
                    if (identifier == "")
                    {
                        continue;
                    }

                    if (!shownCustomArchiveWarning)
                    {
                        shownCustomArchiveWarning = true;
                        popupModalsController.ShowYesNoModal(rootTransform, "This playlist uses mirror download links. Would you like to use them?",
                                                             CustomArchivePreferred, noButtonPressedCallback: CustomArchiveNotPreferred, animateParentCanvas: false);
                        await downloadPauseSemaphore.WaitAsync();

                        if (!preferCustomArchiveURL)
                        {
                            i--;
                            continue;
                        }
                    }
                    await DownloaderUtils.instance.BeatmapDownloadByCustomURL(customArchiveURL, identifier, tokenSource.Token);
                }
                else if (!string.IsNullOrEmpty(MissingSongs[i].Hash))
                {
                    await DownloaderUtils.instance.BeatmapDownloadByHash(MissingSongs[i].Hash, tokenSource.Token);
                }
                else if (!string.IsNullOrEmpty(MissingSongs[i].Key))
                {
                    string hash = await DownloaderUtils.instance.BeatmapDownloadByKey(MissingSongs[i].Key.ToLower(), tokenSource.Token);

                    if (!string.IsNullOrEmpty(hash))
                    {
                        MissingSongs[i].Hash = hash;
                    }
                }
                popupModalsController.OkText = string.Format("{0}/{1} songs downloaded", i + 1, MissingSongs.Count);
            }

            popupModalsController.OkText       = "Download Complete!";
            popupModalsController.OkButtonText = "Ok";

            parentManager.StorePlaylist((BeatSaberPlaylistsLib.Types.IPlaylist)selectedPlaylist);

            downloadingBeatmapLevelCollections = Accessors.AnnotatedBeatmapLevelCollectionsAccessor(ref annotatedBeatmapLevelCollectionsViewController).ToArray();
            downloadingBeatmapCollectionIdx    = annotatedBeatmapLevelCollectionsViewController.selectedItemIndex;
            SongCore.Loader.Instance.RefreshSongs(false);
            LevelFilteringNavigationController_UpdateSecondChildControllerContent.SecondChildControllerUpdatedEvent += LevelFilteringNavigationController_UpdateSecondChildControllerContent_SecondChildControllerUpdatedEvent;
        }
Exemple #2
0
        private void DeletePlaylist()
        {
            parentManager.DeletePlaylist((BeatSaberPlaylistsLib.Types.IPlaylist)selectedPlaylist);
            int selectedIndex = annotatedBeatmapLevelCollectionsViewController.selectedItemIndex;
            List <IAnnotatedBeatmapLevelCollection> annotatedBeatmapLevelCollections = Accessors.AnnotatedBeatmapLevelCollectionsAccessor(ref annotatedBeatmapLevelCollectionsViewController).ToList();

            annotatedBeatmapLevelCollections.RemoveAt(selectedIndex);
            selectedIndex--;
            LevelCollectionTableViewUpdatedEvent?.Invoke(annotatedBeatmapLevelCollections.ToArray(), selectedIndex < 0 ? 0 : selectedIndex);
        }