Program.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using CommonLang;
  2. using CommonLang.Property;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Threading;
  7. using System.Windows.Forms;
  8. using XmdsBattleClientBot.Bot;
  9. using XmdsBattleClientWin32;
  10. namespace XmdsBotTest
  11. {
  12. public static class LaunchArgs
  13. {
  14. public static string DefaultBotPrefix { get; private set; }
  15. public static int DefaultBotCount { get; private set; }
  16. public static bool IsAuto { get; private set; }
  17. public static void Init(string[] args)
  18. {
  19. Properties argp = new Properties();
  20. foreach (var arg in args)
  21. {
  22. argp.ParseLine(arg);
  23. }
  24. string b_name = argp.Get("n");
  25. string b_count = argp.Get("c");
  26. if (b_name != null && b_count != null)
  27. {
  28. LaunchArgs.IsAuto = true;
  29. LaunchArgs.DefaultBotPrefix = b_name;
  30. LaunchArgs.DefaultBotCount = int.Parse(b_count);
  31. }
  32. else
  33. {
  34. LaunchArgs.IsAuto = false;
  35. }
  36. }
  37. }
  38. static class Program
  39. {
  40. private static bool first_start = true;
  41. /// <summary>
  42. /// 应用程序的主入口点。
  43. /// </summary>
  44. [STAThread]
  45. static void Main(params string[] args)
  46. {
  47. /*
  48. while (true)
  49. {
  50. Console.WriteLine("123123");
  51. BotClient bot = new BotClient("SB1020", "", FormLauncher.LastConfig);
  52. bot.connect();
  53. Thread.Sleep(1000);
  54. }
  55. */
  56. ReflectionUtil.LoadDlls(new System.IO.DirectoryInfo(Application.StartupPath));
  57. LaunchArgs.Init(args);
  58. Application.EnableVisualStyles();
  59. Application.SetCompatibleTextRenderingDefault(false);
  60. var launcher = new FormLauncher();
  61. launcher.Shown += Launcher_Shown;
  62. launcher.OnStart += Launcher_OnStart;
  63. Application.Run(launcher);
  64. if (!Application.StartupPath.StartsWith(@"D:\robot\"))
  65. {
  66. //TODO 2017/1/22 CommonSecure.ConnectWS.Run(launcher);
  67. }
  68. }
  69. private static void Launcher_Shown(object sender, EventArgs e)
  70. {
  71. if (LaunchArgs.IsAuto && first_start)
  72. {
  73. first_start = false;
  74. (sender as FormLauncher).Start();
  75. }
  76. }
  77. private static void Launcher_OnStart(FormLauncher sender, XmdsBattleClientBot.BotConfig config)
  78. {
  79. var bot = new FormBotTest(config);
  80. bot.FormClosed += new FormClosedEventHandler((object sender2, FormClosedEventArgs e2) =>
  81. {
  82. sender.Show();
  83. });
  84. bot.Show();
  85. }
  86. }
  87. }