Remove unnecessary methods and local variables.

This commit is contained in:
Dean Herbert 2017-02-13 18:30:47 +09:00
parent 1aeb48b920
commit 11643d2e09
No known key found for this signature in database
GPG Key ID: 46D71BF4958ABB49
6 changed files with 21 additions and 41 deletions

View File

@ -20,34 +20,22 @@ namespace osu.Desktop.Beatmaps.IO
public static void Register() => AddReader<LegacyFilesystemReader>((storage, path) => Directory.Exists(path)); public static void Register() => AddReader<LegacyFilesystemReader>((storage, path) => Directory.Exists(path));
private string basePath { get; set; } private string basePath { get; set; }
private string[] beatmaps { get; set; }
private string storyboard { get; set; }
private Beatmap firstMap { get; set; } private Beatmap firstMap { get; set; }
public LegacyFilesystemReader(string path) public LegacyFilesystemReader(string path)
{ {
basePath = path; basePath = path;
beatmaps = Directory.GetFiles(basePath, @"*.osu").Select(f => Path.GetFileName(f)).ToArray(); BeatmapFilenames = Directory.GetFiles(basePath, @"*.osu").Select(f => Path.GetFileName(f)).ToArray();
if (beatmaps.Length == 0) if (BeatmapFilenames.Length == 0)
throw new FileNotFoundException(@"This directory contains no beatmaps"); throw new FileNotFoundException(@"This directory contains no beatmaps");
storyboard = Directory.GetFiles(basePath, @"*.osb").Select(f => Path.GetFileName(f)).FirstOrDefault(); StoryboardFilename = Directory.GetFiles(basePath, @"*.osb").Select(f => Path.GetFileName(f)).FirstOrDefault();
using (var stream = new StreamReader(GetStream(beatmaps[0]))) using (var stream = new StreamReader(GetStream(BeatmapFilenames[0])))
{ {
var decoder = BeatmapDecoder.GetDecoder(stream); var decoder = BeatmapDecoder.GetDecoder(stream);
firstMap = decoder.Decode(stream); firstMap = decoder.Decode(stream);
} }
} }
public override string[] ReadBeatmaps()
{
return beatmaps;
}
public override string ReadStoryboard()
{
return storyboard;
}
public override Stream GetStream(string name) public override Stream GetStream(string name)
{ {
return File.OpenRead(Path.Combine(basePath, name)); return File.OpenRead(Path.Combine(basePath, name));

View File

@ -39,7 +39,7 @@ namespace osu.Game.Tests.Beatmaps.IO
"Soleily - Renatus (MMzz) [Muzukashii].osu", "Soleily - Renatus (MMzz) [Muzukashii].osu",
"Soleily - Renatus (MMzz) [Oni].osu" "Soleily - Renatus (MMzz) [Oni].osu"
}; };
var maps = reader.ReadBeatmaps(); var maps = reader.BeatmapFilenames;
foreach (var map in expected) foreach (var map in expected)
Assert.Contains(map, maps); Assert.Contains(map, maps);
} }

View File

@ -39,14 +39,17 @@ namespace osu.Game.Beatmaps.IO
/// Reads the beatmap metadata from this archive. /// Reads the beatmap metadata from this archive.
/// </summary> /// </summary>
public abstract BeatmapMetadata ReadMetadata(); public abstract BeatmapMetadata ReadMetadata();
/// <summary> /// <summary>
/// Gets a list of beatmap file names. /// Gets a list of beatmap file names.
/// </summary> /// </summary>
public abstract string[] ReadBeatmaps(); public string[] BeatmapFilenames { get; protected set; }
/// <summary> /// <summary>
/// Gets the storyboard file name. /// The storyboard filename. Null if no storyboard is present.
/// </summary> /// </summary>
public abstract string ReadStoryboard(); public string StoryboardFilename { get; protected set; }
/// <summary> /// <summary>
/// Opens a stream for reading a specific file from this archive. /// Opens a stream for reading a specific file from this archive.
/// </summary> /// </summary>

View File

@ -25,37 +25,25 @@ namespace osu.Game.Beatmaps.IO
private Stream archiveStream; private Stream archiveStream;
private ZipFile archive; private ZipFile archive;
private string[] beatmaps;
private string storyboard;
private Beatmap firstMap; private Beatmap firstMap;
public OszArchiveReader(Stream archiveStream) public OszArchiveReader(Stream archiveStream)
{ {
this.archiveStream = archiveStream; this.archiveStream = archiveStream;
archive = ZipFile.Read(archiveStream); archive = ZipFile.Read(archiveStream);
beatmaps = archive.Entries.Where(e => e.FileName.EndsWith(@".osu")) BeatmapFilenames = archive.Entries.Where(e => e.FileName.EndsWith(@".osu"))
.Select(e => e.FileName).ToArray(); .Select(e => e.FileName).ToArray();
if (beatmaps.Length == 0) if (BeatmapFilenames.Length == 0)
throw new FileNotFoundException(@"This directory contains no beatmaps"); throw new FileNotFoundException(@"This directory contains no beatmaps");
storyboard = archive.Entries.Where(e => e.FileName.EndsWith(@".osb")) StoryboardFilename = archive.Entries.Where(e => e.FileName.EndsWith(@".osb"))
.Select(e => e.FileName).FirstOrDefault(); .Select(e => e.FileName).FirstOrDefault();
using (var stream = new StreamReader(GetStream(beatmaps[0]))) using (var stream = new StreamReader(GetStream(BeatmapFilenames[0])))
{ {
var decoder = BeatmapDecoder.GetDecoder(stream); var decoder = BeatmapDecoder.GetDecoder(stream);
firstMap = decoder.Decode(stream); firstMap = decoder.Decode(stream);
} }
} }
public override string[] ReadBeatmaps()
{
return beatmaps;
}
public override string ReadStoryboard()
{
return storyboard;
}
public override Stream GetStream(string name) public override Stream GetStream(string name)
{ {
ZipEntry entry = archive.Entries.SingleOrDefault(e => e.FileName == name); ZipEntry entry = archive.Entries.SingleOrDefault(e => e.FileName == name);

View File

@ -68,6 +68,7 @@ namespace osu.Game.Beatmaps
beatmap = decoder?.Decode(stream); beatmap = decoder?.Decode(stream);
} }
if (WithStoryboard && beatmap != null && BeatmapSetInfo.StoryboardFile != null) if (WithStoryboard && beatmap != null && BeatmapSetInfo.StoryboardFile != null)
using (var stream = new StreamReader(reader.GetStream(BeatmapSetInfo.StoryboardFile))) using (var stream = new StreamReader(reader.GetStream(BeatmapSetInfo.StoryboardFile)))
decoder?.Decode(stream, beatmap); decoder?.Decode(stream, beatmap);

View File

@ -125,7 +125,7 @@ namespace osu.Game.Database
using (var reader = ArchiveReader.GetReader(storage, path)) using (var reader = ArchiveReader.GetReader(storage, path))
{ {
string[] mapNames = reader.ReadBeatmaps(); string[] mapNames = reader.BeatmapFilenames;
foreach (var name in mapNames) foreach (var name in mapNames)
{ {
using (var stream = new StreamReader(reader.GetStream(name))) using (var stream = new StreamReader(reader.GetStream(name)))
@ -139,7 +139,7 @@ namespace osu.Game.Database
beatmapSet.Beatmaps.Add(beatmap.BeatmapInfo); beatmapSet.Beatmaps.Add(beatmap.BeatmapInfo);
} }
beatmapSet.StoryboardFile = reader.ReadStoryboard(); beatmapSet.StoryboardFile = reader.StoryboardFilename;
} }
} }