Exemplo n.º 1
0
        public override bool Equals(Object other)
        {
            if (!(other is TypeLibKey))
            {
                return(false);
            }
            TypeLibKey b          = (TypeLibKey)other;
            bool       guidEquals = b._guid.Equals(_guid);

            if (!guidEquals)
            {
                return(false);
            }
            if (_version != null && b._version != null)
            {
                return(_version.Equals(b._version));
            }
            // Our version specified and the other not, no match
            if (_version != null && b._version == null)
            {
                return(false);
            }
            // We don't care about version, match any version, or
            // no version is specified for either one, that's a match
            return(true);
        }
Exemplo n.º 2
0
        public int CompareTo(Object other)
        {
            if (!(other is TypeLibKey))
            {
                return(-1);
            }
            TypeLibKey b = (TypeLibKey)other;

            if (b != null)
            {
                int compVal = _guid.CompareTo(b._guid);
                if (compVal != 0)
                {
                    return(compVal);
                }
                if (_version != null && b._version != null)
                {
                    return(_version.CompareTo(b._version));
                }
                if ((_version != null && b._version == null) ||
                    (_version == null && b._version != null))
                {
                    return(-1);
                }
                return(0);
            }
            return(-1);
        }
Exemplo n.º 3
0
		// Finds the type library tree node no matter where it is
		internal static BrowserTreeNode FindTypeLib(TypeLibKey libKey)
		{
			BrowserTreeNode node;
			BrowserTreeNode findRoot;
			// First try favorites
			findRoot = _favTypeLibNode;
			node = FindTypeLib(libKey, findRoot);
			// Then the registered part
			if (node == null)
			{
				node = FindTypeLib(libKey, _typeLibNode);
			}
			return node;
		}
Exemplo n.º 4
0
		internal static TypeLibKey GetTypeLibKey(TYPELIBATTR typeLibAttr)
		{
			TypeLibKey typeLibKey = new TypeLibKey(typeLibAttr.guid,
				typeLibAttr.wMajorVerNum + "." + typeLibAttr.wMinorVerNum);
			TraceUtil.WriteLineInfo(null, "TypeLibKey: " + typeLibKey);
			return typeLibKey;
		}
Exemplo n.º 5
0
		// s/b protected, stupid compiler
		internal static BrowserTreeNode FindTypeLib(TypeLibKey libKey, BrowserTreeNode parent)
		{
			BrowserTreeNode typeLibNode = null;
			// Will happen if not COM product
			if (parent == null)
				return null;
			// Make sure we get all of the children added
			parent.ExpandNode();
			foreach (BrowserTreeNode node in parent.LogicalNodes) {
				if (node is ComTypeLibTreeNode) {
					if (((ComTypeLibTreeNode)node).TypeLib.Key.Equals(libKey)) {
						typeLibNode = node;
						break;
					}
				}
			}
			return typeLibNode;
		}
Exemplo n.º 6
0
		// If the UCOMITypeLib pointer is good, then remember
		// that, because the type library may not be in the registry
		// or a file we can open.  But we can still convert it and
		// read its information
		internal static TypeLibrary GetTypeLib(TypeLibKey key, UCOMITypeLib iTypeLib)
		{
			TraceUtil.WriteLineInfo(null, "TypeLib - GetTypeLib: " + key);
			lock (typeof(TypeLibrary)) {
				TypeLibrary lib = (TypeLibrary)_openedTypeLibs[key];
				if (lib != null && lib._converted)
					return lib;
				try {
					if (lib == null) {
						// Have to create one
						lib = new TypeLibrary(key);
						lib._iTypeLib = iTypeLib;
						try {
							lib.PopulateFromRegistry(key);
						} catch (Exception ex) {
							// This could be ok, sometimes a typelib is not
							// in the registry
							TraceUtil.WriteLineWarning
								(typeof(TypeLibrary),
								"GetTypeLib exception (not in registry)  "
								+ ex);
							if (lib._iTypeLib == null) {
								throw new Exception("Failed to find type library information in registry", ex);
							}
						}
					}
					lib.TranslateTypeLib();
					// Generate the C# source after the translation for
					// now because the source generation requires the 
					// definitions to be read which can cause a call
					// to GetTypeLib(), don't want to be re-entered
					// FIXME
					//lib.GenerateSource();
					return lib;
				} catch (Exception ex) {
					TraceUtil.WriteLineWarning(typeof(TypeLibrary), "GetTypeLib exception " + ex);
					throw new Exception("Error getting type library: ", ex);
				}
			}
		}
Exemplo n.º 7
0
		// Reads the type library information
		internal void ReadTypeLibFile()
		{
			if (_openedFile)
				return;
			TraceUtil.WriteLineInfo(this,
									"Opening: " + _fileName);
			// We may have received a pointer to this typelibrary
			// without having to open the file
			if (_iTypeLib == null) {
				try {
					ActiveX.LoadTypeLibEx(_fileName, 
										 RegKind.RegKind_None, 
										 out _iTypeLib); 
				} catch (Exception ex) {
					TraceUtil.WriteLineWarning(this, 
											  "Failed to load typelib file: " 
											  + _fileName + " " + ex);
					return;
				}
			}
	
			if(_iTypeLib == null) {
				TraceUtil.WriteLineWarning(this, 
										  "Failed to load typelib file: " 
										  + _fileName);
				return;
			}
			_typeLibKey = GetTypeLibKey(_iTypeLib);
			GetDocumentation(-1);
			// When a assembly is exported to a type lib, the assembly
			// FullName is stored as this custom attribute in the type
			// library.  We save this name here and then we need to
			// get an assembly for this typelib, we just load it with 
			// this name.
			if (_iTypeLib is ITypeLib2) {
				Guid assyDataGuid = new Guid("90883F05-3D28-11D2-8F17-00A0C9A6186D");
				Object custData;
				int ret = ((ITypeLib2)_iTypeLib).GetCustData(ref assyDataGuid, out custData);
				if (ret == 0) {
					_translatedAssyFullName = (String)custData;
					TraceUtil.WriteLineInfo(this, 
											"TypeLib was translated from: " 
											+ _translatedAssyFullName);
				}
			}
			// Create the names if we will/have converted the typelib
			if (_translatedAssyFullName == null)
				CreateAssyNames();
			lock (typeof(TypeLibrary)) {
				// We may have already seen this one, just forget
				// the new one
				if (_openedTypeLibs[_typeLibKey] == null)
					_openedTypeLibs.Add(_typeLibKey, this);
			}
			_openedFile = true;
			TraceUtil.WriteLineInfo(this, "Opened: " + this);
		}
Exemplo n.º 8
0
		// Associates the specified assembly with the type library.
		// This is called when assemblies are restored, or when
		// they are loaded and must be hooked up to a type library
		internal static void AssociateAssyWithTypeLib(Assembly assy,
													 Guid guid,
													 string version,
													 bool primaryInterop)
		{
			try {
				lock (typeof(TypeLibrary)) {
					TraceUtil.WriteLineInfo(null, 
											"AssocateAssy - "
											+ "guid/version: " 
											+ guid + " " + version);
						
					TypeLibKey typeLibKey = new TypeLibKey(guid,
														  version);
					// We should already know about it, if not, 
					// just ignore it
					TypeLibrary lib =
						(TypeLibrary)_openedTypeLibs[typeLibKey];
					if (lib == null) {
						TraceUtil.WriteLineInfo(typeof(TypeLibrary),
												"no typelib found for assy: "
												+ assy);
						return;
					}
					if (primaryInterop)
						lib._primaryInteropAssy = assy;
					lib.SetAssemblyPointer(assy);
				}
			} catch (Exception ex) {
				TraceUtil.WriteLineWarning(null, "TypeLib - deleting bad assy entry: " 
					+ assy + " " + ex);
				// Remove the typelib information associated with the
				// assembly
				AssemblySupport.ForgetAssemblyTypeLib(assy);
			}
		}
Exemplo n.º 9
0
		internal static TypeLibrary GetTypeLib(TypeLibKey key)
		{
			return GetTypeLib(key, null);
		}
Exemplo n.º 10
0
		// Called when a type library is loaded from the remembered
		// type libraries upon start up
		internal static void RestoreTypeLib(String fileName,
											Guid guid,
											string version)
		{
			TypeLibrary lib = null;
			try {
				lock (typeof(TypeLibrary)) {
					TraceUtil.WriteLineInfo(null, 
											"RestoreTypeLib - guid/version: " 
											+ guid + " " + version);
						
					TypeLibKey typeLibKey = new TypeLibKey(guid, version);
					// We should not have already seen this one, but
					// if we have, we will be decent about it
					lib = (TypeLibrary)_openedTypeLibs[typeLibKey];
					if (lib == null) {
						lib = new TypeLibrary(typeLibKey);
						try {
							lib.PopulateFromRegistry(typeLibKey);
						}
						catch (Exception ex) {
							// Get the file name we recorded since its not
							// registered
							lib._fileName = fileName;
							// Might not be registered, ignore error
							TraceUtil.WriteLineInfo
								(typeof(TypeLibrary),
								"Unregistered typelib restore: " 
								+ fileName 
								+ " exception: " + ex);
						}
					}
					lib.ReadTypeLibFile();
					if (lib._openedFile) {
						if (!_searchMode) {
							ComSupport.AddTypeLib(lib);
						}
						TraceUtil.WriteLineInfo(null, 
												"TypeLib - loaded/restored: " 
												+ lib);
					} else {
						// Something's wrong, don't try and open again
						lib.ForgetMe();
						TraceUtil.WriteLineInfo(null, 
												"TypeLib - failed to open "
												+ "- forgotten: " 
												+ lib);
					}
				}
			} catch (Exception ex) {
				TraceUtil.WriteLineWarning
					(null, "TypeLib - deleting bad typelib entry: " 
					+ lib + " " + ex);
				// Something's wrong, don't try and open again
				lib.ForgetMe();
			}
		}
Exemplo n.º 11
0
		// Returns the TypeLibrary if it has been opened, for use
		// when we don't need the library translated nor to see its
		// contents
		internal static TypeLibrary GetTypeLibOpened(Guid guid,
													String version)
		{
			TypeLibKey typeLibKey = new TypeLibKey(guid,
												  version);
			lock (typeof(TypeLibrary)) {
				TypeLibrary lib = (TypeLibrary)_openedTypeLibs[typeLibKey];
				TraceUtil.WriteLineInfo(null, 
										"GetTypeLibOpened: " 
										+ ((lib == null) ? "false " : "true ")
										+ guid + " " + version);
				return lib;
			}
		}
Exemplo n.º 12
0
		protected static void GetTypeLibsFromRegistry(String guidStr)
		{
			TypeLibrary lib = null;
			RegistryKey regKey = Windows.KeyTypeLib.OpenSubKey(guidStr);
			String[] subKeyNames = regKey.GetSubKeyNames();
			foreach (String versionStr in subKeyNames) {
				RegistryKey versionKey = regKey.OpenSubKey(versionStr);
				try {
					if (versionKey == null) {
						throw new Exception("Version entry not "
											+ "found for typelib: " 
											+ guidStr);
					}
					TypeLibKey key = new TypeLibKey(new Guid(guidStr), versionStr);
					// See if we already know about it
					TypeLibrary convLib = (TypeLibrary)_openedTypeLibs[key];
					if (convLib == null) {
						lib = new TypeLibrary();
						lib.Key = key;
						lib.PopulateFromRegistry(versionKey);
						// We don't read the type lib info until the user
						// wants the detail text or something else 
						// that requires it
					} else {
						lib = convLib;
					}
					_registeredTypeLibs.Add(lib, lib);
				} catch (Exception ex) {
					TraceUtil.WriteLineInfo(null,
											"TypeLib - failure to read: "
											+ versionKey + " " + ex);
				}
			}
		}
Exemplo n.º 13
0
		protected TypeLibrary(TypeLibKey key) : this()
		{
			_typeLibKey = key;
		}
Exemplo n.º 14
0
		protected void PopulateFromRegistry(TypeLibKey typeLibKey)
		{
			TraceUtil.WriteLineInfo(null, "TypeLib - PopulateFromRegistry");
			String guidStr = Utils.MakeGuidStr(typeLibKey._guid);
			_regKey = Windows.KeyTypeLib.OpenSubKey(guidStr);
			if (_regKey == null) {
				throw new Exception("Type lib not found in registry for guid: "
									+ guidStr);
			}
			RegistryKey versionKey;
			if (typeLibKey._version != null) {
				versionKey = _regKey.OpenSubKey(typeLibKey._version);
				if (versionKey == null) {
					throw new Exception("Version entry " 
								 + typeLibKey._version
								 + " not found for typelib: " 
								 + guidStr);
				}
			} else {
				String[] versions = _regKey.GetSubKeyNames();
				if (versions.Length == 0) {
					throw new Exception("No version keys found for typelib: " + guidStr);
				}
				// Just use the first version
				versionKey = _regKey.OpenSubKey(versions[0]);
			}
			PopulateFromRegistry(versionKey);
		}