public ScoreSaberDataFile(byte[] data) { Stopwatch timer = new Stopwatch(); timer.Start(); SongVersionToScoreSaberData = new Dictionary <string, ScoreSaberData>(); System.Globalization.NumberStyles style = System.Globalization.NumberStyles.AllowDecimalPoint; string result = System.Text.Encoding.UTF8.GetString(data); JSONNode rootNode = JSON.Parse(result); foreach (KeyValuePair <string, JSONNode> kvp in rootNode) { JSONNode difficultyNodes = kvp.Value; foreach (KeyValuePair <string, JSONNode> innerKvp in difficultyNodes) { JSONNode node = innerKvp.Value; String version = node["key"]; String name = node["name"]; String difficultyName = node["difficulty"]; if (difficultyName == "Expert+") { difficultyName = "ExpertPlus"; } float pp = 0; float.TryParse(node["pp"], style, System.Globalization.CultureInfo.InvariantCulture, out pp); float starDifficulty = 0; float.TryParse(node["star"], style, System.Globalization.CultureInfo.InvariantCulture, out starDifficulty); ScoreSaberData ppData = null; if (!SongVersionToScoreSaberData.ContainsKey(version)) { ppData = new ScoreSaberData { version = version, name = name }; SongVersionToScoreSaberData.Add(version, ppData); } else { ppData = SongVersionToScoreSaberData[version]; } // add difficulty ppData.AddDifficultyRating(difficultyName, pp, starDifficulty); } } timer.Stop(); Logger.Debug("Processing ScoreSaber data took {0}ms", timer.ElapsedMilliseconds); }
/// <summary> /// Load the settings file for this plugin. /// If we fail to load return Default settings. /// </summary> /// <returns>SongBrowserSettings</returns> public static SongBrowserSettings Load() { Logger.Trace("Load()"); SongBrowserSettings retVal = null; // No Settings file. String settingsFilePath = SongBrowserSettings.SettingsPath(); if (File.Exists(settingsFilePath)) { // Deserialization from JSON FileStream fs = null; try { fs = File.OpenRead(settingsFilePath); XmlSerializer serializer = new XmlSerializer(typeof(SongBrowserSettings)); retVal = (SongBrowserSettings)serializer.Deserialize(fs); // Success loading, sane time to make a backup retVal.SaveBackup(); } catch (Exception e) { Logger.Exception("Unable to deserialize song browser settings file, using default settings: ", e); retVal = new SongBrowserSettings { DisableSavingSettings = true }; } finally { if (fs != null) { fs.Close(); } } } else { Logger.Debug("Settings file does not exist, returning defaults: " + settingsFilePath); retVal = new SongBrowserSettings(); } // check if the playlist directory exists, make it otherwise. String playlistDirPath = Path.Combine(Environment.CurrentDirectory, "Playlists"); if (!Directory.Exists(playlistDirPath)) { Directory.CreateDirectory(playlistDirPath); } // Load Downloader favorites but only once, we'll convert them once, empty the song_browser_setting.xml favorites and never load it again. String playlistPath = Path.Combine(Environment.CurrentDirectory, "Playlists", DefaultConvertedFavoritesPlaylistName); if (!File.Exists(playlistPath)) { if (File.Exists(SongBrowserSettings.DownloaderFavoritesFilePath())) { String[] downloaderFavorites = File.ReadAllLines(SongBrowserSettings.DownloaderFavoritesFilePath()); retVal.Favorites.UnionWith(downloaderFavorites); } Playlist p = new Playlist { playlistTitle = "Song Browser Favorites", playlistAuthor = "SongBrowser", fileLoc = "", image = Base64Sprites.PlaylistIconB64, songs = new List <PlaylistSong>(), }; p.CreateNew(playlistPath); } if (String.IsNullOrEmpty(retVal.currentEditingPlaylistFile)) { retVal.currentEditingPlaylistFile = playlistPath; } return(retVal); }