Example #1
0
        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);
            }
        }
Example #2
0
        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();
        }
Example #3
0
        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();
        }
        protected void SetupPlaylistsWithSongs(int playlistCount, int songCount)
        {
            BeatSaberQuestomConfig config = null;

            using (var fp = GetProvider())
            {
                var q = GetQaeConfig(fp);
                using (QuestomAssetsEngine qae = new QuestomAssetsEngine(q))
                {
                    config = qae.GetCurrentConfig();

                    for (int p = 0; p < playlistCount; p++)
                    {
                        var playlist = new BeatSaberPlaylist()
                        {
                            PlaylistID   = string.Format(PlaylistIDFormat, p),
                            PlaylistName = string.Format(PlaylistNameFormat, p)
                        };
                        for (int i = 0; i < songCount; i++)
                        {
                            var song = new BeatSaberSong()
                            {
                                SongID         = string.Format(SongIDFormat, p, i),
                                CustomSongPath = MakeTestSongDir()
                            };

                            playlist.SongList.Add(song);
                        }
                        config.Playlists.Add(playlist);
                    }
                    qae.UpdateConfig(config);
                    qae.Save();
                }
            }
        }
        public void DoesNotDuplicateSong()
        {
            SetupPlaylistsWithSongs(2, 2);
            BeatSaberQuestomConfig oldConfig = null;

            using (var fp = GetProvider())
            {
                var q = GetQaeConfig(fp);
                using (QuestomAssetsEngine qae = new QuestomAssetsEngine(q))
                {
                    oldConfig = qae.GetCurrentConfig();
                    var config = CopyIDs(oldConfig);
                    var song   = new BeatSaberSong()
                    {
                        SongID         = config.Playlists[0].SongList[0].SongID,
                        CustomSongPath = MakeTestSongDir()
                    };
                    oldConfig.Playlists[0].SongList.Add(song);
                    qae.UpdateConfig(config);
                }
            }
            using (var fp = GetProvider())
            {
                var q = GetQaeConfig(fp);
                using (QuestomAssetsEngine qae = new QuestomAssetsEngine(q))
                {
                    var testConfig = qae.GetCurrentConfig();
                    Assert.AreEqual(2, testConfig.Playlists[0].SongList.Count());
                    Assert.AreEqual(2, testConfig.Playlists[1].SongList.Count());
                }
            }
            Assert.Pass();
        }
Example #6
0
        private void SetupPlaylistsWithSongs(int playlistCount, int songCount)
        {
            BeatSaberQuestomConfig config = null;
            QuestomAssetsEngine    qae    = new QuestomAssetsEngine(_apkFile);

            config = qae.GetCurrentConfig();

            for (int p = 0; p < playlistCount; p++)
            {
                var playlist = new BeatSaberPlaylist()
                {
                    PlaylistID   = string.Format(PlaylistIDFormat, p),
                    PlaylistName = string.Format(PlaylistNameFormat, p),
                    CoverArt     = new System.Drawing.Bitmap(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);
        }
Example #7
0
        public void DoesNotDuplicateSong()
        {
            SetupPlaylistsWithSongs(2, 2);
            BeatSaberQuestomConfig oldConfig = null;
            QuestomAssetsEngine    qae       = new QuestomAssetsEngine(_apkFile);

            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);

            qae = new QuestomAssetsEngine(_apkFile, true);

            var testConfig = qae.GetCurrentConfig(false);

            Assert.AreEqual(2, testConfig.Playlists[0].SongList.Count());
            Assert.AreEqual(2, testConfig.Playlists[1].SongList.Count());

            Assert.Pass();
        }
Example #8
0
        public void MovesSongToNewPlaylist()
        {
            SetupPlaylistsWithSongs(2, 2);
            BeatSaberQuestomConfig oldConfig = null;
            QuestomAssetsEngine    qae       = new QuestomAssetsEngine(_apkFile);

            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);


            qae = new QuestomAssetsEngine(_apkFile, 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 MovesSongToNewPlaylist()
        {
            SetupPlaylistsWithSongs(2, 2);
            BeatSaberQuestomConfig oldConfig = null;

            using (var fp = GetProvider())
            {
                var q = GetQaeConfig(fp);
                using (QuestomAssetsEngine qae = new QuestomAssetsEngine(q))
                {
                    oldConfig = qae.GetCurrentConfig();
                    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);
                    qae.Save();
                }
            }
            using (var fp = GetProvider())
            {
                var q = GetQaeConfig(fp);
                using (QuestomAssetsEngine qae = new QuestomAssetsEngine(q))
                {
                    var testConfig = qae.GetCurrentConfig();
                    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 loadlots()
        {
            QuestomAssets.Utils.ImageUtils.Instance = new ImageUtilsWin();

            try
            {
                QaeConfig cfg2 = new QaeConfig()
                {
                    AssetsPath       = "Data",
                    RootFileProvider = new FolderFileProvider(@"C:\Users\VR\Desktop\platform-tools_r28.0.3-windows\perftest", false),
                    SongsPath        = "customsongs",
                    SongFileProvider = new FolderFileProvider(@"C:\Users\VR\Desktop\platform-tools_r28.0.3-windows\perftest", false)
                };

                var qae2    = new QuestomAssetsEngine(cfg2);
                var config  = qae2.GetCurrentConfig();
                var folders = GetCustomSongsFromPath(@"C:\Users\VR\Desktop\platform-tools_r28.0.3-windows\perftest\customsongs");
                if (folders.Count < 1)
                {
                    Log.LogErr("Request to reload songs folder, but didn't find any songs!");
                    //not found probably isn't the right response code for this, but meh

                    return;
                }
                Log.LogMsg($"Starting to reload custom songs from folders.  Found {folders.Count} folders to evaluate");
                //todo: probably don't just grab this one
                var playlist = config.Playlists.FirstOrDefault(x => x.PlaylistID == "CustomSongs");
                if (playlist == null)
                {
                    playlist = new BeatSaberPlaylist()
                    {
                        PlaylistID   = "CustomSongs",
                        PlaylistName = "Custom Songs"
                    };
                    config.Playlists.Add(playlist);
                }
                int addedCtr = 0;

                foreach (var folder in folders)
                {
                    string songId = folder.Replace("/", "");
                    songId = songId.Replace(" ", "");
                    if (config.Playlists.SelectMany(x => x.SongList).Any(x => x.SongID?.ToLower() == songId.ToLower()))
                    {
                        //SendStatusMessage($"Folder {folder} already loaded");
                        Log.LogMsg($"Custom song in folder {folder} appears to already be loaded, skipping it.");
                        continue;
                    }
                    //safety check to make sure we aren't importing one with the same ID as a beatsaber song.  It could be re-ID'ed, but this is a stopgap
                    if (BSConst.KnownLevelIDs.Contains(songId))
                    {
                        Log.LogErr($"Song in path {folder} would conflict with a built in songID and will be skipped");
                        continue;
                    }
                    // SendStatusMessage($"Adding song in {folder}");
                    Log.LogMsg($"Adding custom song in folder {folder} to playlist ID {playlist.PlaylistID}");
                    playlist.SongList.Add(new BeatSaberSong()
                    {
                        SongID         = songId,
                        CustomSongPath = Path.Combine(cfg2.SongsPath, folder)
                    });
                    addedCtr++;
                    //maybe limit how many
                    //if (addedCtr > 200)
                    //{
                    //    ShowToast("Too Many Songs", "That's too many at once.  After these finish and you 'Sync to Beat Saber', then try 'Reload Songs Folder' again to load more.", ToastType.Warning, 10);
                    //    break;
                    //}
                }
                if (addedCtr > 0)
                {
                    Log.LogMsg("Updating config with loaded song folders");

                    qae2.UpdateConfig(config);
                }
                qae2.Save();
            }
            finally
            {
            }
            QaeConfig cfg3 = new QaeConfig()
            {
                AssetsPath       = "Data",
                RootFileProvider = new FolderFileProvider(@"C:\Users\VR\Desktop\platform-tools_r28.0.3-windows\perftest\Data", false),
                SongsPath        = "customsongs",
                SongFileProvider = new FolderFileProvider(@"C:\Users\VR\Desktop\platform-tools_r28.0.3-windows\perftest\Data\customsongs", false)
            };

            var qae3 = new QuestomAssetsEngine(cfg3);

            Assert.Pass();
        }
Example #11
0
        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);
            }
        }
Example #12
0
        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);
            }
        }