2019-01-24 16:43:03 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using osu.Framework.Platform;
|
|
|
|
|
using osu.Game.Database;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.IPC
|
|
|
|
|
{
|
|
|
|
|
public class ArchiveImportIPCChannel : IpcChannel<ArchiveImportMessage>
|
|
|
|
|
{
|
|
|
|
|
private readonly ICanAcceptFiles importer;
|
|
|
|
|
|
|
|
|
|
public ArchiveImportIPCChannel(IIpcHost host, ICanAcceptFiles importer = null)
|
|
|
|
|
: base(host)
|
|
|
|
|
{
|
|
|
|
|
this.importer = importer;
|
2021-11-28 21:59:49 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
MessageReceived += msg =>
|
|
|
|
|
{
|
|
|
|
|
Debug.Assert(importer != null);
|
|
|
|
|
ImportAsync(msg.Path).ContinueWith(t =>
|
|
|
|
|
{
|
|
|
|
|
if (t.Exception != null) throw t.Exception;
|
|
|
|
|
}, TaskContinuationOptions.OnlyOnFaulted);
|
2021-11-28 21:59:49 +08:00
|
|
|
|
|
|
|
|
|
return null;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task ImportAsync(string path)
|
|
|
|
|
{
|
|
|
|
|
if (importer == null)
|
|
|
|
|
{
|
2020-05-05 09:31:11 +08:00
|
|
|
|
// we want to contact a remote osu! to handle the import.
|
2021-03-08 11:57:16 +08:00
|
|
|
|
await SendMessageAsync(new ArchiveImportMessage { Path = path }).ConfigureAwait(false);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-26 17:44:03 +08:00
|
|
|
|
if (importer.HandledExtensions.Contains(Path.GetExtension(path)?.ToLowerInvariant()))
|
2021-03-08 11:57:16 +08:00
|
|
|
|
await importer.Import(path).ConfigureAwait(false);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class ArchiveImportMessage
|
|
|
|
|
{
|
|
|
|
|
public string Path;
|
|
|
|
|
}
|
|
|
|
|
}
|