示例#1
0
 private void Loader_SongsLoadedEvent(SongCore.Loader arg1, Dictionary <string, CustomPreviewBeatmapLevel> arg2)
 {
     if (!PluginUI.instance.moreSongsButton.Interactable)
     {
         PluginUI.instance.moreSongsButton.Interactable = true;
     }
 }
示例#2
0
        public void SongsLoaded(SongCore.Loader sender, Dictionary <string, CustomPreviewBeatmapLevel> levels)
        {
            if (_multiplayerButton != null)
            {
                _multiplayerButton.interactable = true;
            }

            SongInfo.GetOriginalLevelHashes();
        }
示例#3
0
 public void SongCore_SongsLoadedEvent(SongCore.Loader sender, Dictionary <string, CustomPreviewBeatmapLevel> levels)
 {
     try
     {
         PlaylistsCollection.MatchSongsForAllPlaylists(true);
     }
     catch (Exception e)
     {
         Logger.Exception("Unable to match songs for all playlists! Exception: " + e);
     }
 }
 /// <summary>
 /// Only gets called once during boot of BeatSaber.
 /// </summary>
 /// <param name="loader"></param>
 /// <param name="levels"></param>
 private void OnSongLoaderLoadedSongs(SongCore.Loader loader, ConcurrentDictionary <string, CustomPreviewBeatmapLevel> levels)
 {
     Logger.Trace("OnSongLoaderLoadedSongs-SongBrowserApplication()");
     try
     {
         _songBrowserUI.UpdateLevelDataModel();
         _songBrowserUI.RefreshSongList();
     }
     catch (Exception e)
     {
         Logger.Exception("Exception during OnSongLoaderLoadedSongs: ", e);
     }
 }
示例#5
0
        /// <summary>
        /// When a downloaded song is downloaded
        /// </summary>
        /// <param name="p_Loader">Loader instance</param>
        /// <param name="p_Maps">All loaded songs</param>
        private void OnDownloadedSongLoaded(SongCore.Loader p_Loader, ConcurrentDictionary <string, CustomPreviewBeatmapLevel> p_Maps)
        {
            /// Remove callback
            SongCore.Loader.SongsLoadedEvent -= OnDownloadedSongLoaded;

            /// Avoid refresh if not active view anymore
            if (!CanBeUpdated)
            {
                return;
            }

            StartCoroutine(PlayDownloadedLevel());
        }
示例#6
0
        /// <summary>
        /// When a downloaded song is downloaded
        /// </summary>
        /// <param name="p_Loader">Loader instance</param>
        /// <param name="p_Maps">All loaded songs</param>
        private void OnDownloadedSongLoaded(SongCore.Loader p_Loader, ConcurrentDictionary <string, CustomPreviewBeatmapLevel> p_Maps)
        {
            /// Remove callback
            SongCore.Loader.SongsLoadedEvent -= OnDownloadedSongLoaded;

            /// Avoid refresh if not active view anymore
            if (!isInViewControllerHierarchy)
            {
                return;
            }

            HMMainThreadDispatcher.instance.Enqueue(() =>
            {
                /// Reselect the cell
                PlaySong();

                /// Hide loading modal
                HideLoadingModal();
            });
        }
示例#7
0
 private void PlayNow_SongsLoaded(SongCore.Loader arg1, Dictionary <string, CustomPreviewBeatmapLevel> arg2)
 {
     SongCore.Loader.SongsLoadedEvent -= PlayNow_SongsLoaded;
     roomInfo.selectedSong.UpdateLevelId();
     PlayNow_Pressed();
 }
示例#8
0
 private void Loader_SongsLoadedEvent(SongCore.Loader arg1, Dictionary <string, CustomPreviewBeatmapLevel> arg2)
 {
     SongCore.Loader.SongsLoadedEvent -= Loader_SongsLoadedEvent;
     SongCore.Loader.Instance.RefreshSongs();
 }
示例#9
0
        public async void Start()
        {
            Plugin.log?.Debug("BeatSync Start()");
            IsRunning = true;
            SetupComponents();

            if (playlistManager != null)
            {
                var recentPlaylist = Plugin.config.RecentPlaylistDays > 0 ? playlistManager.GetOrAddPlaylist(BuiltInPlaylist.BeatSyncRecent) : null;
                if (recentPlaylist != null && Plugin.config.RecentPlaylistDays > 0)
                {
                    var minDate      = DateTime.Now - new TimeSpan(Plugin.config.RecentPlaylistDays, 0, 0, 0);
                    int removedCount = recentPlaylist.RemoveAll(s => s.DateAdded < minDate);
                    if (removedCount > 0)
                    {
                        Plugin.log?.Info($"Removed {removedCount} old songs from the RecentPlaylist.");
                        recentPlaylist.RaisePlaylistChanged();
                        try
                        {
                            playlistManager.StorePlaylist(recentPlaylist);
                        }
                        catch (Exception ex)
                        {
                            Plugin.log?.Warn($"Unable to write {recentPlaylist.Filename}: {ex.Message}");
                            Plugin.log?.Debug(ex);
                        }
                    }
                    else
                    {
                        Plugin.log?.Info("Didn't remove any songs from RecentPlaylist.");
                    }
                }
            }
            var syncInterval = new TimeSpan(Plugin.modConfig.TimeBetweenSyncs.Hours, Plugin.modConfig.TimeBetweenSyncs.Minutes, 0);
            var nowTime      = DateTime.Now;

            if (Plugin.config.LastRun + syncInterval <= nowTime)
            {
                if (Plugin.config.LastRun != DateTime.MinValue)
                {
                    Plugin.log?.Info($"BeatSync ran {TimeSpanToString(nowTime - Plugin.config.LastRun)} ago");
                }
                if (songHasher != null)
                {
                    await songHasher.InitializeAsync().ConfigureAwait(false);

                    Plugin.log?.Info($"Hashed {songHasher.HashDictionary.Count} songs in {CustomLevelsDirectory}.");
                }
                else
                {
                    Plugin.log?.Error($"SongHasher was null.");
                }
                // Start downloader
                IJobBuilder    jobBuilder     = CreateJobBuilder(Plugin.config);
                SongDownloader songDownloader = new SongDownloader();
                JobManager     JobManager     = new JobManager(Plugin.config.MaxConcurrentDownloads);
                JobManager.Start(CancelAllToken);
                Stopwatch sw = new Stopwatch();
                sw.Start();
                if (jobBuilder.SongTargets.Count() == 0)
                {
                    Plugin.log?.Error("jobBuilder has no SongTargets.");
                }
                JobStats[] sourceStats = await songDownloader.RunAsync(Plugin.config, jobBuilder, JobManager).ConfigureAwait(false); // TODO: CancellationToken

                JobStats beatSyncStats = sourceStats.Aggregate((a, b) => a + b);
                await JobManager.CompleteAsync();

                int      recentPlaylistDays = Plugin.config.RecentPlaylistDays;
                DateTime cutoff             = DateTime.Now - new TimeSpan(recentPlaylistDays, 0, 0, 0);
                foreach (SongTarget target in jobBuilder.SongTargets)
                {
                    if (target is ITargetWithPlaylists targetWithPlaylists)
                    {
                        PlaylistManager?targetPlaylistManager = targetWithPlaylists.PlaylistManager;
                        if (recentPlaylistDays > 0)
                        {
                            BeatSaberPlaylistsLib.Types.IPlaylist?recent = targetPlaylistManager?.GetOrAddPlaylist(BuiltInPlaylist.BeatSyncRecent);
                            if (recent != null && recent.Count > 0)
                            {
                                int songsRemoved = recent.RemoveAll(s => s.DateAdded < cutoff);
                                if (songsRemoved > 0)
                                {
                                    recent.RaisePlaylistChanged();
                                }
                            }
                        }
                        try
                        {
                            targetPlaylistManager?.StoreAllPlaylists();
                        }
                        catch (AggregateException ex)
                        {
                            Plugin.log?.Error($"Error storing playlists: {ex.Message}");
                            foreach (var e in ex.InnerExceptions)
                            {
                                Plugin.log?.Debug(e);
                            }
                        }
                        catch (Exception ex)
                        {
                            Plugin.log?.Error($"Error storing playlists: {ex.Message}");
                            Plugin.log?.Debug(ex);
                        }
                    }
                    if (target is ITargetWithHistory targetWithHistory)
                    {
                        try
                        {
                            targetWithHistory.HistoryManager?.WriteToFile();
                        }
                        catch (Exception ex)
                        {
                            Plugin.log?.Info($"Unable to save history at '{targetWithHistory.HistoryManager?.HistoryPath}': {ex.Message}");
                        }
                    }
                }
                sw.Stop();
                Plugin.log?.Info($"Finished after {sw.Elapsed.TotalSeconds}s: {beatSyncStats}");
                Plugin.config.LastRun = DateTime.Now;
                Plugin.ConfigManager.SaveConfig();
                SongCore.Loader loader = SongCore.Loader.Instance;
                SongCore.Loader.SongsLoadedEvent -= Loader_SongsLoadedEvent;
                SongCore.Loader.SongsLoadedEvent += Loader_SongsLoadedEvent;
                if (!SongCore.Loader.AreSongsLoading)
                {
                    SongCore.Loader.SongsLoadedEvent -= Loader_SongsLoadedEvent;
                    if (SongCore.Loader.AreSongsLoaded)
                    {
                        loader.RefreshSongs();
                    }
                }
            }
            else
            {
                Plugin.log?.Info($"BeatSync ran {TimeSpanToString(nowTime - Plugin.config.LastRun)} ago, skipping because TimeBetweenSyncs is {Plugin.modConfig.TimeBetweenSyncs}");
            }
        }
示例#10
0
 private void SongLoader_SongsLoadedEvent(SongCore.Loader arg1, ConcurrentDictionary <string, CustomPreviewBeatmapLevel> arg2)
 {
     _songListTableView?.ReloadData();
 }
 private void SongLoader_SongsLoadedEvent(SongCore.Loader sender, Dictionary <string, CustomPreviewBeatmapLevel> levels)
 {
     _alreadyDownloadedSongs = levels.Values.Select(x => new Song(x)).ToList();
 }
示例#12
0
 private void SongLoader_SongsLoadedEvent(SongCore.Loader sender, ConcurrentDictionary <string, CustomPreviewBeatmapLevel> levels)
 {
     Plugin.log.Debug("Establishing Already Downloaded Songs");
     _alreadyDownloadedSongs = new HashSet <string>(levels.Values.Select(x => SongCore.Collections.hashForLevelID(x.levelID)));
 }
示例#13
0
 private void Loader_SongsLoadedEvent(SongCore.Loader arg1, Dictionary <string, CustomPreviewBeatmapLevel> arg2)
 {
     PlaylistsCollection.MatchSongsForAllPlaylists();
     //   DebugLogPlaylists();
 }
 private void SongLoader_SongsLoadedEvent(SongCore.Loader sender, Dictionary <string, CustomPreviewBeatmapLevel> levels)
 {
     _alreadyDownloadedSongs = new HashSet <string>(levels.Values.Select(x => x.levelID.Split('_')[2]?.ToUpper()));
 }
示例#15
0
 private void SongLoader_SongsLoadedEvent(SongCore.Loader arg1, Dictionary <string, CustomPreviewBeatmapLevel> arg2)
 {
     SongCore.Loader.SongsLoadedEvent -= SongLoader_SongsLoadedEvent;
     _moreSongsButton.interactable     = true;
 }