Program.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using Azylee.Core.AppUtils;
  2. using Azylee.Core.DataUtils.StringUtils;
  3. using Azylee.Core.IOUtils.DirUtils;
  4. using Azylee.Core.IOUtils.FileUtils;
  5. using Azylee.Core.IOUtils.TxtUtils;
  6. using Azylee.Core.ProcessUtils;
  7. using Azylee.Core.ThreadUtils.SleepUtils;
  8. using Azylee.Core.VersionUtils;
  9. using Azylee.Core.WindowsUtils.CMDUtils;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Threading.Tasks;
  15. using System.Windows.Forms;
  16. namespace Azylee.Launch
  17. {
  18. internal static class Program
  19. {
  20. static AppUnique AppUnique = new AppUnique();
  21. /// <summary>
  22. /// 应用程序的主入口点。
  23. /// </summary>
  24. [STAThread]
  25. static void Main(string[] args)
  26. {
  27. string app = AppDomain.CurrentDomain.BaseDirectory;
  28. string bootstrap = DirTool.Combine(app, "bootstrap.ini");
  29. bool isStart = false;
  30. string appName = IniTool.GetString(bootstrap, "app", "name", "");
  31. string appFile = IniTool.GetString(bootstrap, "app", "file", "");
  32. string appType = IniTool.GetString(bootstrap, "app", "type", "");
  33. string readyVersion = IniTool.GetString(bootstrap, "version", "ready", "");
  34. //程序单开验证
  35. if (AppUnique.IsUnique($"{appName}-{appFile}"))
  36. {
  37. if (args.Contains("-delay5")) Sleep.S(5);//带参数等待:5秒
  38. if (args.Contains("-delay10")) Sleep.S(10);//带参数等待:10秒
  39. if (args.Contains("-delay30")) Sleep.S(30);//带参数等待:30秒
  40. // 执行最新准备好的版本
  41. if (StringTool.Ok(readyVersion))
  42. {
  43. // 优先读取准备就绪的版本号
  44. string runAppFile = DirTool.Combine(app, readyVersion, appFile);
  45. // 如果没有准备就绪的版本号程序,则获取文件夹中最大的版本号文件夹
  46. if (!File.Exists(runAppFile))
  47. {
  48. if (AppLaunchTool.GetNewVersion(app, appFile, out Version version, out string startFile))
  49. {
  50. readyVersion = version.ToString();
  51. runAppFile = startFile;
  52. }
  53. }
  54. // 写入当前启动程序的版本号信息
  55. IniTool.Set(bootstrap, "version", "current", readyVersion);
  56. // 根据配置的类型,启动程序
  57. if (File.Exists(runAppFile))
  58. {
  59. switch (appType)
  60. {
  61. case "exe":
  62. isStart = ProcessTool.StartCustom(runAppFile);
  63. break;
  64. case "cmd":
  65. case "bat":
  66. CMDProcessTool.Execute(runAppFile);
  67. break;
  68. default: break;
  69. }
  70. }
  71. }
  72. }
  73. }
  74. }
  75. }