mirror of
https://github.com/osukey/osukey.git
synced 2025-06-09 21:37:59 +09:00
Change IPC to make sense.
This commit is contained in:
parent
b294386077
commit
aa9d85624d
@ -29,7 +29,7 @@ namespace osu.Desktop
|
|||||||
{
|
{
|
||||||
if (!host.IsPrimaryInstance)
|
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
|
// Restore the cwd so relative paths given at the command line work correctly
|
||||||
Directory.SetCurrentDirectory(cwd);
|
Directory.SetCurrentDirectory(cwd);
|
||||||
foreach (var file in args)
|
foreach (var file in args)
|
||||||
|
@ -69,7 +69,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
|
|
||||||
Assert.IsTrue(File.Exists(temp));
|
Assert.IsTrue(File.Exists(temp));
|
||||||
|
|
||||||
var importer = new BeatmapImporter(client);
|
var importer = new BeatmapIPCChannel(client);
|
||||||
if (!importer.ImportAsync(temp).Wait(1000))
|
if (!importer.ImportAsync(temp).Wait(1000))
|
||||||
Assert.Fail(@"IPC took too long to send");
|
Assert.Fail(@"IPC took too long to send");
|
||||||
|
|
||||||
|
@ -25,14 +25,14 @@ namespace osu.Game.Database
|
|||||||
public event Action<BeatmapSetInfo> BeatmapSetAdded;
|
public event Action<BeatmapSetInfo> BeatmapSetAdded;
|
||||||
public event Action<BeatmapSetInfo> BeatmapSetRemoved;
|
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;
|
this.storage = storage;
|
||||||
|
|
||||||
if (importHost != null)
|
if (importHost != null)
|
||||||
ipc = new BeatmapImporter(importHost, this);
|
ipc = new BeatmapIPCChannel(importHost, this);
|
||||||
|
|
||||||
if (connection == null)
|
if (connection == null)
|
||||||
{
|
{
|
||||||
|
43
osu.Game/IPC/BeatmapIPCChannel.cs
Normal file
43
osu.Game/IPC/BeatmapIPCChannel.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -190,7 +190,7 @@
|
|||||||
<Compile Include="Graphics\UserInterface\PercentageCounter.cs" />
|
<Compile Include="Graphics\UserInterface\PercentageCounter.cs" />
|
||||||
<Compile Include="Graphics\UserInterface\ScoreCounter.cs" />
|
<Compile Include="Graphics\UserInterface\ScoreCounter.cs" />
|
||||||
<Compile Include="Graphics\UserInterface\StarCounter.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\APIAccess.cs" />
|
||||||
<Compile Include="Online\API\APIRequest.cs" />
|
<Compile Include="Online\API\APIRequest.cs" />
|
||||||
<Compile Include="Online\API\OAuth.cs" />
|
<Compile Include="Online\API\OAuth.cs" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user