diff --git a/BeatSyncLib/Hashing/SongHasher.cs b/BeatSyncLib/Hashing/SongHasher.cs index f4a0ee9..1018cf1 100644 --- a/BeatSyncLib/Hashing/SongHasher.cs +++ b/BeatSyncLib/Hashing/SongHasher.cs @@ -1,4 +1,5 @@ using BeatSyncLib.Utilities; +using Newtonsoft.Json; using System; using System.Collections.Concurrent; using System.Diagnostics; @@ -64,20 +65,31 @@ public async Task HashDirectoryAsync() Logger.log?.Warn("Somehow the directory is null in AddMissingHashes, this will [probably] never happen."); return; } + catch (JsonException ex) + { + Logger.log?.Warn($"Invalid JSON in beatmap at '{d.FullName}', skipping. {ex.Message}"); + return; + } + catch (Exception ex) + { + Logger.log?.Warn($"Unhandled exception hashing beatmap at '{d.FullName}', skipping. {ex.Message}"); + Logger.log?.Debug(ex); + return; + } if (data == null) { Logger.log?.Warn($"GetSongHashData({d.FullName}) returned null"); return; } - else if (string.IsNullOrEmpty(data.songHash)) + else if (data.songHash == null || data.songHash.Length == 0) { Logger.log?.Warn($"GetSongHashData(\"{d.Name}\") returned a null string for hash (No info.dat?)."); return; } if (!ExistingSongs.TryAdd(data.songHash, d.FullName)) - Logger.log?.Debug($"Duplicate song detected: {ExistingSongs[data.songHash].Split('\\', '/').LastOrDefault()} : {d.Name}"); + Logger.log?.Debug($"Duplicate song detected: {ExistingSongs[data.songHash]?.Split('\\', '/').LastOrDefault()} : {d.Name}"); if (!HashDictionary.TryAdd(d.FullName, data)) { Logger.log?.Warn($"Couldn't add {d.FullName} to HashDictionary"); @@ -145,7 +157,8 @@ private static int GetStringHashSafe(string str) s += 2; } return hash1 + (hash2 * 1566083941); - }catch(Exception) + } + catch (Exception) { return 0; diff --git a/BeatSyncLib/Utilities/Util.cs b/BeatSyncLib/Utilities/Util.cs index 1d92262..08a3d26 100644 --- a/BeatSyncLib/Utilities/Util.cs +++ b/BeatSyncLib/Utilities/Util.cs @@ -1,4 +1,5 @@ using Newtonsoft.Json.Linq; +using Newtonsoft.Json; using System; using System.IO; using System.Linq; @@ -165,6 +166,7 @@ public enum ByteUnit /// Hash of the song files. Null if the info.dat file doesn't exist /// /// + ///