Exemple #1
0
 public UpgradeService(UpgradeConfig config)
 {
     if (string.IsNullOrEmpty(config.TargetFolder))
     {
         this._targetFolder = AppDomain.CurrentDomain.BaseDirectory;
     }
     else
     {
         this._targetFolder = config.TargetFolder;
     }
     this._ftpServerIp = config.FtpHost;
     this._ftpUser     = config.FtpUser;
     this._ftpPassword = config.FtpPassword;
     this._ftpOverTLS  = config.FtpOverTLS;
     _versionService   = new VersionService(config.VersionInfoSecretKey ?? "Zl.AutoUpgrade.SecretKey");
 }
Exemple #2
0
        /// <summary>
        /// 由托管exe调用,尝试升级。如果返回true,托管exe应该退出程序,否则会因托管exe正在运行而无法正常升级,升级成功后Updater有义务调用RunManagedExe()再重新启动托管exe。
        /// </summary>
        /// <param name="upgradeConfig">升级配置</param>
        /// <param name="updaterExeFileName">自定义的Updater Exe文件路径</param>
        /// <returns>是否需要升级且已启动升级</returns>
        public static UpgradeStatus TryUpgrade(UpgradeConfig upgradeConfig, string updaterExeFileName)
        {
            FileInfo fileInfo = new FileInfo(updaterExeFileName);

            if (!fileInfo.Exists)
            {
                throw new Exception("Can't found the updater exe");
            }
            if (IsUpdaterRunning())
            {
                return(UpgradeStatus.Upgrading);
            }
            var args = Environment.GetCommandLineArgs().ToList();

            args.RemoveAt(0);
            if (args.LastOrDefault() == UpdatedSign)
            {
                return(UpgradeStatus.Ended);
            }

            IUpgradeService upgradeService = new UpgradeService(upgradeConfig);

            if (!upgradeService.DetectNewVersion())
            {
                return(UpgradeStatus.NoNewVersion);
            }
            if (string.IsNullOrEmpty(upgradeConfig.TargetFolder))
            {
                upgradeConfig.TargetFolder = AppDomain.CurrentDomain.BaseDirectory;
            }
            else
            {
                upgradeConfig.TargetFolder = new DirectoryInfo(upgradeConfig.TargetFolder).FullName;
            }
            UpgradeCmdArg arg = new UpgradeCmdArg()
            {
                Config              = upgradeConfig,
                ManagedExeFileName  = System.Reflection.Assembly.GetEntryAssembly().Location,
                ManagedExeArguments = string.Join(" ", args)
            };

            System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
            startInfo.FileName  = fileInfo.FullName;
            startInfo.Arguments = "\"" + Convert.ToBase64String(XmlSerializer.ToBinary(arg)) + "\"";
            System.Diagnostics.Process.Start(startInfo);
            return(UpgradeStatus.Started);
        }
Exemple #3
0
 /// <summary>
 /// 由托管exe调用,尝试升级。如果返回true,托管exe应该退出程序,否则会因托管exe正在运行而无法正常升级,升级成功后Updater有义务调用RunManagedExe()再重新启动托管exe。
 /// </summary>
 /// <param name="upgradeConfig">升级配置</param>
 /// <param name="updaterExeFileName">自定义的Updater程序集</param>
 /// <returns>是否需要升级且已启动升级</returns>
 public static UpgradeStatus TryUpgrade(UpgradeConfig upgradeConfig, Assembly updaterExeAssembly)
 {
     return(TryUpgrade(upgradeConfig, updaterExeAssembly.Location));
 }