예제 #1
0
        private void okButton_Click(object sender, EventArgs e)
        {
            CancelEventArgs cea = new CancelEventArgs();

            ValidateAdd(this, cea);

            if (cea.Cancel)
            {
                DialogResult = DialogResult.None;
            }
            else if (Context != null)
            {
                RepositoryTreeNode rtn = repositoryTree.SelectedNode;

                if (rtn != null && rtn.RepositoryRoot != null)
                {
                    IAnkhConfigurationService config = Context.GetService <IAnkhConfigurationService>();

                    RegistryLifoList lifo = config.GetRecentReposUrls();

                    string url = rtn.RepositoryRoot.ToString();
                    if (!lifo.Contains(url))
                    {
                        lifo.Add(url);
                    }
                }
            }
        }
예제 #2
0
        public void OnExecute(CommandEventArgs e)
        {
            IAnkhConfigurationService configSvc = e.GetService <IAnkhConfigurationService>();

            if (configSvc != null)
            {
                AnkhConfig cfg = configSvc.Instance;
                using (ConfigureRecentChangesPageDialog dlg = new ConfigureRecentChangesPageDialog())
                {
                    int seconds = Math.Max(0, cfg.RecentChangesRefreshInterval);
                    dlg.RefreshInterval = seconds / 60;
                    if (dlg.ShowDialog(e.Context) == System.Windows.Forms.DialogResult.OK)
                    {
                        cfg.RecentChangesRefreshInterval = Math.Max(dlg.RefreshInterval * 60, 0);

                        configSvc.SaveConfig(cfg);
                        RecentChangesPage rcPage = e.GetService <RecentChangesPage>();
                        if (rcPage != null)
                        {
                            rcPage.RefreshIntervalConfigModified();
                        }
                    }
                }
            }
        }
예제 #3
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (Context != null)
            {
                IAnkhConfigurationService config = Context.GetService <IAnkhConfigurationService>();

                _items = config.GetRecentLogMessages();

                logMessageList.Items.Clear();

                foreach (string i in _items)
                {
                    if (string.IsNullOrEmpty(i))
                    {
                        continue;
                    }

                    ListViewItem item = new ListViewItem();

                    item.Text = i.Trim().Replace("\r", "").Replace("\n", "\x23CE");
                    item.Tag  = i;
                    logMessageList.Items.Add(i);
                }
            }
        }
예제 #4
0
 private bool UseExternalMergeTool()
 {
     IAnkhConfigurationService cs = GetService<IAnkhConfigurationService>();
     if (cs == null) { return false; }
     string mergePath = cs.Instance.MergeExePath;
     return !string.IsNullOrEmpty(mergePath);
 }
예제 #5
0
        StringDictionary GetFileExtensionMappings()
        {
            IAnkhConfigurationService configService = site.GetService(typeof(IAnkhConfigurationService)) as IAnkhConfigurationService;

            StringDictionary map = new StringDictionary();

            if (configService == null)
            {
                return(map);
            }

            using (RegistryKey key = configService.OpenVSInstanceKey("Default Editors"))
            {
                if (key != null)
                {
                    foreach (string name in key.GetSubKeyNames())
                    {
                        using (RegistryKey extkey = key.OpenSubKey(name, false))
                        {
                            if (extkey != null)
                            {
                                object obj = extkey.GetValue("Custom");
                                if (obj is string)
                                {
                                    string ext = "." + name;
                                    map[ext] = obj.ToString(); // extension -> editor.
                                }
                            }
                        }
                    }
                }
            }
            return(map);
        }
예제 #6
0
        public void Navigate(Uri url, AnkhBrowserArgs args)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            AnkhBrowserResults results;

            bool useExternal = args.External;

            IAnkhConfigurationService cs = GetService <IAnkhConfigurationService>();

            if (cs != null && cs.Instance.ForceExternalBrowser)
            {
                useExternal = true;
            }

            if (args != null && useExternal)
            {
                try
                {
                    NavigateInExternalBrowser(url);
                    return;
                }
                catch { } // BA: log/ignore the exception, and open the URL using VS's browser service
            }
            Navigate(url, args, out results);
        }
예제 #7
0
        public void OnExecute(CommandEventArgs e)
        {
            IAnkhSolutionSettings slnSettings = e.GetService <IAnkhSolutionSettings>();
            List <ISvnLogItem>    logItems    = new List <ISvnLogItem>(e.Selection.GetSelection <ISvnLogItem>());

            if (logItems.Count != 1)
            {
                return;
            }

            using (EditLogMessageDialog dialog = new EditLogMessageDialog())
            {
                dialog.Context    = e.Context;
                dialog.LogMessage = logItems[0].LogMessage;

                if (dialog.ShowDialog(e.Context) == DialogResult.OK)
                {
                    if (dialog.LogMessage == logItems[0].LogMessage)
                    {
                        return; // No changes
                    }
                    IAnkhConfigurationService config = e.GetService <IAnkhConfigurationService>();

                    if (config != null)
                    {
                        if (dialog.LogMessage != null && dialog.LogMessage.Trim().Length > 0)
                        {
                            config.GetRecentLogMessages().Add(dialog.LogMessage);
                        }
                    }

                    using (SvnClient client = e.GetService <ISvnClientPool>().GetClient())
                    {
                        SvnSetRevisionPropertyArgs sa = new SvnSetRevisionPropertyArgs();
                        sa.AddExpectedError(SvnErrorCode.SVN_ERR_REPOS_DISABLED_FEATURE);
                        client.SetRevisionProperty(logItems[0].RepositoryRoot, logItems[0].Revision, SvnPropertyNames.SvnLog, dialog.LogMessage, sa);

                        if (sa.LastException != null &&
                            sa.LastException.SvnErrorCode == SvnErrorCode.SVN_ERR_REPOS_DISABLED_FEATURE)
                        {
                            AnkhMessageBox mb = new AnkhMessageBox(e.Context);

                            mb.Show(sa.LastException.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Information);

                            return;
                        }
                    }

                    ILogControl logWindow = e.Selection.GetActiveControl <ILogControl>();

                    if (logWindow != null)
                    {
                        // TODO: Somehow repair scroll position/number of items loaded
                        logWindow.Restart();
                    }
                }
            }
        }
예제 #8
0
        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);
                    }
                }
            }
        }
예제 #9
0
        public void Hook(bool enableSolution, bool enableProjects)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (enableSolution != _hookedSolution)
            {
                IVsSolution solution = GetService <IVsSolution>(typeof(SVsSolution));

                if (enableSolution && solution != null)
                {
                    Marshal.ThrowExceptionForHR(solution.AdviseSolutionEvents(this, out _documentCookie));
                    _hookedSolution = true;
                }
                else if (_hookedSolution)
                {
                    Marshal.ThrowExceptionForHR(solution.UnadviseSolutionEvents(_documentCookie));
                    _hookedSolution = false;
                }
            }

            if (enableProjects != _hookedProjects)
            {
                IVsTrackProjectDocuments2 tracker = GetService <IVsTrackProjectDocuments2>(typeof(SVsTrackProjectDocuments));

                if (enableProjects && tracker != null)
                {
                    Marshal.ThrowExceptionForHR(tracker.AdviseTrackProjectDocumentsEvents(this, out _projectCookie));

                    _hookedProjects = true;
                }
                else if (_hookedProjects)
                {
                    Marshal.ThrowExceptionForHR(tracker.UnadviseTrackProjectDocumentsEvents(_projectCookie));
                    _hookedProjects = false;
                }

                IAnkhConfigurationService cfg = GetService <IAnkhConfigurationService>();

                if (cfg != null && !cfg.Instance.DontHookSolutionExplorerRefresh)
                {
                    IAnkhGlobalCommandHook cmdHook = GetService <IAnkhGlobalCommandHook>();

                    if (cmdHook != null)
                    {
                        CommandID slnRefresh = new CommandID(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.SLNREFRESH);
                        if (enableProjects)
                        {
                            cmdHook.HookCommand(slnRefresh, OnSolutionRefreshCommand);
                        }
                        else
                        {
                            cmdHook.UnhookCommand(slnRefresh, OnSolutionRefreshCommand);
                        }
                    }
                }
            }
        }
예제 #10
0
        void LoadThemeData()
        {
            if (!VSVersion.VS2012OrLater)
            {
                _themed = false;
                return;
            }

            _themeLight = _themeDark = false;
            IAnkhConfigurationService config = GetService <IAnkhConfigurationService>();
            IWinFormsThemingService   wts    = GetService <IWinFormsThemingService>();

            Guid themeGuid;

            if (config == null || wts == null || !wts.GetCurrentTheme(out themeGuid))
            {
                _themed = false;
                return;
            }

            if (themeGuid == Guid.Empty)
            {
                // Before the first theme switch no theme is set, but the light theme
                // is used anyway
                _themed     = true;
                _themeLight = true;
                _themeDark  = true;
                return;
            }

            using (RegistryKey rk = config.OpenVSInstanceKey("Extensions\\AnkhSVN\\Themes"))
            {
                object v;

                if (rk != null)
                {
                    v = rk.GetValue(themeGuid.ToString("B"));
                }
                else
                {
                    v = null;
                }

                if (v is int)
                {
                    _themed = true;
                    int vv = (int)v;

                    _themeLight = (vv & 0x01) != 0;
                    _themeDark  = (vv & 0x02) != 0;
                }
                else
                {
                    _themed = true;
                }
            }
        }
예제 #11
0
        private void SetFloat(AnkhDiffToolArgs args)
        {
            IAnkhConfigurationService cs = GetService <IAnkhConfigurationService>();

            if (cs != null)
            {
                args.ShowDiffAsDocument = !cs.Instance.FloatDiffEditors;
            }
        }
예제 #12
0
        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);
        }
예제 #13
0
        public override void ResetSettings()
        {
            base.ResetSettings();

            IAnkhServiceProvider sp = (IAnkhServiceProvider)GetService(typeof(IAnkhServiceProvider));
            if (sp != null)
            {
                IAnkhConfigurationService cfgSvc = sp.GetService<IAnkhConfigurationService>();
                cfgSvc.LoadDefaultConfig();
            }
        }
예제 #14
0
        static Hashtable GetEditors(IServiceProvider site)
        {
            if (AnkhEditorFactory.editors != null)
            {
                return(AnkhEditorFactory.editors);
            }

            Hashtable editors = new Hashtable();
            IAnkhConfigurationService configService = site.GetService(typeof(IAnkhConfigurationService)) as IAnkhConfigurationService;

            if (configService == null)
            {
                return(editors);
            }

            using (RegistryKey editorsKey = configService.OpenVSInstanceKey("Editors"))
            {
                if (editorsKey != null)
                {
                    foreach (string editorGuid in editorsKey.GetSubKeyNames())
                    {
                        Guid guid = GetGuid(editorGuid);
                        using (RegistryKey editorKey = editorsKey.OpenSubKey(editorGuid, false))
                        {
                            object      value      = editorKey.GetValue(null);
                            string      name       = (value != null) ? value.ToString() : editorGuid.ToString();
                            RegistryKey extensions = editorKey.OpenSubKey("Extensions", false);
                            if (extensions != null)
                            {
                                foreach (string s in extensions.GetValueNames())
                                {
                                    if (!string.IsNullOrEmpty(s))
                                    {
                                        EditorInfo ei = new EditorInfo();
                                        ei.Name = name;
                                        ei.Guid = guid;
                                        object obj = extensions.GetValue(s);
                                        if (obj is int)
                                        {
                                            ei.Priority = (int)obj;
                                        }
                                        string ext = (s == "*") ? s : "." + s;
                                        AddEditorInfo(editors, ext, ei);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(AnkhEditorFactory.editors = editors);
        }
예제 #15
0
        /// <summary>
        /// Gets path to the diff executable while taking care of config file settings.
        /// </summary>
        /// <param name="context"></param>
        /// <returns>The exe path.</returns>
        protected string GetDiffPath(DiffMode mode, String filename)
        {
            IAnkhConfigurationService cs = GetService <IAnkhConfigurationService>();

            switch (mode)
            {
            case DiffMode.PreferInternal:
                return(null);

            default:
                return(cs.Instance.GetDiffExePath(filename));
            }
        }
예제 #16
0
        public override void OnUpdate(CommandUpdateEventArgs e)
        {
            IAnkhSolutionSettings ss = e.GetService <IAnkhSolutionSettings>();

            if (ss != null && !string.IsNullOrEmpty(ss.ProjectRoot) && ss.ProjectRootSvnItem.IsVersioned)
            {
                IAnkhConfigurationService cs = e.GetService <IAnkhConfigurationService>();

                if (!string.IsNullOrEmpty(cs.Instance.PatchExePath))
                {
                    return;
                }
            }

            e.Enabled = false;
        }
예제 #17
0
        void LoadProjectFlagMap()
        {
            _projectFlagMapLoaded = true;

            IAnkhConfigurationService configService = GetService <IAnkhConfigurationService>();

            if (configService == null)
            {
                return;
            }

            using (RegistryKey projectHandlingKey = configService.OpenVSInstanceKey("Extensions\\AnkhSVN\\ProjectHandling"))
            {
                if (projectHandlingKey == null)
                {
                    return;
                }

                foreach (string typeValue in projectHandlingKey.GetSubKeyNames())
                {
                    if (typeValue.Length != 38) // No proper guid
                    {
                        continue;
                    }

                    try
                    {
                        using (RegistryKey projectTypeKey = projectHandlingKey.OpenSubKey(typeValue))
                        {
                            object v = projectTypeKey.GetValue("flags");

                            if (!(v is int))
                            {
                                continue;
                            }

                            Guid            projectType = new Guid(typeValue);
                            SccProjectFlags flags       = (SccProjectFlags)(int)v;
                            _projectFlagMap.Add(projectType, flags);
                        }
                    }
                    catch
                    { /* Parse Error */ }
                }
            }
        }
예제 #18
0
        public bool GetCurrentTheme(out Guid themeGuid)
        {
            if (VSVersion.VS2013OrLater)
            {
                return(GetThemeViaApi(out themeGuid));
            }
            else
            {
                IAnkhConfigurationService config = GetService <IAnkhConfigurationService>();
                themeGuid = Guid.Empty;

                if (config == null)
                {
                    return(false);
                }

                string currentTheme;

                using (RegistryKey rk = config.OpenVSUserKey("General"))
                {
                    if (rk != null)
                    {
                        currentTheme = rk.GetValue("CurrentTheme") as string;
                    }
                    else
                    {
                        currentTheme = null;
                    }
                }

                try
                {
                    if (!string.IsNullOrEmpty(currentTheme))
                    {
                        themeGuid = new Guid(currentTheme);
                        return(true);
                    }
                }
                catch { }
                {
                    currentTheme = null;
                }

                return(true);
            }
        }
예제 #19
0
        /// <summary>
        /// Gets the UI version (as might be remapped by the MSI)
        /// </summary>
        /// <returns></returns>
        private Version GetUIVersion()
        {
            // We can't use our services here to help us :(
            // This code might be used from devenv.exe /setup

            IAnkhConfigurationService configService = GetService <IAnkhConfigurationService>();

            if (configService == null)
            {
                return(null);
            }

            using (RegistryKey rk = configService.OpenVSInstanceKey("Packages\\" + typeof(AnkhSvnPackage).GUID.ToString("b")))
            {
                if (rk == null)
                {
                    return(null);
                }

                string v = rk.GetValue(Ankh.VSPackage.Attributes.ProvideUIVersionAttribute.RemapName) as string;

                if (string.IsNullOrEmpty(v))
                {
                    return(null);
                }

                if (v.IndexOf('[') >= 0)
                {
                    return(null); // When not using remapping we can expect "[ProductVersion]" as value
                }
                try
                {
                    return(new Version(v));
                }
                catch
                {
                    return(null);
                }
            }
        }
        private void okButton_Click(object sender, EventArgs e)
        {
            RepositoryTreeNode rtn = reposBrowser.SelectedNode;

            if (rtn != null && rtn.Origin != null)
            {
                IAnkhConfigurationService ics  = GetService <IAnkhConfigurationService>();
                RegistryLifoList          lifo = null;

                if (ics != null)
                {
                    lifo = ics.GetRecentReposUrls();
                }

                string url = rtn.Origin.RepositoryRoot.AbsoluteUri;

                if (lifo != null && !lifo.Contains(url))
                {
                    lifo.Add(url);
                }
            }
        }
예제 #21
0
        /// <include file='doc\PropertySheet.uex' path='docs/doc[@for="LanguagePreferences.Init"]/*' />
        public virtual void Init()
        {
            IAnkhConfigurationService configService = GetService <IAnkhConfigurationService>();

            if (configService != null)
            {
                using (RegistryKey key = configService.OpenVSInstanceKey(null))
                {
                    if (key != null)
                    {
                        InitMachinePreferences(key, name);
                    }
                }
                using (RegistryKey key = configService.OpenVSUserKey(null))
                {
                    if (key != null)
                    {
                        InitUserPreferences(key, name);
                    }
                }
            }
            Connect();
        }
예제 #22
0
        static StringDictionary GetLanguageExtensions(IServiceProvider site)
        {
            if (AnkhEditorFactory.languageExtensions != null)
            {
                return(AnkhEditorFactory.languageExtensions);
            }

            IAnkhConfigurationService configService = site.GetService(typeof(IAnkhConfigurationService)) as IAnkhConfigurationService;
            StringDictionary          extensions    = new StringDictionary();

            if (configService != null)
            {
                using (RegistryKey key = configService.OpenVSInstanceKey("Languages\\File Extensions"))
                {
                    if (key != null)
                    {
                        foreach (string ext in key.GetSubKeyNames())
                        {
                            using (RegistryKey extkey = key.OpenSubKey(ext, false))
                            {
                                if (extkey != null)
                                {
                                    string fe   = ext;
                                    string guid = extkey.GetValue(null) as string; // get default value
                                    if (!extensions.ContainsKey(fe))
                                    {
                                        extensions.Add(fe, guid);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(AnkhEditorFactory.languageExtensions = extensions);
        }
        public int OnAfterOpenSolution(object pUnkReserved, int fNewSolution)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            _solutionLoaded = true;
            SccEvents.OnSolutionOpened(true);

            GetService <IAnkhServiceEvents>().OnSolutionOpened(EventArgs.Empty);

            if (!SccProvider.IsActive)
            {
                return(VSErr.S_OK);
            }
            try
            {
                VerifySolutionNaming();

                IAnkhSolutionSettings ss = GetService <IAnkhSolutionSettings>();

                if (ss != null && ss.ProjectRoot != null)
                {
                    string rootDir = Path.GetPathRoot(ss.ProjectRoot);
                    if (rootDir.Length == 3 && rootDir.EndsWith(":\\", StringComparison.OrdinalIgnoreCase))
                    {
                        DriveInfo di    = new DriveInfo(rootDir);
                        bool      oldFs = false;

                        switch ((di.DriveFormat ?? "").ToUpperInvariant())
                        {
                        case "FAT32":
                        case "FAT":
                            oldFs = true;
                            break;
                        }

                        if (oldFs)
                        {
                            IAnkhConfigurationService cs = GetService <IAnkhConfigurationService>();

                            if (!cs.GetWarningBool(AnkhWarningBool.FatFsFound))
                            {
                                using (SccFilesystemWarningDialog dlg = new SccFilesystemWarningDialog())
                                {
                                    dlg.Text = Path.GetFileName(ss.SolutionFilename);
                                    if (DialogResult.OK == dlg.ShowDialog(Context))
                                    {
                                        cs.SetWarningBool(AnkhWarningBool.FatFsFound, true);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                IAnkhErrorHandler handler = GetService <IAnkhErrorHandler>();

                if (handler.IsEnabled(ex))
                {
                    handler.OnError(ex);
                }
                else
                {
                    throw;
                }
            }

            return(VSErr.S_OK);
        }
예제 #24
0
        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 */ }
        }
예제 #25
0
        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);
                    }
                }
            }
        }
예제 #26
0
        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);
        }