2018-01-05 19:21:19 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-03-04 18:02:36 +08: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 12:22:46 +08:00
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2017-03-04 18:02:36 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.IPC
|
|
|
|
|
{
|
|
|
|
|
public class ScoreIPCChannel : IpcChannel<ScoreImportMessage>
|
|
|
|
|
{
|
2017-07-27 15:56:41 +08:00
|
|
|
|
private readonly ScoreStore scores;
|
2017-03-04 18:02:36 +08:00
|
|
|
|
|
2017-07-27 15:56:41 +08:00
|
|
|
|
public ScoreIPCChannel(IIpcHost host, ScoreStore scores = null)
|
2017-03-04 18:02:36 +08:00
|
|
|
|
: base(host)
|
|
|
|
|
{
|
|
|
|
|
this.scores = scores;
|
2017-03-09 13:24:16 +08:00
|
|
|
|
MessageReceived += msg =>
|
2017-03-04 18:02:36 +08:00
|
|
|
|
{
|
|
|
|
|
Debug.Assert(scores != null);
|
2017-03-09 13:24:16 +08:00
|
|
|
|
ImportAsync(msg.Path).ContinueWith(t =>
|
|
|
|
|
{
|
|
|
|
|
if (t.Exception != null) throw t.Exception;
|
|
|
|
|
}, TaskContinuationOptions.OnlyOnFaulted);
|
2017-03-04 18:02:36 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task ImportAsync(string path)
|
|
|
|
|
{
|
|
|
|
|
if (scores == null)
|
|
|
|
|
{
|
|
|
|
|
//we want to contact a remote osu! to handle the import.
|
|
|
|
|
await SendMessageAsync(new ScoreImportMessage { Path = path });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
scores.ReadReplayFile(path);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class ScoreImportMessage
|
|
|
|
|
{
|
|
|
|
|
public string Path;
|
|
|
|
|
}
|
|
|
|
|
}
|