From caa6e9c82b3d60f1f1ac4c7f560676e427b62816 Mon Sep 17 00:00:00 2001 From: Alex Amadori Date: Mon, 13 Mar 2017 11:29:24 +0100 Subject: [PATCH] General improvements --- osu.Desktop/OsuGameDesktop.cs | 5 +++-- osu.Game.Tests/Beatmaps/IO/ImportBeatmapTest.cs | 3 ++- osu.Game/Beatmaps/IO/BeatmapArchiveReader.cs | 3 ++- osu.Game/Beatmaps/IO/OszArchiveReader.cs | 2 +- osu.Game/Database/BeatmapDatabase.cs | 2 +- osu.Game/{Beatmaps => }/IO/ArchiveReader.cs | 0 osu.Game/osu.Game.csproj | 2 +- 7 files changed, 10 insertions(+), 7 deletions(-) rename osu.Game/{Beatmaps => }/IO/ArchiveReader.cs (100%) diff --git a/osu.Desktop/OsuGameDesktop.cs b/osu.Desktop/OsuGameDesktop.cs index 3b827f2809..a05925654d 100644 --- a/osu.Desktop/OsuGameDesktop.cs +++ b/osu.Desktop/OsuGameDesktop.cs @@ -12,6 +12,7 @@ using System.Drawing; using System.IO; using System.Threading.Tasks; using osu.Game.Screens.Menu; +using osu.Game.Beatmaps.IO; namespace osu.Desktop { @@ -57,7 +58,7 @@ namespace osu.Desktop var dropData = (object[])e.Data.GetData(DataFormats.FileDrop); var filePaths = dropData.Select(f => f.ToString()).ToArray(); - if (filePaths.All(f => Path.GetExtension(f) == @".osz")) + if (filePaths.All(f => Path.GetExtension(f) == BeatmapArchiveReader.OszExtension)) Task.Run(() => BeatmapDatabase.Import(filePaths)); else if (filePaths.All(f => Path.GetExtension(f) == @".osr")) Task.Run(() => @@ -67,7 +68,7 @@ namespace osu.Desktop }); } - private static readonly string[] allowed_extensions = { @".osz", @".osr" }; + private static readonly string[] allowed_extensions = { BeatmapArchiveReader.OszExtension, @".osr" }; private void dragEnter(DragEventArgs e) { diff --git a/osu.Game.Tests/Beatmaps/IO/ImportBeatmapTest.cs b/osu.Game.Tests/Beatmaps/IO/ImportBeatmapTest.cs index 69434505ce..5239286b56 100644 --- a/osu.Game.Tests/Beatmaps/IO/ImportBeatmapTest.cs +++ b/osu.Game.Tests/Beatmaps/IO/ImportBeatmapTest.cs @@ -17,6 +17,7 @@ using osu.Game.Modes.Catch; using osu.Game.Modes.Mania; using osu.Game.Modes.Osu; using osu.Game.Modes.Taiko; +using osu.Game.Beatmaps.IO; namespace osu.Game.Tests.Beatmaps.IO { @@ -106,7 +107,7 @@ namespace osu.Game.Tests.Beatmaps.IO private string prepareTempCopy(string path) { - var temp = Path.GetTempPath()+Guid.NewGuid()+".osz"; + var temp = Path.GetTempPath() + Guid.NewGuid() + BeatmapArchiveReader.OszExtension; return new FileInfo(path).CopyTo(temp, true).FullName; } diff --git a/osu.Game/Beatmaps/IO/BeatmapArchiveReader.cs b/osu.Game/Beatmaps/IO/BeatmapArchiveReader.cs index a1a7149f2e..d274d45694 100644 --- a/osu.Game/Beatmaps/IO/BeatmapArchiveReader.cs +++ b/osu.Game/Beatmaps/IO/BeatmapArchiveReader.cs @@ -10,6 +10,7 @@ namespace osu.Game.Beatmaps.IO { public abstract class BeatmapArchiveReader : ArchiveReader { + public const string OszExtension = @".osz"; public static BeatmapArchiveReader GetBeatmapArchiveReader(Storage storage, string path) { @@ -19,7 +20,7 @@ namespace osu.Game.Beatmaps.IO } catch (InvalidCastException e) { - Logger.Error(e, "A tricky ArchiveReader instance passed the test to be a BeatmapArhiveReader, but it's really not"); + Logger.Error(e, "A tricky " + $@"{nameof(ArchiveReader)}" + " instance passed the test to be a " + $@"{nameof(BeatmapArchiveReader)}" + ", but it's really not"); throw; } } diff --git a/osu.Game/Beatmaps/IO/OszArchiveReader.cs b/osu.Game/Beatmaps/IO/OszArchiveReader.cs index bf5174f7f9..60d379db61 100644 --- a/osu.Game/Beatmaps/IO/OszArchiveReader.cs +++ b/osu.Game/Beatmaps/IO/OszArchiveReader.cs @@ -16,7 +16,7 @@ namespace osu.Game.Beatmaps.IO AddReader((storage, path) => { using (var stream = storage.GetStream(path)) - return Path.GetExtension(path) == ".osz" && ZipFile.IsZipFile(stream, false); + return Path.GetExtension(path) == OszExtension && ZipFile.IsZipFile(stream, false); }); OsuLegacyDecoder.Register(); } diff --git a/osu.Game/Database/BeatmapDatabase.cs b/osu.Game/Database/BeatmapDatabase.cs index d50d00c6b3..c7b02acae1 100644 --- a/osu.Game/Database/BeatmapDatabase.cs +++ b/osu.Game/Database/BeatmapDatabase.cs @@ -186,7 +186,7 @@ namespace osu.Game.Database { hash = input.GetMd5Hash(); input.Seek(0, SeekOrigin.Begin); - path = Path.Combine(@"beatmaps", hash.Remove(1), hash.Remove(2), hash+".osz"); + path = Path.Combine(@"beatmaps", hash.Remove(1), hash.Remove(2), hash + BeatmapArchiveReader.OszExtension); if (!storage.Exists(path)) using (var output = storage.GetStream(path, FileAccess.Write)) input.CopyTo(output); diff --git a/osu.Game/Beatmaps/IO/ArchiveReader.cs b/osu.Game/IO/ArchiveReader.cs similarity index 100% rename from osu.Game/Beatmaps/IO/ArchiveReader.cs rename to osu.Game/IO/ArchiveReader.cs diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index d81cb2daff..8ae8c3d88e 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -327,7 +327,7 @@ - +