diff --git a/osu.Game/IO/FileAbstraction/StreamFileAbstraction.cs b/osu.Game/IO/FileAbstraction/StreamFileAbstraction.cs deleted file mode 100644 index 8d14385707..0000000000 --- a/osu.Game/IO/FileAbstraction/StreamFileAbstraction.cs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -using System; -using System.IO; - -namespace osu.Game.IO.FileAbstraction -{ - public class StreamFileAbstraction : TagLib.File.IFileAbstraction - { - public StreamFileAbstraction(string filename, Stream fileStream) - { - ReadStream = fileStream; - Name = filename; - } - - public string Name { get; } - - public Stream ReadStream { get; } - public Stream WriteStream => ReadStream; - - public void CloseStream(Stream stream) - { - ArgumentNullException.ThrowIfNull(stream); - - stream.Close(); - } - } -} diff --git a/osu.Game/Rulesets/Edit/Checks/CheckAudioInVideo.cs b/osu.Game/Rulesets/Edit/Checks/CheckAudioInVideo.cs index 71a493c4cc..005902a8a1 100644 --- a/osu.Game/Rulesets/Edit/Checks/CheckAudioInVideo.cs +++ b/osu.Game/Rulesets/Edit/Checks/CheckAudioInVideo.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.IO; using osu.Framework.Logging; using osu.Game.Beatmaps; -using osu.Game.IO.FileAbstraction; using osu.Game.Rulesets.Edit.Checks.Components; using osu.Game.Storyboards; using osu.Game.Utils; @@ -62,7 +61,7 @@ namespace osu.Game.Rulesets.Edit.Checks { // We use TagLib here for platform invariance; BASS cannot detect audio presence on Linux. using (Stream data = context.WorkingBeatmap.GetStream(storagePath)) - using (File tagFile = TagLibUtils.CreateFile(new StreamFileAbstraction(filename, data))) + using (File tagFile = TagLibUtils.GetTagLibFile(filename, data)) { if (tagFile.Properties.AudioChannels == 0) continue; diff --git a/osu.Game/Rulesets/Edit/Checks/CheckVideoResolution.cs b/osu.Game/Rulesets/Edit/Checks/CheckVideoResolution.cs index 8cd9422eb4..c050932aa6 100644 --- a/osu.Game/Rulesets/Edit/Checks/CheckVideoResolution.cs +++ b/osu.Game/Rulesets/Edit/Checks/CheckVideoResolution.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.IO; using osu.Framework.Logging; using osu.Game.Beatmaps; -using osu.Game.IO.FileAbstraction; using osu.Game.Rulesets.Edit.Checks.Components; using osu.Game.Storyboards; using osu.Game.Utils; @@ -46,7 +45,7 @@ namespace osu.Game.Rulesets.Edit.Checks try { using (Stream data = context.WorkingBeatmap.GetStream(storagePath)) - using (File tagFile = TagLibUtils.CreateFile(new StreamFileAbstraction(filename, data))) + using (File tagFile = TagLibUtils.GetTagLibFile(filename, data)) { int height = tagFile.Properties.VideoHeight; int width = tagFile.Properties.VideoWidth; diff --git a/osu.Game/Screens/Edit/Setup/ResourcesSection.cs b/osu.Game/Screens/Edit/Setup/ResourcesSection.cs index 037b4eb08f..5399f1fd6f 100644 --- a/osu.Game/Screens/Edit/Setup/ResourcesSection.cs +++ b/osu.Game/Screens/Edit/Setup/ResourcesSection.cs @@ -102,7 +102,7 @@ namespace osu.Game.Screens.Edit.Setup try { - tagSource = TagLibUtils.CreateFile(source.FullName); + tagSource = TagLibUtils.GetTagLibFile(source.FullName); } catch (Exception e) { diff --git a/osu.Game/Utils/TagLibUtils.cs b/osu.Game/Utils/TagLibUtils.cs index e7bcf02237..4989d04238 100644 --- a/osu.Game/Utils/TagLibUtils.cs +++ b/osu.Game/Utils/TagLibUtils.cs @@ -1,32 +1,56 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using System.IO; -using osu.Game.IO.FileAbstraction; using TagLib; +using File = TagLib.File; namespace osu.Game.Utils { public class TagLibUtils { /// - /// Creates a with culture-invariant MIME type detection. + /// Creates a with culture-invariant MIME type detection, based on stream data. /// - /// The file abstraction of the file to be created. /// The created. - public static TagLib.File CreateFile(StreamFileAbstraction fileAbstraction) => - TagLib.File.Create(fileAbstraction, getMimeType(fileAbstraction.Name), ReadStyle.Average); + public static File GetTagLibFile(string filename, Stream stream) + { + var fileAbstraction = new StreamFileAbstraction(filename, stream); + + return File.Create(fileAbstraction, getMimeType(fileAbstraction.Name), ReadStyle.Average | ReadStyle.PictureLazy); + } /// - /// Creates a with culture-invariant MIME type detection. + /// Creates a with culture-invariant MIME type detection based on a file on disk. /// /// The full path of the file to be created. /// The created. - public static TagLib.File CreateFile(string filePath) => - TagLib.File.Create(filePath, getMimeType(filePath), ReadStyle.Average); + public static File GetTagLibFile(string filePath) => + File.Create(filePath, getMimeType(filePath), ReadStyle.Average | ReadStyle.PictureLazy); // Manual MIME type resolution to avoid culture variance (ie. https://github.com/ppy/osu/issues/32962) - private static string getMimeType(string fileName) => - @"taglib/" + Path.GetExtension(fileName).TrimStart('.'); + private static string getMimeType(string fileName) => @"taglib/" + Path.GetExtension(fileName).TrimStart('.'); + + private class StreamFileAbstraction : File.IFileAbstraction + { + public StreamFileAbstraction(string filename, Stream fileStream) + { + ReadStream = fileStream; + Name = filename; + } + + public string Name { get; } + + public Stream ReadStream { get; } + public Stream WriteStream => ReadStream; + + public void CloseStream(Stream stream) + { + ArgumentNullException.ThrowIfNull(stream); + + stream.Close(); + } + } } }