12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- using System;
- using System.IO;
- using Vinno.FIS.Sonopost.Common;
- using Vinno.IUS.Common.Log;
- namespace Vinno.FIS.Sonopost.Helpers
- {
- public class UpgradeHelper
- {
- /// <summary>
- /// 启动更新程序
- /// </summary>
- public static void StartUpgrade(string upgradeZipFilePath, bool updateSetting = false, bool deleteAllFiles = false)
- {
- Logger.WriteLineInfo($"Start Upgrade,Path:{upgradeZipFilePath}");
- if (!File.Exists(upgradeZipFilePath))
- {
- Logger.WriteLineError($"Can not find upgrade zip file!");
- return;
- }
- var upgradeFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SonopostConstants.UpgradeFolderName);
- var upgradeFile = Path.Combine(upgradeFolderPath, SonopostConstants.UpgradeAppFileName);
- var upgradePath = Path.Combine(SonopostConstants.DataFolder, "UpgradeTemp");
- var newUpgradeFolderPath = Path.Combine(upgradePath, SonopostConstants.UpgradeFolderName);
- CompressHelper.DeCompressAll(upgradeZipFilePath, upgradePath);
- if (!Directory.Exists(upgradePath) || Directory.GetFiles(upgradePath).Length == 0)
- {
- Logger.WriteLineError($"Can not find upgrade files!");
- return;
- }
- Logger.WriteLineInfo("DeCompress success,Start upgrade process!");
- var settingFile = Path.Combine(upgradePath, SonopostConstants.SystemSettingsFolder, SonopostConstants.SystemSettingFileName);
- if (File.Exists(settingFile) && updateSetting == false)
- {
- FileHelper.DeleteFile(settingFile);
- }
- DirectoryHelper.CopyDirectoryContent(newUpgradeFolderPath, upgradeFolderPath);
- int processId = ProcessHelper.StartProcess(upgradeFile, $"{upgradePath} {AppDomain.CurrentDomain.BaseDirectory} {deleteAllFiles}");
- if (processId == 0)
- {
- Logger.WriteLineError($"Start Upgrade Process Fail!");
- }
- }
- }
- }
|