mirror of
https://github.com/ppy/osu.git
synced 2025-03-15 22:27:46 +08:00
Refactor to use scoped using
(and also correctly dispose TagLib portion)
This commit is contained in:
parent
f2f97602f2
commit
82f7f99f37
@ -6,6 +6,8 @@ using System.IO;
|
||||
using osu.Game.IO.FileAbstraction;
|
||||
using osu.Game.Rulesets.Edit.Checks.Components;
|
||||
using osu.Game.Storyboards;
|
||||
using TagLib;
|
||||
using File = TagLib.File;
|
||||
|
||||
namespace osu.Game.Rulesets.Edit.Checks
|
||||
{
|
||||
@ -50,31 +52,30 @@ namespace osu.Game.Rulesets.Edit.Checks
|
||||
continue;
|
||||
}
|
||||
|
||||
using Stream data = context.WorkingBeatmap.GetStream(storagePath);
|
||||
var fileAbstraction = new StreamFileAbstraction(filename, data);
|
||||
|
||||
// We use TagLib here for platform invariance; BASS cannot detect audio presence on Linux.
|
||||
TagLib.File tagFile = null;
|
||||
string errorReason = null;
|
||||
Issue issue;
|
||||
|
||||
try
|
||||
{
|
||||
tagFile = TagLib.File.Create(fileAbstraction);
|
||||
}
|
||||
catch (TagLib.CorruptFileException) { errorReason = "Corrupt file"; }
|
||||
catch (TagLib.UnsupportedFormatException) { errorReason = "Unsupported format"; }
|
||||
|
||||
if (errorReason != null)
|
||||
// We use TagLib here for platform invariance; BASS cannot detect audio presence on Linux.
|
||||
using (Stream data = context.WorkingBeatmap.GetStream(storagePath))
|
||||
using (File tagFile = File.Create(new StreamFileAbstraction(filename, data)))
|
||||
{
|
||||
yield return new IssueTemplateFileError(this).Create(filename, errorReason);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tagFile.Properties.AudioChannels == 0)
|
||||
continue;
|
||||
}
|
||||
|
||||
yield return new IssueTemplateHasAudioTrack(this).Create(filename);
|
||||
issue = new IssueTemplateHasAudioTrack(this).Create(filename);
|
||||
}
|
||||
catch (CorruptFileException)
|
||||
{
|
||||
issue = new IssueTemplateFileError(this).Create(filename, "Corrupt file");
|
||||
}
|
||||
catch (UnsupportedFormatException)
|
||||
{
|
||||
issue = new IssueTemplateFileError(this).Create(filename, "Unsupported format");
|
||||
}
|
||||
|
||||
yield return issue;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,8 @@ namespace osu.Game.Rulesets.Edit.Checks
|
||||
|
||||
foreach (var file in beatmapSet.Files)
|
||||
{
|
||||
using Stream data = context.WorkingBeatmap.GetStream(file.FileInfo.StoragePath);
|
||||
using (Stream data = context.WorkingBeatmap.GetStream(file.FileInfo.StoragePath))
|
||||
{
|
||||
if (data == null)
|
||||
continue;
|
||||
|
||||
@ -56,6 +57,7 @@ namespace osu.Game.Rulesets.Edit.Checks
|
||||
yield return new IssueTemplateTooShort(this).Create(file.Filename, ms);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool hasAudioExtension(string filename) => audioExtensions.Any(filename.ToLower().EndsWith);
|
||||
private bool probablyHasAudioData(Stream data) => data.Length > min_bytes_threshold;
|
||||
|
@ -22,11 +22,13 @@ namespace osu.Game.Rulesets.Edit.Checks
|
||||
|
||||
foreach (var file in beatmapSet.Files)
|
||||
{
|
||||
using Stream data = context.WorkingBeatmap.GetStream(file.FileInfo.StoragePath);
|
||||
using (Stream data = context.WorkingBeatmap.GetStream(file.FileInfo.StoragePath))
|
||||
{
|
||||
if (data?.Length == 0)
|
||||
yield return new IssueTemplateZeroBytes(this).Create(file.Filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class IssueTemplateZeroBytes : IssueTemplate
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user