public void DoesNotDuplicateSong() { SetupPlaylistsWithSongs(2, 2); BeatSaberQuestomConfig oldConfig = null; using (var apk = new ApkAssetsFileProvider(_apkFile, FileCacheMode.Memory, false)) { QuestomAssetsEngine qae = new QuestomAssetsEngine(apk, "assets/bin/Data/", false); oldConfig = qae.GetCurrentConfig(false); var config = CopyIDs(oldConfig); var song = new BeatSaberSong() { SongID = config.Playlists[0].SongList[0].SongID, CustomSongFolder = TEST_SONG_FOLDER }; oldConfig.Playlists[0].SongList.Add(song); qae.UpdateConfig(config); } using (var apk = new ApkAssetsFileProvider(_apkFile, FileCacheMode.Memory, true)) { QuestomAssetsEngine qae = new QuestomAssetsEngine(apk, "assets/bin/Data/", true); var testConfig = qae.GetCurrentConfig(false); Assert.AreEqual(2, testConfig.Playlists[0].SongList.Count()); Assert.AreEqual(2, testConfig.Playlists[1].SongList.Count()); } Assert.Pass(); }
private void SetupPlaylistsWithSongs(int playlistCount, int songCount) { BeatSaberQuestomConfig config = null; using (var apk = new ApkAssetsFileProvider(_apkFile, FileCacheMode.Memory)) { QuestomAssetsEngine qae = new QuestomAssetsEngine(apk, "assets/bin/Data/"); config = qae.GetCurrentConfig(); for (int p = 0; p < playlistCount; p++) { var playlist = new BeatSaberPlaylist() { PlaylistID = string.Format(PlaylistIDFormat, p), PlaylistName = string.Format(PlaylistNameFormat, p), CoverArtBytes = File.ReadAllBytes(COVER_ART_FILE) }; for (int i = 0; i < songCount; i++) { var song = new BeatSaberSong() { SongID = string.Format(SongIDFormat, p, i), CustomSongFolder = TEST_SONG_FOLDER }; playlist.SongList.Add(song); } config.Playlists.Add(playlist); } qae.UpdateConfig(config); } }
public void AddsPlaylistWithSong() { SetupPlaylistsWithSongs(1, 1); using (var apk = new ApkAssetsFileProvider(_apkFile, FileCacheMode.Memory, false)) { QuestomAssetsEngine qae = new QuestomAssetsEngine(apk, "assets/bin/Data/", false); var newConfig = qae.GetCurrentConfig(false); Assert.AreEqual(1, newConfig.Playlists.Count, "Playlist count should be 1!"); var playlist = newConfig.Playlists[0]; Assert.AreEqual(string.Format(PlaylistIDFormat, 0), playlist.PlaylistID); Assert.AreEqual(string.Format(PlaylistNameFormat, 0), playlist.PlaylistName); Assert.IsNotNull(playlist.CoverArtBytes, "Playlist cover art didn't reload!"); //Assert.AreEqual(1024, playlist.CoverArt.Width, "Playlist cover art is not 1024 width!"); //Assert.AreEqual(1024, playlist.CoverArt.Height, "Playlist cover art is not 1024 height!"); Assert.AreEqual(1, playlist.SongList.Count, "Songs count should be 1!"); var song = playlist.SongList[0]; Assert.AreEqual(string.Format(SongIDFormat, 0, 0), song.SongID); Assert.AreEqual(TestSongName, song.SongName); Assert.AreEqual(TestSongSubName, song.SongSubName); Assert.AreEqual(TestSongAuthorName, song.SongAuthorName); Assert.IsNotNull(song.CoverArtBytes, "Cover art didn't load!"); //Assert.AreEqual(256, song.CoverArt.Width, "Song cover art is not 256 width!"); //Assert.AreEqual(256, song.CoverArt.Height, "Song cover art is not 256 height!"); } Assert.Pass(); }
public void MovesSongToNewPlaylist() { SetupPlaylistsWithSongs(2, 2); BeatSaberQuestomConfig oldConfig = null; using (var apk = new ApkAssetsFileProvider(_apkFile, FileCacheMode.Memory, false)) { QuestomAssetsEngine qae = new QuestomAssetsEngine(apk, "assets/bin/Data/", false); oldConfig = qae.GetCurrentConfig(false); var config = CopyIDs(oldConfig); var song = config.Playlists[0].SongList[0]; config.Playlists[1].SongList.Add(song); config.Playlists[0].SongList.Remove(song); qae.UpdateConfig(config); } using (var apk = new ApkAssetsFileProvider(_apkFile, FileCacheMode.Memory, true)) { QuestomAssetsEngine qae = new QuestomAssetsEngine(apk, "assets/bin/Data/", true); var testConfig = qae.GetCurrentConfig(false); Assert.AreEqual(2, testConfig.Playlists.Count); Assert.AreEqual(1, testConfig.Playlists[0].SongList.Count()); Assert.AreEqual(3, testConfig.Playlists[1].SongList.Count()); Assert.AreEqual(string.Format(SongIDFormat, 0, 1), testConfig.Playlists[0].SongList[0].SongID); Assert.AreEqual(string.Format(SongIDFormat, 1, 0), testConfig.Playlists[1].SongList[0].SongID); Assert.AreEqual(string.Format(SongIDFormat, 1, 1), testConfig.Playlists[1].SongList[1].SongID); Assert.AreEqual(string.Format(SongIDFormat, 0, 0), testConfig.Playlists[1].SongList[2].SongID); Assert.AreEqual(oldConfig.Playlists[0].PlaylistName, testConfig.Playlists[0].PlaylistName); Assert.AreEqual(oldConfig.Playlists[1].PlaylistName, testConfig.Playlists[1].PlaylistName); } Assert.Pass(); }
public void LoadsConfig() { BeatSaberQuestomConfig config = null; using (var apk = new ApkAssetsFileProvider(_apkFile, FileCacheMode.Memory, true)) { QuestomAssetsEngine qae = new QuestomAssetsEngine(apk, "assets/bin/Data/", true); config = qae.GetCurrentConfig(false); } Assert.IsNotNull(config, "Didn't load current config"); Assert.Pass(); }
public void LoadsConfigImages() { SetupPlaylistsWithSongs(1, 1); BeatSaberQuestomConfig config = null; using (var apk = new ApkAssetsFileProvider(_apkFile, FileCacheMode.Memory, true)) { QuestomAssetsEngine qae = new QuestomAssetsEngine(apk, "assets/bin/Data/", true); config = qae.GetCurrentConfig(); Assert.IsNotNull(config, "Didn't load current config"); Assert.IsNotNull(config.Playlists[0].CoverArtBytes); Assert.IsNotNull(config.Playlists[0].SongList[0].CoverArtBytes); //todo: //Assert.AreEqual(1024, config.Playlists[0].CoverArt.Width); //Assert.AreEqual(1024, config.Playlists[0].CoverArt.Height); //Assert.AreEqual(256, config.Playlists[0].SongList[0].CoverArt.Width); //Assert.AreEqual(256, config.Playlists[0].SongList[0].CoverArt.Height); } Assert.Pass(); }
static int FolderMode(FolderMode args) { QuestomAssets.Log.SetLogSink(new ConsoleSink()); if (!string.IsNullOrWhiteSpace(args.CoverArt) && !File.Exists(args.CoverArt)) { Log.LogErr("Playlist cover art file doesn't exist!"); return(-1); } var customSongsFolders = GetCustomSongsFromPath(args.CustomSongsFolder); if (customSongsFolders.Count < 1) { Log.LogErr("No custom songs found!"); return(-1); } try { Log.LogMsg($"Opening APK at '{args.ApkFile}'"); using (var apkFileProvider = new ApkAssetsFileProvider(args.ApkFile, FileCacheMode.Memory, false)) { QuestomAssetsEngine q = new QuestomAssetsEngine(apkFileProvider, BSConst.KnownFiles.AssetsRootPath); //Log.LogMsg($"Loading configuration..."); //var cfg = q.GetCurrentConfig(apkFileProvider, BSConst.KnownFiles.AssetsRootPath, true); //Log.LogMsg($"Configuration loaded"); //if (!args.NoPatch) //{ // Log.LogMsg($"Applying patches..."); // if (!q.ApplyPatchSettingsFile(apkFileProvider)) // { // Log.LogErr("Failed to apply patches. Cannot continue."); // return -1; // } //} //BeatSaberPlaylist playlist = cfg.Playlists.FirstOrDefault(x => x.PlaylistID == "CustomSongs"); //if (playlist == null) //{ // Log.LogMsg("Playlist doesn't already exist, creating it"); // playlist = new BeatSaberPlaylist() // { // PlaylistID = "CustomSongs", // PlaylistName = "Custom Songs" // }; // cfg.Playlists.Add(playlist); //} //else if (args.DeleteSongs) //{ // Log.LogMsg("Deleting current songs from playlist before reloading"); // playlist.SongList.Clear(); //} //try //{ // playlist.CoverArtBytes = string.IsNullOrWhiteSpace(args.CoverArt) ? null : File.ReadAllBytes(args.CoverArt); //} //catch (Exception ex) //{ // Log.LogErr($"Unable to load playlist cover art from {args.CoverArt}", ex); // playlist.CoverArtBytes = null; //} //Log.LogMsg($"Attempting to load {customSongsFolders.Count} custom songs..."); //foreach (var cs in customSongsFolders) //{ // playlist.SongList.Add(new BeatSaberSong() // { // CustomSongFolder = cs // }); //} Log.LogMsg("Applying new configuration..."); // q.UpdateConfig(cfg, apkFileProvider, BSConst.KnownFiles.AssetsRootPath); Log.LogMsg("Configuration updated"); Log.LogMsg("Signing APK..."); q.SignAPK(); Log.LogMsg("APK signed"); return(0); } } catch (Exception ex) { Log.LogErr("Something went horribly wrong", ex); return(-1); } }
static int OutputConfig(OutputConfig args) { if (!string.IsNullOrWhiteSpace(args.OutputFile) || args.ForceLog) { Log.SetLogSink(new ConsoleSink()); } try { Log.LogMsg($"Opening APK at '{args.ApkFile}'"); using (var apkFileProvider = new ApkAssetsFileProvider(args.ApkFile, FileCacheMode.Memory, false)) { QuestomAssetsEngine q = new QuestomAssetsEngine(apkFileProvider, BSConst.KnownFiles.AssetsRootPath); Log.LogMsg($"Loading configuration..."); var cfg = q.GetCurrentConfig(args.NoImages); Log.LogMsg($"Configuration loaded"); TextWriter outWriter = null; try { string toPlace = string.IsNullOrWhiteSpace(args.OutputFile) ? "stdout" : args.OutputFile; Log.LogMsg($"Writing configuration to {toPlace}..."); if (string.IsNullOrWhiteSpace(args.OutputFile)) { //write to stdout outWriter = Console.Out; outWriter.WriteLine("/* JSON START */"); } else { //write to file outWriter = new StreamWriter(new FileStream(args.OutputFile, FileMode.Create)); } var ser = new JsonSerializer(); ser.Formatting = Formatting.Indented; ser.Serialize(outWriter, cfg); if (string.IsNullOrWhiteSpace(args.OutputFile)) { outWriter.WriteLine(""); outWriter.WriteLine("/* JSON END */"); } } finally { if (outWriter != null) { outWriter.Dispose(); outWriter = null; } } return(0); } } catch (Exception ex) { Log.LogErr("Something went horribly wrong", ex); return(-1); } }
static int UpdateConfig(UpdateConfig args) { QuestomAssets.Log.SetLogSink(new ConsoleSink()); try { Log.LogMsg($"Opening APK at '{args.ApkFile}'"); using (var apkFileProvider = new ApkAssetsFileProvider(args.ApkFile, FileCacheMode.Memory, false)) { QuestomAssetsEngine q = new QuestomAssetsEngine(apkFileProvider, BSConst.KnownFiles.AssetsRootPath); if (!args.NoPatch) { Log.LogMsg($"Applying patches..."); if (!q.ApplyPatchSettingsFile()) { Log.LogErr("Failed to apply patches. Cannot continue."); return(-1); } Log.LogMsg("Patches complete"); } else { Log.LogMsg("Skipping patches."); } BeatSaberQuestomConfig config = null; TextReader inReader = null; string from = string.IsNullOrWhiteSpace(args.InputFile) ? "stdin" : args.InputFile; Log.LogMsg($"Reading configuration from {from}..."); try { if (string.IsNullOrWhiteSpace(args.InputFile)) { inReader = Console.In; } else { inReader = new StreamReader(args.InputFile); } using (var jReader = new JsonTextReader(inReader)) config = new JsonSerializer().Deserialize <BeatSaberQuestomConfig>(jReader); } finally { if (inReader != null) { inReader.Dispose(); inReader = null; } } Log.LogMsg($"Config parsed"); Log.LogMsg("Applying new configuration..."); q.UpdateConfig(config); Log.LogMsg("Configuration updated"); Log.LogMsg("Signing APK..."); q.SignAPK(); Log.LogMsg("APK signed."); } return(0); } catch (Exception ex) { Log.LogErr("Something went horribly wrong", ex); return(-1); } }