2019-01-24 08:43:03 +00: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 09:19:50 +00:00
|
|
|
|
|
2017-03-04 09:51:16 +00:00
|
|
|
|
using System.Diagnostics;
|
2018-02-14 11:26:49 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2017-03-04 09:51:16 +00:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using osu.Framework.Platform;
|
2018-02-15 03:21:11 +00:00
|
|
|
|
using osu.Game.Database;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-03-04 09:51:16 +00:00
|
|
|
|
namespace osu.Game.IPC
|
|
|
|
|
{
|
2018-02-14 11:26:49 +00:00
|
|
|
|
public class ArchiveImportIPCChannel : IpcChannel<ArchiveImportMessage>
|
2017-03-04 09:51:16 +00:00
|
|
|
|
{
|
2018-02-15 05:19:16 +00:00
|
|
|
|
private readonly ICanAcceptFiles importer;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-02-15 05:19:16 +00:00
|
|
|
|
public ArchiveImportIPCChannel(IIpcHost host, ICanAcceptFiles importer = null)
|
2017-03-04 09:51:16 +00:00
|
|
|
|
: base(host)
|
|
|
|
|
{
|
2018-02-14 11:26:49 +00:00
|
|
|
|
this.importer = importer;
|
2021-11-28 13:59:49 +00:00
|
|
|
|
|
2017-03-09 05:24:16 +00:00
|
|
|
|
MessageReceived += msg =>
|
2017-03-04 09:51:16 +00:00
|
|
|
|
{
|
2018-02-14 11:26:49 +00:00
|
|
|
|
Debug.Assert(importer != null);
|
2017-03-09 06:52:40 +00:00
|
|
|
|
ImportAsync(msg.Path).ContinueWith(t =>
|
|
|
|
|
{
|
|
|
|
|
if (t.Exception != null) throw t.Exception;
|
|
|
|
|
}, TaskContinuationOptions.OnlyOnFaulted);
|
2021-11-28 13:59:49 +00:00
|
|
|
|
|
|
|
|
|
return null;
|
2017-03-04 09:51:16 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-03-04 09:51:16 +00:00
|
|
|
|
public async Task ImportAsync(string path)
|
|
|
|
|
{
|
2018-02-14 11:26:49 +00:00
|
|
|
|
if (importer == null)
|
2017-03-04 09:51:16 +00:00
|
|
|
|
{
|
2020-05-05 01:31:11 +00:00
|
|
|
|
// we want to contact a remote osu! to handle the import.
|
2021-03-08 03:57:16 +00:00
|
|
|
|
await SendMessageAsync(new ArchiveImportMessage { Path = path }).ConfigureAwait(false);
|
2017-03-04 09:51:16 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-09-26 09:44:03 +00:00
|
|
|
|
if (importer.HandledExtensions.Contains(Path.GetExtension(path)?.ToLowerInvariant()))
|
2021-03-08 03:57:16 +00:00
|
|
|
|
await importer.Import(path).ConfigureAwait(false);
|
2017-03-04 09:51:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-02-14 11:26:49 +00:00
|
|
|
|
public class ArchiveImportMessage
|
2017-03-04 09:51:16 +00:00
|
|
|
|
{
|
|
|
|
|
public string Path;
|
|
|
|
|
}
|
|
|
|
|
}
|