improve:外部点名
This commit is contained in:
@@ -0,0 +1,81 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
namespace Ink_Canvas.Helpers
|
||||||
|
{
|
||||||
|
public static class ExternalCallerLauncher
|
||||||
|
{
|
||||||
|
private static readonly string[] ClassIslandProtocols =
|
||||||
|
{
|
||||||
|
"classisland://plugins/IslandCaller/Simple/1",
|
||||||
|
"classisland://plugins/IslandCaller/Simple",
|
||||||
|
"classisland://plugins/IslandCaller/Run"
|
||||||
|
};
|
||||||
|
|
||||||
|
public static string[] GetProtocolsByType(int externalCallerType)
|
||||||
|
{
|
||||||
|
switch (externalCallerType)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
return ClassIslandProtocols;
|
||||||
|
case 1:
|
||||||
|
return new[]
|
||||||
|
{
|
||||||
|
"secrandom://roll_call/quick_draw",
|
||||||
|
"secrandom://direct_extraction"
|
||||||
|
};
|
||||||
|
case 2:
|
||||||
|
return new[] { "namepicker://" };
|
||||||
|
default:
|
||||||
|
return ClassIslandProtocols;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string[] GetProtocolsByName(string externalCallerName)
|
||||||
|
{
|
||||||
|
switch (externalCallerName)
|
||||||
|
{
|
||||||
|
case "ClassIsland":
|
||||||
|
return ClassIslandProtocols;
|
||||||
|
case "SecRandom":
|
||||||
|
return new[]
|
||||||
|
{
|
||||||
|
"secrandom://roll_call/quick_draw",
|
||||||
|
"secrandom://direct_extraction"
|
||||||
|
};
|
||||||
|
case "NamePicker":
|
||||||
|
return new[] { "namepicker://" };
|
||||||
|
default:
|
||||||
|
return ClassIslandProtocols;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool TryLaunch(IEnumerable<string> protocols, out Exception lastException)
|
||||||
|
{
|
||||||
|
lastException = null;
|
||||||
|
if (protocols == null) return false;
|
||||||
|
|
||||||
|
foreach (var protocol in protocols)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(protocol)) continue;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Process.Start(new ProcessStartInfo
|
||||||
|
{
|
||||||
|
FileName = protocol,
|
||||||
|
UseShellExecute = true
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
lastException = ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1365,28 +1365,27 @@ namespace Ink_Canvas
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string protocol = "";
|
string[] protocols;
|
||||||
switch (Settings.RandSettings.ExternalCallerType)
|
switch (Settings.RandSettings.ExternalCallerType)
|
||||||
{
|
{
|
||||||
case 0: // ClassIsland点名
|
case 0: // ClassIsland点名
|
||||||
protocol = "classisland://plugins/IslandCaller/Simple/1";
|
protocols = ExternalCallerLauncher.GetProtocolsByType(0);
|
||||||
break;
|
break;
|
||||||
case 1: // SecRandom点名
|
case 1: // SecRandom点名
|
||||||
protocol = "secrandom://direct_extraction";
|
protocols = ExternalCallerLauncher.GetProtocolsByType(1);
|
||||||
break;
|
break;
|
||||||
case 2: // NamePicker点名
|
case 2: // NamePicker点名
|
||||||
protocol = "namepicker://";
|
protocols = ExternalCallerLauncher.GetProtocolsByType(2);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
protocol = "classisland://plugins/IslandCaller/Simple/1";
|
protocols = ExternalCallerLauncher.GetProtocolsByType(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Process.Start(new ProcessStartInfo
|
if (!ExternalCallerLauncher.TryLaunch(protocols, out Exception lastException))
|
||||||
{
|
{
|
||||||
FileName = protocol,
|
throw lastException ?? new InvalidOperationException("external caller protocols are unavailable");
|
||||||
UseShellExecute = true
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1523,28 +1523,27 @@ namespace Ink_Canvas
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string protocol = "";
|
string[] protocols;
|
||||||
switch (selectedExternalCaller)
|
switch (selectedExternalCaller)
|
||||||
{
|
{
|
||||||
case "ClassIsland":
|
case "ClassIsland":
|
||||||
protocol = "classisland://plugins/IslandCaller/Simple/1";
|
protocols = ExternalCallerLauncher.GetProtocolsByName("ClassIsland");
|
||||||
break;
|
break;
|
||||||
case "SecRandom":
|
case "SecRandom":
|
||||||
protocol = "secrandom://direct_extraction";
|
protocols = ExternalCallerLauncher.GetProtocolsByName("SecRandom");
|
||||||
break;
|
break;
|
||||||
case "NamePicker":
|
case "NamePicker":
|
||||||
protocol = "namepicker://";
|
protocols = ExternalCallerLauncher.GetProtocolsByName("NamePicker");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
protocol = "classisland://plugins/IslandCaller/Simple/1";
|
protocols = ExternalCallerLauncher.GetProtocolsByName("ClassIsland");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo
|
if (!ExternalCallerLauncher.TryLaunch(protocols, out Exception lastException))
|
||||||
{
|
{
|
||||||
FileName = protocol,
|
throw lastException ?? new InvalidOperationException("external caller protocols are unavailable");
|
||||||
UseShellExecute = true
|
}
|
||||||
});
|
|
||||||
|
|
||||||
UpdateStatusDisplay($"已启动外部点名: {selectedExternalCaller}");
|
UpdateStatusDisplay($"已启动外部点名: {selectedExternalCaller}");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -428,28 +428,27 @@ namespace Ink_Canvas
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string protocol = "";
|
string[] protocols;
|
||||||
switch (ComboBoxCallerType.SelectedIndex)
|
switch (ComboBoxCallerType.SelectedIndex)
|
||||||
{
|
{
|
||||||
case 0: // ClassIsland点名
|
case 0: // ClassIsland点名
|
||||||
protocol = "classisland://plugins/IslandCaller/Simple/1";
|
protocols = ExternalCallerLauncher.GetProtocolsByType(0);
|
||||||
break;
|
break;
|
||||||
case 1: // SecRandom点名
|
case 1: // SecRandom点名
|
||||||
protocol = "secrandom://direct_extraction";
|
protocols = ExternalCallerLauncher.GetProtocolsByType(1);
|
||||||
break;
|
break;
|
||||||
case 2: // NamePicker点名
|
case 2: // NamePicker点名
|
||||||
protocol = "namepicker://";
|
protocols = ExternalCallerLauncher.GetProtocolsByType(2);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
protocol = "classisland://plugins/IslandCaller/Simple/1";
|
protocols = ExternalCallerLauncher.GetProtocolsByType(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Process.Start(new ProcessStartInfo
|
if (!ExternalCallerLauncher.TryLaunch(protocols, out Exception lastException))
|
||||||
{
|
{
|
||||||
FileName = protocol,
|
throw lastException ?? new InvalidOperationException("external caller protocols are unavailable");
|
||||||
UseShellExecute = true
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user