Move init of network helpers from ArgParser to MainForm ctor
This commit is contained in:
parent
1c1aa348cf
commit
251f0e7af8
|
@ -5,8 +5,6 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
using BizHawk.Client.Common;
|
|
||||||
|
|
||||||
namespace BizHawk.Client.EmuHawk
|
namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -19,7 +17,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
public static class ArgParser
|
public static class ArgParser
|
||||||
{
|
{
|
||||||
/// <exception cref="ArgParserException"><c>--socket_ip</c> passed without specifying <c>--socket_port</c> or vice-versa</exception>
|
/// <exception cref="ArgParserException"><c>--socket_ip</c> passed without specifying <c>--socket_port</c> or vice-versa</exception>
|
||||||
public static void ParseArguments(out ParsedCLIFlags parsed, string[] args, Func<byte[]> takeScreenshotCallback)
|
public static void ParseArguments(out ParsedCLIFlags parsed, string[] args)
|
||||||
{
|
{
|
||||||
string? cmdLoadSlot = null;
|
string? cmdLoadSlot = null;
|
||||||
string? cmdLoadState = null;
|
string? cmdLoadState = null;
|
||||||
|
@ -164,16 +162,13 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var httpCommunication = urlGet == null && urlPost == null
|
var httpAddresses = urlGet == null && urlPost == null
|
||||||
? null // don't bother
|
? ((string?, string?)?) null // don't bother
|
||||||
: new HttpCommunication(takeScreenshotCallback, urlGet, urlPost);
|
: (urlGet, urlPost);
|
||||||
var memoryMappedFiles = mmfFilename == null
|
(string, int)? socketAddress;
|
||||||
? null // don't bother
|
|
||||||
: new MemoryMappedFiles(takeScreenshotCallback, mmfFilename);
|
|
||||||
SocketServer? socketServer;
|
|
||||||
if (socketIP == null && socketPort == null)
|
if (socketIP == null && socketPort == null)
|
||||||
{
|
{
|
||||||
socketServer = null; // don't bother
|
socketAddress = null; // don't bother
|
||||||
}
|
}
|
||||||
else if (socketIP == null || socketPort == null)
|
else if (socketIP == null || socketPort == null)
|
||||||
{
|
{
|
||||||
|
@ -181,7 +176,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
socketServer = new SocketServer(takeScreenshotCallback, socketIP, socketPort.Value);
|
socketAddress = (socketIP, socketPort.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
parsed = new ParsedCLIFlags(
|
parsed = new ParsedCLIFlags(
|
||||||
|
@ -200,9 +195,9 @@ namespace BizHawk.Client.EmuHawk
|
||||||
startFullscreen: startFullscreen ?? false,
|
startFullscreen: startFullscreen ?? false,
|
||||||
luaScript: luaScript,
|
luaScript: luaScript,
|
||||||
luaConsole: luaConsole ?? false,
|
luaConsole: luaConsole ?? false,
|
||||||
socketServer: socketServer,
|
socketAddress: socketAddress,
|
||||||
memoryMappedFiles: memoryMappedFiles,
|
mmfFilename: mmfFilename,
|
||||||
httpCommunication: httpCommunication,
|
httpAddresses: httpAddresses,
|
||||||
audiosync: audiosync,
|
audiosync: audiosync,
|
||||||
openExtToolDll: openExtToolDll,
|
openExtToolDll: openExtToolDll,
|
||||||
cmdRom: cmdRom
|
cmdRom: cmdRom
|
||||||
|
@ -252,11 +247,11 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
public readonly bool luaConsole;
|
public readonly bool luaConsole;
|
||||||
|
|
||||||
public readonly SocketServer? socketServer;
|
public readonly (string IP, int Port)? SocketAddress;
|
||||||
|
|
||||||
public readonly MemoryMappedFiles? memoryMappedFiles;
|
public readonly string? MMFFilename;
|
||||||
|
|
||||||
public readonly HttpCommunication? httpCommunication;
|
public readonly (string? UrlGet, string? UrlPost)? HTTPAddresses;
|
||||||
|
|
||||||
public readonly bool? audiosync;
|
public readonly bool? audiosync;
|
||||||
|
|
||||||
|
@ -279,9 +274,9 @@ namespace BizHawk.Client.EmuHawk
|
||||||
bool startFullscreen,
|
bool startFullscreen,
|
||||||
string? luaScript,
|
string? luaScript,
|
||||||
bool luaConsole,
|
bool luaConsole,
|
||||||
SocketServer? socketServer,
|
(string IP, int Port)? socketAddress,
|
||||||
MemoryMappedFiles? memoryMappedFiles,
|
string? mmfFilename,
|
||||||
HttpCommunication? httpCommunication,
|
(string? UrlGet, string? UrlPost)? httpAddresses,
|
||||||
bool? audiosync,
|
bool? audiosync,
|
||||||
string? openExtToolDll,
|
string? openExtToolDll,
|
||||||
string? cmdRom)
|
string? cmdRom)
|
||||||
|
@ -301,9 +296,9 @@ namespace BizHawk.Client.EmuHawk
|
||||||
this.startFullscreen = startFullscreen;
|
this.startFullscreen = startFullscreen;
|
||||||
this.luaScript = luaScript;
|
this.luaScript = luaScript;
|
||||||
this.luaConsole = luaConsole;
|
this.luaConsole = luaConsole;
|
||||||
this.socketServer = socketServer;
|
SocketAddress = socketAddress;
|
||||||
this.memoryMappedFiles = memoryMappedFiles;
|
MMFFilename = mmfFilename;
|
||||||
this.httpCommunication = httpCommunication;
|
HTTPAddresses = httpAddresses;
|
||||||
this.audiosync = audiosync;
|
this.audiosync = audiosync;
|
||||||
this.openExtToolDll = openExtToolDll;
|
this.openExtToolDll = openExtToolDll;
|
||||||
this.cmdRom = cmdRom;
|
this.cmdRom = cmdRom;
|
||||||
|
|
|
@ -318,11 +318,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ArgParser.ParseArguments(
|
ArgParser.ParseArguments(out _argParser, args);
|
||||||
out _argParser,
|
|
||||||
args,
|
|
||||||
() => (byte[]) new ImageConverter().ConvertTo(MakeScreenshotImage().ToSysdrawingBitmap(), typeof(byte[]))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
catch (ArgParserException e)
|
catch (ArgParserException e)
|
||||||
{
|
{
|
||||||
|
@ -550,7 +546,18 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
|
|
||||||
// set up networking before Lua
|
// set up networking before Lua
|
||||||
NetworkingHelpers = (_argParser.httpCommunication, _argParser.memoryMappedFiles, _argParser.socketServer);
|
byte[] NetworkingTakeScreenshot() => (byte[]) new ImageConverter().ConvertTo(MakeScreenshotImage().ToSysdrawingBitmap(), typeof(byte[]));
|
||||||
|
NetworkingHelpers = (
|
||||||
|
_argParser.HTTPAddresses == null
|
||||||
|
? null
|
||||||
|
: new HttpCommunication(NetworkingTakeScreenshot, _argParser.HTTPAddresses.Value.UrlGet, _argParser.HTTPAddresses.Value.UrlPost),
|
||||||
|
_argParser.MMFFilename == null
|
||||||
|
? null
|
||||||
|
: new MemoryMappedFiles(NetworkingTakeScreenshot, _argParser.MMFFilename),
|
||||||
|
_argParser.SocketAddress == null
|
||||||
|
? null
|
||||||
|
: new SocketServer(NetworkingTakeScreenshot, _argParser.SocketAddress.Value.IP, _argParser.SocketAddress.Value.Port)
|
||||||
|
);
|
||||||
|
|
||||||
//start Lua Console if requested in the command line arguments
|
//start Lua Console if requested in the command line arguments
|
||||||
if (_argParser.luaConsole)
|
if (_argParser.luaConsole)
|
||||||
|
|
Loading…
Reference in New Issue