diff --git a/osu.Desktop/Program.cs b/osu.Desktop/Program.cs index 3171e474dc..ddf58ac363 100644 --- a/osu.Desktop/Program.cs +++ b/osu.Desktop/Program.cs @@ -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) diff --git a/osu.Game.Tests/Beatmaps/IO/ImportBeatmapTest.cs b/osu.Game.Tests/Beatmaps/IO/ImportBeatmapTest.cs index 90d1aa542f..3132d63188 100644 --- a/osu.Game.Tests/Beatmaps/IO/ImportBeatmapTest.cs +++ b/osu.Game.Tests/Beatmaps/IO/ImportBeatmapTest.cs @@ -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"); diff --git a/osu.Game/Database/BeatmapDatabase.cs b/osu.Game/Database/BeatmapDatabase.cs index 03f904b7e8..df8ead7f94 100644 --- a/osu.Game/Database/BeatmapDatabase.cs +++ b/osu.Game/Database/BeatmapDatabase.cs @@ -25,14 +25,14 @@ namespace osu.Game.Database public event Action BeatmapSetAdded; public event Action 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); } diff --git a/osu.Game/IPC/BeatmapIPCChannel.cs b/osu.Game/IPC/BeatmapIPCChannel.cs new file mode 100644 index 0000000000..8c53910146 --- /dev/null +++ b/osu.Game/IPC/BeatmapIPCChannel.cs @@ -0,0 +1,43 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// 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 + { + 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; + } +} diff --git a/osu.Game/IPC/BeatmapImporter.cs b/osu.Game/IPC/BeatmapImporter.cs deleted file mode 100644 index b6ce4d1e35..0000000000 --- a/osu.Game/IPC/BeatmapImporter.cs +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . -// 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 channel; - private BeatmapDatabase beatmaps; - - public BeatmapImporter(GameHost host, BeatmapDatabase beatmaps = null) - { - this.beatmaps = beatmaps; - - channel = new IpcChannel(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; - } -} diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 9851edd8c1..f5c9b8723e 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -190,7 +190,7 @@ - +