/// <summary> /// updateThread: This is the Thread that runs for checking updates against the config file /// 此方法先通过与配置文件进行比较,然后下载版本最新的程序 /// </summary> private void updateThread() { AssemblyName myAssemblyName = null; string stUpdateName = "update"; AutoUpdateConfig config = new AutoUpdateConfig(); RaiseUpdateProgress(string.Format("正在检查版本号...")); //For using untrusted SSL Certificates System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy(); //Do the load of the config file if (config.LoadConfig(this.ConfigURL, this.LoginUserName, this.LoginUserPass)) { IList <UpdateFileInfo> _needUpdateList = new List <UpdateFileInfo>(); foreach (UpdateFileInfo _cvfile in config.CurrentVersionfiles) { string _fname = string.Format("{0}\\{1}", LocalPath, _cvfile.FileName); RaiseUpdateProgress(string.Format("比较文件{0}的版本号...", _cvfile.FileName)); //取当前版本号 if (File.Exists(_fname)) { myAssemblyName = AssemblyName.GetAssemblyName(_fname); //比较版本号,如果有新版本,加入下载更新列表 Version vConfig = new Version(_cvfile.AvailableVersion); if (myAssemblyName.Version < vConfig) { _needUpdateList.Add(_cvfile); } } else { //如果本地不存在此文件 _needUpdateList.Add(_cvfile); } } if (_needUpdateList.Count > 0) { //如果需下载列表中有记录 { foreach (UpdateFileInfo _nuFile in _needUpdateList) { int i = 0; while (i < 3) { i++; if (UpdateFileProcess(_nuFile, stUpdateName)) { i = 100; } } if (i < 90) { RaiseUpdateError(string.Format("下载升级文件{0}失败!\n自动更新过程失败!", _nuFile.AppFileURL)); this._finishedFlag = true; return; } } if (this.AutoRestart) { this.restart(); } } } } else { RaiseUpdateError(string.Format("{0}中未找到版本信息,无法完成自动更新。请重新配置自动更新地址! ", this.ConfigURL)); } this._finishedFlag = true; }
/// <summary> /// updateThread: This is the Thread that runs for checking updates against the config file /// 此方法先通过与配置文件进行比较,然后下载版本最新的程序 /// </summary> private void updateThread() { AssemblyName myAssemblyName = null; AutoUpdateConfig config = new AutoUpdateConfig(); RaiseUpdateProgress(string.Format("正在检查版本号...")); //Do the load of the config file if (config.LoadConfig(this.ConfigURL, this.LoginUserName, this.LoginUserPass)) { IList <UpdateFileInfo> _needUpdateList = new List <UpdateFileInfo>(); foreach (UpdateFileInfo _cvfile in config.CurrentVersionfiles) { string _fname = string.Format("{0}\\{1}", LocalPath, _cvfile.FileName); RaiseUpdateProgress(string.Format("比较文件{0}的版本号...", _cvfile.FileName)); //取当前版本号 if (File.Exists(_fname)) { myAssemblyName = AssemblyName.GetAssemblyName(_fname); //比较版本号,如果有新版本,加入下载更新列表 Version vConfig = new Version(_cvfile.AvailableVersion); if (myAssemblyName.Version < vConfig) { _needUpdateList.Add(_cvfile); } } else { //如果本地不存在此文件 _needUpdateList.Add(_cvfile); } } if (_needUpdateList.Count > 0) { //如果需下载列表中有记录 { //判断下载列表中是否包含SinoSZJS.Base.DLL //如果不存在,一定要下载。因为此文件的版本号是固定不变的 CheckBaseFileExist(_needUpdateList, config.CurrentVersionfiles); foreach (UpdateFileInfo _nuFile in _needUpdateList) { int i = 0; while (i < 3) { i++; if (UpdateFileProcess(_nuFile, stUpdateName)) { i = 100; } } if (i < 90) { RaiseUpdateError(string.Format("下载升级文件{0}失败!\n自动更新过程失败!", _nuFile.AppFileURL)); this._finishedFlag = true; return; } } //更新配置文件 if (!UpdateConfigFile()) { RaiseUpdateError("更新配置文件失败!\n自动更新过程失败!"); this._finishedFlag = true; return; } if (this.AutoRestart) { this.restart(); } } } } else { RaiseUpdateError(string.Format("{0}中未找到版本信息,无法完成自动更新。请重新配置自动更新地址! ", this.ConfigURL)); } this._finishedFlag = true; }