From e216bfcf105edf58e54369821722ab1b77c22c43 Mon Sep 17 00:00:00 2001 From: MillhioreF Date: Sun, 13 Aug 2017 00:40:05 -0500 Subject: [PATCH] Recommended fixes (obsolete try/catch, fix infinite loop during variable parsing in a better way) --- osu.Game/Beatmaps/BeatmapManager.cs | 10 ++-------- osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs | 4 +++- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index 4b063adde0..e388f5b6d1 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -307,16 +307,10 @@ namespace osu.Game.Beatmaps /// The imported beatmap, or an existing instance if it is already present. private BeatmapSetInfo importToStorage(ArchiveReader reader) { - string mapName; // let's make sure there are actually .osu files to import. - try - { - mapName = reader.Filenames.First(f => f.EndsWith(".osu")); - } - catch - { + string mapName = reader.Filenames.FirstOrDefault(f => f.EndsWith(".osu")); + if (string.IsNullOrEmpty(mapName)) throw new InvalidOperationException("No beatmap files found in the map folder."); - } // for now, concatenate all .osu files in the set to create a unique hash. MemoryStream hashable = new MemoryStream(); diff --git a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs index 39f0a0378c..46cbad2487 100644 --- a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs @@ -222,8 +222,9 @@ namespace osu.Game.Beatmaps.Formats /// The line which may contains variables. private void decodeVariables(ref string line) { - if (line.IndexOf('$') >= 0) + while (line.IndexOf('$') >= 0) { + string origLine = line; string[] split = line.Split(','); for (int i = 0; i < split.Length; i++) { @@ -233,6 +234,7 @@ namespace osu.Game.Beatmaps.Formats } line = string.Join(",", split); + if (line == origLine) break; } }