public static IList <tagVsSccFilesFlags> CreateSccFlagsCADWORD(CADWORD cadWord) { IList <tagVsSccFilesFlags> flags = new List <tagVsSccFilesFlags>(); if (cadWord.cElems == 0) { return(flags); } // Demand unmanaged permissions in order to access unmanaged memory. new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand(); IntPtr tempPtr = cadWord.pElems; int size = Marshal.SizeOf(typeof(IntPtr)); for (int i = 0; i < cadWord.cElems; i++) { tagVsSccFilesFlags member = (tagVsSccFilesFlags)Marshal.ReadInt32(tempPtr); flags.Add(member); tempPtr = new IntPtr(tempPtr.ToInt64() + size); } // Free the array of and set size to 0 Marshal.FreeCoTaskMem(cadWord.pElems); cadWord.cElems = 0; return(flags); }
public static CADWORD CreateCADWORD(IList <tagVsSccFilesFlags> flags) { CADWORD cadWord = new CADWORD(); if (flags != null) { // Demand unmanaged permissions in order to access unmanaged memory. new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand(); cadWord.cElems = (uint)flags.Count; int size = Marshal.SizeOf(typeof(UInt32)); cadWord.pElems = Marshal.AllocCoTaskMem(flags.Count * size); IntPtr ptr = cadWord.pElems; foreach (tagVsSccFilesFlags flag in flags) { Marshal.WriteInt32(ptr, (int)flag); ptr = new IntPtr(ptr.ToInt64() + size); } } return(cadWord); }
private static string[] GetSpecialFiles(IVsSccProject2 project, uint itemId, string fileName) { var specialFiles = new CALPOLESTR[1]; var specialFlags = new CADWORD[1]; if (ErrorHandler.Succeeded(project.GetSccSpecialFiles(itemId, fileName, specialFiles, specialFlags))) { return(GetFileNames(specialFiles[0])); } return(new string[0]); }
/// <summary> /// Returns a list of source controllable files associated with the specified node /// </summary> private static IList <string> GetNodeFiles(IVsSccProject2 pscp2, uint itemid) { // NOTE: the function returns only a list of files, containing both regular files and special files // If you want to hide the special files (similar with solution explorer), you may need to return // the special files in a hastable (key=master_file, values=special_file_list) // Initialize output parameters IList <string> sccFiles = new List <string>(); if (pscp2 != null) { CALPOLESTR[] pathStr = new CALPOLESTR[1]; CADWORD[] flags = new CADWORD[1]; if (pscp2.GetSccFiles(itemid, pathStr, flags) == 0) { //#4 BugFix : Visual Studio Crashing when clicking on Web Reference // The previus MS sample code used 'Marshal.PtrToStringAuto' which caused // a chrash of the studio (2010 only) in some conditions. This also could // be the reason for some further bugs e.g. in commit, update tasks. string[] files = GetFileNamesFromOleBuffer(pathStr, true); for (int elemIndex = 0; elemIndex < pathStr[0].cElems; elemIndex++) { String path = files[elemIndex]; sccFiles.Add(path); // See if there are special files if (flags.Length > 0 && flags[0].cElems > 0) { int flag = Marshal.ReadInt32(flags[0].pElems, elemIndex); if (flag != 0) { // We have special files CALPOLESTR[] specialFiles = new CALPOLESTR[1]; CADWORD[] specialFlags = new CADWORD[1]; pscp2.GetSccSpecialFiles(itemid, path, specialFiles, specialFlags); string[] specialFileNames = GetFileNamesFromOleBuffer(specialFiles, true); foreach (var f in specialFileNames) { sccFiles.Add(f); } } } } } } return(sccFiles); }
public int GetSccFiles(uint itemid, CALPOLESTR[] pCaStringsOut, CADWORD[] pCaFlagsOut) { if ((null == pCaStringsOut) || (0 == pCaStringsOut.Length)) { throw new ArgumentNullException(); } if ((null == pCaFlagsOut) || (0 == pCaFlagsOut.Length)) { throw new ArgumentNullException(); } pCaStringsOut[0] = new CALPOLESTR(); pCaStringsOut[0].cElems = 0; pCaStringsOut[0].pElems = IntPtr.Zero; pCaFlagsOut[0] = new CADWORD(); pCaFlagsOut[0].cElems = 0; pCaFlagsOut[0].pElems = IntPtr.Zero; string fileForNode = null; if (itemid == VSConstants.VSITEMID_ROOT) { fileForNode = _projFile; } else if (itemid >= 0 && itemid < _items.Count) { fileForNode = _items[(int)itemid]; } if (fileForNode != null) { // There is only one scc controllable file per each hierarchy node pCaStringsOut[0].cElems = 1; pCaStringsOut[0].pElems = Marshal.AllocCoTaskMem(IntPtr.Size); Marshal.WriteIntPtr(pCaStringsOut[0].pElems, Marshal.StringToCoTaskMemUni(fileForNode)); pCaFlagsOut[0].cElems = 1; pCaFlagsOut[0].pElems = Marshal.AllocCoTaskMem(sizeof(Int32)); Marshal.WriteInt32(pCaFlagsOut[0].pElems, 0); } return(VSConstants.S_OK); }
//[CLSCompliant(false)] static bool GetSccFiles(IVsHierarchy hierarchy, IVsSccProject2 sccProject, uint id, out string[] files, bool includeSpecial, bool includeNoScc, IDictionary <string, uint> map) { ThreadHelper.ThrowIfNotOnUIThread(); int[] flags; files = null; if (!GetSccFiles(hierarchy, sccProject, id, out files, out flags, includeNoScc, map)) { return(false); } else if (flags == null || sccProject == null || !includeSpecial) { return(true); } int n = Math.Min(files.Length, flags.Length); List <string> allFiles = new List <string>(files); for (int i = 0; i < n; i++) { if (0 != (flags[i] & (int)tagVsSccFilesFlags.SFF_HasSpecialFiles)) { CALPOLESTR[] str = new CALPOLESTR[1]; CADWORD[] dw = new CADWORD[1]; if (VSErr.Succeeded(sccProject.GetSccSpecialFiles(id, allFiles[i], str, dw))) { files = GetFileNamesFromOleBuffer(str, true); GetFlagsFromOleBuffer(dw, true); // Free the flags (No need to parse at this time) if (files != null && files.Length > 0) { allFiles.AddRange(files); } } } } files = allFiles.ToArray(); return(true); }
public static CADWORD CreateCADWORD(IList <tagVsSccFilesFlags> flags) { CADWORD cadWord = new CADWORD(); if (flags != null) { cadWord.cElems = (uint)flags.Count; int size = Marshal.SizeOf(typeof(UInt32)); cadWord.pElems = Marshal.AllocCoTaskMem(flags.Count * size); IntPtr ptr = cadWord.pElems; foreach (tagVsSccFilesFlags flag in flags) { Marshal.WriteInt32(ptr, (int)flag); ptr = new IntPtr(ptr.ToInt64() + size); } } return(cadWord); }
public static IList <tagVsSccFilesFlags> CreateSccFlagsCADWORD(CADWORD cadWord) { IList <tagVsSccFilesFlags> flags = new List <tagVsSccFilesFlags>(); if (cadWord.cElems == 0) { return(flags); } IntPtr tempPtr = cadWord.pElems; int size = Marshal.SizeOf(typeof(IntPtr)); for (int i = 0; i < cadWord.cElems; i++) { tagVsSccFilesFlags member = (tagVsSccFilesFlags)Marshal.ReadInt32(tempPtr); flags.Add(member); tempPtr = new IntPtr(tempPtr.ToInt64() + size); } // Free the array of and set size to 0 Marshal.FreeCoTaskMem(cadWord.pElems); cadWord.cElems = 0; return(flags); }
public static string[] GetItemFiles(IVsSccProject2 project, uint itemId) { var itemFiles = new List <string>(); var files = new CALPOLESTR[1]; var flags = new CADWORD[1]; if (ErrorHandler.Succeeded(project.GetSccFiles(itemId, files, flags))) { var fileNames = GetFileNames(files[0]); for (int i = 0; i < files[0].cElems; i++) { itemFiles.Add(fileNames[i]); if (HasSpecialFiles(flags, i)) { itemFiles.AddRange(GetSpecialFiles(project, itemId, fileNames[i])); } } } return(itemFiles.ToArray()); }
/// <summary> /// Returns a list of source controllable files associated with the specified node /// </summary> public IList <string> GetNodeFiles(IVsSccProject2 pscp2, uint itemid) { // NOTE: the function returns only a list of files, containing both regular files and special files // If you want to hide the special files (similar with solution explorer), you may need to return // the special files in a hashtable (key=master_file, values=special_file_list) // Initialize output parameters IList <string> sccFiles = new List <string>(); if (pscp2 != null) { CALPOLESTR[] pathStr = new CALPOLESTR[1]; CADWORD[] flags = new CADWORD[1]; if (pscp2.GetSccFiles(itemid, pathStr, flags) == VSConstants.S_OK) { if (pathStr[0].cElems > 0) { for (int elemIndex = 0; elemIndex < pathStr[0].cElems; elemIndex++) { IntPtr pathIntPtr = Marshal.ReadIntPtr(pathStr[0].pElems, elemIndex * IntPtr.Size); String path = Marshal.PtrToStringAuto(pathIntPtr); sccFiles.Add(path); // See if there are special files if (flags.Length > 0 && flags[0].cElems > 0) { int flag = Marshal.ReadInt32(flags[0].pElems, elemIndex * IntPtr.Size); if (flag != 0) { // We have special files CALPOLESTR[] specialFiles = new CALPOLESTR[1]; CADWORD[] specialFlags = new CADWORD[1]; if (pscp2.GetSccSpecialFiles(itemid, path, specialFiles, specialFlags) == VSConstants.S_OK) { for (int i = 0; i < specialFiles[0].cElems; i++) { IntPtr specialPathIntPtr = Marshal.ReadIntPtr(specialFiles[0].pElems, i * IntPtr.Size); String specialPath = Marshal.PtrToStringAuto(specialPathIntPtr); sccFiles.Add(specialPath); Marshal.FreeCoTaskMem(specialPathIntPtr); } if (specialFiles[0].cElems > 0) { Marshal.FreeCoTaskMem(specialFiles[0].pElems); } } } } Marshal.FreeCoTaskMem(pathIntPtr); } } else { // This is a special file, so the GetSccFiles will not return it's path, // so get it directly from the project string path = string.Empty; IVsProject pscp = pscp2 as IVsProject; if (pscp != null) { pscp.GetMkDocument(itemid, out path); } // can't be null, blank or end with back slash (that's a directory) if ((string.IsNullOrEmpty(path) == false) && (path.EndsWith("\\") == false) && (SccService.ScmProvider.IsFileCached(path))) { //got a valid path sccFiles.Add(path); } } } } return(sccFiles); }
/// <summary> /// Returns a list of source controllable files associated with the specified node /// </summary> private IList <string> GetNodeFiles(IVsSccProject2 pscp2, uint itemid) { // NOTE: the function returns only a list of files, containing both regular files and special files // If you want to hide the special files (similar with solution explorer), you may need to return // the special files in a hastable (key=master_file, values=special_file_list) // Initialize output parameters IList <string> sccFiles = new List <string>(); if (pscp2 != null) { CALPOLESTR[] pathStr = new CALPOLESTR[1]; CADWORD[] flags = new CADWORD[1]; if (pscp2.GetSccFiles(itemid, pathStr, flags) == 0) { for (int elemIndex = 0; elemIndex < pathStr[0].cElems; elemIndex++) { IntPtr pathIntPtr = Marshal.ReadIntPtr(pathStr[0].pElems, elemIndex); String path = Marshal.PtrToStringAuto(pathIntPtr); sccFiles.Add(path); // See if there are special files if (flags.Length > 0 && flags[0].cElems > 0) { int flag = Marshal.ReadInt32(flags[0].pElems, elemIndex); if (flag != 0) { // We have special files CALPOLESTR[] specialFiles = new CALPOLESTR[1]; CADWORD[] specialFlags = new CADWORD[1]; pscp2.GetSccSpecialFiles(itemid, path, specialFiles, specialFlags); for (int i = 0; i < specialFiles[0].cElems; i++) { IntPtr specialPathIntPtr = Marshal.ReadIntPtr(specialFiles[0].pElems, i * IntPtr.Size); String specialPath = Marshal.PtrToStringAuto(specialPathIntPtr); sccFiles.Add(specialPath); Marshal.FreeCoTaskMem(specialPathIntPtr); } if (specialFiles[0].cElems > 0) { Marshal.FreeCoTaskMem(specialFiles[0].pElems); } } } Marshal.FreeCoTaskMem(pathIntPtr); } if (pathStr[0].cElems > 0) { Marshal.FreeCoTaskMem(pathStr[0].pElems); } } } else if (itemid == VSConstants.VSITEMID_ROOT) { sccFiles.Add(GetSolutionFileName()); } return(sccFiles); }
/// <summary> /// Returns a list of source controllable files associated with the specified node /// </summary> private IList<string> GetNodeFiles(IVsSccProject2 pscp2, uint itemid) { // NOTE: the function returns only a list of files, containing both regular files and special files // If you want to hide the special files (similar with solution explorer), you may need to return // the special files in a hastable (key=master_file, values=special_file_list) // Initialize output parameters IList<string> sccFiles = new List<string>(); if (pscp2 != null) { var pathStr = new CALPOLESTR[1]; var flags = new CADWORD[1]; if (pscp2.GetSccFiles(itemid, pathStr, flags) == 0) { for (int elemIndex = 0; elemIndex < pathStr[0].cElems; elemIndex++) { var pathIntPtr = Marshal.ReadIntPtr(pathStr[0].pElems, elemIndex); var path = Marshal.PtrToStringAuto(pathIntPtr); sccFiles.Add(path); // See if there are special files if (flags.Length > 0 && flags[0].cElems > 0) { int flag = Marshal.ReadInt32(flags[0].pElems, elemIndex); if (flag != 0) { // We have special files var specialFiles = new CALPOLESTR[1]; var specialFlags = new CADWORD[1]; pscp2.GetSccSpecialFiles(itemid, path, specialFiles, specialFlags); for (int i = 0; i < specialFiles[0].cElems; i++) { IntPtr specialPathIntPtr = Marshal.ReadIntPtr(specialFiles[0].pElems, i * IntPtr.Size); String specialPath = Marshal.PtrToStringAuto(specialPathIntPtr); sccFiles.Add(specialPath); Marshal.FreeCoTaskMem(specialPathIntPtr); } if (specialFiles[0].cElems > 0) { Marshal.FreeCoTaskMem(specialFiles[0].pElems); } } } Marshal.FreeCoTaskMem(pathIntPtr); } if (pathStr[0].cElems > 0) { Marshal.FreeCoTaskMem(pathStr[0].pElems); } } } return sccFiles; }
public int RegisterSccProject(IVsSccProject2 pscp2Project, string pszSccProjectName, string pszSccAuxPath, string pszSccLocalPath, string pszProvider) { if (ExpectedProjectName != null) { AreEqual(ExpectedProjectName, pszSccProjectName); } if (ExpectedAuxPath != null) { AreEqual(ExpectedAuxPath, pszSccAuxPath); } if (ExpectedLocalPath != null) { AreEqual(ExpectedLocalPath, pszSccLocalPath); } if (ExpectedProvider != null) { AreEqual(ExpectedProvider, pszProvider); } var project = _loadedProjects[pscp2Project] = new ProjectInfo(pscp2Project, pszSccProjectName); CALPOLESTR[] str = new CALPOLESTR[1]; CADWORD[] cadword = new CADWORD[1]; // try it once w/ VSITEMID_ROOT, make sure we get back just the project. if (ErrorHandler.Failed(pscp2Project.GetSccFiles(VSConstants.VSITEMID_ROOT, str, cadword))) { Fail("Failed to get SccFiles"); } AreEqual(UnpackCALPOLESTR(str[0]).Length, 1); object propRes; if (ErrorHandler.Failed(((IVsHierarchy)pscp2Project).GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_FirstChild, out propRes))) { Fail("Failed to get first child of root node"); } int curSibling = (int)propRes; while (ErrorHandler.Succeeded(((IVsHierarchy)pscp2Project).GetProperty((uint)curSibling, (int)__VSHPROPID.VSHPROPID_NextSibling, out propRes))) { curSibling = (int)propRes; if (curSibling == unchecked ((int)VSConstants.VSITEMID_NIL)) { break; } if (ErrorHandler.Failed(pscp2Project.GetSccFiles((uint)curSibling, str, cadword))) { Fail("Failed to get SccFiles"); } string[] files = UnpackCALPOLESTR(str[0]); foreach (var file in files) { uint pItemId; if (ErrorHandler.Succeeded(((IVsHierarchy)pscp2Project).ParseCanonicalName(file, out pItemId))) { project.Files.Add(file, new FileInfo(project, file, pItemId)); } } } // couple extra test cases to make sure we handle weird inputs... pscp2Project.GetSccFiles(VSConstants.VSITEMID_ROOT, null, null); pscp2Project.GetSccFiles(VSConstants.VSITEMID_ROOT, new CALPOLESTR[0], new CADWORD[0]); AreEqual(VSConstants.E_INVALIDARG, pscp2Project.GetSccFiles(VSConstants.VSITEMID_SELECTION, null, null)); AreEqual(VSConstants.E_INVALIDARG, pscp2Project.GetSccFiles(0xffffffff, null, null)); pscp2Project.GetSccSpecialFiles(VSConstants.VSITEMID_ROOT, "", str, cadword); pscp2Project.GetSccSpecialFiles(VSConstants.VSITEMID_ROOT, "", null, null); AreEqual(VSConstants.E_INVALIDARG, pscp2Project.GetSccSpecialFiles(VSConstants.VSITEMID_SELECTION, "", null, null)); AreEqual(VSConstants.E_INVALIDARG, pscp2Project.GetSccSpecialFiles(0xffffffff, "", null, null)); return(VSConstants.S_OK); }
//[CLSCompliant(false)] public static bool GetSccFiles(IVsHierarchy hierarchy, IVsSccProject2 sccProject, uint id, out string[] files, out int[] flags, bool includeNoScc, IDictionary<string, uint> map) { if (hierarchy == null) throw new ArgumentNullException("hierarchy"); int hr; bool ok = false; files = null; flags = null; try { if (sccProject != null) { CALPOLESTR[] str = new CALPOLESTR[1]; CADWORD[] dw = new CADWORD[1]; if (ErrorHandler.Succeeded(hr = sccProject.GetSccFiles(id, str, dw))) { files = GetFileNamesFromOleBuffer(str, true); flags = GetFlagsFromOleBuffer(dw, true); if (!includeNoScc || files.Length > 0) return ok = true; // We have a result else ok = true; // Try the GetMkDocument route to find an alternative } else if (hr != VSConstants.E_NOTIMPL) return false; // } // If sccProject2.GetSccFiles() returns E_NOTIMPL we must try GetMkDocument // We also try this if the item does not implement IVsSccProject2 IVsProject project = hierarchy as IVsProject; if (project != null) { string mkDocument; if (ErrorHandler.Succeeded(project.GetMkDocument(id, out mkDocument))) { if (!IsValidPath(mkDocument)) files = new string[0]; else files = new string[] { mkDocument }; return true; } return ok; // No need to check our interface for projects } if (hierarchy is IVsSolution) { return ok; // Will fail in GetCanonicalName in VS2008 SP1 Beta 1 } string name; try { if (ErrorHandler.Succeeded(hierarchy.GetCanonicalName(id, out name))) { if (IsValidPath(name, true)) { files = new string[] { name }; return true; } } } catch { } // Ok, this seems to error in some managed tree implementations like TFS :( return ok; } finally { if (ok && map != null && files != null) { foreach (string file in files) map[file] = id; } } }
//[CLSCompliant(false)] public static bool GetSccFiles(IVsHierarchy hierarchy, IVsSccProject2 sccProject, uint id, out string[] files, out int[] flags, bool includeNoScc, IDictionary <string, uint> map) { ThreadHelper.ThrowIfNotOnUIThread(); if (hierarchy == null) { throw new ArgumentNullException("hierarchy"); } int hr; bool ok = false; files = null; flags = null; try { if (sccProject != null) { CALPOLESTR[] str = new CALPOLESTR[1]; CADWORD[] dw = new CADWORD[1]; if (VSErr.Succeeded(hr = sccProject.GetSccFiles(id, str, dw))) { files = GetFileNamesFromOleBuffer(str, true); flags = GetFlagsFromOleBuffer(dw, true); if (!includeNoScc || files.Length > 0) { return(ok = true); // We have a result } else { ok = true; // Try the GetMkDocument route to find an alternative } } else if (hr != VSErr.E_NOTIMPL) { return(false); // } } // If sccProject2.GetSccFiles() returns E_NOTIMPL we must try GetMkDocument // We also try this if the item does not implement IVsSccProject2 IVsProject project = hierarchy as IVsProject; if (project != null) { string mkDocument; try { if (VSErr.Succeeded(project.GetMkDocument(id, out mkDocument))) { if (!IsValidPath(mkDocument, true)) { files = new string[0]; } else { files = new string[] { mkDocument } }; return(true); } } catch { } return(ok); // No need to check our interface for projects } if (hierarchy is IVsSolution) { return(ok); // Will fail in GetCanonicalName in VS2008 SP1 Beta 1 } string name; try { if (VSErr.Succeeded(hierarchy.GetCanonicalName(id, out name))) { if (IsValidPath(name, true)) { files = new string[] { name }; return(true); } } } catch { } // Ok, this seems to error in some managed tree implementations like TFS :( return(ok); } finally { if (ok && map != null && files != null) { foreach (string file in files) { map[file] = id; } } } }
public int RegisterSccProject(IVsSccProject2 pscp2Project, string pszSccProjectName, string pszSccAuxPath, string pszSccLocalPath, string pszProvider) { if (ExpectedProjectName != null) { AreEqual(ExpectedProjectName, pszSccProjectName); } if (ExpectedAuxPath != null) { AreEqual(ExpectedAuxPath, pszSccAuxPath); } if (ExpectedLocalPath != null) { AreEqual(ExpectedLocalPath, pszSccLocalPath); } if (ExpectedProvider != null) { AreEqual(ExpectedProvider, pszProvider); } var project = _loadedProjects[pscp2Project] = new ProjectInfo(pscp2Project, pszSccProjectName); CALPOLESTR[] str = new CALPOLESTR[1]; CADWORD[] cadword = new CADWORD[1]; // try it once w/ VSITEMID_ROOT, make sure we get back just the project. if (ErrorHandler.Failed(pscp2Project.GetSccFiles(VSConstants.VSITEMID_ROOT, str, cadword))) { Fail("Failed to get SccFiles"); } AreEqual(UnpackCALPOLESTR(str[0]).Length, 1); object propRes; if(ErrorHandler.Failed(((IVsHierarchy)pscp2Project).GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_FirstChild, out propRes))) { Fail("Failed to get first child of root node"); } int curSibling = (int)propRes; while(ErrorHandler.Succeeded(((IVsHierarchy)pscp2Project).GetProperty((uint)curSibling, (int)__VSHPROPID.VSHPROPID_NextSibling, out propRes))) { curSibling = (int)propRes; if(curSibling == unchecked((int)VSConstants.VSITEMID_NIL)) { break; } if (ErrorHandler.Failed(pscp2Project.GetSccFiles((uint)curSibling, str, cadword))) { Fail("Failed to get SccFiles"); } string[] files = UnpackCALPOLESTR(str[0]); foreach (var file in files) { uint pItemId; if (ErrorHandler.Succeeded(((IVsHierarchy)pscp2Project).ParseCanonicalName(file, out pItemId))) { project.Files.Add(file, new FileInfo(project, file, pItemId)); } } } // couple extra test cases to make sure we handle weird inputs... pscp2Project.GetSccFiles(VSConstants.VSITEMID_ROOT, null, null); pscp2Project.GetSccFiles(VSConstants.VSITEMID_ROOT, new CALPOLESTR[0], new CADWORD[0]); AreEqual(VSConstants.E_INVALIDARG, pscp2Project.GetSccFiles(VSConstants.VSITEMID_SELECTION, null, null)); AreEqual(VSConstants.E_INVALIDARG, pscp2Project.GetSccFiles(0xffffffff, null, null)); pscp2Project.GetSccSpecialFiles(VSConstants.VSITEMID_ROOT, "", str, cadword); pscp2Project.GetSccSpecialFiles(VSConstants.VSITEMID_ROOT, "", null, null); AreEqual(VSConstants.E_INVALIDARG, pscp2Project.GetSccSpecialFiles(VSConstants.VSITEMID_SELECTION, "", null, null)); AreEqual(VSConstants.E_INVALIDARG, pscp2Project.GetSccSpecialFiles(0xffffffff, "", null, null)); return VSConstants.S_OK; }
public int GetSccFiles(uint itemid, CALPOLESTR[] pCaStringsOut, CADWORD[] pCaFlagsOut) { HierarchyNode node = this.NodeFromItemId(itemid); if (node is Project || node is HierarchyItemNode){ string url = node.FullPath; pCaStringsOut[0].cElems = 1; IntPtr pElems = Marshal.AllocCoTaskMem(IntPtr.Size); IntPtr pElem = Marshal.StringToCoTaskMemAuto(url); Marshal.WriteIntPtr(pElems, pElem); pCaStringsOut[0].pElems = pElems; pCaFlagsOut[0].cElems = 0; return (int)HResult.S_OK; } return (int)HResult.E_NOTIMPL; }
private static string[] GetSpecialFiles(IVsSccProject2 project, uint itemId, string fileName) { var specialFiles = new CALPOLESTR[1]; var specialFlags = new CADWORD[1]; if (ErrorHandler.Succeeded(project.GetSccSpecialFiles(itemId, fileName, specialFiles, specialFlags))) { return GetFileNames(specialFiles[0]); } return new string[0]; }
//[CLSCompliant(false)] internal static int[] GetFlagsFromOleBuffer(CADWORD[] dwords, bool free) { if (dwords == null) throw new ArgumentNullException("dwords"); int n = (int)dwords[0].cElems; int[] items = (n > 0) ? new int[n] : null; bool foundFlag = false; for (int i = 0; i < n; i++) { int v = items[i] = Marshal.ReadInt32(dwords[0].pElems, i * sizeof(int)); if (v != 0) foundFlag = true; } if (free && dwords[0].pElems != IntPtr.Zero) Marshal.FreeCoTaskMem(dwords[0].pElems); return foundFlag ? items : null; }
//[CLSCompliant(false)] static bool GetSccFiles(IVsHierarchy hierarchy, IVsSccProject2 sccProject, uint id, out string[] files, bool includeSpecial, bool includeNoScc, IDictionary<string, uint> map) { int[] flags; files = null; if (!GetSccFiles(hierarchy, sccProject, id, out files, out flags, includeNoScc, map)) return false; else if (flags == null || sccProject == null || !includeSpecial) return true; int n = Math.Min(files.Length, flags.Length); List<string> allFiles = new List<string>(files); for (int i = 0; i < n; i++) { if (0 != (flags[i] & (int)tagVsSccFilesFlags.SFF_HasSpecialFiles)) { CALPOLESTR[] str = new CALPOLESTR[1]; CADWORD[] dw = new CADWORD[1]; if (ErrorHandler.Succeeded(sccProject.GetSccSpecialFiles(id, allFiles[i], str, dw))) { files = GetFileNamesFromOleBuffer(str, true); GetFlagsFromOleBuffer(dw, true); // Free the flags (No need to parse at this time) if (files != null && files.Length > 0) allFiles.AddRange(files); } } } files = allFiles.ToArray(); return true; }
public int RegisterSccProject(IVsSccProject2 pscp2Project, string pszSccProjectName, string pszSccAuxPath, string pszSccLocalPath, string pszProvider) { if (ExpectedProjectName != null) { AreEqual(ExpectedProjectName, pszSccProjectName); } if (ExpectedAuxPath != null) { AreEqual(ExpectedAuxPath, pszSccAuxPath); } if (ExpectedLocalPath != null) { AreEqual(ExpectedLocalPath, pszSccLocalPath); } if (ExpectedProvider != null) { AreEqual(ExpectedProvider, pszProvider); } var project = _loadedProjects[pscp2Project] = new ProjectInfo(pscp2Project, pszSccProjectName); CALPOLESTR[] str = new CALPOLESTR[1]; CADWORD[] cadword = new CADWORD[1]; // try it once w/ the correct item ID var projectId = GetItemId((IVsHierarchy)pscp2Project); if (ErrorHandler.Failed(pscp2Project.GetSccFiles(projectId, str, cadword))) { Fail("Failed to get SccFiles"); } string[] files = UnpackCALPOLESTR(str[0]); foreach (var file in files) { uint pItemId; if (ErrorHandler.Succeeded(((IVsHierarchy)pscp2Project).ParseCanonicalName(file, out pItemId))) { project.Files.Add(file, new FileInfo(project, file, pItemId)); } } // try it once w/ VSITEMID_ROOT, make sure we get the same count back... if (ErrorHandler.Failed(pscp2Project.GetSccFiles(VSConstants.VSITEMID_ROOT, str, cadword))) { Fail("Failed to get SccFiles"); } AreEqual(UnpackCALPOLESTR(str[0]).Length, files.Length); // couple extra test cases to make sure we handle weird inputs... pscp2Project.GetSccFiles(projectId, null, null); pscp2Project.GetSccFiles(projectId, new CALPOLESTR[0], new CADWORD[0]); AreEqual(VSConstants.E_INVALIDARG, pscp2Project.GetSccFiles(VSConstants.VSITEMID_SELECTION, null, null)); AreEqual(VSConstants.E_INVALIDARG, pscp2Project.GetSccFiles(0xffffffff, null, null)); pscp2Project.GetSccSpecialFiles(projectId, "", str, cadword); pscp2Project.GetSccSpecialFiles(projectId, "", null, null); AreEqual(VSConstants.E_INVALIDARG, pscp2Project.GetSccSpecialFiles(VSConstants.VSITEMID_SELECTION, "", null, null)); AreEqual(VSConstants.E_INVALIDARG, pscp2Project.GetSccSpecialFiles(0xffffffff, "", null, null)); return(VSConstants.S_OK); }
public static CADWORD CreateCADWORD(IList<tagVsSccFilesFlags> flags) { CADWORD cadWord = new CADWORD(); if (flags != null) { // Demand unmanaged permissions in order to access unmanaged memory. new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand(); cadWord.cElems = (uint)flags.Count; int size = Marshal.SizeOf(typeof(UInt32)); cadWord.pElems = Marshal.AllocCoTaskMem(flags.Count * size); IntPtr ptr = cadWord.pElems; foreach (tagVsSccFilesFlags flag in flags) { Marshal.WriteInt32(ptr, (int)flag); ptr = new IntPtr(ptr.ToInt64() + size); } } return cadWord; }
public static string[] GetItemFiles(IVsSccProject2 project, uint itemId) { var itemFiles = new List<string>(); var files = new CALPOLESTR[1]; var flags = new CADWORD[1]; if (ErrorHandler.Succeeded(project.GetSccFiles(itemId, files, flags))) { var fileNames = GetFileNames(files[0]); for (int i = 0; i < files[0].cElems; i++) { itemFiles.Add(fileNames[i]); if (HasSpecialFiles(flags, i)) { itemFiles.AddRange(GetSpecialFiles(project, itemId, fileNames[i])); } } } return itemFiles.ToArray(); }
/// <summary> /// This method is called to discover special (hidden files) associated with a given VSITEMID within this hierarchy. /// </summary> /// <param name="itemid">Identifier for the VSITEMID being queried.</param> /// <param name="sccFile">One of the files associated with the node</param> /// <param name="stringsOut">Pointer to an array of CALPOLESTR strings containing the file names for this item.</param> /// <param name="flagsOut">Pointer to a CADWORD array of flags stored in DWORDs indicating that some of the files have special behaviors.</param> /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code. </returns> /// <remarks>This method is called to discover any special or hidden files associated with an item in the project hierarchy. It is called when GetSccFiles returns with the SFF_HasSpecialFiles flag set for any of the files associated with the node.</remarks> public virtual int GetSccSpecialFiles(uint itemid, string sccFile, CALPOLESTR[] stringsOut, CADWORD[] flagsOut) { if (itemid == VSConstants.VSITEMID_SELECTION) { throw new ArgumentException(SR.GetString(SR.InvalidParameter, CultureInfo.CurrentUICulture), "itemid"); } HierarchyNode n = this.NodeFromItemId(itemid); if (n == null) { throw new ArgumentException(SR.GetString(SR.InvalidParameter, CultureInfo.CurrentUICulture), "itemid"); } List<string> files = new List<string>(); List<tagVsSccFilesFlags> flags = new List<tagVsSccFilesFlags>(); n.GetSccSpecialFiles(sccFile, files, flags); if (stringsOut != null && stringsOut.Length > 0) { stringsOut[0] = Utilities.CreateCALPOLESTR(files); } if (flagsOut != null && flagsOut.Length > 0) { flagsOut[0] = Utilities.CreateCADWORD(flags); } return VSConstants.S_OK; }
public int GetSccSpecialFiles(uint itemid, string pszSccFile, CALPOLESTR[] pCaStringsOut, CADWORD[] pCaFlagsOut) { return VSConstants.E_NOTIMPL; }
/// <summary> /// Returns a list of source controllable files associated with the specified node /// </summary> private static async Task<IList<string>> GetNodeFiles(IVsSccProject2 pscp2, uint itemid) { // NOTE: the function returns only a list of files, containing both regular files and special files // If you want to hide the special files (similar with solution explorer), you may need to return // the special files in a hastable (key=master_file, values=special_file_list) // Initialize output parameters IList<string> sccFiles = new List<string>(); if (pscp2 != null) { CALPOLESTR[] pathStr = new CALPOLESTR[1]; CADWORD[] flags = new CADWORD[1]; await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); if (pscp2.GetSccFiles(itemid, pathStr, flags) == 0) { for (int elemIndex = 0; elemIndex < pathStr[0].cElems; elemIndex++) { IntPtr pathIntPtr = Marshal.ReadIntPtr(pathStr[0].pElems, elemIndex); String path = Marshal.PtrToStringAuto(pathIntPtr); sccFiles.Add(path); // See if there are special files if (flags.Length > 0 && flags[0].cElems > 0) { int flag = Marshal.ReadInt32(flags[0].pElems, elemIndex); if (flag != 0) { // We have special files CALPOLESTR[] specialFiles = new CALPOLESTR[1]; CADWORD[] specialFlags = new CADWORD[1]; pscp2.GetSccSpecialFiles(itemid, path, specialFiles, specialFlags); for (int i = 0; i < specialFiles[0].cElems; i++) { IntPtr specialPathIntPtr = Marshal.ReadIntPtr(specialFiles[0].pElems, i * IntPtr.Size); String specialPath = Marshal.PtrToStringAuto(specialPathIntPtr); sccFiles.Add(specialPath); Marshal.FreeCoTaskMem(specialPathIntPtr); } if (specialFiles[0].cElems > 0) { Marshal.FreeCoTaskMem(specialFiles[0].pElems); } } } Marshal.FreeCoTaskMem(pathIntPtr); } if (pathStr[0].cElems > 0) { Marshal.FreeCoTaskMem(pathStr[0].pElems); } } } else if (itemid == VSConstants.VSITEMID_ROOT) { sccFiles.Add(await GetSolutionFileName()); } return sccFiles; }
/// <summary> /// Returns a list of source controllable files associated with the specified node /// </summary> private static IList <string> GetNodeFiles(IVsSccProject2 pscp2, uint itemid) { // NOTE: the function returns only a list of files, containing both regular files and special files // If you want to hide the special files (similar with solution explorer), you may need to return // the special files in a hashtable (key=master_file, values=special_file_list) // Initialize output parameters IList <string> sccFiles = new List <string>(); if (pscp2 != null) { var pathStr = new CALPOLESTR[1]; var flags = new CADWORD[1]; if (pscp2.GetSccFiles(itemid, pathStr, flags) == 0) { uint arraySize = pathStr[0].cElems; IntPtr arrayPtr = pathStr[0].pElems; for (int elemIndex = 0; elemIndex < arraySize; elemIndex++) { IntPtr pathIntPtr = Marshal.ReadIntPtr(arrayPtr, elemIndex * IntPtr.Size); String path; try { path = Marshal.PtrToStringAuto(pathIntPtr); } catch (Exception ex) { Log.Error("In GetNodeFiles: " + ex.Message); continue; } //Log.Debug(string.Format("Regular file: {0}", path)); does this continually for selected file sccFiles.Add(path); // See if there are special files uint flagsArraySize = flags[0].cElems; IntPtr flagsPtr = flags[0].pElems; if (flags.Length > 0 && flagsArraySize > 0) { int flag = Marshal.ReadInt32(flagsPtr, elemIndex); if (flag != 0) { // We have special files var specialFiles = new CALPOLESTR[1]; var specialFlags = new CADWORD[1]; pscp2.GetSccSpecialFiles(itemid, path, specialFiles, specialFlags); for (int i = 0; i < specialFiles[0].cElems; i++) { IntPtr specialPathIntPtr = Marshal.ReadIntPtr(specialFiles[0].pElems, i * IntPtr.Size); String specialPath = Marshal.PtrToStringAuto(specialPathIntPtr); //Log.Debug(string.Format("Special file: {0}", path)); sccFiles.Add(specialPath); Marshal.FreeCoTaskMem(specialPathIntPtr); } if (specialFiles[0].cElems > 0) { Marshal.FreeCoTaskMem(specialFiles[0].pElems); } } } Marshal.FreeCoTaskMem(pathIntPtr); } if (arraySize > 0) { Marshal.FreeCoTaskMem(arrayPtr); } } } return(sccFiles); }
public int GetSccFiles(uint itemid, CALPOLESTR[] pCaStringsOut, CADWORD[] pCaFlagsOut) { if ((null == pCaStringsOut) || (0 == pCaStringsOut.Length)) throw new ArgumentNullException(); if ((null == pCaFlagsOut) || (0 == pCaFlagsOut.Length)) throw new ArgumentNullException(); pCaStringsOut[0] = new CALPOLESTR(); pCaStringsOut[0].cElems = 0; pCaStringsOut[0].pElems = IntPtr.Zero; pCaFlagsOut[0] = new CADWORD(); pCaFlagsOut[0].cElems = 0; pCaFlagsOut[0].pElems = IntPtr.Zero; string fileForNode = null; if (itemid == VSConstants.VSITEMID_ROOT) { fileForNode = _projFile; } else if (itemid >= 0 && itemid < _items.Count) { fileForNode = _items[(int)itemid]; } if (fileForNode != null) { // There is only one scc controllable file per each hierarchy node pCaStringsOut[0].cElems = 1; pCaStringsOut[0].pElems = Marshal.AllocCoTaskMem(IntPtr.Size); Marshal.WriteIntPtr(pCaStringsOut[0].pElems, Marshal.StringToCoTaskMemUni(fileForNode)); pCaFlagsOut[0].cElems = 1; pCaFlagsOut[0].pElems = Marshal.AllocCoTaskMem(sizeof(Int32)); Marshal.WriteInt32(pCaFlagsOut[0].pElems, 0); } return VSConstants.S_OK; }
private static bool HasSpecialFiles(CADWORD[] flags, int i) { if (flags[0].cElems > 0) { return Marshal.ReadInt32(flags[0].pElems, i) != 0; } return false; }