Esempio n. 1
0
        static bool ConvertFile(string path)
        {
            bool fileExists = File.Exists(path);

            if (fileExists == false)
            {
                Console.WriteLine($"File \"{path}\" does not exist");
                return(false);
            }

            using (StreamReader file = File.OpenText(path))
            {
                try
                {
                    var legacy   = PlaylistConverter.DeserializeLegacyPlaylist(file);
                    var playlist = PlaylistConverter.ConvertLegacyPlaylist(legacy);

                    string newPath = path.Replace(".bplist", ".blist").Replace(".json", ".blist");
                    using (FileStream fs = File.Open(newPath, FileMode.OpenOrCreate))
                    {
                        PlaylistLib.SerializeStream(playlist, fs);
                        return(true);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Exception in {path}");
                    Console.WriteLine(ex.ToString());
                    return(false);
                }
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                ExitMessage("Please drag a .bplist file onto this .exe", 1);
            }

            string path       = args[0];
            bool   fileExists = File.Exists(path);

            if (!fileExists)
            {
                ExitMessage("The specified file does not exist!", 1);
            }

            string text     = File.ReadAllText(path);
            var    legacy   = PlaylistConverter.DeserializeLegacyPlaylist(text);
            var    playlist = PlaylistConverter.ConvertLegacyPlaylist(legacy);

            string newPath = path.Replace(".bplist", ".blist");

            using (FileStream fs = File.Open(newPath, FileMode.OpenOrCreate))
            {
                using (MemoryStream ms = PlaylistLib.SerializeStream(playlist))
                {
                    ms.CopyTo(fs);
                    fs.Flush();
                }
            }
        }
Esempio n. 3
0
 /* Overwrites a legacy playlist with Blister playlist. Does not change file name. */
 public static void OverwritePlaylist(string path, Playlist playlist)
 {
     using (FileStream fs = File.Open(path, FileMode.OpenOrCreate))
     {
         PlaylistLib.SerializeStream(playlist, fs);
     }
 }
Esempio n. 4
0
        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);
            }
        }
Esempio n. 5
0
 public void LoadBlisterPlaylist()
 {
     string playlistFile = Path.Combine(PlaylistsPath, "BeatSyncBSaberBookmarks.blist");
     var    playlist     = PlaylistLib.Deserialize(File.OpenRead(playlistFile));
 }
Esempio n. 6
0
        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);
            }
        }