osu/osu.Game/IPC/BeatmapIPCChannel.cs

47 lines
1.3 KiB
C#
Raw Normal View History

2018-01-05 11:21:19 +00:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
2017-03-04 09:51:16 +00:00
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Diagnostics;
using System.Threading.Tasks;
using osu.Framework.Platform;
2017-07-26 04:22:46 +00:00
using osu.Game.Beatmaps;
2017-03-04 09:51:16 +00:00
namespace osu.Game.IPC
{
public class BeatmapIPCChannel : IpcChannel<BeatmapImportMessage>
{
private readonly BeatmapManager beatmaps;
2017-03-04 09:51:16 +00:00
public BeatmapIPCChannel(IIpcHost host, BeatmapManager beatmaps = null)
2017-03-04 09:51:16 +00:00
: base(host)
{
this.beatmaps = beatmaps;
2017-03-09 05:24:16 +00:00
MessageReceived += msg =>
2017-03-04 09:51:16 +00:00
{
Debug.Assert(beatmaps != null);
ImportAsync(msg.Path).ContinueWith(t =>
{
if (t.Exception != null) throw t.Exception;
}, TaskContinuationOptions.OnlyOnFaulted);
2017-03-04 09:51:16 +00:00
};
}
public async Task ImportAsync(string path)
{
if (beatmaps == null)
{
//we want to contact a remote osu! to handle the import.
await SendMessageAsync(new BeatmapImportMessage { Path = path });
return;
}
beatmaps.Import(path);
}
}
public class BeatmapImportMessage
{
public string Path;
}
}