mirror of
https://github.com/ppy/osu.git
synced 2025-03-15 15:27:20 +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"; }
|
||||
// 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)))
|
||||
{
|
||||
if (tagFile.Properties.AudioChannels == 0)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (errorReason != null)
|
||||
issue = new IssueTemplateHasAudioTrack(this).Create(filename);
|
||||
}
|
||||
catch (CorruptFileException)
|
||||
{
|
||||
yield return new IssueTemplateFileError(this).Create(filename, errorReason);
|
||||
|
||||
continue;
|
||||
issue = new IssueTemplateFileError(this).Create(filename, "Corrupt file");
|
||||
}
|
||||
catch (UnsupportedFormatException)
|
||||
{
|
||||
issue = new IssueTemplateFileError(this).Create(filename, "Unsupported format");
|
||||
}
|
||||
|
||||
if (tagFile.Properties.AudioChannels == 0)
|
||||
continue;
|
||||
|
||||
yield return new IssueTemplateHasAudioTrack(this).Create(filename);
|
||||
yield return issue;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,29 +31,31 @@ namespace osu.Game.Rulesets.Edit.Checks
|
||||
|
||||
foreach (var file in beatmapSet.Files)
|
||||
{
|
||||
using Stream data = context.WorkingBeatmap.GetStream(file.FileInfo.StoragePath);
|
||||
if (data == null)
|
||||
continue;
|
||||
|
||||
var fileCallbacks = new FileCallbacks(new DataStreamFileProcedures(data));
|
||||
int decodeStream = Bass.CreateStream(StreamSystem.NoBuffer, BassFlags.Decode | BassFlags.Prescan, fileCallbacks.Callbacks, fileCallbacks.Handle);
|
||||
|
||||
if (decodeStream == 0)
|
||||
using (Stream data = context.WorkingBeatmap.GetStream(file.FileInfo.StoragePath))
|
||||
{
|
||||
// If the file is not likely to be properly parsed by Bass, we don't produce Error issues about it.
|
||||
// Image files and audio files devoid of audio data both fail, for example, but neither would be issues in this check.
|
||||
if (hasAudioExtension(file.Filename) && probablyHasAudioData(data))
|
||||
yield return new IssueTemplateBadFormat(this).Create(file.Filename);
|
||||
if (data == null)
|
||||
continue;
|
||||
|
||||
continue;
|
||||
var fileCallbacks = new FileCallbacks(new DataStreamFileProcedures(data));
|
||||
int decodeStream = Bass.CreateStream(StreamSystem.NoBuffer, BassFlags.Decode | BassFlags.Prescan, fileCallbacks.Callbacks, fileCallbacks.Handle);
|
||||
|
||||
if (decodeStream == 0)
|
||||
{
|
||||
// If the file is not likely to be properly parsed by Bass, we don't produce Error issues about it.
|
||||
// Image files and audio files devoid of audio data both fail, for example, but neither would be issues in this check.
|
||||
if (hasAudioExtension(file.Filename) && probablyHasAudioData(data))
|
||||
yield return new IssueTemplateBadFormat(this).Create(file.Filename);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
long length = Bass.ChannelGetLength(decodeStream);
|
||||
double ms = Bass.ChannelBytes2Seconds(decodeStream, length) * 1000;
|
||||
|
||||
// Extremely short audio files do not play on some soundcards, resulting in nothing being heard in-game for some users.
|
||||
if (ms > 0 && ms < ms_threshold)
|
||||
yield return new IssueTemplateTooShort(this).Create(file.Filename, ms);
|
||||
}
|
||||
|
||||
long length = Bass.ChannelGetLength(decodeStream);
|
||||
double ms = Bass.ChannelBytes2Seconds(decodeStream, length) * 1000;
|
||||
|
||||
// Extremely short audio files do not play on some soundcards, resulting in nothing being heard in-game for some users.
|
||||
if (ms > 0 && ms < ms_threshold)
|
||||
yield return new IssueTemplateTooShort(this).Create(file.Filename, ms);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,9 +22,11 @@ namespace osu.Game.Rulesets.Edit.Checks
|
||||
|
||||
foreach (var file in beatmapSet.Files)
|
||||
{
|
||||
using Stream data = context.WorkingBeatmap.GetStream(file.FileInfo.StoragePath);
|
||||
if (data?.Length == 0)
|
||||
yield return new IssueTemplateZeroBytes(this).Create(file.Filename);
|
||||
using (Stream data = context.WorkingBeatmap.GetStream(file.FileInfo.StoragePath))
|
||||
{
|
||||
if (data?.Length == 0)
|
||||
yield return new IssueTemplateZeroBytes(this).Create(file.Filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user