mirror of
https://github.com/osukey/osukey.git
synced 2025-05-30 09:57:21 +09:00
Refactoring
This commit is contained in:
parent
f506cb35bc
commit
36fffbd917
@ -23,7 +23,6 @@ namespace osu.Desktop.LegacyIpc
|
|||||||
|
|
||||||
public new object Value
|
public new object Value
|
||||||
{
|
{
|
||||||
get => base.Value;
|
|
||||||
set => base.Value = new Data
|
set => base.Value = new Data
|
||||||
{
|
{
|
||||||
MessageType = value.GetType().Name,
|
MessageType = value.GetType().Name,
|
||||||
|
@ -2,14 +2,22 @@
|
|||||||
// 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;
|
using System;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
using osu.Framework.Logging;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
|
|
||||||
namespace osu.Desktop.LegacyIpc
|
namespace osu.Desktop.LegacyIpc
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Provides IPC to legacy osu! clients.
|
||||||
|
/// </summary>
|
||||||
public class LegacyTcpIpcProvider : TcpIpcProvider
|
public class LegacyTcpIpcProvider : TcpIpcProvider
|
||||||
{
|
{
|
||||||
|
private static readonly Logger logger = Logger.GetLogger("ipc");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Invoked when a message is received from a legacy client.
|
||||||
|
/// </summary>
|
||||||
public new Func<object, object> MessageReceived;
|
public new Func<object, object> MessageReceived;
|
||||||
|
|
||||||
public LegacyTcpIpcProvider()
|
public LegacyTcpIpcProvider()
|
||||||
@ -19,35 +27,22 @@ namespace osu.Desktop.LegacyIpc
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
logger.Add($"Processing incoming IPC message: {msg.Value}");
|
||||||
|
|
||||||
var legacyData = ((JObject)msg.Value).ToObject<LegacyIpcMessage.Data>();
|
var legacyData = ((JObject)msg.Value).ToObject<LegacyIpcMessage.Data>();
|
||||||
object value = parseObject((JObject)legacyData.MessageData, legacyData.MessageType);
|
object value = parseObject((JObject)legacyData!.MessageData, legacyData.MessageType);
|
||||||
|
|
||||||
object result = MessageReceived?.Invoke(value);
|
object result = MessageReceived?.Invoke(value);
|
||||||
return result != null ? new LegacyIpcMessage { Value = result } : null;
|
return result != null ? new LegacyIpcMessage { Value = result } : null;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine(ex);
|
logger.Add("Processing IPC message failed!", exception: ex);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task SendMessageAsync(object message) => base.SendMessageAsync(new LegacyIpcMessage { Value = message });
|
|
||||||
|
|
||||||
public async Task<T> SendMessageWithResponseAsync<T>(object message)
|
|
||||||
{
|
|
||||||
var result = await base.SendMessageWithResponseAsync(new LegacyIpcMessage { Value = message }).ConfigureAwait(false);
|
|
||||||
|
|
||||||
var legacyData = ((JObject)result.Value).ToObject<LegacyIpcMessage.Data>();
|
|
||||||
return (T)parseObject((JObject)legacyData.MessageData, legacyData.MessageType);
|
|
||||||
}
|
|
||||||
|
|
||||||
public new Task SendMessageAsync(IpcMessage message) => throw new InvalidOperationException("Use typed overloads.");
|
|
||||||
|
|
||||||
public new Task<IpcMessage> SendMessageWithResponseAsync(IpcMessage message) => throw new InvalidOperationException("Use typed overloads.");
|
|
||||||
|
|
||||||
private object parseObject(JObject value, string type)
|
private object parseObject(JObject value, string type)
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
|
@ -28,8 +28,6 @@ namespace osu.Desktop
|
|||||||
{
|
{
|
||||||
private const string base_game_name = @"osu";
|
private const string base_game_name = @"osu";
|
||||||
|
|
||||||
private static LegacyTcpIpcProvider legacyIpcProvider;
|
|
||||||
|
|
||||||
[STAThread]
|
[STAThread]
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user