static Configurations() { _adminUI = new AdminUIConfig(); _providers = new ProvidersConfig(); _pages = new PagesConfig(); _webData = new WebDataConfig(); _authentication = new AuthenticationConfig(); _imageCompressor = new ImageCompressorConfig(); _autoUpdate = new AutoUpdateConfig(); _logSystem = new LogSystemConfig(); _netProxy = new NetProxyConfig(); _userOptions = new UserOptionsConfig(); _userAccessControlConfig = new UserAccessControlConfig(); ReadSettings(); }
/// <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; }
private void simpleButton1_Click(object sender, EventArgs e) { //取源目录文件列表 string SourcePath = this.be_SourceDir.EditValue.ToString(); string DownloadUrl = this.te_URL.EditValue.ToString(); string TargetPath = this.be_TargetDir.EditValue.ToString() + "\\"; string SourceConfigFile = this.buttonEdit1.EditValue.ToString(); if (SourcePath == "" || DownloadUrl == "" || TargetPath == "" || SourceConfigFile == "") { MessageBox.Show("请录入生成目录、源升级文件目录、源配置文件、下级网站地址等内容!"); return; } AssemblyName myAssemblyName = null; #region 生成DLL配置文件列表 //配置文件 AutoUpdateConfig _configFile = new AutoUpdateConfig(); _configFile.CurrentVersionfiles = new List <UpdateFileInfo>(); DirectoryInfo dirInfo = new DirectoryInfo(SourcePath); foreach (FileSystemInfo _fs in dirInfo.GetFileSystemInfos()) { string FileName = ""; string FileExt = ""; //如果是文件 if (_fs is FileInfo) { FileInfo fi = (FileInfo)_fs; FileName = fi.Name; //取得文件的扩展名 FileExt = fi.Extension.ToUpper(); if (FileExt == ".DLL" || FileExt == ".EXE") { string _packFileName = FileName + ".zip"; myAssemblyName = AssemblyName.GetAssemblyName(_fs.FullName); //比较版本号,如果有新版本,加入下载更新列表 string _downloadFileName = DownloadUrl + _packFileName; string TargetFileName = TargetPath + _packFileName; ZipFile(_fs.FullName, TargetFileName); UpdateFileInfo _ufi = new UpdateFileInfo(fi.Name, myAssemblyName.Version.ToString(), _downloadFileName); _configFile.CurrentVersionfiles.Add(_ufi); this.te_Out.EditValue = (string)this.te_Out.EditValue + "\r\n" + string.Format(" {0},{1},{2} ", _ufi.FileName, _ufi.AvailableVersion, _ufi.AppFileURL); Application.DoEvents(); } } } //生成配置文件 string _ConfigFileName = TargetPath + "UpdateVersion.xml"; if (File.Exists(_ConfigFileName)) { File.Delete(_ConfigFileName); } StreamWriter _fw = File.CreateText(_ConfigFileName); _fw.WriteLine(@"<VersionConfig>"); foreach (UpdateFileInfo _ufi in _configFile.CurrentVersionfiles) { _fw.WriteLine(string.Format("<FileName Name=\"{0}\" Version=\"{1}\" AppFileURL=\"{2}\"/>", _ufi.FileName, _ufi.AvailableVersion, _ufi.AppFileURL)); } _fw.WriteLine(@"</VersionConfig>"); _fw.Close(); #endregion #region 生成客户端配置更新文件 string _pluginFileName = TargetPath + "UpdateApp.xml"; File.Copy(SourceConfigFile, _pluginFileName, true); #endregion MessageBox.Show("自动更新升级包制作完成!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); }