public void tmrStart_Tick(object sender, EventArgs e) { // finds which is the latest version available, and gets the index file for it tmrStart.Enabled = false; this.Cursor = Cursors.WaitCursor; string errorAction = "Update_Contact_Failed"; // first part of error message - changes throughout function try { txtLatest.Text = "?"; // will be left in place if fn fails early m_Server = new Repo2SoapClient("Repo2Soap", Server.TechURL + "repo2.asmx"); string latest = m_Server.LastVersionB(Server.Software, Server.PRODUCT, SoftwareVersion.VersionString, "", false, Server.Language2, RootApplication.GetNetVersion(), RootApplication.GetMachineID()); // if it is prefixed with "w", then it needs to be downloaded from the website m_RequiresWeb = false; if (latest.StartsWith("w", StringComparison.InvariantCultureIgnoreCase)) { m_RequiresWeb = true; latest = latest.Substring(1); } latest = latest.Split('#')[0]; // other info can be appended after #. Not used here txtLatest.Text = latest; m_LatestNumber = SoftwareVersion.VersionNumberFromString(latest); errorAction = "Update_Version_Fetch_Failed"; m_Latest = null; if (!m_RequiresWeb) { m_Latest = GetVersionIndex(latest); } errorAction = "Update_Check_Failed"; //MessageBox.Show("m_LatestNumber=" + m_LatestNumber + ", SoftwareVersion.Version=" + SoftwareVersion.Version); if (m_LatestNumber <= SoftwareVersion.Version + 0.001) // the +0.001 added as bizarrely this condition was failing on 32 bit machines when both were "700.7" { lblStatus.Text = Strings.Item("Update_Latest_Installed"); btnDownload.Visible = false; int errors = 0; System.Text.StringBuilder sb = new System.Text.StringBuilder(); VerifyVersion(m_Latest, false, ref sb, ref errors); //Clipboard.SetText(sb.ToString()); if (errors > 0) { lblStatus.Text = Strings.Item("Update_Installation_Damaged"); btnDownload.Text = Strings.Item("Update_Reinstall"); btnDownload.Visible = true; } } else if (m_RequiresWeb) { lblStatus.Text = Strings.Item("Update_Newer_Manual"); btnDownload.Text = Strings.Item("Update_Show_Website"); btnDownload.Visible = true; } else { lblStatus.Text = Strings.Item("Update_Newer_Available"); btnDownload.Text = Strings.Item("Update_Download_Install").Replace("%0", latest); btnDownload.Visible = true; } } catch (Exception ex) { lblStatus.Text = Strings.Item(errorAction).Trim() + " " + ex.Message; } finally { this.Cursor = Cursors.Default; } }
private void DoStartupCheck(Action callbackWhenAvailable) { try { Repo2SoapClient server = new Repo2SoapClient("Repo2Soap", Server.TechURL + "repo2.asmx"); string latest = server.LastVersionB(Server.Software, Server.PRODUCT, SoftwareVersion.VersionString, "", false, Server.Language2, GetNetVersion(), GetMachineID()); if (latest.StartsWith("w")) { latest = latest.Substring(1); // ignore update-via-download flag; all that's important is what version is available } // run the rest on UI thread Menu.Invoke(new Action(() => { var parts = latest.Split('#'); #if !DEBUG for (int index = 1; index < parts.Length; index++) { // process any directives.They are in form "1.2.3#warn" - where each item between # is a command switch (parts[index].ToLower()) { case "warn": const string SkipKey = "Skip_Upgrade_Message"; var skip = Config.SystemConfig.ReadInteger(SkipKey, 0); if (skip > 0) { Config.SystemConfig.Write(SkipKey, skip - 1); } else { Config.SystemConfig.Write(SkipKey, 10); MessageBox.Show(Strings.Item("Update_Warn")); } SaveSystemConfig(); break; } } #endif latest = parts[0]; if (string.IsNullOrEmpty(latest)) { return; } float asNumber = SoftwareVersion.VersionNumberFromString(latest); UpdateAvailable = asNumber > SoftwareVersion.Version + 0.001; // see frmUpdate Config.SystemConfig.Write(CONFIG_UPDATECHECK_STATE, (int)StartState.Complete); Globals.Root.SaveSystemConfig(); if (UpdateAvailable) { callbackWhenAvailable.Invoke(); } })); } catch (Exception ex) { try { #if !DEBUG Utilities.LogSubError(ex); #endif } catch { } } }