Program.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using Azylee.Core.AppUtils;
  2. using Azylee.Core.DataUtils.StringUtils;
  3. using Azylee.Core.IOUtils.DirUtils;
  4. using Azylee.Core.IOUtils.TxtUtils;
  5. using Azylee.Core.ProcessUtils;
  6. using Azylee.Core.ThreadUtils.SleepUtils;
  7. using Azylee.Core.WindowsUtils.CMDUtils;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14. namespace Azylee.Launch
  15. {
  16. internal static class Program
  17. {
  18. static AppUnique AppUnique = new AppUnique();
  19. /// <summary>
  20. /// 应用程序的主入口点。
  21. /// </summary>
  22. [STAThread]
  23. static void Main(string[] args)
  24. {
  25. string app = AppDomain.CurrentDomain.BaseDirectory;
  26. string bootstrap = DirTool.Combine(app, "bootstrap.ini");
  27. bool isStart = false;
  28. string appName = IniTool.GetString(bootstrap, "app", "name", "");
  29. string appFile = IniTool.GetString(bootstrap, "app", "file", "");
  30. string appType = IniTool.GetString(bootstrap, "app", "type", "");
  31. string currentVersion = IniTool.GetString(bootstrap, "version", "current", "");
  32. string readyVersion = IniTool.GetString(bootstrap, "version", "ready", "");
  33. //程序单开验证
  34. if (AppUnique.IsUnique($"{appName}-{appFile}"))
  35. {
  36. if (args.Contains("-delay5")) Sleep.S(5);//带参数等待:5秒
  37. if (args.Contains("-delay10")) Sleep.S(10);//带参数等待:10秒
  38. if (args.Contains("-delay30")) Sleep.S(30);//带参数等待:30秒
  39. // 执行最新准备好的版本
  40. if (StringTool.Ok(readyVersion))
  41. {
  42. string runAppFile = DirTool.Combine(app, readyVersion, appFile);
  43. if (Str.Ok(readyVersion) && File.Exists(runAppFile))
  44. {
  45. switch (appType)
  46. {
  47. case "exe":
  48. isStart = ProcessTool.StartCustom(runAppFile);
  49. break;
  50. case "cmd":
  51. case "bat":
  52. CMDProcessTool.Execute(runAppFile);
  53. break;
  54. default: break;
  55. }
  56. }
  57. }
  58. }
  59. }
  60. }
  61. }