AppManagerComponent.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.Linq;
  6. using Base;
  7. namespace Model
  8. {
  9. [ObjectEvent]
  10. public class AppManagerComponentEvent : ObjectEvent<AppManagerComponent>, IAwake
  11. {
  12. public void Awake()
  13. {
  14. this.GetValue().Awake();
  15. }
  16. }
  17. public class AppManagerComponent : Component
  18. {
  19. private readonly Dictionary<int, Process> processes = new Dictionary<int, Process>();
  20. public void Awake()
  21. {
  22. string[] ips = NetHelper.GetAddressIPs();
  23. StartConfig[] startConfigs = Game.Scene.GetComponent<StartConfigComponent>().GetAll();
  24. string configFile = Game.Scene.GetComponent<StartConfigComponent>().Options.Config;
  25. foreach (StartConfig startConfig in startConfigs)
  26. {
  27. if (!ips.Contains(startConfig.ServerIP) && startConfig.ServerIP != "*")
  28. {
  29. continue;
  30. }
  31. if (startConfig.AppType.Is(AppType.Manager))
  32. {
  33. continue;
  34. }
  35. #if __MonoCS__
  36. const string exe = @"mono";
  37. string arguments = $"--debug App.exe --appId={startConfig.AppId} --appType={startConfig.AppType} --config={configFile}";
  38. #else
  39. const string exe = @"App.exe";
  40. string arguments = $"--appId={startConfig.AppId} --appType={startConfig.AppType} --config={configFile}";
  41. #endif
  42. Log.Info($"{exe} {arguments}");
  43. try
  44. {
  45. ProcessStartInfo info = new ProcessStartInfo
  46. {
  47. FileName = exe,
  48. Arguments = arguments,
  49. CreateNoWindow = true,
  50. UseShellExecute = true
  51. };
  52. Process process = Process.Start(info);
  53. this.processes.Add(process.Id, process);
  54. }
  55. catch (Exception e)
  56. {
  57. Log.Error(e.ToString());
  58. }
  59. }
  60. }
  61. }
  62. }