1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 22:47:24 +08:00

Merge pull request #22515 from Susko3/use-ipc-archive-importer

Allow importing beatmaps via file associations on desktop platforms
This commit is contained in:
Dean Herbert 2023-02-06 17:22:56 +09:00 committed by GitHub
commit 67ec3199c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 5 deletions

View File

@ -29,6 +29,7 @@ namespace osu.Desktop
internal partial class OsuGameDesktop : OsuGame internal partial class OsuGameDesktop : OsuGame
{ {
private OsuSchemeLinkIPCChannel? osuSchemeLinkIPCChannel; private OsuSchemeLinkIPCChannel? osuSchemeLinkIPCChannel;
private ArchiveImportIPCChannel? archiveImportIPCChannel;
public OsuGameDesktop(string[]? args = null) public OsuGameDesktop(string[]? args = null)
: base(args) : base(args)
@ -123,6 +124,7 @@ namespace osu.Desktop
LoadComponentAsync(new ElevatedPrivilegesChecker(), Add); LoadComponentAsync(new ElevatedPrivilegesChecker(), Add);
osuSchemeLinkIPCChannel = new OsuSchemeLinkIPCChannel(Host, this); osuSchemeLinkIPCChannel = new OsuSchemeLinkIPCChannel(Host, this);
archiveImportIPCChannel = new ArchiveImportIPCChannel(Host, this);
} }
public override void SetHost(GameHost host) public override void SetHost(GameHost host)
@ -181,6 +183,7 @@ namespace osu.Desktop
{ {
base.Dispose(isDisposing); base.Dispose(isDisposing);
osuSchemeLinkIPCChannel?.Dispose(); osuSchemeLinkIPCChannel?.Dispose();
archiveImportIPCChannel?.Dispose();
} }
private class SDL2BatteryInfo : BatteryInfo private class SDL2BatteryInfo : BatteryInfo

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System.IO;
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework; using osu.Framework;
@ -14,6 +15,8 @@ using osu.Game.Online.API;
using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Overlays.Notifications;
using osu.Game.Tests.Resources;
namespace osu.Game.Tests.Visual.Navigation namespace osu.Game.Tests.Visual.Navigation
{ {
@ -23,11 +26,13 @@ namespace osu.Game.Tests.Visual.Navigation
{ {
private HeadlessGameHost ipcSenderHost = null!; private HeadlessGameHost ipcSenderHost = null!;
private OsuSchemeLinkIPCChannel osuSchemeLinkIPCReceiver = null!;
private OsuSchemeLinkIPCChannel osuSchemeLinkIPCSender = null!; private OsuSchemeLinkIPCChannel osuSchemeLinkIPCSender = null!;
private ArchiveImportIPCChannel archiveImportIPCSender = null!;
private const int requested_beatmap_set_id = 1; private const int requested_beatmap_set_id = 1;
protected override TestOsuGame CreateTestGame() => new IpcGame(LocalStorage, API);
[Resolved] [Resolved]
private GameHost gameHost { get; set; } = null!; private GameHost gameHost { get; set; } = null!;
@ -56,11 +61,11 @@ namespace osu.Game.Tests.Visual.Navigation
return false; return false;
}; };
}); });
AddStep("create IPC receiver channel", () => osuSchemeLinkIPCReceiver = new OsuSchemeLinkIPCChannel(gameHost, Game)); AddStep("create IPC sender channels", () =>
AddStep("create IPC sender channel", () =>
{ {
ipcSenderHost = new HeadlessGameHost(gameHost.Name, new HostOptions { BindIPC = true }); ipcSenderHost = new HeadlessGameHost(gameHost.Name, new HostOptions { BindIPC = true });
osuSchemeLinkIPCSender = new OsuSchemeLinkIPCChannel(ipcSenderHost); osuSchemeLinkIPCSender = new OsuSchemeLinkIPCChannel(ipcSenderHost);
archiveImportIPCSender = new ArchiveImportIPCChannel(ipcSenderHost);
}); });
} }
@ -72,15 +77,50 @@ namespace osu.Game.Tests.Visual.Navigation
AddUntilStep("beatmap overlay showing content", () => Game.ChildrenOfType<BeatmapSetOverlay>().FirstOrDefault()?.Header.BeatmapSet.Value.OnlineID == requested_beatmap_set_id); AddUntilStep("beatmap overlay showing content", () => Game.ChildrenOfType<BeatmapSetOverlay>().FirstOrDefault()?.Header.BeatmapSet.Value.OnlineID == requested_beatmap_set_id);
} }
[Test]
public void TestArchiveImportLinkIPCChannel()
{
string? beatmapFilepath = null;
AddStep("import beatmap via IPC", () => archiveImportIPCSender.ImportAsync(beatmapFilepath = TestResources.GetQuickTestBeatmapForImport()).WaitSafely());
AddUntilStep("import complete notification was presented", () => Game.Notifications.ChildrenOfType<ProgressCompletionNotification>().Count(), () => Is.EqualTo(1));
AddAssert("original file deleted", () => File.Exists(beatmapFilepath), () => Is.False);
}
public override void TearDownSteps() public override void TearDownSteps()
{ {
AddStep("dispose IPC receiver", () => osuSchemeLinkIPCReceiver.Dispose()); AddStep("dispose IPC senders", () =>
AddStep("dispose IPC sender", () =>
{ {
osuSchemeLinkIPCSender.Dispose(); osuSchemeLinkIPCSender.Dispose();
archiveImportIPCSender.Dispose();
ipcSenderHost.Dispose(); ipcSenderHost.Dispose();
}); });
base.TearDownSteps(); base.TearDownSteps();
} }
private partial class IpcGame : TestOsuGame
{
private OsuSchemeLinkIPCChannel? osuSchemeLinkIPCChannel;
private ArchiveImportIPCChannel? archiveImportIPCChannel;
public IpcGame(Storage storage, IAPIProvider api, string[]? args = null)
: base(storage, api, args)
{
}
protected override void LoadComplete()
{
base.LoadComplete();
osuSchemeLinkIPCChannel = new OsuSchemeLinkIPCChannel(Host, this);
archiveImportIPCChannel = new ArchiveImportIPCChannel(Host, this);
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
osuSchemeLinkIPCChannel?.Dispose();
archiveImportIPCChannel?.Dispose();
}
}
} }
} }