/// <summary> /// Adds a song to the history. /// </summary> /// <param name="song">The song that should be added.</param> public void AddSongToHistory(Song song) { if (SongHistory.Any()) { if (((SongHistory.Last().StartTime - song.StartTime) < TimeSpan.FromSeconds(1)) && !((SongHistory.Last().StartTime - song.StartTime) < TimeSpan.FromSeconds(-1))) { return; } } SongHistory.Add(song); StoreHistory(song); }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// /// <summary> /// Load database /// </summary> private void LoadDatabase() { try { string l_FilePath = m_DBFilePath; if (!System.IO.File.Exists(l_FilePath)) { Logger.Instance.Error("File not found " + m_DBFilePath); return; } var l_JSON = JObject.Parse(System.IO.File.ReadAllText(l_FilePath, UTF8Encoding.UTF8)); if (l_JSON["queue"] != null) { JArray l_JSONSongs = (JArray)l_JSON["queue"]; for (int l_SongIt = 0; l_SongIt < l_JSONSongs.Count; l_SongIt++) { SongEntry l_Entry = new SongEntry(); if ((l_JSONSongs[l_SongIt] as JObject).ContainsKey("key")) l_Entry.BeatMap = new BeatSaverSharp.Beatmap(m_BeatSaver, (string)l_JSONSongs[l_SongIt]["key"]); else { l_Entry.BeatMap = new BeatSaverSharp.Beatmap(m_BeatSaver, "", "", ""); JsonConvert.PopulateObject((string)l_JSONSongs[l_SongIt]["btm"], l_Entry.BeatMap); } if ((l_JSONSongs[l_SongIt] as JObject).ContainsKey("rqt")) l_Entry.RequestTime = SDK.Misc.Time.FromUnixTime(l_JSONSongs[l_SongIt]["rqt"].Value<long>()); l_Entry.RequesterName = (string)l_JSONSongs[l_SongIt]["rqn"]; if ((l_JSONSongs[l_SongIt] as JObject).ContainsKey("npr")) l_Entry.NamePrefix = (string)l_JSONSongs[l_SongIt]["npr"]; SongQueue.Add(l_Entry); /// Start populate l_Entry.BeatMap.Populate().ContinueWith(x => OnBeatmapPopulated(x, l_Entry)); } } if (l_JSON["history"] != null) { JArray l_JSONSongs = (JArray)l_JSON["history"]; for (int l_SongIt = 0; l_SongIt < l_JSONSongs.Count; l_SongIt++) { SongEntry l_Entry = new SongEntry(); if ((l_JSONSongs[l_SongIt] as JObject).ContainsKey("key")) l_Entry.BeatMap = new BeatSaverSharp.Beatmap(m_BeatSaver, (string)l_JSONSongs[l_SongIt]["key"]); else { l_Entry.BeatMap = new BeatSaverSharp.Beatmap(m_BeatSaver, "", "", ""); JsonConvert.PopulateObject((string)l_JSONSongs[l_SongIt]["btm"], l_Entry.BeatMap); } if ((l_JSONSongs[l_SongIt] as JObject).ContainsKey("rqt")) l_Entry.RequestTime = SDK.Misc.Time.FromUnixTime(l_JSONSongs[l_SongIt]["rqt"].Value<long>()); l_Entry.RequesterName = (string)l_JSONSongs[l_SongIt]["rqn"]; if ((l_JSONSongs[l_SongIt] as JObject).ContainsKey("npr")) l_Entry.NamePrefix = (string)l_JSONSongs[l_SongIt]["npr"]; SongHistory.Add(l_Entry); /// Start populate l_Entry.BeatMap.Populate().ContinueWith(x => OnBeatmapPopulated(x, l_Entry)); } } if (l_JSON["blacklist"] != null) { JArray l_JSONSongs = (JArray)l_JSON["blacklist"]; for (int l_SongIt = 0; l_SongIt < l_JSONSongs.Count; l_SongIt++) { SongEntry l_Entry = new SongEntry(); if ((l_JSONSongs[l_SongIt] as JObject).ContainsKey("key")) l_Entry.BeatMap = new BeatSaverSharp.Beatmap(m_BeatSaver, (string)l_JSONSongs[l_SongIt]["key"]); else { l_Entry.BeatMap = new BeatSaverSharp.Beatmap(m_BeatSaver, "", "", ""); JsonConvert.PopulateObject((string)l_JSONSongs[l_SongIt]["btm"], l_Entry.BeatMap); } if ((l_JSONSongs[l_SongIt] as JObject).ContainsKey("rqt")) l_Entry.RequestTime = SDK.Misc.Time.FromUnixTime(l_JSONSongs[l_SongIt]["rqt"].Value<long>()); l_Entry.RequesterName = (string)l_JSONSongs[l_SongIt]["rqn"]; if ((l_JSONSongs[l_SongIt] as JObject).ContainsKey("npr")) l_Entry.NamePrefix = (string)l_JSONSongs[l_SongIt]["npr"]; SongBlackList.Add(l_Entry); /// Start populate l_Entry.BeatMap.Populate().ContinueWith(x => OnBeatmapPopulated(x, l_Entry)); } } } catch (System.Exception p_Exception) { Logger.Instance.Critical("LoadDataBase"); Logger.Instance.Critical(p_Exception); } }