AppManagerComponent.cs 1.5 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. foreach (StartConfig startConfig in startConfigs)
  25. {
  26. if (!ips.Contains(startConfig.ServerIP) && startConfig.ServerIP != "*")
  27. {
  28. continue;
  29. }
  30. if (startConfig.AppType == AppType.Manager)
  31. {
  32. continue;
  33. }
  34. #if __MonoCS__
  35. const string exe = @"mono";
  36. string arguments = $"--debug App.exe --appId={startConfig.AppId} --appType={startConfig.AppType}";
  37. #else
  38. const string exe = @"App.exe";
  39. string arguments = $"--appId={startConfig.AppId} --appType={startConfig.AppType}";
  40. #endif
  41. Log.Info($"{exe} {arguments}");
  42. try
  43. {
  44. ProcessStartInfo info = new ProcessStartInfo
  45. {
  46. FileName = exe,
  47. Arguments = arguments,
  48. CreateNoWindow = true,
  49. UseShellExecute = true
  50. };
  51. Process process = Process.Start(info);
  52. this.processes.Add(process.Id, process);
  53. }
  54. catch (Exception e)
  55. {
  56. Log.Error(e.ToString());
  57. }
  58. }
  59. }
  60. }
  61. }