1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-19 06:02:56 +08:00
osu-lazer/osu.Game/IPC/ArchiveImportIPCChannel.cs

50 lines
1.5 KiB
C#
Raw Normal View History

2018-01-05 19:21:19 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
2017-03-04 17:51:16 +08:00
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Diagnostics;
using System.IO;
using System.Linq;
2017-03-04 17:51:16 +08:00
using System.Threading.Tasks;
using osu.Framework.Platform;
using osu.Game.Database;
2017-03-04 17:51:16 +08:00
namespace osu.Game.IPC
{
public class ArchiveImportIPCChannel : IpcChannel<ArchiveImportMessage>
2017-03-04 17:51:16 +08:00
{
2018-02-15 13:19:16 +08:00
private readonly ICanAcceptFiles importer;
2017-03-04 17:51:16 +08:00
2018-02-15 13:19:16 +08:00
public ArchiveImportIPCChannel(IIpcHost host, ICanAcceptFiles importer = null)
2017-03-04 17:51:16 +08:00
: base(host)
{
this.importer = importer;
2017-03-09 13:24:16 +08:00
MessageReceived += msg =>
2017-03-04 17:51:16 +08:00
{
Debug.Assert(importer != null);
ImportAsync(msg.Path).ContinueWith(t =>
{
if (t.Exception != null) throw t.Exception;
}, TaskContinuationOptions.OnlyOnFaulted);
2017-03-04 17:51:16 +08:00
};
}
public async Task ImportAsync(string path)
{
if (importer == null)
2017-03-04 17:51:16 +08:00
{
//we want to contact a remote osu! to handle the import.
await SendMessageAsync(new ArchiveImportMessage { Path = path });
2017-03-04 17:51:16 +08:00
return;
}
if (importer.HandledExtensions.Contains(Path.GetExtension(path)))
importer.Import(path);
2017-03-04 17:51:16 +08:00
}
}
public class ArchiveImportMessage
2017-03-04 17:51:16 +08:00
{
public string Path;
}
}