1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 22:02:56 +08:00

Change IPC to make sense.

This commit is contained in:
Dean Herbert 2017-03-04 18:51:16 +09:00
parent b294386077
commit aa9d85624d
No known key found for this signature in database
GPG Key ID: 46D71BF4958ABB49
6 changed files with 50 additions and 53 deletions

View File

@ -29,7 +29,7 @@ namespace osu.Desktop
{
if (!host.IsPrimaryInstance)
{
var importer = new BeatmapImporter(host);
var importer = new BeatmapIPCChannel(host);
// Restore the cwd so relative paths given at the command line work correctly
Directory.SetCurrentDirectory(cwd);
foreach (var file in args)

View File

@ -69,7 +69,7 @@ namespace osu.Game.Tests.Beatmaps.IO
Assert.IsTrue(File.Exists(temp));
var importer = new BeatmapImporter(client);
var importer = new BeatmapIPCChannel(client);
if (!importer.ImportAsync(temp).Wait(1000))
Assert.Fail(@"IPC took too long to send");

View File

@ -25,14 +25,14 @@ namespace osu.Game.Database
public event Action<BeatmapSetInfo> BeatmapSetAdded;
public event Action<BeatmapSetInfo> BeatmapSetRemoved;
private BeatmapImporter ipc;
private BeatmapIPCChannel ipc;
public BeatmapDatabase(Storage storage, GameHost importHost = null)
public BeatmapDatabase(Storage storage, IIpcHost importHost = null)
{
this.storage = storage;
if (importHost != null)
ipc = new BeatmapImporter(importHost, this);
ipc = new BeatmapIPCChannel(importHost, this);
if (connection == null)
{
@ -151,7 +151,7 @@ namespace osu.Game.Database
e = e.InnerException ?? e;
Logger.Error(e, $@"Could not import beatmap set");
}
// Batch commit with multiple sets to database
Import(sets);
}

View File

@ -0,0 +1,43 @@
// Copyright (c) 2007-2017 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.Database;
namespace osu.Game.IPC
{
public class BeatmapIPCChannel : IpcChannel<BeatmapImportMessage>
{
private BeatmapDatabase beatmaps;
public BeatmapIPCChannel(IIpcHost host, BeatmapDatabase beatmaps = null)
: base(host)
{
this.beatmaps = beatmaps;
MessageReceived += (msg) =>
{
Debug.Assert(beatmaps != null);
ImportAsync(msg.Path);
};
}
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;
}
}

View File

@ -1,46 +0,0 @@
// Copyright (c) 2007-2017 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.Database;
namespace osu.Game.IPC
{
public class BeatmapImporter
{
private IpcChannel<BeatmapImportMessage> channel;
private BeatmapDatabase beatmaps;
public BeatmapImporter(GameHost host, BeatmapDatabase beatmaps = null)
{
this.beatmaps = beatmaps;
channel = new IpcChannel<BeatmapImportMessage>(host);
channel.MessageReceived += messageReceived;
}
public async Task ImportAsync(string path)
{
if (beatmaps != null)
beatmaps.Import(path);
else
{
await channel.SendMessageAsync(new BeatmapImportMessage { Path = path });
}
}
private void messageReceived(BeatmapImportMessage msg)
{
Debug.Assert(beatmaps != null);
ImportAsync(msg.Path);
}
}
public class BeatmapImportMessage
{
public string Path;
}
}

View File

@ -190,7 +190,7 @@
<Compile Include="Graphics\UserInterface\PercentageCounter.cs" />
<Compile Include="Graphics\UserInterface\ScoreCounter.cs" />
<Compile Include="Graphics\UserInterface\StarCounter.cs" />
<Compile Include="IPC\BeatmapImporter.cs" />
<Compile Include="IPC\BeatmapIPCChannel.cs" />
<Compile Include="Online\API\APIAccess.cs" />
<Compile Include="Online\API\APIRequest.cs" />
<Compile Include="Online\API\OAuth.cs" />