2017-02-07 12:59:30 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2016-10-21 17:25:22 +08:00
|
|
|
|
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using osu.Framework.Platform;
|
|
|
|
|
using osu.Game.Database;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.IPC
|
|
|
|
|
{
|
|
|
|
|
public class BeatmapImporter
|
|
|
|
|
{
|
|
|
|
|
private IpcChannel<BeatmapImportMessage> channel;
|
|
|
|
|
private BeatmapDatabase beatmaps;
|
|
|
|
|
|
2017-02-23 14:38:17 +08:00
|
|
|
|
public BeatmapImporter(GameHost host, BeatmapDatabase beatmaps = null)
|
2016-10-21 17:25:22 +08:00
|
|
|
|
{
|
|
|
|
|
this.beatmaps = beatmaps;
|
|
|
|
|
|
|
|
|
|
channel = new IpcChannel<BeatmapImportMessage>(host);
|
|
|
|
|
channel.MessageReceived += messageReceived;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-24 05:32:10 +08:00
|
|
|
|
public async Task ImportAsync(string path)
|
2016-10-21 17:25:22 +08:00
|
|
|
|
{
|
|
|
|
|
if (beatmaps != null)
|
|
|
|
|
beatmaps.Import(path);
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-02-24 05:32:10 +08:00
|
|
|
|
await channel.SendMessageAsync(new BeatmapImportMessage { Path = path });
|
2016-10-21 17:25:22 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void messageReceived(BeatmapImportMessage msg)
|
|
|
|
|
{
|
|
|
|
|
Debug.Assert(beatmaps != null);
|
|
|
|
|
|
2017-02-24 05:32:10 +08:00
|
|
|
|
ImportAsync(msg.Path);
|
2016-10-21 17:25:22 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class BeatmapImportMessage
|
|
|
|
|
{
|
|
|
|
|
public string Path;
|
|
|
|
|
}
|
|
|
|
|
}
|