private void ReadTranslateUserData(Stream store)
        {
            _translateDataLoaded = true;
            if (store.Length < 2 * sizeof(int))
            {
                return;
            }

            using (BinaryReader br = new BinaryReader(store))
            {
                int version         = br.ReadInt32(); // The enlist version used to write the data
                int requiredVersion = br.ReadInt32(); // All enlist versions older then this should ignore all data

                if ((requiredVersion > TranslateSerializerVersion) || version < MinSupportedTranslateSerializerVersion)
                {
                    return; // Older versions (we) should ignore this data
                }
                string oldSolutionDir = br.ReadString();
                string slnDir         = RawSolutionDirectory ?? oldSolutionDir;
                int    nItems         = br.ReadInt32();

                for (int iItem = 0; iItem < nItems; iItem++)
                {
                    int      nStrings = br.ReadInt32();
                    string[] strings  = new string[nStrings];

                    for (int iString = 0; iString < nStrings; iString++)
                    {
                        bool relative = br.ReadBoolean();

                        string path = br.ReadString();

                        if (relative)
                        {
                            path = Path.Combine(slnDir, path);
                        }

                        strings[iString] = path;
                    }

                    if (strings.Length >= 3)
                    {
                        SccTranslatePathInfo tpi = new SccTranslatePathInfo(strings[0], strings[1], strings[2]);

                        if (!_translationMap.ContainsKey(tpi.SolutionPath))
                        {
                            _translationMap[tpi.SolutionPath] = tpi;

                            if (tpi.SolutionPath != tpi.EnlistmentUNCPath)
                            {
                                _trueNameMap[tpi.EnlistmentUNCPath] = tpi.SolutionPath;
                            }
                        }
                    }
                }
            }
        }
        private bool TryGetTranslation(string path, out SccTranslatePathInfo info)
        {
            EnsureEnlistUserSettings();

            if (string.IsNullOrEmpty(path))
            {
                info = null;
                return(false);
            }

            if (_translationMap.TryGetValue(path, out info))
            {
                return(true);
            }

            if (_translationMap.TryGetValue(path + "\\", out info))
            {
                return(true);
            }

            return(false);
        }
        internal void EnlistAndCheckout(IVsHierarchy vsHierarchy, string pszProjectMk)
        {
            string slnProjectMk;

            if (!_trueNameMap.TryGetValue(pszProjectMk, out slnProjectMk))
            {
                slnProjectMk = pszProjectMk;
            }

            SccSvnOrigin origin;

            if (!_originMap.TryGetValue(slnProjectMk, out origin))
            {
                return;
            }

            if (string.IsNullOrEmpty(origin.SvnUri))
            {
                return;
            }

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

            if (sol == null)
            {
                return;
            }

            IVsProjectFactory factory;

            if (!VSErr.Succeeded(sol.GetProjectFactory(0, null, pszProjectMk, out factory)))
            {
                return;
            }

            IVsSccProjectEnlistmentFactory enlistFactory = factory as IVsSccProjectEnlistmentFactory;

            if (enlistFactory == null)
            {
                return;
            }

            string enlistPath, enlistPathUNC;

            if (!VSErr.Succeeded(enlistFactory.GetDefaultEnlistment(pszProjectMk, out enlistPath, out enlistPathUNC)))
            {
                return;
            }

            uint flags;
            int  hr;

            // Website projects return E_NOTIMPL on these methods
            if (!VSErr.Succeeded(hr = enlistFactory.GetEnlistmentFactoryOptions(out flags)))
            {
                if (hr != VSErr.E_NOTIMPL)
                {
                    return;
                }
                flags = 0;
            }
            if (!VSErr.Succeeded(hr = enlistFactory.OnBeforeEnlistmentCreate(pszProjectMk, enlistPath, enlistPathUNC)))
            {
                return;
            }

            Uri projectUri;

            if (!Uri.TryCreate(origin.SvnUri, UriKind.Absolute, out projectUri))
            {
                Uri relativeUri;

                if (!Uri.TryCreate(origin.SvnUri, UriKind.Relative, out relativeUri))
                {
                    return;
                }

                // We have a Uri relative from the solution file
                if (StatusCache == null)
                {
                    return;
                }

                SvnItem slnDirItem = StatusCache[SolutionDirectory];

                if (!slnDirItem.IsVersioned || slnDirItem.Uri == null)
                {
                    return;
                }

                projectUri = new Uri(slnDirItem.Uri, relativeUri);
            }

            GetService <IProgressRunner>().RunModal(Resources.CheckingOutProject,
                                                    delegate(object sender, ProgressWorkerArgs e)
            {
                e.Client.CheckOut(projectUri, SvnTools.GetNormalizedFullPath(enlistPathUNC));
            });

            if (!VSErr.Succeeded(hr = enlistFactory.OnAfterEnlistmentCreate(pszProjectMk, enlistPath, enlistPathUNC)))
            {
                return;
            }

            SccTranslatePathInfo tpi = new SccTranslatePathInfo(slnProjectMk, enlistPath, enlistPathUNC);

            _translationMap[tpi.SolutionPath] = tpi;

            if (tpi.SolutionPath != tpi.EnlistmentUNCPath)
            {
                _trueNameMap[tpi.EnlistmentUNCPath] = tpi.SolutionPath;
            }
        }
        void EnsureEnlistment(string slnProjectName, string pszProjectMk, SccSvnOrigin origin)
        {
            SccTranslatePathInfo tpi;

            if (TryGetTranslation(slnProjectName, out tpi))
            {
                return; // We have existing local data
            }
            IVsSolution sol = GetService <IVsSolution>(typeof(SVsSolution));

            if (sol == null)
            {
                return;
            }

            IVsProjectFactory factory;

            if (!VSErr.Succeeded(sol.GetProjectFactory(0, null, pszProjectMk, out factory)))
            {
                return;
            }

            IVsSccProjectEnlistmentFactory enlistFactory = factory as IVsSccProjectEnlistmentFactory;

            if (enlistFactory == null)
            {
                return;
            }

            string enlistPath, enlistPathUNC;

            if (!VSErr.Succeeded(enlistFactory.GetDefaultEnlistment(pszProjectMk, out enlistPath, out enlistPathUNC)))
            {
                return;
            }

            // ### We should now proceed with the editing operations as documented
            // ### in IVsSccEnlistmentPathTranslation.idl

            // ### But since we don't have per user settings yet we currently just
            // ### pass the defaults as that happens to be the same behavior as
            // ### before

            if (IsSafeSccPath(pszProjectMk) &&
                !string.IsNullOrEmpty(SolutionSettings.ProjectRoot)
                /*&& (SvnItem.IsBelowRoot(pszProjectMk, SolutionSettings.ProjectRoot) || string.IsNullOrEmpty(origin.SvnUri))*/
                && StatusCache != null && StatusCache[pszProjectMk].Exists)
            {
                int    pfValidEnlistment;
                string chosenUNC;

                // We have a website that has a default location below our project root or without a Svn Uri
                // At least for now we should default to enlist at that location to make
                // sure we don't break backwards compatibility
                string suffix = ".sccEnlistAttemptLocation";

                if (VSErr.Succeeded(enlistFactory.ValidateEnlistmentEdit(0, slnProjectName, pszProjectMk + suffix, out chosenUNC, out pfValidEnlistment)) &&
                    pfValidEnlistment != 0 &&
                    chosenUNC.EndsWith(suffix))
                {
                    enlistPath    = pszProjectMk;
                    enlistPathUNC = chosenUNC.Substring(0, chosenUNC.Length - suffix.Length);
                }
            }

            string slnProjectMk;

            // Maybe we already translated the path?
            if (!_trueNameMap.TryGetValue(pszProjectMk, out slnProjectMk))
            {
                slnProjectMk = pszProjectMk;
            }

            tpi = new SccTranslatePathInfo(slnProjectMk, enlistPath, CalculateTruePath(enlistPathUNC));

            _translationMap[slnProjectMk] = tpi;

            if (enlistPathUNC != slnProjectMk)
            {
                _trueNameMap[enlistPathUNC] = slnProjectMk;
            }
        }