private static bool UpdateApplicable(UpdateInfo ui, bool autoCheck) { if (ui.AvailableVersion.CompareTo(Version.CurrentVersion) <= 0) return false; if (ui.Reset && ui.AvailableVersion.CompareTo(pgmSettings.AULastIgnoredVsn) != 0) pgmSettings.AULastIgnoredVsn = Version.CurrentVersion; if (autoCheck && ui.AvailableVersion.CompareTo(pgmSettings.AULastIgnoredVsn) <= 0) return false; return true; }
public static bool GetUpdate(bool autoCheck) { UpdateInfo ui = null; string ini = PortableSettingsProvider.GetApplicationIniFile("Update"); if (!File.Exists(ini)) { CopyableMessageBox.Show( "Problem checking for update" + (autoCheck ? " - will try again later" : "") + "\n" + ini + " - not found" , PortableSettingsProvider.ExecutableName + " AutoUpdate" , CopyableMessageBoxButtons.OK , CopyableMessageBoxIcon.Error); return(true); } try { string url = new StreamReader(ini).ReadLine(); if (url == null) { throw new IOException(ini + " - failed to read url"); } url = url.Trim(); try { using (S4PIDemoFE.Splash splash = new S4PIDemoFE.Splash("Checking for updates...")) { splash.Show(); Application.DoEvents(); ui = new UpdateInfo(url); } } catch (System.Net.WebException we) { if (we != null) { CopyableMessageBox.Show( "Problem checking for update" + (autoCheck ? " - will try again later" : "") + "\n" + (we.Response != null ? "\nURL: " + we.Response.ResponseUri : "") + "\n" + we.Message , PortableSettingsProvider.ExecutableName + " AutoUpdate" , CopyableMessageBoxButtons.OK , CopyableMessageBoxIcon.Error); return(true); } } } catch (IOException ioe) { CopyableMessageBox.Show( "Problem checking for update" + (autoCheck ? " - will try again later" : "") + "\n" + ioe.Message , PortableSettingsProvider.ExecutableName + " AutoUpdate" , CopyableMessageBoxButtons.OK , CopyableMessageBoxIcon.Error); return(true); } if (UpdateApplicable(ui, autoCheck)) { int dr = CopyableMessageBox.Show( String.Format("{0}\n{3}\n\nCurrent version: {1}\nAvailable version: {2}", ui.Message, Version.CurrentVersion, ui.AvailableVersion, ui.UpdateURL) , PortableSettingsProvider.ExecutableName + " update available" , CopyableMessageBoxIcon.Question , new List <string>(new string[] { "&Visit link", "&Later", "&Skip version", }), 1, 2 ); switch (dr) { case 0: System.Diagnostics.Process.Start(ui.UpdateURL); break; case 2: pgmSettings.AULastIgnoredVsn = ui.AvailableVersion; pgmSettings.Save(); break; } return(true); } return(false); }
public static bool GetUpdate(bool autoCheck) { UpdateInfo ui = null; string ini = PortableSettingsProvider.GetApplicationIniFile("Update"); if (!File.Exists(ini)) { CopyableMessageBox.Show( "Problem checking for update" + (autoCheck ? " - will try again later" : "") + "\n" + ini + " - not found" , PortableSettingsProvider.ExecutableName + " AutoUpdate" , CopyableMessageBoxButtons.OK , CopyableMessageBoxIcon.Error); return true; } try { string url = new StreamReader(ini).ReadLine(); if (url == null) throw new IOException(ini + " - failed to read url"); url = url.Trim(); try { using (ObjectCloner.Splash splash = new ObjectCloner.Splash("Checking for updates...")) { splash.Show(); Application.DoEvents(); ui = new UpdateInfo(url); } } catch (System.Net.WebException we) { if (we != null) { CopyableMessageBox.Show( "Problem checking for update" + (autoCheck ? " - will try again later" : "") + "\n" + (we.Response != null ? "\nURL: " + we.Response.ResponseUri : "") + "\n" + we.Message , PortableSettingsProvider.ExecutableName + " AutoUpdate" , CopyableMessageBoxButtons.OK , CopyableMessageBoxIcon.Error); return true; } } } catch (IOException ioe) { CopyableMessageBox.Show( "Problem checking for update" + (autoCheck ? " - will try again later" : "") + "\n" + ioe.Message , PortableSettingsProvider.ExecutableName + " AutoUpdate" , CopyableMessageBoxButtons.OK , CopyableMessageBoxIcon.Error); return true; } if (UpdateApplicable(ui, autoCheck)) { int dr = CopyableMessageBox.Show( String.Format("{0}\n{3}\n\nCurrent version: {1}\nAvailable version: {2}", ui.Message, Version.CurrentVersion, ui.AvailableVersion, ui.UpdateURL) , PortableSettingsProvider.ExecutableName + " update available" , CopyableMessageBoxIcon.Question , new List<string>(new string[] { "&Visit link", "&Later", "&Skip version", }), 1, 2 ); switch (dr) { case 0: System.Diagnostics.Process.Start(ui.UpdateURL); break; case 2: pgmSettings.AULastIgnoredVsn = ui.AvailableVersion; pgmSettings.Save(); break; } return true; } return false; }
public void UpdateFileList() { var configPath = AppDomain.CurrentDomain.BaseDirectory + configName; if (!File.Exists(configPath)) { MessageBox.Show("获取更新配置失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var info = convert.Deserialize <UpdateInfo>(File.ReadAllText(configPath)); File.Delete(configPath); var localPath = Application.StartupPath; var q = from file in Directory.GetFiles(localPath, "*.*", SearchOption.AllDirectories) join fileNew in info.FileList on new { Path = Path.GetDirectoryName(file).Replace(localPath, ""), Name = Path.GetFileName(file), MD5 = GetMD5HashFromFile(file) } equals new { Path = fileNew.Path, Name = fileNew.Name, MD5 = fileNew.MD5 } select fileNew.ID; info.FileList.RemoveAll(m => q.Contains(m.ID)); foreach (var fileItem in info.FileList) { var item = this.lvUpdate.Items.Add(fileItem.ID, fileItem.Name, -1); item.SubItems.Add(FormatFileSize(fileItem.Size)); item.SubItems.Add(fileItem.MD5); item.SubItems.Add("0"); item.SubItems.Add("").Tag = fileItem.Size; } new Thread(obj => { UpdateInfo tInfo = obj as UpdateInfo; foreach (var fileItem in info.FileList) { this.lvUpdate.Invoke(this.actFocus, fileItem.ID); currentFileID = fileItem.ID; currentCount = 0; var result = false; if (fileItem.Name == "AutoUpdate.exe") { result = this.Download(tInfo.UpdatePath + fileItem.Path, fileItem.Name, fileItem.Path, "AutoUpdate.exe.tmp"); } else { result = this.Download(tInfo.UpdatePath + fileItem.Path, fileItem.Name, fileItem.Path, fileItem.Name); } this.lvUpdate.Invoke(this.actUpdate, fileItem.ID, result); } Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); config.AppSettings.Settings["UpdateTime"].Value = this.dtLastUpdateTime.ToString("yyyy-MM-dd HH:mm:ss"); config.Save(ConfigurationSaveMode.Modified); this.Invoke(new Action(() => { this.Close(); })); }) { IsBackground = true }.Start(info); }