Launch.cs 2.1 KB

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