private static void Delete() { var song = SongDataHolder.I.songData; SongBrowser.DebugText("Deleted " + song.title); SongBrowser.RemoveSong(song.songID); }
private static void LoadFavorites() { if (File.Exists(favoritesPath)) { try { string text = File.ReadAllText(favoritesPath); favorites = JSON.Load(text).Make <Favorites>(); } catch (Exception ex) { MelonLoader.MelonLogger.Msg($"Unable to load favorites from file: {ex.Message}"); SongBrowser.DebugText("Unable to load favorites"); // make a backup of the existing file, just in case it still contains something string backupPath = favoritesPath + DateTime.Now.ToString("yyyyMMdd_hhmmss") + ".temp"; File.Copy(favoritesPath, backupPath); favorites = new Favorites(); favorites.songIDs = new List <string>(); } } else { favorites = new Favorites(); favorites.songIDs = new List <string>(); } }
public static void SaveFavorites() { string text = JSON.Dump(favorites); try { int favCount = favorites.songIDs.Count; File.WriteAllText(favoritesPath + ".tmp", text); // check that file can be loaded and contains the correct number of favorites string saved = File.ReadAllText(favoritesPath + ".tmp"); Favorites favs = JSON.Load(saved).Make <Favorites>(); if (favCount == favs.songIDs.Count) { // override existing favorites now that we know it worked File.Delete(favoritesPath); File.Copy(favoritesPath + ".tmp", favoritesPath); } else { SongBrowser.DebugText("Unable to save favorites"); } } catch (Exception ex) { MelonLoader.MelonLogger.Msg($"Unable to save favorites: {ex.Message}"); SongBrowser.DebugText("Unable to save favorites"); } }
private static void OnDeleteButtonShot() { var song = SongDataHolder.I.songData; SongBrowser.DebugText("Deleted " + song.title); SongBrowser.RemoveSong(song.songID); GameObject.FindObjectOfType <LaunchPanel>().Back(); }
public static void AddFavorite(string songID) { var song = SongList.I.GetSong(songID); if (!song.extrasSong) { return; } if (favorites.songIDs.Contains(songID)) { favorites.songIDs.Remove(songID); SongBrowser.DebugText($"Removed {song.title} from favorites!"); SaveFavorites(); } else { favorites.songIDs.Add(songID); SongBrowser.DebugText($"Added {song.title} to favorites!"); SaveFavorites(); } }