Esempio n. 1
0
#pragma warning restore 0067

        public TypeLibInfo GetTypeLibInfo(TLIApplication tliapp = null)
        {
            tliapp = tliapp ?? tliappInstance.Value;
            try {
                return(tliapp.TypeLibInfoFromRegistry(TypeLibID, MajorVersion, MinorVersion, LCID));
            } catch (Exception) {
                // sometimes the version includes an alphabetical component -- e.g. c.0
                // since TypeLibInfoFromRegistry only takes numeric arguments for major / minor versions, it throws an exception when 0 is passed in
                // so we use the path stored in the registry; preferring 64-bit if available
                var path = Path64bit.IsNullOrEmpty() ? Path32bit : Path64bit;
                return(tliapp.TypeLibInfoFromFile(path));
            }
        }
Esempio n. 2
0
        public static XmlDocument DetectDependencies(string[] fileNames)
        {
            TLIApplication typeLibApplication = new TLIApplication();

            XmlDocument returnDocument = new XmlDocument();

            returnDocument.AppendChild(returnDocument.CreateElement("Root"));

            foreach (string fileName in fileNames)
            {
                DetectDependencies(typeLibApplication, fileName, returnDocument);
            }

            Marshal.ReleaseComObject(typeLibApplication);

            return(returnDocument);
        }
Esempio n. 3
0
 private static void DetectMembers(TLIApplication typeLibApplication, string fileName, XmlDocument returnDocument, Members members)
 {
     foreach (MemberInfo itemMember in members)
     {
         VarTypeInfo typeInfo = itemMember.ReturnType;
         if ((typeInfo != null) && (true == typeInfo.IsExternalType))
         {
             XmlNode fileNode = null;
             foreach (XmlNode itemNode in returnDocument.FirstChild.ChildNodes)
             {
                 if (itemNode.Attributes["File"].InnerText == typeInfo.TypeLibInfoExternal.ContainingFile)
                 {
                     fileNode = itemNode;
                     break;
                 }
             }
             if (null == fileNode)
             {
                 fileNode = returnDocument.CreateElement("Component");
                 XmlAttribute attribute = returnDocument.CreateAttribute("File");
                 attribute.InnerText = typeInfo.TypeLibInfoExternal.ContainingFile;
                 fileNode.Attributes.Append(attribute);
                 attribute           = returnDocument.CreateAttribute("Name");
                 attribute.InnerText = typeInfo.TypeLibInfoExternal.Name;
                 fileNode.Attributes.Append(attribute);
                 returnDocument.FirstChild.AppendChild(fileNode);
                 AddDependencyComponentNode(fileNode, fileName);
                 DetectDependencies(typeLibApplication, typeInfo.TypeLibInfoExternal.ContainingFile, returnDocument);
             }
             else
             {
                 AddDependencyComponentNode(fileNode, fileName);
             }
         }
         if (null != typeInfo)
         {
             Marshal.ReleaseComObject(typeInfo);
         }
     }
 }
Esempio n. 4
0
        private static void DetectDependencies(TLIApplication typeLibApplication, string fileName, XmlDocument returnDocument)
        {
            TypeLibInfo libInfo = typeLibApplication.TypeLibInfoFromFile(fileName);

            CoClasses classInfos = libInfo.CoClasses;

            foreach (CoClassInfo itemInfo in classInfos)
            {
                DetectMembers(typeLibApplication, fileName, returnDocument, itemInfo.DefaultInterface.Members);
                Marshal.ReleaseComObject(itemInfo);
            }
            Marshal.ReleaseComObject(classInfos);

            Interfaces faceInfos = libInfo.Interfaces;

            foreach (InterfaceInfo itemInfo in faceInfos)
            {
                DetectMembers(typeLibApplication, fileName, returnDocument, itemInfo.Members);
                Marshal.ReleaseComObject(itemInfo);
            }
            Marshal.ReleaseComObject(faceInfos);

            Marshal.ReleaseComObject(libInfo);
        }
Esempio n. 5
0
        private static List <TypeLibDetails> initializer()
        {
            var tliapp = new TLIApplication();
            var ret    = new List <TypeLibDetails>();

            using (var key = Registry.ClassesRoot.OpenSubKey("TypeLib")) {
                foreach (var tlbid in key.GetSubKeyNames())
                {
                    using (var tlbkey = key.OpenSubKey(tlbid)) {
                        foreach (var version in tlbkey.GetSubKeyNames())
                        {
                            var indexOf = version.IndexOf(".");
                            version.Substring(0, indexOf).TryParse(out short?majorVersion);
                            version.Substring(indexOf + 1).TryParse(out short?minorVersion);
                            using (var versionKey = tlbkey.OpenSubKey(version)) {
                                var libraryName = (string)versionKey.GetValue("");
                                foreach (var lcid in versionKey.GetSubKeyNames())
                                {
                                    if (!short.TryParse(lcid, out short lcidParsed))
                                    {
                                        continue;
                                    }                                                              //exclude non-numeric keys such as FLAGS and HELPDIR
                                    using (var lcidKey = versionKey.OpenSubKey(lcid)) {
                                        var names = lcidKey.GetSubKeyNames();
                                        var td    = new TypeLibDetails()
                                        {
                                            TypeLibID    = tlbid,
                                            Name         = libraryName,
                                            Version      = version,
                                            MajorVersion = majorVersion ?? 0,
                                            MinorVersion = minorVersion ?? 0,
                                            LCID         = lcidParsed,
                                            Is32bit      = names.Contains("win32"),
                                            Is64bit      = names.Contains("win64"),
                                            RegistryKey  = lcidKey.ToString()
                                        };
                                        if (td.Is32bit)
                                        {
                                            td.Path32bit = (string)lcidKey.OpenSubKey("win32").GetValue("");
                                        }
                                        if (td.Is64bit)
                                        {
                                            td.Path64bit = (string)lcidKey.OpenSubKey("win64").GetValue("");
                                        }
                                        if (!char.IsDigit(td.Version[0]))
                                        {
                                            var versions = new[] { td.Path32bit, td.Path64bit }
                                            .Where(x => !x.IsNullOrEmpty())
                                            .Select(x => {
                                                var tli = tliapp.TypeLibInfoFromFile(x);
                                                return(tli.MajorVersion, tli.MinorVersion);
                                            })
                                            .Distinct()
                                            .ToList();
                                            if (versions.Count > 1)
                                            {
                                                continue;
                                            }                                   // we can't resolve an absolute major / minor version, because the different paths have two different versions
                                            td.MajorVersion = versions[0].MajorVersion;
                                            td.MinorVersion = versions[0].MinorVersion;
                                        }
                                        ret.Add(td);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(ret.OrderBy(x => x.Name).ToList());
        }