Ejemplo n.º 1
0
        public static void SaveVsComObjects(this SdkInterfaceLibraryEntities entities, Process process, object obj, string serviceName, string packageName, string typeName)
        {
            var type = obj.GetType();
            var pUnk = Marshal.GetIUnknownForObject(obj);

            foreach (var assemblyRef in Assembly.GetExecutingAssembly().GetReferencedAssemblies())
            {
                if (assemblyRef.Name.StartsWith("Microsoft.VisualStudio.", "EnvDTE"))
                {
                    var assembly = Assembly.Load(assemblyRef);

                    foreach (var refType in assembly.GetTypes().Where(t => t.IsInterface && t.HasCustomAttribute <GuidAttribute>()))
                    {
                        if (type.Implements(refType))
                        {
                            var interfaceId = entities.GetInterfaceId(refType);

                            if (serviceName != null)
                            {
                                var tblService = entities.SaveIfNotExists <tblService>(s => s.ServiceName == serviceName, () =>
                                {
                                    return(new tblService
                                    {
                                        ServiceId = Guid.NewGuid(),
                                        ServiceName = serviceName,
                                        ComponentId = entities.CreateComponent(type, Guid.Empty, process, obj).ComponentId
                                    });
                                });
                            }
                            else if (packageName != null)
                            {
                                Debugger.Break();
                            }
                        }
                        else
                        {
                            foreach (var guidAttr in refType.GetCustomAttributes <GuidAttribute>())
                            {
                                var    guid = Guid.Parse(guidAttr.Value);
                                IntPtr ppv;

                                if (Marshal.QueryInterface(pUnk, ref guid, out ppv) == VSConstants.S_OK)
                                {
                                    var tblService = entities.SaveIfNotExists <tblService>(s => s.ServiceName == serviceName, () =>
                                    {
                                        return(new tblService
                                        {
                                            ServiceId = Guid.NewGuid(),
                                            ServiceName = serviceName,
                                            ComponentId = entities.CreateComponent(type, Guid.Empty, process, obj).ComponentId
                                        });
                                    });
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private static Guid GetInterfaceId(this SdkInterfaceLibraryEntities entities, Type refType)
        {
            var guidAttribute = refType.GetCustomAttribute <GuidAttribute>();
            var guid          = Guid.Parse(guidAttribute.Value);
            var tblInterface  = entities.SaveIfNotExists <tblInterface>(i => i.InterfaceGuid == guid, () =>
            {
                return(new tblInterface
                {
                    InterfaceId = Guid.NewGuid(),
                    InterfaceGuid = guid,
                    InterfaceName = refType.FullName,
                });
            });

            return(tblInterface.InterfaceId);
        }
Ejemplo n.º 3
0
        public static tblComponent CreateComponent(this SdkInterfaceLibraryEntities entities, Type type, Guid typeGuid, Process process, object objComponent)
        {
            var tblModule    = GetModuleObject(type, process, objComponent);
            var tblComponent = new tblComponent
            {
                ComponentId   = Guid.NewGuid(),
                ComponentType = entities.GetComponentTypeName(tblModule, type, typeGuid),
                ModuleId      = entities.SaveIfNotExists <tblModule>(m => m.ModuleFileName == tblModule.ModuleFileName, () =>
                {
                    return(tblModule);
                }).ModuleId
            };

            entities.tblComponents.AddObject(tblComponent);
            entities.SaveChanges();

            return(tblComponent);
        }
Ejemplo n.º 4
0
        public static void SaveServices(this SdkInterfaceLibraryEntities entities, Process process, Microsoft.VisualStudio.OLE.Interop.IServiceProvider serviceProvider)
        {
            var executingAssembly = Assembly.GetExecutingAssembly();

            foreach (var assemblyRef in executingAssembly.GetReferencedAssemblies())
            {
                if (assemblyRef.Name.StartsWith("Microsoft.VisualStudio.", "EnvDTE."))
                {
                    var assembly = Assembly.Load(assemblyRef);

                    foreach (var refType in assembly.GetTypes().Where(t => t.IsInterface && t.HasCustomAttribute <GuidAttribute>()))
                    {
                        var    attr         = refType.GetCustomAttribute <GuidAttribute>();
                        var    guid         = Guid.Parse(attr.Value);
                        var    IID_IUnknown = new Guid("00000000-0000-0000-C000-000000000046");
                        IntPtr pUnk;

                        if (ErrorHandler.Succeeded(serviceProvider.QueryService(ref guid, ref IID_IUnknown, out pUnk)))
                        {
                            var serviceName = GetServiceFromGuid(guid);
                            var obj         = Marshal.GetObjectForIUnknown(pUnk);
                            var tblService  = entities.SaveIfNotExists <tblService>(s => s.ServiceName == serviceName, () =>
                            {
                                return(new tblService
                                {
                                    ServiceId = Guid.NewGuid(),
                                    ServiceName = serviceName,
                                    ComponentId = entities.CreateComponent(refType, Guid.Empty, process, obj).ComponentId
                                });
                            });

                            entities.SaveVsComObjects(process, obj, serviceName, string.Empty, string.Empty);
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public IEnumerable <string> GetAllHeaders()
        {
            SetDiagnosticsStatus("Retrieving SDK Headers");

            if (TESTING)
            {
                foreach (var pair in includeDirectories)
                {
                    var includeDirectory = pair.Value;
                    var vendorSdk        = pair.Key;
                    var sdkId            = vendorSdk.VendorSdkId;

                    foreach (var file in includeDirectory.GetFiles("*.*", SearchOption.AllDirectories).Take(20).Where(f => f.Extension.IsOneOf(".h", ".c", string.Empty)))
                    {
                        var notExists     = false;
                        var tblHeaderFile = entities.SaveIfNotExists <tblSDKHeaderFile>(h => h.HeaderFileName == file.FullName && h.VendorSdkId == sdkId, () =>
                        {
                            notExists = true;

                            return(new tblSDKHeaderFile
                            {
                                HeaderFileId = Guid.NewGuid(),
                                HeaderFileName = file.FullName,
                                VendorSdkId = sdkId
                            });
                        });

                        if (notExists || !tblHeaderFile.IsParsedSuccessfully())
                        {
                            yield return(file.FullName);
                        }
                    }
                }
            }
            else
            {
                foreach (var pair in includeDirectories)
                {
                    var includeDirectory = pair.Value;
                    var vendorSdk        = pair.Key;
                    var sdkId            = vendorSdk.VendorSdkId;

                    foreach (var file in includeDirectory.GetFiles("*.*", SearchOption.AllDirectories).Where(f => f.Extension.IsOneOf(".h", ".c", string.Empty)))
                    {
                        var notExists     = false;
                        var tblHeaderFile = entities.SaveIfNotExists <tblSDKHeaderFile>(h => h.HeaderFileName == file.FullName && h.VendorSdkId == sdkId, () =>
                        {
                            notExists = true;

                            return(new tblSDKHeaderFile
                            {
                                HeaderFileId = Guid.NewGuid(),
                                HeaderFileName = file.FullName,
                                VendorSdkId = sdkId
                            });
                        });

                        if (notExists || !tblHeaderFile.IsParsedSuccessfully())
                        {
                            yield return(file.FullName);
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public SDKSymbolResolver()
        {
            var vcDirectory           = new DirectoryInfo(VSEnvironment.ExpandEnvironmentVariables("$(VCInstallDir)"));
            var crtDirectory          = new DirectoryInfo(VSEnvironment.ExpandEnvironmentVariables(@"$(VCInstallDir)crt\src"));
            var windowsSdkDirectory   = new DirectoryInfo(VSEnvironment.ExpandEnvironmentVariables("$(WindowsSdkDir)"));
            var atlmfcDirectory       = new DirectoryInfo(VSEnvironment.ExpandEnvironmentVariables(@"$(VCInstallDir)atlmfc"));
            var frameworkSdkDirectory = new DirectoryInfo(VSEnvironment.ExpandEnvironmentVariables(@"$(FrameworkSDKDir)"));
            var connectionString      = SDKLibraryConnection.ConnectionString;

            logFile = new FileInfo(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "SDKSymbolResolver.log"));

            if (logFile.Exists)
            {
                logFile.Delete();
            }

            versionRegex = new Regex(@"v?(?<version>\d+?\.\d+?\w*)");

            lockObject    = LockManager.CreateObject();
            searchManager = new SearchManager();
            searchManager.AddCatalog("MSVCInclude");

            entities          = new SdkInterfaceLibraryEntities(connectionString);
            tblSDKHeaderFiles = entities.tblSDKHeaderFiles;
            tblVendorSDKs     = entities.tblVendorSDKs;

            HeaderEntityExtensions.Entities    = entities;
            HeaderEntityExtensions.WriteLog   += new EventHandlerT <string>(HeaderEntityExtensions_WriteLog);
            HeaderEntityExtensions.IndentLog  += new EventHandler(HeaderEntityExtensions_IndentLog);
            HeaderEntityExtensions.OutdentLog += new EventHandler(HeaderEntityExtensions_OutdentLog);

            var tblMSVendor = entities.SaveIfNotExists <tblVendor>(v => v.VendorName == "Microsoft", () =>
            {
                return(new tblVendor
                {
                    VendorId = Guid.NewGuid(),
                    VendorName = "Microsoft"
                });
            });

            if (crtDirectory.Exists)
            {
                var version = string.Empty;

                if (versionRegex.IsMatch(crtDirectory.FullName))
                {
                    var match = versionRegex.Match(crtDirectory.FullName);

                    version = match.Groups["version"].Value;
                }

                var tblMSVendorSdk = entities.SaveIfNotExists <tblVendorSDK>(s => s.SdkName == "C Runtime Language" && s.SdkVersion == version, () =>
                {
                    return(new tblVendorSDK
                    {
                        VendorSdkId = Guid.NewGuid(),
                        VendorId = tblMSVendor.VendorId,
                        SdkName = "C Runtime Language",
                        SdkVersion = version,
                        SdkRootFolder = crtDirectory.FullName,
                        IncludeFolders = string.Empty,
                        SourceFolders = string.Empty,
                        LibraryFolders = string.Empty,
                        ExecutableFolders = string.Empty,
                    });
                });
            }

            if (vcDirectory.Exists)
            {
                var version = string.Empty;

                if (versionRegex.IsMatch(vcDirectory.FullName))
                {
                    var match = versionRegex.Match(vcDirectory.FullName);

                    version = match.Groups["version"].Value;
                }

                var tblMSVendorSdk = entities.SaveIfNotExists <tblVendorSDK>(s => s.SdkName == "Visual C++" && s.SdkVersion == version, () =>
                {
                    return(new tblVendorSDK
                    {
                        VendorSdkId = Guid.NewGuid(),
                        VendorId = tblMSVendor.VendorId,
                        SdkName = "Visual C++",
                        SdkVersion = version,
                        SdkRootFolder = vcDirectory.FullName,
                        IncludeFolders = "include",
                        SourceFolders = "src",
                        LibraryFolders = "lib",
                        ExecutableFolders = "bin",
                    });
                });
            }

            if (windowsSdkDirectory.Exists)
            {
                var version = string.Empty;

                if (versionRegex.IsMatch(vcDirectory.FullName))
                {
                    var match = versionRegex.Match(windowsSdkDirectory.FullName);

                    version = match.Groups["version"].Value;
                }

                var tblMSVendorSdk = entities.SaveIfNotExists <tblVendorSDK>(s => s.SdkName == "Windows SDK" && s.SdkVersion == version, () =>
                {
                    return(new tblVendorSDK
                    {
                        VendorSdkId = Guid.NewGuid(),
                        VendorId = tblMSVendor.VendorId,
                        SdkName = "Windows SDK",
                        SdkVersion = version,
                        SdkRootFolder = windowsSdkDirectory.FullName,
                        IncludeFolders = "include",
                        SourceFolders = "src",
                        LibraryFolders = "lib",
                        ExecutableFolders = "bin"
                    });
                });
            }

            if (atlmfcDirectory.Exists)
            {
                var version = string.Empty;

                if (versionRegex.IsMatch(vcDirectory.FullName))
                {
                    var match = versionRegex.Match(atlmfcDirectory.FullName);

                    version = match.Groups["version"].Value;
                }

                var tblMSVendorSdk = entities.SaveIfNotExists <tblVendorSDK>(s => s.SdkName == "ATL MFC" && s.SdkVersion == version, () =>
                {
                    return(new tblVendorSDK
                    {
                        VendorSdkId = Guid.NewGuid(),
                        VendorId = tblMSVendor.VendorId,
                        SdkName = "ATL MFC",
                        SdkVersion = version,
                        SdkRootFolder = atlmfcDirectory.FullName,
                        IncludeFolders = "include",
                        SourceFolders = "src",
                        LibraryFolders = "lib",
                        ExecutableFolders = "bin"
                    });
                });
            }

            if (frameworkSdkDirectory.Exists)
            {
                var version = string.Empty;

                if (versionRegex.IsMatch(vcDirectory.FullName))
                {
                    var match = versionRegex.Match(frameworkSdkDirectory.FullName);

                    version = match.Groups["version"].Value;
                }

                var tblMSVendorSdk = entities.SaveIfNotExists <tblVendorSDK>(s => s.SdkName == "Framework SDK" && s.SdkVersion == version, () =>
                {
                    return(new tblVendorSDK
                    {
                        VendorSdkId = Guid.NewGuid(),
                        VendorId = tblMSVendor.VendorId,
                        SdkName = "Framework SDK",
                        SdkVersion = version,
                        SdkRootFolder = frameworkSdkDirectory.FullName,
                        IncludeFolders = "include",
                        SourceFolders = "src",
                        LibraryFolders = "lib",
                        ExecutableFolders = "bin"
                    });
                });
            }

            serializedEventArgs = new List <EventArgsXml>();
            includeDirectories  = new Dictionary <tblVendorSDK, DirectoryInfo>();
            libraryDirectories  = new Dictionary <tblVendorSDK, DirectoryInfo>();
            tblVendorSDKs       = entities.tblVendorSDKs;

            foreach (var tblVendorSdk in tblVendorSDKs)
            {
                AddIncludes(tblVendorSdk);
            }

            this.OnParserDiagnostic += new Utils.EventHandlerT <CppSharp.Parser.ParserDiagnostic>(symbolResolver_OnParserDiagnostic);
            this.OnParserProgress   += new ParserProgressEventHandler(symbolResolver_OnParserProgress);
        }