WatcherHelper.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Collections;
  3. using System.Diagnostics;
  4. namespace ET
  5. {
  6. public static class WatcherHelper
  7. {
  8. public static StartMachineConfig GetThisMachineConfig()
  9. {
  10. string[] localIP = NetworkHelper.GetAddressIPs();
  11. StartMachineConfig startMachineConfig = null;
  12. foreach (StartMachineConfig config in StartMachineConfigCategory.Instance.GetAll().Values)
  13. {
  14. if (!WatcherHelper.IsThisMachine(config.InnerIP, localIP))
  15. {
  16. continue;
  17. }
  18. startMachineConfig = config;
  19. break;
  20. }
  21. if (startMachineConfig == null)
  22. {
  23. throw new Exception("not found this machine ip config!");
  24. }
  25. return startMachineConfig;
  26. }
  27. public static bool IsThisMachine(string ip, string[] localIPs)
  28. {
  29. if (ip != "127.0.0.1" && ip != "0.0.0.0" && !((IList) localIPs).Contains(ip))
  30. {
  31. return false;
  32. }
  33. return true;
  34. }
  35. public static Process StartProcess(int processId, int createScenes = 0)
  36. {
  37. StartProcessConfig startProcessConfig = StartProcessConfigCategory.Instance.Get(processId);
  38. const string exe = "dotnet";
  39. string arguments = $"{startProcessConfig.AppName}.dll" +
  40. $" --Process={startProcessConfig.Id}" +
  41. $" --AppType={startProcessConfig.AppName}" +
  42. $" --Develop={Game.Options.Develop}" +
  43. $" --CreateScenes={createScenes}" +
  44. $" --LogLevel={Game.Options.LogLevel}";
  45. Log.Debug($"{exe} {arguments}");
  46. Process process = ProcessHelper.Run(exe, arguments);
  47. return process;
  48. }
  49. }
  50. }