bool AllowReadOnlyNonSccWrites()
        {
            IVsSccToolsOptions sccToolsOptions = GetService <IVsSccToolsOptions>(typeof(SVsSccToolsOptions));

            if (sccToolsOptions == null)
            {
                return(true);
            }

            object o;

            if (!VSErr.Succeeded(
                    sccToolsOptions.GetSccToolsOption(SccToolsOptionsEnum.ksctoAllowReadOnlyFilesNotUnderSccToBeEdited,
                                                      out o)))
            {
                return(true);
            }

            if (!(o is bool))
            {
                return(true);
            }

            return((bool)o);
        }
        public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText)
        {
            foreach (IOleCommandTarget target in _targets)
            {
                int hr = target.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText);

                if (hr != VSErr.OLECMDERR_E_NOTSUPPORTED && hr != VSErr.OLECMDERR_E_UNKNOWNGROUP)
                {
                    return(hr);
                }
            }

            IOleCommandTarget t = _baseTarget ?? (_baseTarget = (IOleCommandTarget)_pane.BaseGetService(typeof(IOleCommandTarget)));

            int r = VSErr.OLECMDERR_E_NOTSUPPORTED;

            if (t != null)
            {
                r = t.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText);
            }

            if (VSErr.Succeeded(r))
            {
                return(r);
            }
            else
            {
                return(VSErr.OLECMDERR_E_NOTSUPPORTED);
            }
        }
        private bool SolutionNavigatorInstalled()
        {
            if (!VSVersion.VS2010)
            {
                return(false);
            }

            IVsShell shell = GetService <IVsShell>(typeof(SVsShell));

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

            Guid solutionNavigatorPackage = new Guid("{cf6a5c16-83b0-4d04-b702-195c35c6e887}");

            int bInstalled;

            if (!VSErr.Succeeded(shell.IsPackageInstalled(ref solutionNavigatorPackage, out bInstalled)))
            {
                return(false);
            }

            return(bInstalled != 0);
        }
        private static void OpenSolution(CommandEventArgs e, CheckoutProject dlg)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            IVsSolution2 sol = e.GetService <IVsSolution2>(typeof(SVsSolution));

            if (sol != null)
            {
                sol.CloseSolutionElement(VSItemId.Root, null, 0); // Closes the current solution
            }

            IAnkhSccService scc = e.GetService <IAnkhSccService>();

            if (scc != null)
            {
                scc.RegisterAsPrimarySccProvider(); // Make us the current SCC provider!
            }
            CheckOutAndOpenSolution(e, dlg.ProjectTop, dlg.Revision, dlg.ProjectTop, dlg.SelectedPath, dlg.ProjectUri);

            sol = e.GetService <IVsSolution2>(typeof(SVsSolution));

            if (sol != null)
            {
                string file, user, dir;

                if (VSErr.Succeeded(sol.GetSolutionInfo(out dir, out file, out user)) &&
                    !string.IsNullOrEmpty(file))
                {
                    scc.SetProjectManaged(null, true);
                }
            }
        }
Exemple #5
0
            public void Tick()
            {
                if (_dlg == null)
                {
                    if (_start > DateTime.UtcNow)
                    {
                        return;
                    }

                    IVsThreadedWaitDialog dlg = _context.GetService <IVsThreadedWaitDialog>(typeof(SVsThreadedWaitDialog));

                    if (dlg != null)
                    {
                        if (VSErr.Succeeded(dlg.StartWaitDialog(_caption, _message, null, (uint)__VSTWDFLAGS.VSTWDFLAGS_TOPMOST, null, null)))
                        {
                            _dlg = dlg;
                        }
                    }
                }
                else
                {
                    int canceled;
                    _dlg.GiveTimeSlice(null, null, 0, out canceled);
                }
            }
Exemple #6
0
        bool GetOtherSccActive()
        {
            EnsureContexts();

            try
            {
                foreach (SccData scc in _otherSccProviderContexts)
                {
                    if (scc.Active)
                    {
                        // Ok, let's ask the service if it has any files under source control?

                        Guid gService = new Guid(scc._service);

                        IVsSccProvider pv = GetService <IAnkhQueryService>().QueryService <IVsSccProvider>(gService);

                        int iManaging;
                        if (pv != null && VSErr.Succeeded(pv.AnyItemsUnderSourceControl(out iManaging)))
                        {
                            if (iManaging != 0)
                            {
                                return(true);
                            }
                        }
                        break;
                    }
                }
            }
            catch { }

            return(false);
        }
Exemple #7
0
        public bool PromptSaveDocument(string path)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }

            SccDocumentData data;

            if (!_docMap.TryGetValue(path, out data))
            {
                return(false);
            }

            data.CheckDirty(_poller);

            if (!data.IsDirty || (data.Cookie == 0))
            {
                return(true); // Not/never modified, no need to save
            }
            // Save the document if it is dirty
            return(VSErr.Succeeded(RunningDocumentTable.SaveDocuments((uint)__VSRDTSAVEOPTIONS.RDTSAVEOPT_PromptSave,
                                                                      data.Hierarchy, data.ItemId, data.Cookie)));
        }
Exemple #8
0
        public void SetManaged(bool managed)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (managed == IsManaged || ExcludedFromScc)
            {
                return;
            }

            bool ok;

            if (managed)
            {
                // Set some constant strings as marker
                ok = VSErr.Succeeded(SccProject.SetSccLocation("Svn", "Svn", "Svn", AnkhId.SubversionSccName));
            }
            else
            {
                // The managed package framework assumes empty strings for clearing; null will fail there
                ok = VSErr.Succeeded(SccProject.SetSccLocation("", "", "", ""));
            }

            if (ok)
            {
                IsManaged = managed;
            }
        }
        void Hook(bool enable)
        {
            if (enable == _hooked)
            {
                return;
            }

            IVsRunningDocumentTable rdt = RunningDocumentTable;

            if (rdt == null)
            {
                return;
            }

            if (enable)
            {
                if (VSErr.Succeeded(rdt.AdviseRunningDocTableEvents(this, out _cookie)))
                {
                    _hooked = true;
                }
            }
            else
            {
                _docMap.Clear();
                _cookieMap.Clear();

                _hooked = false;
                rdt.UnadviseRunningDocTableEvents(_cookie);
            }
        }
        private void NotifyLoaded(bool started)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            // We set the user context AnkhLoadCompleted active when we are loaded
            // This event can be used to trigger loading other packages that depend on AnkhSVN
            //
            // When the use:
            // [ProvideAutoLoad(AnkhId.AnkhLoadCompleted)]
            // On their package, they load automatically when we are completely loaded
            //

            IVsMonitorSelection ms = GetService <IVsMonitorSelection>();

            if (ms != null)
            {
                Guid gAnkhLoaded = new Guid(started ? AnkhId.AnkhRuntimeStarted : AnkhId.AnkhServicesAvailable);

                uint cky;
                if (VSErr.Succeeded(ms.GetCmdUIContextCookie(ref gAnkhLoaded, out cky)))
                {
                    ms.SetCmdUIContext(cky, 1);
                }
            }
        }
Exemple #11
0
        protected override void OnInitialize()
        {
            base.OnInitialize();

            GetService <SelectionContext>(typeof(ISelectionContext)).CmdUIContextChanged += OnCmdUIContextChanged;
            GetService <AnkhServiceEvents>().ThemeChanged += OnThemeChanged;

            IVsShell shell = GetService <IVsShell>(typeof(SVsShell));

            if (shell != null)
            {
                object v;

                if (!VSErr.Succeeded(shell.GetProperty((int)__VSSPROPID.VSSPROPID_Zombie, out v)))
                {
                    _zombie = false;
                }
                else
                {
                    _zombie = (v is bool) && ((bool)v);
                }

                if (!VSErr.Succeeded(shell.AdviseShellPropertyChanges(this, out _shellPropsCookie)))
                {
                    _shellPropsCookie = 0;
                }
            }

            // We might already have cached some stale values!
            foreach (CmdStateCacheItem i in _cookieMap.Values)
            {
                i.Reload(Monitor);
            }
        }
Exemple #12
0
        public int AddAdornments()
        {
            IVsTextView primaryView, secondaryView;

            if (VSErr.Succeeded(_window.GetPrimaryView(out primaryView)) && primaryView != null)
            {
                OnNewView(primaryView);
            }

            if (VSErr.Succeeded(_window.GetSecondaryView(out secondaryView)) && secondaryView != null)
            {
                OnNewView(secondaryView);
            }

            if (primaryView != null || secondaryView != null)
            {
                AnkhLanguageDropDownBar bar = Language.CreateDropDownBar(this);

                if (bar != null)
                {
                    _bar = bar;

                    bar.Initialize();
                }
            }

            return(VSErr.S_OK);
        }
Exemple #13
0
        public T QueryService <T>(Guid serviceGuid) where T : class
        {
            IOleServiceProvider sp = GetService <IOleServiceProvider>();
            IntPtr handle;

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

            if (!VSErr.Succeeded(sp.QueryService(ref serviceGuid, ref IID_IUnknown, out handle)) ||
                handle == IntPtr.Zero)
            {
                return(null);
            }

            try
            {
                object ob = Marshal.GetObjectForIUnknown(handle);

                return(ob as T);
            }
            finally
            {
                Marshal.Release(handle);
            }
        }
Exemple #14
0
        IEnumerable <T> InternalGetSelection <T>()
            where T : class
        {
            ISelectionContainer sc = _currentContainer;

            uint nItems;

            if (sc == null || !VSErr.Succeeded(sc.CountObjects((uint)ShellConstants.GETOBJS_SELECTED, out nItems)))
            {
                yield break;
            }

            object[] objs = new object[(int)nItems];
            if (VSErr.Succeeded(sc.GetObjects((uint)ShellConstants.GETOBJS_SELECTED, nItems, objs)))
            {
                foreach (object o in objs)
                {
                    T i = o as T;

                    if (i != null)
                    {
                        yield return(i);
                    }
                }
            }
        }
Exemple #15
0
        void IAnkhIdleProcessor.OnIdle(AnkhIdleArgs e)
        {
            OnIdle(e);
            if (_shouldSynchronize || _shouldUpdate)
            {
                _shouldSynchronize = false;
                _shouldUpdate      = false;

                if (_activeView != null)
                {
                    int line, col;
                    if (VSErr.Succeeded(_activeView.GetCaretPos(out line, out col)))
                    {
                        SynchronizeCombos(_activeView, line, col);
                    }
                }

                _shouldSendSync = true;
            }

            if (_shouldSendSync && _bar != null)
            {
                _shouldSendSync = false;

                foreach (ComboMemberCollection cmc in _combos)
                {
                    if (cmc.IsDirty(true))
                    {
                        _bar.RefreshCombo(cmc.Index, cmc.Current);
                    }
                }
            }
        }
Exemple #16
0
        public void EnsureSelection()
        {
            if (Tracker == null)
            {
                return;
            }

            IntPtr             ppHier;
            uint               itemid;
            IVsMultiItemSelect ms;
            IntPtr             ppSc;

            if (!VSErr.Succeeded(Tracker.GetCurrentSelection(out ppHier, out itemid, out ms, out ppSc)))
            {
                return;
            }

            if (ppHier != IntPtr.Zero)
            {
                Marshal.Release(ppHier);
            }

            if (ppSc != IntPtr.Zero)
            {
                object me = Marshal.GetObjectForIUnknown(ppSc);
                Marshal.Release(ppSc);

                if (me == this)
                {
                    return;
                }
            }

            NotifySelectionUpdated();
        }
Exemple #17
0
        public bool GetRawOtherSccProviderActive()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            IVsSccManager2 manager = GetService <IVsSccManager2>(typeof(SVsSccManager));

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

            // If the active manager is not installed, it is not active
            int installed = 0;

            if (!VSErr.Succeeded(manager.IsInstalled(out installed)) || (installed == 0))
            {
                return(false);
            }

            if (GetOtherSccActive())
            {
                return(true);
            }

            return(false);
        }
        public int OnItemAdded(uint itemidParent, uint itemidSiblingPrev, uint itemidAdded)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            string r;

            object var;
            if (VSErr.Succeeded(ProjectHierarchy.GetProperty(itemidAdded, (int)__VSHPROPID.VSHPROPID_IsNonMemberItem, out var))
                && (bool)var)
            {
                return VSErr.S_OK; // Extra item for show all files
            }

            if (_loaded)
            {
                if (VSErr.Succeeded(VsProject.GetMkDocument(itemidAdded, out r))
                    && SvnItem.IsValidPath(r))
                {
                    // Check out VSHPROPID_IsNewUnsavedItem
                    if (!SvnItem.PathExists(r))
                    {
                        SetPreCreatedItem(itemidAdded);
                    }
                    else
                    {
                        SetPreCreatedItem(VSItemId.Nil);

                        SetDirty();
                    }
                }
            }

            return VSErr.S_OK;
        }
Exemple #19
0
        void LoadSolutionInfo()
        {
            string dir, path, user;

            _rawSolutionDirectory = null;
            _solutionDirectory    = null;
            _solutionFile         = "";

            IVsSolution sol = GetService <IVsSolution>(typeof(SVsSolution));

            if (sol == null ||
                !VSErr.Succeeded(sol.GetSolutionInfo(out dir, out path, out user)))
            {
                return;
            }

            if (string.IsNullOrEmpty(dir) || string.IsNullOrEmpty(path))
            {
                // Cache negative result; will be returned as null
            }
            else
            {
                if (IsSafeSccPath(dir))
                {
                    _rawSolutionDirectory = dir;
                    _solutionDirectory    = SvnTools.GetTruePath(dir, true) ?? SvnTools.GetNormalizedFullPath(dir);
                }

                if (IsSafeSccPath(path))
                {
                    _solutionFile = SvnTools.GetTruePath(path, true) ?? SvnTools.GetNormalizedFullPath(path);
                }
            }
        }
Exemple #20
0
        static string GetLine(IVsTextLines lines, int lineNr)
        {
            if (lineNr < 0)
            {
                throw new ArgumentOutOfRangeException("lineNr");
            }
            else if (lines == null)
            {
                return(null);
            }

            int lastLine, lastIndex;

            if (!VSErr.Succeeded(lines.GetLastLineIndex(out lastLine, out lastIndex)))
            {
                return(null);
            }

            if (lineNr > lastLine)
            {
                return(null);
            }

            LINEDATA[] data = new LINEDATA[1];

            if (!VSErr.Succeeded(lines.GetLineData(lineNr, data, null)))
            {
                return(null);
            }

            return(Marshal.PtrToStringUni(data[0].pszText, data[0].iLength));
        }
Exemple #21
0
        public void RunHelp(IAnkhControlWithHelp control)
        {
            UriBuilder ub = new UriBuilder("http://svc.ankhsvn.net/svc/go/");

            ub.Query = string.Format("t=ctrlHelp&v={0}&l={1}&dt={2}", GetService <IAnkhPackage>().UIVersion, CultureInfo.CurrentUICulture.LCID, Uri.EscapeUriString(control.DialogHelpTypeName));

            try
            {
                bool          showHelpInBrowser = true;
                IVsHelpSystem help = GetService <IVsHelpSystem>(typeof(SVsHelpService));
                if (help != null)
                {
                    showHelpInBrowser = !VSErr.Succeeded(help.DisplayTopicFromURL(ub.Uri.AbsoluteUri, (uint)VHS_COMMAND.VHS_Default));
                }

                if (showHelpInBrowser)
                {
                    Help.ShowHelp(control.Control, ub.Uri.AbsoluteUri);
                }
            }
            catch (Exception ex)
            {
                IAnkhErrorHandler eh = GetService <IAnkhErrorHandler>();

                if (eh != null && eh.IsEnabled(ex))
                {
                    eh.OnError(ex);
                }
                else
                {
                    throw;
                }
            }
        }
Exemple #22
0
        List <IVsHierarchy> GetProjects(IAnkhServiceProvider context, __VSENUMPROJFLAGS flags)
        {
            IVsSolution      solution = context.GetService <IVsSolution>(typeof(SVsSolution));
            Guid             gNone    = Guid.Empty;
            IEnumHierarchies hierEnum;

            Marshal.ThrowExceptionForHR(solution.GetProjectEnum((uint)flags, ref gNone, out hierEnum));

            IVsHierarchy[]      hiers  = new IVsHierarchy[32];
            List <IVsHierarchy> result = new List <IVsHierarchy>();

            uint fetched;

            while (VSErr.Succeeded(hierEnum.Next((uint)hiers.Length, hiers, out fetched)))
            {
                if ((int)fetched == hiers.Length)
                {
                    result.AddRange(hiers);
                }
                else if (fetched > 0)
                {
                    for (int i = 0; i < (int)fetched; i++)
                    {
                        result.Add(hiers[i]);
                    }
                }
                else
                {
                    break;
                }
            }

            return(result);
        }
Exemple #23
0
        internal void OnHandleCreated()
        {
            if (_pane == null)
            {
                if (_panel == null)
                {
                    _panel          = new Panel();
                    _panel.Location = new Point(0, 0);
                    _panel.Size     = _form.ClientRectangle.Size;
                    _form.Controls.Add(_panel);
                }

                _pane = new VSFormContainerPane(_form.Context, this, _panel);

                IVsWindowPane p = _pane;

                IntPtr    hwnd;
                Rectangle r = new Rectangle(_form.Location, _form.Size);
                _form.Location = new Point(0, 0);

                if (!VSErr.Succeeded(p.CreatePaneWindow(_form.Handle, 0, 0, r.Width, r.Height, out hwnd)))
                {
                    _pane.Dispose();
                    _pane = null;
                    return;
                }
                _form.Size  = r.Size;
                _panel.Size = _form.ClientSize;

                IButtonControl cancelButton = _form.CancelButton;
                IButtonControl acceptButton = _form.AcceptButton;

                for (int i = 0; i < _form.Controls.Count; i++)
                {
                    Control cc = _form.Controls[i];

                    if (cc != _panel)
                    {
                        _panel.Controls.Add(cc);
                        i--;
                        if (cc == cancelButton)
                        {
                            _form.CancelButton = cancelButton;
                        }

                        if (cc == acceptButton)
                        {
                            _form.AcceptButton = acceptButton;
                        }
                    }
                }
                _form.SizeChanged += new EventHandler(VSForm_SizeChanged);
            }
            if (!_loadRegistered)
            {
                _loadRegistered = true;
                _form.Load     += new EventHandler(OnLoad);
            }
        }
Exemple #24
0
            internal void Reload(IVsMonitorSelection monitor)
            {
                ThreadHelper.ThrowIfNotOnUIThread();

                int active;

                _active = VSErr.Succeeded(monitor.IsCmdUIContextActive(_cookie, out active)) && active != 0;
            }
Exemple #25
0
            public DiffToolMonitor(IAnkhServiceProvider context, string monitor, bool monitorDir, int[] resolvedExitCodes)
                : base(context)
            {
                ThreadHelper.ThrowIfNotOnUIThread();

                if (string.IsNullOrEmpty(monitor))
                {
                    throw new ArgumentNullException("monitor");
                }
                else if (!SvnItem.IsValidPath(monitor))
                {
                    throw new ArgumentOutOfRangeException("monitor");
                }

                _monitorDir = monitorDir;
                _toMonitor  = monitor;

                IVsFileChangeEx fx = GetService <IVsFileChangeEx>(typeof(SVsFileChangeEx));

                _cookie = 0;
                if (fx == null)
                {
                }
                else if (!_monitorDir)
                {
                    if (!VSErr.Succeeded(fx.AdviseFileChange(monitor,
                                                             (uint)(_VSFILECHANGEFLAGS.VSFILECHG_Time | _VSFILECHANGEFLAGS.VSFILECHG_Size
                                                                    | _VSFILECHANGEFLAGS.VSFILECHG_Add | _VSFILECHANGEFLAGS.VSFILECHG_Del
                                                                    | _VSFILECHANGEFLAGS.VSFILECHG_Attr),
                                                             this,
                                                             out _cookie)))
                    {
                        _cookie = 0;
                    }
                }
                else
                {
                    if (!VSErr.Succeeded(fx.AdviseDirChange(monitor, 1, this, out _cookie)))
                    {
                        _cookie = 0;
                    }
                }

                IAnkhOpenDocumentTracker odt = GetService <IAnkhOpenDocumentTracker>();

                if (odt != null)
                {
                    if (odt.IgnoreChanges(_toMonitor, true))
                    {
                        _odt = odt;
                    }
                }

                if (resolvedExitCodes != null)
                {
                    _resolvedExitCodes = (int[])resolvedExitCodes.Clone();
                }
            }
Exemple #26
0
        public IDictionary <string, object> GetProjectsThatNeedEnlisting()
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            if (_translationMap.Count == 0)
            {
                return(null);
            }

            Guid        guidEmpty = Guid.Empty;
            IVsSolution solution  = GetService <IVsSolution>(typeof(SVsSolution));

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

            IEnumHierarchies ppEnum;

            if (!VSErr.Succeeded(solution.GetProjectEnum((uint)Microsoft.VisualStudio.Shell.Interop.__VSENUMPROJFLAGS.EPF_UNLOADEDINSOLUTION, ref guidEmpty, out ppEnum)))
            {
                return(null);
            }

            IVsHierarchy[] hiers = new IVsHierarchy[16];

            uint iFetched;
            Dictionary <string, object> map = new Dictionary <string, object>();

            while (VSErr.Succeeded(ppEnum.Next((uint)hiers.Length, hiers, out iFetched)))
            {
                for (uint i = 0; i < iFetched; i++)
                {
                    string name;
                    if (VSErr.Succeeded(hiers[i].GetCanonicalName(VSItemId.Root, out name)))
                    {
                        string slnName;
                        if (!_trueNameMap.TryGetValue(name, out slnName))
                        {
                            slnName = name;
                        }

                        SccSvnOrigin origin;
                        if (_originMap.TryGetValue(slnName, out origin) &&
                            !string.IsNullOrEmpty(origin.Enlist))
                        {
                            map.Add(name, hiers[i]);
                        }
                    }
                }

                if ((int)iFetched < hiers.Length)
                {
                    break;
                }
            }

            return(map);
        }
Exemple #27
0
        public RegistryKey OpenVSUserKey(string name)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            RegistryKey rootKey = null;

            if (VSVersion.VS2005)
            {
                ILocalRegistry3 lr3 = GetService <ILocalRegistry3>(typeof(SLocalRegistry));

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

                string root;

                if (!VSErr.Succeeded(lr3.GetLocalRegistryRoot(out root)))
                {
                    return(null);
                }

                rootKey = Registry.CurrentUser.OpenSubKey(root);
            }
            else
            {
                IMyLocalRegistry4 lr4 = GetService <IMyLocalRegistry4>(typeof(SLocalRegistry));

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

                uint       type;
                const uint VsLocalRegistryRootHandle_CURRENT_USER = unchecked ((uint)-2147483647);
                string     root;
                if (!VSErr.Succeeded(lr4.GetLocalRegistryRootEx(1 /* _VsLocalRegistryType.UserSettings */, out type, out root)))
                {
                    return(null);
                }

                rootKey = ((type == VsLocalRegistryRootHandle_CURRENT_USER) ? Registry.CurrentUser : Registry.LocalMachine).OpenSubKey(root);
            }

            if (rootKey == null)
            {
                return(null);
            }
            else if (string.IsNullOrEmpty(name))
            {
                return(rootKey);
            }

            using (rootKey)
            {
                return(rootKey.OpenSubKey(name));
            }
        }
Exemple #28
0
        private void EnsureContexts()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (_otherSccProviderContexts == null)
            {
                List <SccData> sccs = new List <SccData>();

                ILocalRegistry2 lr = GetService <ILocalRegistry2>(typeof(SLocalRegistry));

                string        root;
                List <string> names = new List <string>();
                if (VSErr.Succeeded(lr.GetLocalRegistryRoot(out root)))
                {
                    RegistryKey baseKey = Registry.LocalMachine;

                    // TODO: Find some way to use the VS2008 RANU api
                    if (root.EndsWith("\\UserSettings"))
                    {
                        root    = root.Substring(0, root.Length - 13) + "\\Configuration";
                        baseKey = Registry.CurrentUser;
                    }

                    using (RegistryKey rk = baseKey.OpenSubKey(root + "\\SourceControlProviders", RegistryKeyPermissionCheck.ReadSubTree))
                    {
                        if (rk != null)
                        {
                            string myId = AnkhId.SccProviderGuid.ToString("B");
                            foreach (string name in rk.GetSubKeyNames())
                            {
                                if (name.Length == 38 && !myId.Equals(name, StringComparison.OrdinalIgnoreCase))
                                {
                                    try
                                    {
                                        using (RegistryKey rks = rk.OpenSubKey(name, RegistryKeyPermissionCheck.ReadSubTree))
                                        {
                                            string service = rks.GetValue("Service") as string;

                                            if (!string.IsNullOrEmpty(service))
                                            {
                                                Guid sccGuid            = new Guid(name);
                                                CmdStateCacheItem cache = GetCache(new Guid(name));

                                                sccs.Add(new SccData(cache, service));
                                            }
                                        }
                                    }
                                    catch { }
                                }
                            }
                        }
                    }
                }

                _otherSccProviderContexts = sccs.ToArray();
            }
        }
Exemple #29
0
        public ProjectNotifier(IAnkhServiceProvider context)
            : base(context)
        {
            uint cookie;

            if (VSErr.Succeeded(Shell.AdviseBroadcastMessages(this, out cookie)))
            {
                _cookie = cookie;
            }
        }
Exemple #30
0
            public SccDocumentLock(OpenDocumentTracker tracker, HybridCollection <string> locked, HybridCollection <string> ignoring, HybridCollection <string> readOnly)
            {
                ThreadHelper.ThrowIfNotOnUIThread();

                if (tracker == null)
                {
                    throw new ArgumentNullException("tracker");
                }
                else if (locked == null)
                {
                    throw new ArgumentNullException("locked");
                }
                else if (ignoring == null)
                {
                    throw new ArgumentNullException("ignoring");
                }
                else if (readOnly == null)
                {
                    throw new ArgumentNullException("readOnly");
                }

                _tracker      = tracker;
                _locked       = locked;
                _ignoring     = ignoring;
                _readonly     = readOnly;
                _fsIgnored    = new HybridCollection <string>(StringComparer.OrdinalIgnoreCase);
                _changedPaths = new HybridCollection <string>(StringComparer.OrdinalIgnoreCase);
                _monitor      = new Dictionary <uint, string>();
                _altMonitor   = new Dictionary <string, FileInfo>();

                _change = tracker.GetService <IVsFileChangeEx>(typeof(SVsFileChangeEx));

                foreach (string file in locked)
                {
                    // This files auto reload could not be suspended by calling Ignore on the document
                    // We must therefore stop posting messages to it by stopping it in the change monitor

                    // But to be able to tell if there are changes.. We keep some stats ourselves

                    if (!ignoring.Contains(file) &&
                        VSErr.Succeeded(_change.IgnoreFile(0, file, 1)))
                    {
                        _fsIgnored.Add(file);
                        FileInfo info = new FileInfo(file);
                        info.Refresh();
                        if (info.Exists)
                        {
                            GC.KeepAlive(info.LastWriteTime);
                            GC.KeepAlive(info.CreationTime);
                            GC.KeepAlive(info.Length);
                        }
                        _altMonitor.Add(file, info);
                    }
                }
            }