mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 01:53:00 +08:00
Don't attempt to import command line arguments as beatmaps.
This commit is contained in:
parent
49ae976af6
commit
870aa2750f
@ -83,64 +83,66 @@ namespace osu.Game.Database
|
|||||||
connection.DeleteAll<BeatmapInfo>();
|
connection.DeleteAll<BeatmapInfo>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Import(params string[] paths)
|
public void Import(IEnumerable<string> paths)
|
||||||
{
|
{
|
||||||
foreach (string p in paths)
|
foreach (string p in paths)
|
||||||
|
Import(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Import(string path)
|
||||||
|
{
|
||||||
|
string hash = null;
|
||||||
|
|
||||||
|
BeatmapMetadata metadata;
|
||||||
|
|
||||||
|
using (var reader = ArchiveReader.GetReader(storage, path))
|
||||||
|
metadata = reader.ReadMetadata();
|
||||||
|
|
||||||
|
if (metadata.OnlineBeatmapSetID.HasValue &&
|
||||||
|
connection.Table<BeatmapSetInfo>().Count(b => b.OnlineBeatmapSetID == metadata.OnlineBeatmapSetID) != 0)
|
||||||
|
return; // TODO: Update this beatmap instead
|
||||||
|
|
||||||
|
if (File.Exists(path)) // Not always the case, i.e. for LegacyFilesystemReader
|
||||||
{
|
{
|
||||||
var path = p;
|
using (var md5 = MD5.Create())
|
||||||
string hash = null;
|
using (var input = storage.GetStream(path))
|
||||||
|
|
||||||
BeatmapMetadata metadata;
|
|
||||||
|
|
||||||
using (var reader = ArchiveReader.GetReader(storage, path))
|
|
||||||
metadata = reader.ReadMetadata();
|
|
||||||
|
|
||||||
if (metadata.OnlineBeatmapSetID.HasValue &&
|
|
||||||
connection.Table<BeatmapSetInfo>().Count(b => b.OnlineBeatmapSetID == metadata.OnlineBeatmapSetID) != 0)
|
|
||||||
return; // TODO: Update this beatmap instead
|
|
||||||
|
|
||||||
if (File.Exists(path)) // Not always the case, i.e. for LegacyFilesystemReader
|
|
||||||
{
|
{
|
||||||
using (var md5 = MD5.Create())
|
hash = BitConverter.ToString(md5.ComputeHash(input)).Replace("-", "").ToLowerInvariant();
|
||||||
using (var input = storage.GetStream(path))
|
input.Seek(0, SeekOrigin.Begin);
|
||||||
{
|
path = Path.Combine(@"beatmaps", hash.Remove(1), hash.Remove(2), hash);
|
||||||
hash = BitConverter.ToString(md5.ComputeHash(input)).Replace("-", "").ToLowerInvariant();
|
using (var output = storage.GetStream(path, FileAccess.Write))
|
||||||
input.Seek(0, SeekOrigin.Begin);
|
input.CopyTo(output);
|
||||||
path = Path.Combine(@"beatmaps", hash.Remove(1), hash.Remove(2), hash);
|
|
||||||
using (var output = storage.GetStream(path, FileAccess.Write))
|
|
||||||
input.CopyTo(output);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
var beatmapSet = new BeatmapSetInfo
|
|
||||||
{
|
|
||||||
OnlineBeatmapSetID = metadata.OnlineBeatmapSetID,
|
|
||||||
Beatmaps = new List<BeatmapInfo>(),
|
|
||||||
Path = path,
|
|
||||||
Hash = hash,
|
|
||||||
Metadata = metadata
|
|
||||||
};
|
|
||||||
|
|
||||||
using (var reader = ArchiveReader.GetReader(storage, path))
|
|
||||||
{
|
|
||||||
string[] mapNames = reader.ReadBeatmaps();
|
|
||||||
foreach (var name in mapNames)
|
|
||||||
{
|
|
||||||
using (var stream = new StreamReader(reader.GetStream(name)))
|
|
||||||
{
|
|
||||||
var decoder = BeatmapDecoder.GetDecoder(stream);
|
|
||||||
Beatmap beatmap = decoder.Decode(stream);
|
|
||||||
beatmap.BeatmapInfo.Path = name;
|
|
||||||
|
|
||||||
// TODO: Diff beatmap metadata with set metadata and leave it here if necessary
|
|
||||||
beatmap.BeatmapInfo.Metadata = null;
|
|
||||||
|
|
||||||
beatmapSet.Beatmaps.Add(beatmap.BeatmapInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Import(new[] { beatmapSet });
|
|
||||||
}
|
}
|
||||||
|
var beatmapSet = new BeatmapSetInfo
|
||||||
|
{
|
||||||
|
OnlineBeatmapSetID = metadata.OnlineBeatmapSetID,
|
||||||
|
Beatmaps = new List<BeatmapInfo>(),
|
||||||
|
Path = path,
|
||||||
|
Hash = hash,
|
||||||
|
Metadata = metadata
|
||||||
|
};
|
||||||
|
|
||||||
|
using (var reader = ArchiveReader.GetReader(storage, path))
|
||||||
|
{
|
||||||
|
string[] mapNames = reader.ReadBeatmaps();
|
||||||
|
foreach (var name in mapNames)
|
||||||
|
{
|
||||||
|
using (var stream = new StreamReader(reader.GetStream(name)))
|
||||||
|
{
|
||||||
|
var decoder = BeatmapDecoder.GetDecoder(stream);
|
||||||
|
Beatmap beatmap = decoder.Decode(stream);
|
||||||
|
beatmap.BeatmapInfo.Path = name;
|
||||||
|
|
||||||
|
// TODO: Diff beatmap metadata with set metadata and leave it here if necessary
|
||||||
|
beatmap.BeatmapInfo.Metadata = null;
|
||||||
|
|
||||||
|
beatmapSet.Beatmaps.Add(beatmap.BeatmapInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Import(new[] { beatmapSet });
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Import(IEnumerable<BeatmapSetInfo> beatmapSets)
|
public void Import(IEnumerable<BeatmapSetInfo> beatmapSets)
|
||||||
|
@ -24,6 +24,7 @@ using osu.Game.Screens.Menu;
|
|||||||
using OpenTK;
|
using OpenTK;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Graphics.Primitives;
|
using osu.Framework.Graphics.Primitives;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace osu.Game
|
namespace osu.Game
|
||||||
{
|
{
|
||||||
@ -67,14 +68,17 @@ namespace osu.Game
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (args?.Length > 0)
|
if (args?.Length > 0)
|
||||||
ImportBeatmaps(args);
|
{
|
||||||
|
var paths = args.Where(a => !a.StartsWith(@"-"));
|
||||||
|
ImportBeatmaps(paths);
|
||||||
|
}
|
||||||
|
|
||||||
Dependencies.Cache(this);
|
Dependencies.Cache(this);
|
||||||
|
|
||||||
PlayMode = LocalConfig.GetBindable<PlayMode>(OsuConfig.PlayMode);
|
PlayMode = LocalConfig.GetBindable<PlayMode>(OsuConfig.PlayMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ImportBeatmaps(params string[] paths)
|
public void ImportBeatmaps(IEnumerable<string> paths)
|
||||||
{
|
{
|
||||||
Schedule(delegate { Dependencies.Get<BeatmapDatabase>().Import(paths); });
|
Schedule(delegate { Dependencies.Get<BeatmapDatabase>().Import(paths); });
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user