static int UpdateConfig(UpdateConfig args) { QuestomAssets.Log.SetLogSink(new ConsoleSink()); try { Log.LogMsg($"Opening APK at '{args.ApkFile}'"); QuestomAssetsEngine q = new QuestomAssetsEngine(args.ApkFile); 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); } }
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}'"); QuestomAssetsEngine q = new QuestomAssetsEngine(args.ApkFile); Log.LogMsg($"Loading configuration..."); var cfg = q.GetCurrentConfig(true); Log.LogMsg($"Configuration loaded"); if (!args.NoPatch) { Log.LogMsg($"Applying patches..."); if (!q.ApplyPatchSettingsFile()) { 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.CoverArt = string.IsNullOrWhiteSpace(args.CoverArt) ? null : new Bitmap(args.CoverArt); } catch (Exception ex) { Log.LogErr($"Unable to load playlist cover art from {args.CoverArt}", ex); playlist.CoverArt = 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); 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 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); } }