private static void ShowUpdate(CommandEventArgs e) { string[] args; try { args = (string[])e.Argument; } catch { return; } if (args == null || args.Length < 8) { return; } string title = args[0], header = args[1], description = args[2], url = args[3], urltext = args[4], version = args[5], newVersion = args[6], tag = args[7]; using (UpdateAvailableDialog uad = new UpdateAvailableDialog()) { try { uad.Text = string.Format(uad.Text, title); uad.headLabel.Text = header; uad.bodyLabel.Text = description; uad.linkLabel.Text = urltext; uad.linkLabel.Links.Add(0, urltext.Length).LinkData = url; if (!string.IsNullOrEmpty(version)) { uad.newVerLabel.Text = newVersion; uad.curVerLabel.Text = GetUIVersion(e.Context).ToString(3); uad.versionPanel.Enabled = uad.versionPanel.Visible = true; } if (string.IsNullOrEmpty(tag)) { uad.sameCheck.Enabled = uad.sameCheck.Visible = false; } } catch { return; // Don't throw a visible exception from a background check! } uad.ShowDialog(e.Context); if (uad.sameCheck.Checked) { IAnkhConfigurationService config = e.GetService <IAnkhConfigurationService>(); using (RegistryKey rk = config.OpenUserInstanceKey("UpdateCheck")) { rk.SetValue("SkipTag", tag); } } } }
public static void MaybePerformUpdateCheck(IAnkhServiceProvider context) { if (context == null) { throw new ArgumentNullException("context"); } if (_checkedOnce) { return; } _checkedOnce = true; IAnkhConfigurationService config = context.GetService <IAnkhConfigurationService>(); using (RegistryKey rk = config.OpenUserInstanceKey("UpdateCheck")) { int interval = 24 * 6; // 6 days object value = rk.GetValue("Interval"); if (value is int) { interval = (int)value; if (interval <= 0) { return; } } TimeSpan ts = TimeSpan.FromHours(interval); value = rk.GetValue("LastVersion"); if (IsDevVersion() || (value is string && (string)value == GetCurrentVersion(context).ToString())) { value = rk.GetValue("LastCheck"); long lv; if (value is string && long.TryParse((string)value, out lv)) { DateTime lc = new DateTime(lv, DateTimeKind.Utc); if ((lc + ts) > DateTime.UtcNow) { return; } // TODO: Check the number of fails to increase the check interval } } } context.GetService <IAnkhScheduler>().Schedule(new TimeSpan(0, 0, 20), AnkhCommand.CheckForUpdates); }
public IEnumerable <Uri> GetRepositoryUris(bool forBrowse) { HybridCollection <Uri> uris = new HybridCollection <Uri>(); if (ProjectRootUri != null) { uris.Add(ProjectRootUri); } // Global keys (over all versions) using (RegistryKey rk = Config.OpenGlobalKey("Repositories")) { if (rk != null) { LoadUris(uris, rk); } } // Per hive using (RegistryKey rk = Config.OpenInstanceKey("Repositories")) { if (rk != null) { LoadUris(uris, rk); } } // Per user + Per hive using (RegistryKey rk = Config.OpenUserInstanceKey("Repositories")) { if (rk != null) { LoadUris(uris, rk); } } // Finally add the last used list from TortoiseSVN try { using (RegistryKey rk = Registry.CurrentUser.OpenSubKey( "SOFTWARE\\TortoiseSVN\\History\\repoURLS", RegistryKeyPermissionCheck.ReadSubTree)) { if (rk != null) { LoadUris(uris, rk); } } } catch (SecurityException) { /* Ignore no read only access; stupid sysadmins */ } IAnkhConfigurationService configSvc = GetService <IAnkhConfigurationService>(); if (configSvc != null) { foreach (string u in configSvc.GetRecentReposUrls()) { Uri uri; if (u != null && Uri.TryCreate(u, UriKind.Absolute, out uri)) { if (!uris.Contains(uri)) { uris.Add(uri); } } } } return(uris); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (urlBox == null) { return; } // Add current project root (if available) first if (SolutionSettings != null && SolutionSettings.ProjectRootUri != null) { if (!urlBox.Items.Contains(SolutionSettings.ProjectRootUri)) { urlBox.Items.Add(SolutionSettings.ProjectRootUri); } } if (Config != null) { // Add last used url using (RegistryKey rk = Config.OpenUserInstanceKey("Dialogs")) { if (rk != null) { string value = rk.GetValue("Last Repository") as string; Uri uri; if (value != null && Uri.TryCreate(value, UriKind.Absolute, out uri)) { if (!urlBox.Items.Contains(uri)) { urlBox.Items.Add(uri); } } } } foreach (string value in Config.GetRecentReposUrls()) { Uri uri; if (value != null && Uri.TryCreate(value, UriKind.Absolute, out uri)) { if (!urlBox.Items.Contains(uri)) { urlBox.Items.Add(uri); } } } } if (SolutionSettings != null) { foreach (Uri uri in SolutionSettings.GetRepositoryUris(true)) { if (!urlBox.Items.Contains(uri)) { urlBox.Items.Add(uri); } } } if (urlBox.Items.Count > 0 && string.IsNullOrEmpty(urlBox.Text.Trim())) { urlBox.SelectedIndex = 0; UpdateDirectories(); } if (string.IsNullOrEmpty(fileTypeBox.Text) && fileTypeBox.Items.Count > 0) { fileTypeBox.SelectedItem = fileTypeBox.Items[0]; } }
RegistryKey OpenFifoKey(bool readOnly) { return(ConfigService.OpenUserInstanceKey(_name)); }
private void OnResponse(IAsyncResult ar) { IAnkhConfigurationService config = Context.GetService <IAnkhConfigurationService>(); bool failed = true; string tag = null; try { WebRequest rq = ((WebRequest)ar.AsyncState); WebResponse wr; try { wr = rq.EndGetResponse(ar); } catch (WebException e) { HttpWebResponse hwr = e.Response as HttpWebResponse; if (hwr != null) { if (hwr.StatusCode == HttpStatusCode.NotFound) { failed = false; return; // File not found.. Update info not yet or no longer available } } return; } catch { return; } if (wr.ContentLength > 65536) // Not for us.. We expect a few hundred bytes max { return; } string body; using (Stream s = wr.GetResponseStream()) using (StreamReader sr = new StreamReader(s)) { body = sr.ReadToEnd().Trim(); } if (string.IsNullOrEmpty(body)) { failed = false; return; } if (body[0] != '<' || body[body.Length - 1] != '>') { return; // No valid xml or empty } failed = false; XmlDocument doc = new XmlDocument(); doc.LoadXml(body); string title = NodeText(doc, "/u/i/t"); string header = NodeText(doc, "/u/i/h") ?? title; string description = NodeText(doc, "/u/i/d"); string url = NodeText(doc, "/u/i/u"); string urltext = NodeText(doc, "/u/i/l"); string version = NodeText(doc, "/u/i/v"); string newVersion = NodeText(doc, "/u/i/n") ?? version; tag = NodeText(doc, "/u/g"); if (!string.IsNullOrEmpty(title) && !string.IsNullOrEmpty(description)) { if (!string.IsNullOrEmpty(version)) { Version v = new Version(version); if (v <= GetCurrentVersion(Context)) { return; } } if (!string.IsNullOrEmpty(tag)) { using (RegistryKey rk = config.OpenUserInstanceKey("UpdateCheck")) { string pTag = rk.GetValue("SkipTag") as string; if (pTag == tag) { return; } } } IAnkhCommandService cs = Context.GetService <IAnkhCommandService>(); cs.PostExecCommand(AnkhCommand.CheckForUpdates, new string[] { title, header, description, url, urltext, version, newVersion, tag }); } } finally { using (RegistryKey rk = config.OpenUserInstanceKey("UpdateCheck")) { object fails = rk.GetValue("Fails", 0); rk.DeleteValue("LastCheck", false); rk.DeleteValue("LastVersion", false); rk.DeleteValue("FailedChecks", false); rk.SetValue("LastCheck", DateTime.UtcNow.Ticks); rk.SetValue("LastVersion", GetCurrentVersion(Context).ToString()); if (tag != null) { rk.SetValue("LastTag", tag); } else { rk.DeleteValue("LastTag", false); } if (failed) { int f = 0; if (fails is int) { f = (int)fails + 1; } rk.SetValue("FailedChecks", f); } } } }
public override void OnExecute(CommandEventArgs e) { if (e.Argument != null) { ShowUpdate(e); return; } int interval = 24 * 6; // 6 days IAnkhConfigurationService config = e.GetService <IAnkhConfigurationService>(); if (config.Instance.DisableUpdateCheck) { return; } using (RegistryKey rk = config.OpenUserInstanceKey("UpdateCheck")) { object value = rk.GetValue("Interval"); if (value is int) { interval = (int)value; if (interval <= 0) { return; } } } Version version = GetCurrentVersion(e.Context); Version osVersion = Environment.OSVersion.Version; StringBuilder sb = new StringBuilder(); sb.Append("http://svc.ankhsvn.net/svc/"); if (IsDevVersion()) { sb.Append("dev/"); } sb.Append("update-info/"); sb.Append(version.ToString(2)); sb.Append(".xml"); sb.Append("?av="); sb.Append(version); sb.Append("&vs="); sb.Append(VSVersion.FullVersion); sb.Append("&os="); sb.Append(osVersion); if (IsDevVersion()) { sb.Append("&dev=1"); } sb.AppendFormat(CultureInfo.InvariantCulture, "&iv={0}", interval); int x = 0; // Create some hashcode that is probably constant and unique for all users // using the same IP address, but not translatable to a single user try { foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces()) { string type = ni.NetworkInterfaceType.ToString(); if (type.Contains("Ethernet") || type.Contains("Wireless")) { x ^= ni.GetPhysicalAddress().GetHashCode(); } } } catch { } sb.AppendFormat(CultureInfo.InvariantCulture, "&xx={0}&pc={1}", x, Environment.ProcessorCount); try { using (RegistryKey rk = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\NET Framework Setup\\NDP")) { if (rk != null) { sb.Append("&dn="); Regex re = new Regex("^[vV]([0-9]+\\.[0-9]+)(\\.[0-9]+)*", RegexOptions.Singleline); bool first = true; HybridCollection <string> vers = new HybridCollection <string>(); foreach (string s in rk.GetSubKeyNames()) { Match m = re.Match(s); if (m.Success) { string v = m.Groups[1].Value; if (vers.Contains(v)) { continue; } vers.Add(v); if (first) { first = false; } else { sb.Append(','); } sb.Append(v); } } } } } catch { } WebRequest wr; try { wr = WebRequest.Create(new Uri(sb.ToString())); } catch (System.Configuration.ConfigurationException) { // The global .Net or Visual Studio configuration probably contains an invalid (proxy) configuration return; // Not our problem } HttpWebRequest hwr = wr as HttpWebRequest; if (hwr != null) { hwr.AllowAutoRedirect = true; hwr.AllowWriteStreamBuffering = true; hwr.UserAgent = string.Format("AnkhSVN/{0} VisualStudio/{1} Windows/{2}", version, VSVersion.FullVersion, osVersion); } try { wr.BeginGetResponse(OnResponse, wr); } catch (NotSupportedException) { /* Raised when an invalid proxy server setting is set */ } }