mirror of
https://github.com/ppy/osu.git
synced 2024-11-19 06:42:54 +08:00
47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
using System.Diagnostics;
|
|
using System.Threading.Tasks;
|
|
using osu.Framework.Platform;
|
|
using osu.Game.Beatmaps;
|
|
|
|
namespace osu.Game.IPC
|
|
{
|
|
public class BeatmapIPCChannel : IpcChannel<BeatmapImportMessage>
|
|
{
|
|
private readonly BeatmapManager beatmaps;
|
|
|
|
public BeatmapIPCChannel(IIpcHost host, BeatmapManager beatmaps = null)
|
|
: base(host)
|
|
{
|
|
this.beatmaps = beatmaps;
|
|
MessageReceived += msg =>
|
|
{
|
|
Debug.Assert(beatmaps != null);
|
|
ImportAsync(msg.Path).ContinueWith(t =>
|
|
{
|
|
if (t.Exception != null) throw t.Exception;
|
|
}, TaskContinuationOptions.OnlyOnFaulted);
|
|
};
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|