private void AutomaticUpdate_Load(object sender, EventArgs e) { string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()"; try { using (new WaitCursor()) { if (!PointHelper.PointIsEmpty(TopLeft)) { Left = (int)TopLeft.X; Top = (int)TopLeft.Y; } string currentVersionNumber = CurrentVersion.Root.Element("Number").Value; DateTime currentReleaseDate = SafeDate.Parse(CurrentVersion.Root.Element("Released").Value); lblInfo.Text = "Your current version of Chem4Word is " + currentVersionNumber + "; Released " + SafeDate.ToShortDate(currentReleaseDate); _telemetry.Write(module, "AutomaticUpdate", lblInfo.Text); var versions = NewVersions.XPathSelectElements("//Version"); foreach (var version in versions) { if (string.IsNullOrEmpty(_downloadUrl)) { _downloadUrl = version.Element("Url").Value; } var thisVersionNumber = version.Element("Number").Value; DateTime thisVersionDate = SafeDate.Parse(version.Element("Released").Value); if (currentReleaseDate >= thisVersionDate) { break; } AddHeaderLine("Version " + thisVersionNumber + "; Released " + SafeDate.ToShortDate(thisVersionDate), Color.Blue); var changes = version.XPathSelectElements("Changes/Change"); foreach (var change in changes) { if (change.Value.StartsWith("Note:")) { AddBulletItem(change.Value.Remove(0, 6), Color.Red); } else { AddBulletItem(change.Value, Color.Black); } } } } } catch (Exception ex) { new ReportError(_telemetry, TopLeft, module, ex).ShowDialog(); } }
public static bool FetchUpdateInfo() { string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()"; bool updateRequired = false; Globals.Chem4WordV3.VersionsBehind = 0; var assembly = Assembly.GetExecutingAssembly(); ReadThisVersion(assembly); if (Globals.Chem4WordV3.ThisVersion != null) { string currentVersionNumber = Globals.Chem4WordV3.ThisVersion.Root.Element("Number").Value; DateTime currentReleaseDate = SafeDate.Parse(Globals.Chem4WordV3.ThisVersion.Root.Element("Released").Value); Debug.WriteLine("Current Version " + currentVersionNumber + " Released " + SafeDate.ToShortDate(currentReleaseDate)); string xml = GetVersionsXmlFile(); if (!string.IsNullOrEmpty(xml)) { #region Got Our File Globals.Chem4WordV3.AllVersions = XDocument.Parse(xml); var versions = Globals.Chem4WordV3.AllVersions.XPathSelectElements("//Version"); foreach (var version in versions) { var thisVersionNumber = version.Element("Number").Value; DateTime thisVersionDate = SafeDate.Parse(version.Element("Released").Value); Debug.WriteLine("New Version " + thisVersionNumber + " Released " + SafeDate.ToShortDate(thisVersionDate)); if (thisVersionDate > currentReleaseDate) { Globals.Chem4WordV3.VersionsBehind++; updateRequired = true; } } // Save VersionsBehind and Last Checked for next start up Debug.WriteLine($"Saving Versions Behind in Registry: {Globals.Chem4WordV3.VersionsBehind}"); RegistryKey key = Registry.CurrentUser.CreateSubKey(Constants.Chem4WordRegistryKey); key?.SetValue(Constants.RegistryValueNameVersionsBehind, Globals.Chem4WordV3.VersionsBehind.ToString()); #endregion Got Our File } } else { Globals.Chem4WordV3.Telemetry.Write(module, "Error", "Failed to parse resource 'Data.This-Version.xml'"); } return(updateRequired); }
public static void ReadSavedValues() { string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()"; try { RegistryKey key = Registry.CurrentUser.OpenSubKey(Constants.Chem4WordRegistryKey); if (key != null) { var names = key.GetValueNames(); if (names.Contains(Constants.RegistryValueNameLastCheck)) { try { var lastChecked = key.GetValue(Constants.RegistryValueNameLastCheck).ToString(); if (!string.IsNullOrEmpty(lastChecked)) { DateTime last = SafeDate.Parse(lastChecked); Globals.Chem4WordV3.VersionLastChecked = last; } } catch { Globals.Chem4WordV3.VersionLastChecked = DateTime.Now.AddDays(-30); } } else { Globals.Chem4WordV3.VersionLastChecked = DateTime.Now.AddDays(-30); } if (names.Contains(Constants.RegistryValueNameLastCheck)) { try { var behind = key.GetValue(Constants.RegistryValueNameVersionsBehind).ToString(); Globals.Chem4WordV3.VersionsBehind = string.IsNullOrEmpty(behind) ? 0 : int.Parse(behind); } catch { Globals.Chem4WordV3.VersionsBehind = 0; } } else { Globals.Chem4WordV3.VersionsBehind = 0; } } else { Globals.Chem4WordV3.VersionLastChecked = DateTime.Now.AddDays(-30); Globals.Chem4WordV3.VersionsBehind = 0; } } catch (Exception ex) { Debug.WriteLine(ex.Message); Globals.Chem4WordV3.Telemetry.Write(module, "Exception", ex.Message); Globals.Chem4WordV3.Telemetry.Write(module, "Exception", ex.StackTrace); if (ex.InnerException != null) { Globals.Chem4WordV3.Telemetry.Write(module, "Exception", ex.InnerException.Message); Globals.Chem4WordV3.Telemetry.Write(module, "Exception", ex.InnerException.StackTrace); } } }
public static int CheckForUpdates(int days) { string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()"; Debug.WriteLine($"{module} days: {days}"); try { if (!string.IsNullOrEmpty(Globals.Chem4WordV3.AddInInfo.DeploymentPath)) { #region CheckForUpdate bool doCheck = true; RegistryKey key = Registry.CurrentUser.CreateSubKey(Constants.Chem4WordRegistryKey); string lastChecked = null; try { lastChecked = key.GetValue(Constants.RegistryValueNameLastCheck).ToString(); } catch { // Should only happen if the value does not exist } string behind = null; try { behind = key.GetValue(Constants.RegistryValueNameVersionsBehind).ToString(); Globals.Chem4WordV3.VersionsBehind = int.Parse(behind); } catch { // Should only happen if the value does not exist } // Bypass for testing if (days > 0) { if (!string.IsNullOrEmpty(lastChecked)) { DateTime last = SafeDate.Parse(lastChecked); TimeSpan delta = DateTime.Today - last; if (delta.TotalDays < days) { doCheck = false; } } if (doCheck) { key.SetValue(Constants.RegistryValueNameLastCheck, DateTime.Today.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)); } } if (doCheck) { bool update = false; using (new UI.WaitCursor()) { update = FetchUpdateInfo(); } if (update) { ShowUpdateForm(); } } #endregion CheckForUpdate } } catch (Exception ex) { Debug.WriteLine(ex.Message); Globals.Chem4WordV3.Telemetry.Write(module, "Exception", ex.Message); Globals.Chem4WordV3.Telemetry.Write(module, "Exception", ex.StackTrace); if (ex.InnerException != null) { Globals.Chem4WordV3.Telemetry.Write(module, "Exception", ex.InnerException.Message); Globals.Chem4WordV3.Telemetry.Write(module, "Exception", ex.InnerException.StackTrace); } } Globals.Chem4WordV3.SetUpdateButtonState(); return(Globals.Chem4WordV3.VersionsBehind); }
public static bool FetchUpdateInfo() { string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()"; bool updateRequired = false; Globals.Chem4WordV3.VersionsBehind = 0; var assembly = Assembly.GetExecutingAssembly(); ReadThisVersion(assembly); if (Globals.Chem4WordV3.ThisVersion != null) { DateTime currentReleaseDate = SafeDate.Parse(Globals.Chem4WordV3.ThisVersion.Root.Element("Released").Value); string xml = GetVersionsXmlFile(); if (!string.IsNullOrEmpty(xml)) { #region Got Our File Globals.Chem4WordV3.AllVersions = XDocument.Parse(xml); RegistryKey registryKey = Registry.CurrentUser.CreateSubKey(Constants.Chem4WordRegistryKey); var expires = Globals.Chem4WordV3.AllVersions.XPathSelectElements("//EndOfLife").FirstOrDefault(); if (expires != null) { var expiryDate = SafeDate.Parse(expires.Value); if (DateTime.Now.ToUniversalTime() > expiryDate) { Globals.Chem4WordV3.IsEndOfLife = true; registryKey?.SetValue(Constants.RegistryValueNameEndOfLife, "true"); } } var versions = Globals.Chem4WordV3.AllVersions.XPathSelectElements("//Version"); bool mostRecent = true; foreach (var version in versions) { var thisVersionNumber = version.Element("Number")?.Value; DateTime thisVersionDate = SafeDate.Parse(version.Element("Released")?.Value); if (thisVersionDate > currentReleaseDate) { Globals.Chem4WordV3.VersionsBehind++; updateRequired = true; } if (mostRecent) { Globals.Chem4WordV3.VersionAvailable = thisVersionNumber; registryKey?.SetValue(Constants.RegistryValueNameAvailableVersion, thisVersionNumber); var isBeta = version.Element("IsBeta")?.Value; Globals.Chem4WordV3.VersionAvailableIsBeta = bool.Parse(isBeta); registryKey?.SetValue(Constants.RegistryValueNameAvailableIsBeta, isBeta); mostRecent = false; } } // Save VersionsBehind and Last Checked for next start up Debug.WriteLine($"Saving Versions Behind in Registry: {Globals.Chem4WordV3.VersionsBehind}"); registryKey?.SetValue(Constants.RegistryValueNameVersionsBehind, Globals.Chem4WordV3.VersionsBehind.ToString()); #endregion Got Our File } } else { Globals.Chem4WordV3.Telemetry.Write(module, "Error", "Failed to parse resource 'Data.This-Version.xml'"); } return(updateRequired); }