From 0a9038cce8329105ed6e241276184935864210c0 Mon Sep 17 00:00:00 2001 From: QingQiz Date: Thu, 1 Sep 2022 21:11:57 +0800 Subject: [PATCH] FIX: Prevent background image from being set to video --- BmsToOsu/Converter/Osu.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/BmsToOsu/Converter/Osu.cs b/BmsToOsu/Converter/Osu.cs index 04a005c..ee32bd0 100644 --- a/BmsToOsu/Converter/Osu.cs +++ b/BmsToOsu/Converter/Osu.cs @@ -63,6 +63,7 @@ public static (string, HashSet fileToCp) ToOsuBeatMap( var bg = ""; + var imgExt = new[] { ".jpg", ".png", ".jpeg" }; if (File.Exists(Path.Join(dir, data.Metadata.BackBmp))) { bg = data.Metadata.BackBmp; @@ -77,15 +78,22 @@ public static (string, HashSet fileToCp) ToOsuBeatMap( } else if (data.BgaFrames.Any()) { - bg = data.BgaFrames[data.BgaFrames.Count / 2].File; + var bga = data.BgaFrames + .Where(x => imgExt + .Any(ext => x.File.EndsWith(ext, StringComparison.OrdinalIgnoreCase))) + .ToList(); + + if (bga.Any()) + { + bg = bga[bga.Count / 2].File; + } } if (string.IsNullOrEmpty(bg)) { - var ext = new[] { ".jpg", ".png", ".jpeg" }; bg = Directory .GetFiles(dir, "*.*", SearchOption.TopDirectoryOnly) - .FirstOrDefault(f => ext.Any(e => f.EndsWith(e, StringComparison.OrdinalIgnoreCase))) ?? ""; + .FirstOrDefault(f => imgExt.Any(e => f.EndsWith(e, StringComparison.OrdinalIgnoreCase))) ?? ""; } if (!string.IsNullOrEmpty(bg))