Launch.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using Azylee.Core.Data.Collections;
  2. using Azylee.Core.Data.String;
  3. using Azylee.Core.Diagnostics;
  4. using Azylee.Core.IO.Dir;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Text;
  10. namespace Azylee.ExeLaunch
  11. {
  12. public class Launch
  13. {
  14. /// <summary>
  15. /// 启动最新版本程序
  16. /// </summary>
  17. /// <param name="path"></param>
  18. /// <param name="exe"></param>
  19. /// <returns></returns>
  20. public static bool Run(string appPath, string startfilename)
  21. {
  22. if (Directory.Exists(appPath))
  23. {
  24. //获取运行目录下所有文件
  25. List<string> paths = DirTool.GetPath(appPath);
  26. if (ListTool.HasElements(paths))
  27. {
  28. //解析属于版本号的文件
  29. Version version = null;
  30. string startfile = null;
  31. foreach (var path in paths)
  32. {
  33. //只解析文件名带三个点的文件夹
  34. string filename = Path.GetFileName(path);
  35. if (StringTool.SubStringCount(filename, ".") == 3)
  36. {
  37. try
  38. {
  39. Version tempVersion = new Version(filename);
  40. string tempFile = DirTool.Combine(path, startfilename);
  41. if ((version == null || tempVersion > version) && File.Exists(tempFile))
  42. {
  43. version = tempVersion;
  44. startfile = tempFile;
  45. }
  46. }
  47. catch { }
  48. }
  49. }
  50. //准备启动
  51. if (startfile != null)
  52. {
  53. return ProcessTool.Start(startfile);
  54. }
  55. }
  56. }
  57. return false;
  58. }
  59. }
  60. }