refactor: Add GetModeControllerByType

This commit is contained in:
ChsBuffer
2020-10-16 15:40:00 +08:00
parent 1b6fe29085
commit 7bbffb002f
2 changed files with 43 additions and 33 deletions

View File

@@ -2,6 +2,8 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Netch.Controllers;
using Netch.Forms;
using Netch.Models;
namespace Netch.Utils
@@ -132,5 +134,37 @@ namespace Netch.Utils
Global.Modes.Remove(mode);
Global.MainForm.InitMode();
}
public static IModeController GetModeControllerByType(int type, out ushort? port, out string portName, out PortType portType)
{
IModeController modeController;
port = null;
portName = string.Empty;
portType = PortType.Both;
switch (type)
{
case 0:
modeController = new NFController();
port = Global.Settings.RedirectorTCPPort;
portName = "Redirector TCP";
break;
case 1:
case 2:
modeController = new TUNTAPController();
break;
case 3:
case 5:
modeController = new HTTPController();
port = Global.Settings.HTTPLocalPort;
portName = "HTTP";
MainForm.StatusPortInfoText.HttpPort = (ushort) port;
break;
default:
Logging.Error("未知模式类型");
throw new StartFailedException();
}
return modeController;
}
}
}