UpgradeHelper.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using System.IO;
  3. using Vinno.FIS.Sonopost.Common;
  4. using Vinno.IUS.Common.Log;
  5. namespace Vinno.FIS.Sonopost.Helpers
  6. {
  7. public class UpgradeHelper
  8. {
  9. /// <summary>
  10. /// 启动更新程序
  11. /// </summary>
  12. public static void StartUpgrade(string upgradeZipFilePath, bool updateSetting = false, bool deleteAllFiles = false)
  13. {
  14. Logger.WriteLineInfo($"Start Upgrade,Path:{upgradeZipFilePath}");
  15. if (!File.Exists(upgradeZipFilePath))
  16. {
  17. Logger.WriteLineError($"Can not find upgrade zip file!");
  18. return;
  19. }
  20. var upgradeFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SonopostConstants.UpgradeFolderName);
  21. var upgradeFile = Path.Combine(upgradeFolderPath, SonopostConstants.UpgradeAppFileName);
  22. var upgradePath = Path.Combine(SonopostConstants.DataFolder, "UpgradeTemp");
  23. var newUpgradeFolderPath = Path.Combine(upgradePath, SonopostConstants.UpgradeFolderName);
  24. CompressHelper.DeCompressAll(upgradeZipFilePath, upgradePath);
  25. if (!Directory.Exists(upgradePath) || Directory.GetFiles(upgradePath).Length == 0)
  26. {
  27. Logger.WriteLineError($"Can not find upgrade files!");
  28. return;
  29. }
  30. Logger.WriteLineInfo("DeCompress success,Start upgrade process!");
  31. var settingFile = Path.Combine(upgradePath, SonopostConstants.SystemSettingsFolder, SonopostConstants.SystemSettingFileName);
  32. if (File.Exists(settingFile) && updateSetting == false)
  33. {
  34. FileHelper.DeleteFile(settingFile);
  35. }
  36. DirectoryHelper.CopyDirectoryContent(newUpgradeFolderPath, upgradeFolderPath);
  37. int processId = ProcessHelper.StartProcess(upgradeFile, $"{upgradePath} {AppDomain.CurrentDomain.BaseDirectory} {deleteAllFiles}");
  38. if (processId == 0)
  39. {
  40. Logger.WriteLineError($"Start Upgrade Process Fail!");
  41. }
  42. }
  43. }
  44. }