ClashController.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using ClashDotNetFramework.Utils;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace ClashDotNetFramework.Controllers
  9. {
  10. public class ClashController : Guard
  11. {
  12. public ClashController()
  13. {
  14. RedirectStd = true;
  15. }
  16. public override string MainFile { get; protected set; } = "Clash.exe";
  17. public override string Name { get; } = "Clash";
  18. public void Start()
  19. {
  20. int port = PortHelper.GetAvailablePort(PortType.TCP);
  21. Global.ClashControllerPort = port;
  22. string arguments = $"-ext-ctl 127.0.0.1:{port}";
  23. StartInstanceAuto(arguments);
  24. }
  25. public void Start(int port)
  26. {
  27. PortHelper.CheckPort(Convert.ToUInt16(port), PortType.TCP);
  28. Global.ClashControllerPort = port;
  29. string arguments = $"-ext-ctl 127.0.0.1:{port}";
  30. StartInstanceAuto(arguments);
  31. }
  32. public override void Stop()
  33. {
  34. StopInstance();
  35. }
  36. }
  37. }