diff --git a/osu.Game/Beatmaps/BeatmapStore.cs b/osu.Game/Beatmaps/BeatmapStore.cs index b84d249893..9e0df553c3 100644 --- a/osu.Game/Beatmaps/BeatmapStore.cs +++ b/osu.Game/Beatmaps/BeatmapStore.cs @@ -108,6 +108,7 @@ namespace osu.Game.Beatmaps /// /// Delete a beatmap from the store. + /// Is a no-op for already deleted beatmaps. /// /// The beatmap to delete. public void Delete(BeatmapSetInfo beatmapSet) @@ -118,6 +119,11 @@ namespace osu.Game.Beatmaps files.Dereference(beatmapSet.Files); } + /// + /// Returns a to a usable state if it has previously been deleted but not yet purged. + /// Is a no-op for already usable beatmaps. + /// + /// The beatmap to restore. public void Undelete(BeatmapSetInfo beatmapSet) { if (!Database.Undelete(beatmapSet)) return; @@ -125,6 +131,12 @@ namespace osu.Game.Beatmaps files.Reference(beatmapSet.Files); } + /// + /// Retrieve a instance for the provided + /// + /// The beatmap to lookup. + /// The currently loaded . Allows for optimisation where elements are shared with the new beatmap. + /// A instance correlating to the provided . public WorkingBeatmap GetWorkingBeatmap(BeatmapInfo beatmapInfo, WorkingBeatmap previous = null) { if (beatmapInfo == null || beatmapInfo == DefaultBeatmap?.BeatmapInfo) @@ -155,6 +167,11 @@ namespace osu.Game.Beatmaps Database.Reset(); } + /// + /// Creates an from a valid storage path. + /// + /// A file or folder path resolving the beatmap content. + /// A reader giving access to the beatmap's content. private ArchiveReader getReaderFrom(string path) { if (ZipFile.IsZipFile(path)) @@ -163,20 +180,26 @@ namespace osu.Game.Beatmaps return new LegacyFilesystemReader(path); } - private BeatmapSetInfo importToStorage(ArchiveReader archiveReader) + /// + /// Import a beamap into our local storage. + /// If the beatmap is already imported, the existing instance will be returned. + /// + /// The beatmap archive to be read. + /// The imported beatmap, or an existing instance if it is already present. + private BeatmapSetInfo importToStorage(ArchiveReader reader) { BeatmapMetadata metadata; - using (var stream = new StreamReader(archiveReader.GetStream(archiveReader.Filenames.First(f => f.EndsWith(".osu"))))) + using (var stream = new StreamReader(reader.GetStream(reader.Filenames.First(f => f.EndsWith(".osu"))))) metadata = BeatmapDecoder.GetDecoder(stream).Decode(stream).Metadata; MemoryStream hashable = new MemoryStream(); List fileInfos = new List(); - foreach (string file in archiveReader.Filenames) + foreach (string file in reader.Filenames) { - using (Stream s = archiveReader.GetStream(file)) + using (Stream s = reader.GetStream(file)) { fileInfos.Add(files.Add(s, file)); s.CopyTo(hashable); @@ -190,9 +213,7 @@ namespace osu.Game.Beatmaps if (existing != null) { Database.GetChildren(existing); - Undelete(existing); - return existing; } @@ -205,11 +226,11 @@ namespace osu.Game.Beatmaps Metadata = metadata }; - var mapNames = archiveReader.Filenames.Where(f => f.EndsWith(".osu")); + var mapNames = reader.Filenames.Where(f => f.EndsWith(".osu")); foreach (var name in mapNames) { - using (var raw = archiveReader.GetStream(name)) + using (var raw = reader.GetStream(name)) using (var ms = new MemoryStream()) //we need a memory stream so we can seek and shit using (var sr = new StreamReader(ms)) {