public static Playlist AddPlaylist(string file) { if (!file.EndsWith("blist")) { return(null); } using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read)) { Playlist plist = PlaylistLib.Deserialize(fs); AddPlaylistToLC(plist); return(plist); } }
public void LoadBlisterPlaylist() { string playlistFile = Path.Combine(PlaylistsPath, "BeatSyncBSaberBookmarks.blist"); var playlist = PlaylistLib.Deserialize(File.OpenRead(playlistFile)); }
public static Dictionary <string, Playlist> LoadAllPlaylistsFromFolders(string[] paths) { if (!isLoading) { isLoading = true; Logger.log.Info("LOADER ::: Loading playlists."); Stopwatch sw = new Stopwatch(); sw.Start(); Dictionary <string, Playlist> playlists = new Dictionary <string, Playlist>(); foreach (var path in paths) { Directory.CreateDirectory(path); string[] filePaths = Directory.GetFiles(path, "*.blist", SearchOption.AllDirectories); foreach (var fPath in filePaths) { try { using (FileStream fs = new FileStream(fPath, FileMode.Open, FileAccess.Read)) { Playlist plist = PlaylistLib.Deserialize(fs); playlists.Add(fPath, plist); if (!AllPlaylists.ContainsKey(fPath)) { AllPlaylists.Add(fPath, plist); } } } catch { Logger.log.Error("Error loading playlist at: " + fPath); } } //Legacy Conversion (bplist) var legacyPathsBP = Directory.GetFiles(path, "*.bplist", SearchOption.AllDirectories); foreach (var filePath in legacyPathsBP) { try { using (StreamReader reader = File.OpenText(filePath)) { var leg = PlaylistConverter.DeserializeLegacyPlaylist(reader); var converted = PlaylistConverter.ConvertLegacyPlaylist(leg); /* * var fileName = Path.GetFileNameWithoutExtension(filePath); * var newFilePath = path + fileName + "_CFB.blist"; * OverwritePlaylist(filePath, converted); * playlists.Add(newFilePath, converted); * if (!AllPlaylists.ContainsKey(newFilePath)) * AllPlaylists.Add(newFilePath, converted); * File.Move(filePath, newFilePath); */ if (!AllPlaylists.ContainsKey(filePath)) { AllPlaylists.Add(filePath, converted); } playlists.Add(filePath, converted); Logger.log.Debug("Converted Playlist " + converted.Title); } } catch (Exception e) { string st = ""; if (e.GetType() == typeof(InvalidBase64Exception)) { st += "Invalid Image: " + e.Message; } else if (e.GetType() == typeof(InvalidMapHashException)) { st += "Invalid Hash <<<" + (e as InvalidMapHashException).Hash + ">>>"; } else if (e.GetType() == typeof(InvalidMapKeyException)) { st += "Invalid Key <<<" + (e as InvalidMapKeyException).Key + ">>>"; } else { st += "Other: " + e.Message; } Logger.log.Error("Error converting playlist: " + Path.GetFileName(filePath) + ". Why? " + st); } } //Legacy Conversion (json) var legacyPathsJSON = Directory.GetFiles(path, "*.json", SearchOption.AllDirectories); foreach (var filePath in legacyPathsJSON) { if (!filePath.Contains("SongBrowserPluginFavorites") && !filePath.Contains("favorites.json")) { try { using (StreamReader reader = File.OpenText(filePath)) { var leg = PlaylistConverter.DeserializeLegacyPlaylist(reader); var converted = PlaylistConverter.ConvertLegacyPlaylist(leg); /* * var fileName = Path.GetFileNameWithoutExtension(filePath); * var newFilePath = path + fileName + "_CFB.blist"; * OverwritePlaylist(filePath, converted); * playlists.Add(newFilePath, converted); * if (!AllPlaylists.ContainsKey(newFilePath)) * AllPlaylists.Add(newFilePath, converted); * File.Move(filePath, newFilePath); */ if (!AllPlaylists.ContainsKey(filePath)) { AllPlaylists.Add(filePath, converted); } playlists.Add(filePath, converted); Logger.log.Debug("Converted Playlist " + converted.Title); } } catch (Exception e) { string st = ""; if (e.GetType() == typeof(InvalidBase64Exception)) { st += "Invalid Image: " + e.Message; } else if (e.GetType() == typeof(InvalidMapHashException)) { st += "Invalid Hash <<<" + (e as InvalidMapHashException).Hash + ">>>"; } else if (e.GetType() == typeof(InvalidMapKeyException)) { st += "Invalid Key <<<" + (e as InvalidMapKeyException).Key + ">>>"; } else { st += "Other: " + e.Message; } Logger.log.Error("Error converting playlist: " + Path.GetFileName(filePath) + ". Why? " + st); } } } } foreach (var pl in playlists) { var n = ScriptableObject.CreateInstance <CustomPlaylistSO>(); n.playlist = pl.Value; n.SetupCover(); PlaylistCore.instance.LoadedPlaylistSO.Add(n); } PlaylistsLoaded?.Invoke(playlists); Logger.log.Info("LOADER ::: Finished loading " + playlists.Count + " playlists. Took: " + sw.Elapsed.Seconds + "." + sw.Elapsed.Milliseconds / 10 + " seconds."); isLoading = false; return(playlists); } else { return(null); } }