diff --git a/Assets/Script/Song/Scanning/SongScanThread.cs b/Assets/Script/Song/Scanning/SongScanThread.cs index 16ca771f7..95bfb806a 100644 --- a/Assets/Script/Song/Scanning/SongScanThread.cs +++ b/Assets/Script/Song/Scanning/SongScanThread.cs @@ -190,45 +190,46 @@ private void ScanSubDirectory(string cacheFolder, string subDir, ICollection SongsInsideCON = XboxCONFileBrowser.BrowseCON(file, _updateFolderPath, _updatableSongs); - // for each CON song that was found (assuming some WERE found) - if (SongsInsideCON != null) { - foreach (ConSongEntry SongInsideCON in SongsInsideCON) { - // validate that the song is good to add in-game - var CONResult = ScanConSong(cacheFolder, SongInsideCON); - switch (CONResult) { - case ScanResult.Ok: - _songsScanned++; - songsScanned = _songsScanned; - songs.Add(SongInsideCON); - break; - case ScanResult.NotASong: - break; - default: - _errorsEncountered++; - errorsEncountered = _errorsEncountered; - _songErrors[cacheFolder].Add(new SongError(subDir, CONResult, SongInsideCON.Name)); - Debug.LogWarning($"Error encountered with {subDir}"); - break; + + try{ // try-catch to prevent crash if user doesn't have permission to access a folder + foreach (var file in Directory.EnumerateFiles(subDir)) { + // for each file found, read first 4 bytes and check for "CON " or "LIVE" + using var fs = new FileStream(file, FileMode.Open, FileAccess.Read); + using var br = new BinaryReader(fs); + string fHeader = Encoding.UTF8.GetString(br.ReadBytes(4)); + if (fHeader == "CON " || fHeader == "LIVE") { + List SongsInsideCON = XboxCONFileBrowser.BrowseCON(file); + // for each CON song that was found (assuming some WERE found) + if (SongsInsideCON != null) { + foreach (ConSongEntry SongInsideCON in SongsInsideCON) { + // validate that the song is good to add in-game + var CONResult = ScanConSong(cacheFolder, SongInsideCON); + switch (CONResult) { + case ScanResult.Ok: + _songsScanned++; + songsScanned = _songsScanned; + songs.Add(SongInsideCON); + break; + case ScanResult.NotASong: + break; + default: + _errorsEncountered++; + errorsEncountered = _errorsEncountered; + _songErrors[cacheFolder].Add(new SongError(subDir, CONResult, SongInsideCON.Name)); + Debug.LogWarning($"Error encountered with {subDir}"); + break; + } } } } } - } - - string[] subdirectories = Directory.GetDirectories(subDir); - - foreach (string subdirectory in subdirectories) { - if(subdirectory != Path.Combine(subDir, "songs_updates")) + string[] subdirectories = Directory.GetDirectories(subDir); + foreach (string subdirectory in subdirectories) { ScanSubDirectory(cacheFolder, subdirectory, songs); + } + }catch(Exception e){ + Debug.LogException(e); } } @@ -376,4 +377,4 @@ private static ScanResult ScanConSong(string cache, ConSongEntry file) { } } -} \ No newline at end of file +} diff --git a/Assets/Script/ThirdParty/TwitchController.cs b/Assets/Script/ThirdParty/TwitchController.cs index 61376f179..83759045a 100644 --- a/Assets/Script/ThirdParty/TwitchController.cs +++ b/Assets/Script/ThirdParty/TwitchController.cs @@ -17,13 +17,14 @@ public static TwitchController Instance { // Creates .TXT file witth current song information public string TextFilePath => Path.Combine(GameManager.PersistentDataPath, "currentSong.txt"); + // Creates .JSON file with current song information + public string JsonFilePath => Path.Combine(GameManager.PersistentDataPath, "currentSong.json"); private void Start() { Instance = this; - // While YARG should delete the file on exit, you never know if a crash or something prevented that. - DeleteCurrentSongFile(); - CreateEmptySongFile(); + // While YARG should blank the file on exit, you never know if a crash or something prevented that. + BlankSongFile(); // Listen to the changing of songs Play.OnSongStart += OnSongStart; @@ -36,29 +37,24 @@ private void Start() { Play.OnPauseToggle += OnPauseToggle; } - private void CreateEmptySongFile() { - // Open the text file for appending - using var writer = new StreamWriter(TextFilePath, false); - - // Make the file blank (Avoid errors in OBS) - writer.Write(""); - } - - private void DeleteCurrentSongFile() { + private void BlankSongFile() { // Open the text file for appending using var writer = new StreamWriter(TextFilePath, false); + using var jsonWriter = new StreamWriter(JsonFilePath, false); // Make the file blank (Avoid errors in OBS) writer.Write(""); + jsonWriter.Write(""); } private void OnApplicationQuit() { - DeleteCurrentSongFile(); + BlankSongFile(); } void OnSongStart(SongEntry song) { // Open the text file for appending using var writer = new StreamWriter(TextFilePath, false); + using var jsonWriter = new StreamWriter(JsonFilePath, false); // Get the input string str = $"{song.Name}\n{song.Artist}\n{song.Album}\n{song.Genre}\n" + @@ -68,17 +64,17 @@ void OnSongStart(SongEntry song) { if (TagRegex.IsMatch(str)) { str = TagRegex.Replace(str, string.Empty); } + + // Convert to JSON + string json = JsonUtility.ToJson(song); // Write text to the file writer.Write(str); + jsonWriter.Write(json); } void OnSongEnd(SongEntry song) { - // Open the text file for appending - using var writer = new StreamWriter(TextFilePath, false); - - // Make the file blank (Avoid errors in OBS) - writer.Write(""); + BlankSongFile(); } private void OnInstrumentSelection(PlayerManager.Player playerInfo) { diff --git a/Assets/Script/ThirdParty/UpdateChecker.cs b/Assets/Script/ThirdParty/UpdateChecker.cs index 7cf30b846..3c623a1d0 100644 --- a/Assets/Script/ThirdParty/UpdateChecker.cs +++ b/Assets/Script/ThirdParty/UpdateChecker.cs @@ -59,6 +59,7 @@ private async void CheckForUpdates() { IsOutOfDate = true; Debug.Log($"Update available! New version: {releaseTag}"); + ToastManager.ToastInformation($"Update available! New version: {releaseTag}"); } else { Debug.Log("Game is up to date."); ToastManager.ToastMessage("Game is up to date."); diff --git a/Assets/Script/UI/MusicLibrary/SongSelection.cs b/Assets/Script/UI/MusicLibrary/SongSelection.cs index a18eab441..45e607ecc 100644 --- a/Assets/Script/UI/MusicLibrary/SongSelection.cs +++ b/Assets/Script/UI/MusicLibrary/SongSelection.cs @@ -60,7 +60,7 @@ private set { _selectedIndex -= _songs.Count; } - if (_songs[value] is SongViewType song) { + if (_songs[_selectedIndex] is SongViewType song) { GameManager.Instance.SelectedSong = song.SongEntry; }