1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 21:23:04 +08:00

General improvements

This commit is contained in:
Alex Amadori 2017-03-13 11:29:24 +01:00
parent 971d8eb7c5
commit caa6e9c82b
7 changed files with 10 additions and 7 deletions

View File

@ -12,6 +12,7 @@ using System.Drawing;
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
using osu.Game.Screens.Menu; using osu.Game.Screens.Menu;
using osu.Game.Beatmaps.IO;
namespace osu.Desktop namespace osu.Desktop
{ {
@ -57,7 +58,7 @@ namespace osu.Desktop
var dropData = (object[])e.Data.GetData(DataFormats.FileDrop); var dropData = (object[])e.Data.GetData(DataFormats.FileDrop);
var filePaths = dropData.Select(f => f.ToString()).ToArray(); 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)); Task.Run(() => BeatmapDatabase.Import(filePaths));
else if (filePaths.All(f => Path.GetExtension(f) == @".osr")) else if (filePaths.All(f => Path.GetExtension(f) == @".osr"))
Task.Run(() => 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) private void dragEnter(DragEventArgs e)
{ {

View File

@ -17,6 +17,7 @@ using osu.Game.Modes.Catch;
using osu.Game.Modes.Mania; using osu.Game.Modes.Mania;
using osu.Game.Modes.Osu; using osu.Game.Modes.Osu;
using osu.Game.Modes.Taiko; using osu.Game.Modes.Taiko;
using osu.Game.Beatmaps.IO;
namespace osu.Game.Tests.Beatmaps.IO namespace osu.Game.Tests.Beatmaps.IO
{ {
@ -106,7 +107,7 @@ namespace osu.Game.Tests.Beatmaps.IO
private string prepareTempCopy(string path) 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; return new FileInfo(path).CopyTo(temp, true).FullName;
} }

View File

@ -10,6 +10,7 @@ namespace osu.Game.Beatmaps.IO
{ {
public abstract class BeatmapArchiveReader : ArchiveReader public abstract class BeatmapArchiveReader : ArchiveReader
{ {
public const string OszExtension = @".osz";
public static BeatmapArchiveReader GetBeatmapArchiveReader(Storage storage, string path) public static BeatmapArchiveReader GetBeatmapArchiveReader(Storage storage, string path)
{ {
@ -19,7 +20,7 @@ namespace osu.Game.Beatmaps.IO
} }
catch (InvalidCastException e) 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; throw;
} }
} }

View File

@ -16,7 +16,7 @@ namespace osu.Game.Beatmaps.IO
AddReader<OszArchiveReader>((storage, path) => AddReader<OszArchiveReader>((storage, path) =>
{ {
using (var stream = storage.GetStream(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(); OsuLegacyDecoder.Register();
} }

View File

@ -186,7 +186,7 @@ namespace osu.Game.Database
{ {
hash = input.GetMd5Hash(); hash = input.GetMd5Hash();
input.Seek(0, SeekOrigin.Begin); 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)) if (!storage.Exists(path))
using (var output = storage.GetStream(path, FileAccess.Write)) using (var output = storage.GetStream(path, FileAccess.Write))
input.CopyTo(output); input.CopyTo(output);

View File

@ -327,7 +327,7 @@
<Compile Include="Screens\Select\Options\BeatmapOptionsEditButton.cs" /> <Compile Include="Screens\Select\Options\BeatmapOptionsEditButton.cs" />
<Compile Include="Screens\Select\Options\BeatmapOptionsOverlay.cs" /> <Compile Include="Screens\Select\Options\BeatmapOptionsOverlay.cs" />
<Compile Include="Screens\Select\Options\BeatmapOptionsRemoveFromUnplayedButton.cs" /> <Compile Include="Screens\Select\Options\BeatmapOptionsRemoveFromUnplayedButton.cs" />
<Compile Include="Beatmaps\IO\ArchiveReader.cs" /> <Compile Include="IO\ArchiveReader.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="$(SolutionDir)\osu-framework\osu.Framework\osu.Framework.csproj"> <ProjectReference Include="$(SolutionDir)\osu-framework\osu.Framework\osu.Framework.csproj">