상속: Mono.Cecil.BaseAssemblyResolver
예제 #1
0
        public CecilWidgetLibrary(AssemblyResolver resolver, string path)
        {
            name = path;
            this.resolver = resolver;

            cache.Refresh (resolver, name);

            if (resolver != null)
                filename = resolver.Resolve (path, null);

            if (filename == null)
                filename = path;

            assembly = AssemblyFactory.GetAssembly (filename);
        }
		public CecilWidgetLibrary (AssemblyResolver resolver, string path)
		{
			name = path;
			this.resolver = resolver;

			if (System.IO.File.Exists (path))
				filename = path;
			else if (resolver != null)
				filename = resolver.Resolve (path, null);
			
			if (filename == null)
				filename = path;
			else
				filename = System.IO.Path.GetFullPath (filename);

			RefreshFromCache ();
		}
		public AssemblyWidgetLibrary (AssemblyResolver resolver, string assemblyPath)
		{
			this.name = assemblyPath;
			
			string ares = resolver.Resolve (assemblyPath, null);
			if (ares != null)
				assemblyPath = ares;
			
			this.resolver = resolver;
			if (assemblyPath.EndsWith (".dll") || assemblyPath.EndsWith (".exe")) {
				if (File.Exists (assemblyPath))
					assembly = Assembly.LoadFrom (assemblyPath);
			} else
				assembly = Assembly.Load (assemblyPath);
				
			if (assembly == null)
				throw new InvalidOperationException ("Couldn't load assembly at " + assemblyPath);

			UpdateCache ();
		}
예제 #4
0
파일: LibraryCache.cs 프로젝트: mono/stetic
        ToolboxItemInfo GetToolboxItemInfo(AssemblyResolver resolver, TypeDefinition tdef)
        {
            if (tdef == null)
                return null;

            ToolboxItemInfo info = null;
            string category = "General";

            foreach (CustomAttribute attr in tdef.CustomAttributes) {
                switch (attr.Constructor.DeclaringType.FullName) {
                case "System.ComponentModel.ToolboxItemAttribute":
                    attr.Resolve ();
                    if (attr.ConstructorParameters.Count > 0) {
                        object param = attr.ConstructorParameters [0];
                        if (param == null)
                            return null;
                        else if (param.GetType () == typeof (bool)) {
                            if ((bool) param)
                                info = new ToolboxItemInfo ("Gtk.Widget");
                            else
                                return null;
                        } else if (param.GetType () == typeof (System.Type))
                            info = new ToolboxItemInfo ("Gtk.Widget");
                        else
                            return null;
                    }
                    break;
                case "System.ComponentModel.CategoryAttribute":
                    attr.Resolve ();
                    if (attr.ConstructorParameters.Count > 0) {
                        object param = attr.ConstructorParameters [0];
                        if (param.GetType () == typeof (string))
                            category = (string) param;
                    }
                    break;
                default:
                    continue;
                }

            }

            if (info == null && tdef.BaseType != null)
                info = GetToolboxItemInfo (resolver, resolver.Resolve (tdef.BaseType));

            if (info != null)
                info.PaletteCategory = category;

            return info;
        }
예제 #5
0
		public bool IsWidgetLibrary (string assemblyRef)
		{
			AssemblyResolver resolver = new AssemblyResolver (Backend);
			return InternalIsWidgetLibrary (resolver, assemblyRef);
		}
예제 #6
0
        void AddObject(TypeDefinition tdef, Dictionary <TypeDefinition, ToolboxItemInfo> localObjects, AssemblyResolver resolver, string basePath, AssemblyDefinition adef)
        {
            if (tdef.IsAbstract || !tdef.IsClass)
            {
                return;
            }

            ToolboxItemInfo tbinfo = GetToolboxItemInfo(resolver, basePath, adef, tdef, true);

            if (tbinfo == null)
            {
                return;
            }

            localObjects [tdef] = tbinfo;

            foreach (var nestedType in tdef.NestedTypes)
            {
                AddObject(nestedType, localObjects, resolver, basePath, adef);
            }
        }
예제 #7
0
		WidgetLibrary AddLibrary (AssemblyResolver resolver, Hashtable visited, string s)
		{
			if (Registry.IsRegistered (s)) {
				WidgetLibrary lib = Registry.GetWidgetLibrary (s);
				CheckDependencies (resolver, visited, lib);
				return lib;
			}
			
			// Avoid registering direct references of libstetic
			if (Path.GetFileName (s) == "libstetic.dll" && s != coreLibrary)
				return null;

			WidgetLibrary alib = CreateLibrary (resolver, s);
			if (alib == null)
				return null;
				
			RegisterLibrary (resolver, visited, alib);
			return alib;
		}
예제 #8
0
		WidgetLibrary CreateLibrary (AssemblyResolver resolver, string name)
		{
			try {
				if (allowInProcLibraries)
					return new AssemblyWidgetLibrary (resolver, name);
				else
					return new CecilWidgetLibrary (resolver, name);
			} catch (Exception) {
				// FIXME: handle the error, but keep loading.
				return null;
			}
		}
예제 #9
0
 internal void LoadLibraries(AssemblyResolver resolver, Hashtable visited, IEnumerable libraries)
 {
     foreach (string s in libraries)
         AddLibrary (resolver, visited, s);
 }
예제 #10
0
		internal void LoadLibraries (AssemblyResolver resolver, IEnumerable libraries)
		{
			try {
				Registry.BeginChangeSet ();
				Hashtable visited = new Hashtable ();
				LoadLibraries (resolver, visited, libraries);
			} finally {
				Registry.EndChangeSet ();
			}
		}
예제 #11
0
		LibraryInfo Refresh (AssemblyResolver resolver, string assembly, string baseDirectory)
		{
			LibraryInfo info = GetInfo (resolver, assembly, baseDirectory);

			if (info == null || info.IsCurrent || !File.Exists (info.File))
				return info;

			info.Timestamp = File.GetLastWriteTime (info.File).ToUniversalTime ();
			info.Guid = Guid.NewGuid ();
			Save ();
			AssemblyDefinition adef = AssemblyDefinition.ReadAssembly (info.File);
			XmlDocument objects = GetObjectsDoc (resolver, adef, info.File, baseDirectory);
			if (objects != null) {
				info.ObjectsDocument = objects;
				XmlDocument gui = GetGuiDoc (adef);
				if (gui != null)
					info.GuiDocument = gui;
			}
			info.OnChanged ();
			return info;
		}
예제 #12
0
		TypeDefinition FindTypeDefinition (Hashtable visited, AssemblyResolver resolver, string basePath, AssemblyDefinition asm, string fullName)
		{
			if (visited.Contains (asm))
				return null;
				
			visited [asm] = asm;
			
			TypeDefinition cls = asm.MainModule.GetType (fullName);
			if (cls != null)
				return cls;
			
			foreach (AssemblyNameReference aref in asm.MainModule.AssemblyReferences) {
				AssemblyDefinition basm = resolver.Resolve (aref, basePath);
				if (basm != null) {
					cls = basm.MainModule.GetType (fullName);
					if (cls != null)
						return cls;
				}
			}
			return null;
		}
예제 #13
0
파일: LibraryCache.cs 프로젝트: mono/stetic
        XmlDocument GetObjectsDoc(AssemblyResolver resolver, AssemblyDefinition adef, string path)
        {
            XmlDocument doc = null;
            try {
                EmbeddedResource res = GetResource (adef, "objects.xml");
                if (res != null) {
                    MemoryStream stream = new MemoryStream (res.Data);
                    doc = new XmlDocument ();
                    using (stream)
                        doc.Load (stream);
                }

                if (resolver == null)
                    resolver = new AssemblyResolver (null);

                Hashtable visited = new Hashtable ();
                foreach (AssemblyNameReference aref in adef.MainModule.AssemblyReferences) {
                    if (!ReferenceChainContainsGtk (resolver, aref, visited))
                        continue;

                    if (doc == null) {
                        doc = new XmlDocument ();
                        doc.AppendChild (doc.CreateElement ("objects"));
                    }
                    AddObjects (doc, resolver, adef);
                    break;
                }

                if (doc != null) {
                    XmlElement elem = doc.CreateElement ("dependencies");
                    doc.DocumentElement.AppendChild (elem);
                    AddDependencies (elem, resolver, path, adef);
                }
            } catch (Exception e) {
                Console.WriteLine ("Got exception loading objects: " + e);
                doc = null;
            }

            return doc;
        }
예제 #14
0
        ToolboxItemInfo GetToolboxItemInfo(AssemblyResolver resolver, string baseDirectory, AssemblyDefinition asm, TypeDefinition tdef, bool checkBaseType)
        {
            if (tdef == null)
            {
                return(null);
            }

            ToolboxItemInfo info     = null;
            string          category = "General";

            foreach (CustomAttribute attr in tdef.CustomAttributes)
            {
                switch (attr.AttributeType.FullName)
                {
                case "System.ComponentModel.ToolboxItemAttribute":
                    if (attr.ConstructorArguments.Count > 0)
                    {
                        object param = attr.ConstructorArguments [0].Value;
                        if (param == null)
                        {
                            return(null);
                        }
                        else if (param.GetType() == typeof(bool))
                        {
                            if ((bool)param)
                            {
                                info = new ToolboxItemInfo("Gtk.Widget");
                            }
                            else
                            {
                                return(null);
                            }
                        }
                        else if (param.GetType() == typeof(TypeReference))
                        {
                            info = new ToolboxItemInfo("Gtk.Widget");
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    break;

                case "System.ComponentModel.CategoryAttribute":
                    if (attr.ConstructorArguments.Count > 0)
                    {
                        object param = attr.ConstructorArguments [0].Value;
                        if (param.GetType() == typeof(string))
                        {
                            category = (string)param;
                        }
                    }
                    break;

                default:
                    continue;
                }
            }

            if (info == null && checkBaseType && tdef.BaseType != null)
            {
                string baseName = tdef.BaseType.FullName;

                foreach (AssemblyNameReference aref in asm.MainModule.AssemblyReferences)
                {
                    LibraryInfo libInfo = GetInfo(resolver, aref.FullName, baseDirectory);
                    if (libInfo != null && libInfo.HasWidgets)
                    {
                        ToolboxItemInfo binfo = libInfo.GetToolboxItem(baseName, aref.Name);
                        if (binfo != null)
                        {
                            info     = new ToolboxItemInfo(baseName);
                            category = binfo.PaletteCategory;
                            break;
                        }
                    }
                }
            }

            if (info != null)
            {
                info.PaletteCategory = category;
            }

            return(info);
        }
예제 #15
0
        ToolboxItemInfo GetToolboxItemInfo(AssemblyResolver resolver, TypeDefinition tdef)
        {
            if (tdef == null)
            {
                return(null);
            }

            ToolboxItemInfo info     = null;
            string          category = "General";

            foreach (CustomAttribute attr in tdef.CustomAttributes)
            {
                switch (attr.Constructor.DeclaringType.FullName)
                {
                case "System.ComponentModel.ToolboxItemAttribute":
                    attr.Resolve();
                    if (attr.ConstructorParameters.Count > 0)
                    {
                        object param = attr.ConstructorParameters [0];
                        if (param == null)
                        {
                            return(null);
                        }
                        else if (param.GetType() == typeof(bool))
                        {
                            if ((bool)param)
                            {
                                info = new ToolboxItemInfo("Gtk.Widget");
                            }
                            else
                            {
                                return(null);
                            }
                        }
                        else if (param.GetType() == typeof(System.Type))
                        {
                            info = new ToolboxItemInfo("Gtk.Widget");
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    break;

                case "System.ComponentModel.CategoryAttribute":
                    attr.Resolve();
                    if (attr.ConstructorParameters.Count > 0)
                    {
                        object param = attr.ConstructorParameters [0];
                        if (param.GetType() == typeof(string))
                        {
                            category = (string)param;
                        }
                    }
                    break;

                default:
                    continue;
                }
            }

            if (info == null && tdef.BaseType != null)
            {
                info = GetToolboxItemInfo(resolver, resolver.Resolve(tdef.BaseType));
            }

            if (info != null)
            {
                info.PaletteCategory = category;
            }

            return(info);
        }
예제 #16
0
        internal TypeDefinition FindTypeDefinition(AssemblyResolver resolver, AssemblyDefinition assembly, string basePath, string fullName)
        {
            TypeDefinition t = FindTypeDefinition(new Hashtable(), resolver, basePath, assembly, fullName);

            return(t);
        }
예제 #17
0
 internal LibraryInfo Refresh(AssemblyResolver resolver, string assembly)
 {
     return(Refresh(resolver, assembly, null));
 }
예제 #18
0
        XmlDocument GetObjectsDoc(AssemblyResolver resolver, AssemblyDefinition adef, string path, string baseDirectory)
        {
            XmlDocument doc       = null;
            bool        isMainLib = Path.GetFileName(path) == "libstetic.dll";

            try {
                EmbeddedResource res = GetResource(adef, "objects.xml");
                if (res != null)
                {
                    MemoryStream stream = new MemoryStream(res.GetResourceData());
                    doc = new XmlDocument();
                    using (stream)
                        doc.Load(stream);
                }

                if (resolver == null)
                {
                    resolver = new AssemblyResolver(null);
                }

                baseDirectory = baseDirectory ?? Path.GetDirectoryName(path);

                if (!isMainLib)
                {
                    // Make sure all referenced assemblies are up to date.
                    foreach (AssemblyNameReference aref in adef.MainModule.AssemblyReferences)
                    {
                        Refresh(resolver, aref.FullName, baseDirectory);
                    }
                }

                if (doc == null)
                {
//					Hashtable visited = new Hashtable ();
                    foreach (AssemblyNameReference aref in adef.MainModule.AssemblyReferences)
                    {
                        if (aref.Name != "gtk-sharp")
                        {
                            LibraryInfo info = GetInfo(resolver, aref.FullName, baseDirectory);
                            if (info == null || !info.HasWidgets)
                            {
                                continue;
                            }
                        }

                        if (doc == null)
                        {
                            doc = new XmlDocument();
                            doc.AppendChild(doc.CreateElement("objects"));
                        }
                        AddObjects(doc, resolver, baseDirectory, adef);
                        break;
                    }
                }

                if (doc != null && !isMainLib)
                {
                    XmlElement elem = doc.CreateElement("dependencies");
                    doc.DocumentElement.AppendChild(elem);
                    AddDependencies(elem, resolver, path, adef);
                }
            } catch (Exception e) {
                Console.WriteLine("Got exception loading objects: " + e);
                doc = null;
            }

            return(doc);
        }
예제 #19
0
        void AddObjects(XmlDocument doc, AssemblyResolver resolver, string basePath, AssemblyDefinition adef)
        {
            Dictionary <TypeDefinition, ToolboxItemInfo> localObjects = new Dictionary <TypeDefinition, ToolboxItemInfo> ();

            foreach (TypeDefinition tdef in adef.MainModule.Types)
            {
                AddObject(tdef, localObjects, resolver, basePath, adef);
            }

            foreach (KeyValuePair <TypeDefinition, ToolboxItemInfo> item in localObjects)
            {
                TypeDefinition  tdef   = item.Key;
                ToolboxItemInfo tbinfo = item.Value;
                XmlElement      elem   = doc.CreateElement("object");
                elem.SetAttribute("type", tdef.FullName);
                elem.SetAttribute("allow-children", "false");
                elem.SetAttribute("palette-category", tbinfo.PaletteCategory);
                if (tdef.IsNotPublic)
                {
                    elem.SetAttribute("internal", "true");
                }
                doc.DocumentElement.AppendChild(elem);

                TypeDefinition curDef = tdef;
                while (curDef != null && curDef.FullName != tbinfo.BaseType)
                {
                    if (curDef != tdef && localObjects.ContainsKey(curDef))
                    {
                        tbinfo.BaseType = curDef.FullName;
                        break;
                    }
                    else if (curDef.Module.Assembly.Name.Name == "gtk-sharp")
                    {
                        tbinfo.BaseType = curDef.FullName;
                        break;
                    }
                    else if (curDef != tdef && GetToolboxItemInfo(resolver, basePath, curDef.Module.Assembly, curDef, false) != null)
                    {
                        tbinfo.BaseType = curDef.FullName;
                        break;
                    }
                    if (curDef.Module.Assembly != adef)
                    {
                        LibraryInfo li = Refresh(resolver, curDef.Module.FullyQualifiedName, basePath);
                        if (li.HasWidgets && li.GetToolboxItem(curDef.FullName, curDef.Module.Assembly.Name.Name) != null)
                        {
                            tbinfo.BaseType = curDef.FullName;
                            break;
                        }
                    }
                    AddProperties(curDef, elem);
                    AddEvents(curDef, elem);
                    if (curDef.BaseType != null && curDef.BaseType.FullName != tbinfo.BaseType)
                    {
                        curDef = FindTypeDefinition(resolver, adef, basePath, curDef.BaseType.FullName);
                    }
                    else
                    {
                        curDef = null;
                    }
                }

                elem.SetAttribute("base-type", tbinfo.BaseType);
            }
        }
예제 #20
0
		internal LibraryInfo Refresh (AssemblyResolver resolver, string assembly)
		{
			return Refresh (resolver, assembly, null);
		}
예제 #21
0
파일: LibraryCache.cs 프로젝트: mono/stetic
        internal LibraryInfo Refresh(AssemblyResolver resolver, string assembly)
        {
            assembly = Path.GetFullPath (assembly);

            if (IsCurrent (assembly))
                return Members [assembly];

            LibraryInfo info = Members [assembly];
            if (info == null) {
                info = new LibraryInfo ();
                info.File = assembly;
                Members.Add (info);
            }
            info.Timestamp = File.GetLastWriteTime (assembly).ToUniversalTime ();
            info.Guid = Guid.NewGuid ();
            Save ();
            AssemblyDefinition adef = AssemblyFactory.GetAssembly (assembly);
            XmlDocument objects = GetObjectsDoc (resolver, adef, assembly);
            if (objects != null) {
                info.ObjectsDocument = objects;
                XmlDocument gui = GetGuiDoc (adef);
                if (gui != null)
                    info.GuiDocument = gui;
            }
            return info;
        }
예제 #22
0
		internal TypeDefinition FindTypeDefinition (AssemblyResolver resolver, AssemblyDefinition assembly, string basePath, string fullName)
		{
			TypeDefinition t = FindTypeDefinition (new Hashtable (), resolver, basePath, assembly, fullName);
			return t;
		}
예제 #23
0
        public bool IsWidgetLibrary(string assemblyRef)
        {
            AssemblyResolver resolver = new AssemblyResolver(Backend);

            return(InternalIsWidgetLibrary(resolver, assemblyRef));
        }
예제 #24
0
		void Read (XmlDocument doc)
		{
			loading = true;

			try {
				Close ();
				
				XmlNode node = doc.SelectSingleNode ("/stetic-interface");
				if (node == null)
					throw new ApplicationException (Catalog.GetString ("Not a Stetic file according to node name."));
				
				// Load the assembly directories
				resolver = new AssemblyResolver (app);
				app.LoadLibraries (resolver, widgetLibraries);
				
				if (ownedGlobalActionGroups) {
					foreach (XmlElement groupElem in node.SelectNodes ("action-group")) 
						AddActionGroup (groupElem);
				}
				
				XmlElement iconsElem = node.SelectSingleNode ("icon-factory") as XmlElement;
				if (iconsElem != null)
					iconFactory.Read (this, iconsElem);
				
				foreach (XmlElement toplevel in node.SelectNodes ("widget"))
					AddWidget (toplevel);
				
			} finally {
				loading = false;
			}
		}
예제 #25
0
		void CheckDependencies (AssemblyResolver resolver, Hashtable visited, WidgetLibrary lib)
		{
			if (visited.Contains (lib.Name) || lib.Name == coreLibrary)
				return;
				
			visited [lib.Name] = lib;
			
			foreach (string dep in lib.GetLibraryDependencies ()) {
				WidgetLibrary depLib = Registry.GetWidgetLibrary (dep);
				if (depLib == null)
					AddLibrary (resolver, visited, dep);
				else
					CheckDependencies (resolver, visited, depLib);
			}
		}
예제 #26
0
        WidgetLibrary AddLibrary(AssemblyResolver resolver, Hashtable visited, string s)
        {
            if (Registry.IsRegistered (s)) {
                WidgetLibrary lib = Registry.GetWidgetLibrary (s);
                CheckDependencies (resolver, visited, lib);
                return lib;
            }

            WidgetLibrary alib = CreateLibrary (resolver, s);
            if (alib == null)
                return null;

            RegisterLibrary (resolver, visited, alib);
            return alib;
        }
예제 #27
0
		void AddDependencies (XmlElement elem, AssemblyResolver resolver, string filename, AssemblyDefinition asm)
		{
			string dir = Path.GetDirectoryName (filename);
			foreach (AssemblyNameReference aref in asm.MainModule.AssemblyReferences) {
				LibraryInfo info = GetInfo (resolver, aref.FullName, dir);
				if (info != null && info.HasWidgets) {
					XmlElement edep = elem.OwnerDocument.CreateElement ("dependency");
					edep.InnerText = info.File;
					elem.AppendChild (edep);
				}
			}
		}
예제 #28
0
		void LoadLibraries (AssemblyResolver resolver, Hashtable visited, IEnumerable libraries)
		{
			// Convert all assembly names to assembly paths before registering the libraries.
			// The registry and the library cache will only handle full paths.
			foreach (string s in libraries) {
				string sr = resolver.Resolve (s, null);
				if (sr != null)
					AddLibrary (resolver, visited, sr);
			}
			Registry.ReloadWidgetLibraries ();
		}
예제 #29
0
		bool ReferenceChainContainsGtk (AssemblyResolver resolver, AssemblyNameReference aref, Hashtable visited)
		{
			if (aref.Name == "gtk-sharp")
				return true;
			else if (visited.Contains (aref.Name))
				return false;

			visited [aref.Name] = aref;

			AssemblyDefinition adef = resolver.Resolve (aref);
			if (adef == null)
				return false;

			foreach (AssemblyNameReference child in adef.MainModule.AssemblyReferences)
				if (ReferenceChainContainsGtk (resolver, child, visited))
					return true;

			return false;
		}
예제 #30
0
		void RegisterLibrary (AssemblyResolver resolver, Hashtable visited, WidgetLibrary lib)
		{
			if (lib == null || visited.Contains (lib.Name))
				return;
				
			visited [lib.Name] = lib;

			foreach (string s in lib.GetLibraryDependencies ()) {
				if (!Application.InternalIsWidgetLibrary (resolver, s))
					continue;
				AddLibrary (resolver, visited, s);
			}
			
			try {
				Registry.RegisterWidgetLibrary (lib);
			} catch (Exception ex) {
				// Catch errors when loading a library to avoid aborting
				// the whole update method. After all, that's not a fatal
				// error (some widgets just won't be shown).
				// FIXME: return the error somewhere
				Console.WriteLine (ex);
			}
		}
예제 #31
0
		ToolboxItemInfo GetToolboxItemInfo (AssemblyResolver resolver, string baseDirectory, AssemblyDefinition asm, TypeDefinition tdef, bool checkBaseType)
		{
			if (tdef == null)
				return null;

			ToolboxItemInfo info = null;
			string category = "General";
			
			foreach (CustomAttribute attr in tdef.CustomAttributes) {
				switch (attr.AttributeType.FullName) {
				case "System.ComponentModel.ToolboxItemAttribute":
					if (attr.ConstructorArguments.Count > 0) {
						object param = attr.ConstructorArguments [0].Value;
						if (param == null)
							return null;
						else if (param.GetType () == typeof (bool)) {
							if ((bool) param)
								info = new ToolboxItemInfo ("Gtk.Widget");
							else 
								return null;
						} else if (param.GetType () == typeof (TypeReference))
							info = new ToolboxItemInfo ("Gtk.Widget");
						else
							return null;
					}
					break;
				case "System.ComponentModel.CategoryAttribute":
					if (attr.ConstructorArguments.Count > 0) {
						object param = attr.ConstructorArguments [0].Value;
						if (param.GetType () == typeof (string))
							category = (string) param;
					}
					break;
				default:
					continue;
				}
			}

			if (info == null && checkBaseType && tdef.BaseType != null) {
				string baseName = tdef.BaseType.FullName;

				foreach (AssemblyNameReference aref in asm.MainModule.AssemblyReferences) {
					LibraryInfo libInfo = GetInfo (resolver, aref.FullName, baseDirectory);
					if (libInfo != null && libInfo.HasWidgets) {
						ToolboxItemInfo binfo = libInfo.GetToolboxItem (baseName, aref.Name);
						if (binfo != null) {
							info = new ToolboxItemInfo (baseName);
							category = binfo.PaletteCategory;
							break;
						}
					}
				}
			}

			if (info != null)
				info.PaletteCategory = category;

			return info;
		}
예제 #32
0
		void CheckDependencies (AssemblyResolver resolver, Hashtable visited, WidgetLibrary lib)
		{
			if (visited.Contains (lib.Name))
				return;
				
			visited [lib.Name] = lib;
			
//			foreach (string dep in lib.GetLibraryDependencies ()) {
//				WidgetLibrary depLib = Registry.GetWidgetLibrary (dep);
//				if (depLib == null)
//					AddLibrary (resolver, visited, dep);
//				else
//					CheckDependencies (resolver, visited, depLib);
//			}
		}
예제 #33
0
		void AddObject (TypeDefinition tdef, Dictionary<TypeDefinition,ToolboxItemInfo> localObjects, AssemblyResolver resolver, string basePath, AssemblyDefinition adef)
		{
			if (tdef.IsAbstract || !tdef.IsClass) 
				return;

			ToolboxItemInfo tbinfo = GetToolboxItemInfo (resolver, basePath, adef, tdef, true);
			if (tbinfo == null)
				return;
			
			localObjects [tdef] = tbinfo;

			foreach (var nestedType in tdef.NestedTypes)
				AddObject (nestedType, localObjects, resolver, basePath, adef);
		}
예제 #34
0
		internal static bool InternalIsWidgetLibrary (AssemblyResolver resolver, string assemblyRef)
		{
			string path;

			if (assemblyRef.EndsWith (".dll") || assemblyRef.EndsWith (".exe")) {
				if (!File.Exists (assemblyRef))
					return false;
				path = assemblyRef;
			}
			else {
				path = resolver.Resolve (assemblyRef, null);
				if (path == null)
					return false;
			}

			return CecilWidgetLibrary.IsWidgetLibrary (path);
		}
예제 #35
0
		void AddObjects (XmlDocument doc, AssemblyResolver resolver, string basePath, AssemblyDefinition adef)
		{
			Dictionary<TypeDefinition,ToolboxItemInfo> localObjects = new Dictionary<TypeDefinition, ToolboxItemInfo> ();
			
			foreach (TypeDefinition tdef in adef.MainModule.Types) {
				AddObject (tdef, localObjects, resolver, basePath, adef);
			}
			
			foreach (KeyValuePair<TypeDefinition,ToolboxItemInfo> item in localObjects) {
				TypeDefinition tdef = item.Key;
				ToolboxItemInfo tbinfo = item.Value;
				XmlElement elem = doc.CreateElement ("object");
				elem.SetAttribute ("type", tdef.FullName);
				elem.SetAttribute ("allow-children", "false");
				elem.SetAttribute ("palette-category", tbinfo.PaletteCategory);
				if (tdef.IsNotPublic)
					elem.SetAttribute ("internal", "true");
				doc.DocumentElement.AppendChild (elem);
				
				TypeDefinition curDef = tdef;
				while (curDef != null && curDef.FullName != tbinfo.BaseType) {
					if (curDef != tdef && localObjects.ContainsKey (curDef)) {
						tbinfo.BaseType = curDef.FullName;
						break;
					}
					else if (curDef.Module.Assembly.Name.Name == "gtk-sharp") {
						tbinfo.BaseType = curDef.FullName;
						break;
					}
					else if (curDef != tdef && GetToolboxItemInfo (resolver, basePath, curDef.Module.Assembly, curDef, false) != null) {
						tbinfo.BaseType = curDef.FullName;
						break;
					}
					if (curDef.Module.Assembly != adef) {
						
						LibraryInfo li = Refresh (resolver, curDef.Module.FullyQualifiedName, basePath);
						if (li.HasWidgets && li.GetToolboxItem (curDef.FullName, curDef.Module.Assembly.Name.Name) != null) {
							tbinfo.BaseType = curDef.FullName;
							break;
						}
					}
					AddProperties (curDef, elem);
					AddEvents (curDef, elem);
					if (curDef.BaseType != null && curDef.BaseType.FullName != tbinfo.BaseType)
						curDef = FindTypeDefinition (resolver, adef, basePath, curDef.BaseType.FullName);
					else
						curDef = null;
				}
				
				elem.SetAttribute ("base-type", tbinfo.BaseType);
			}
		}
예제 #36
0
		XmlDocument GetObjectsDoc (AssemblyResolver resolver, AssemblyDefinition adef, string path, string baseDirectory)
		{
			XmlDocument doc = null;
			bool isMainLib = Path.GetFileName (path) == "libstetic.dll";
			
			try {
				EmbeddedResource res = GetResource (adef, "objects.xml");
				if (res != null) {
					MemoryStream stream = new MemoryStream (res.GetResourceData ());
					doc = new XmlDocument ();
					using (stream)
						doc.Load (stream);
				}

				if (resolver == null)
					resolver = new AssemblyResolver (null);

				baseDirectory = baseDirectory ?? Path.GetDirectoryName (path);
				
				if (!isMainLib) {
					// Make sure all referenced assemblies are up to date.
					foreach (AssemblyNameReference aref in adef.MainModule.AssemblyReferences) {
						Refresh (resolver, aref.FullName, baseDirectory);
					}
				}
			
				if (doc == null) {
//					Hashtable visited = new Hashtable ();
					foreach (AssemblyNameReference aref in adef.MainModule.AssemblyReferences) {
						if (aref.Name != "gtk-sharp") {
							LibraryInfo info = GetInfo (resolver, aref.FullName, baseDirectory);
							if (info == null || !info.HasWidgets)
								continue;
						}

						if (doc == null) {
							doc = new XmlDocument ();
							doc.AppendChild (doc.CreateElement ("objects"));
						}
						AddObjects (doc, resolver, baseDirectory, adef);
						break;
					}
				}

				if (doc != null && !isMainLib) {
					XmlElement elem = doc.CreateElement ("dependencies");
					doc.DocumentElement.AppendChild (elem);
					AddDependencies (elem, resolver, path, adef);
				}
			} catch (Exception e) {
				Console.WriteLine ("Got exception loading objects: " + e);
				doc = null;
			}

			return doc;
		}
예제 #37
0
		LibraryInfo GetInfo (AssemblyResolver resolver, string assembly, string baseDirectory)
		{
			string file = assembly;
			if (File.Exists (assembly))
				file = assembly;
			else {
				if (resolver == null)
					resolver = new AssemblyResolver (null);
				try {
					string path = resolver.Resolve (assembly, baseDirectory);
					if (path != null)
						file = path;
					else
						return null;
				} catch (Exception) {
					return null;
				}
			}

			file = Path.GetFullPath (file);
			
			LibraryInfo info = Members [file];
			if (info == null) {
				info = new LibraryInfo ();
				info.File = file ?? assembly;
				Members.Add (info);
			}
			return info;
		}
예제 #38
0
		void Read (XmlDocument doc)
		{
			loading = true;
			string basePath = fileName != null ? Path.GetDirectoryName (fileName) : null;
			
			try {
				string fn = fileName;
				Close ();
				fileName = fn;
				
				XmlNode node = doc.SelectSingleNode ("/stetic-interface");
				if (node == null)
					throw new ApplicationException (Catalog.GetString ("Not a Stetic file according to node name."));
				
				// Load configuration options
				foreach (XmlNode configNode in node.SelectNodes ("configuration/*")) {
					XmlElement config = configNode as XmlElement;
					if (config == null) continue;
					
					if (config.LocalName == "images-root-path")
						imagesRootPath = config.InnerText;
					else if (config.LocalName == "target-gtk-version")
						targetGtkVersion = config.InnerText;
				}
				
				// Load the assembly directories
				resolver = new AssemblyResolver (app);
				foreach (XmlElement libElem in node.SelectNodes ("import/assembly-directory")) {
					string dir = libElem.GetAttribute ("path");
					if (dir.Length > 0) {
						if (basePath != null && !Path.IsPathRooted (dir)) {
							dir = FromOSAgnosticRelPath (Path.Combine (basePath, dir));
							if (Directory.Exists (dir))
								dir = Path.GetFullPath (dir);
						}
						resolver.Directories.Add (dir);
					}
				}
				
				// Import the referenced libraries
				foreach (XmlElement libElem in node.SelectNodes ("import/widget-library")) {
					string libname = libElem.GetAttribute ("name");
					if (libname.EndsWith (".dll") || libname.EndsWith (".exe")) {
						if (basePath != null && !Path.IsPathRooted (libname)) {
							libname = FromOSAgnosticRelPath (Path.Combine (basePath, libname));
							if (File.Exists (libname))
								libname = Path.GetFullPath (libname);
						}
					}
					widgetLibraries.Add (libname);
					if (libElem.GetAttribute ("internal") == "true")
						internalLibs.Add (libname);
				}
				
				app.LoadLibraries (resolver, widgetLibraries);
				
				ObjectReader reader = new ObjectReader (this, FileFormat.Native);
				
				if (ownedGlobalActionGroups) {
					foreach (XmlElement groupElem in node.SelectNodes ("action-group")) {
						Wrapper.ActionGroup actionGroup = new Wrapper.ActionGroup ();
						actionGroup.Read (reader, groupElem);
						actionGroups.Add (actionGroup);
					}
				}
				
				XmlElement iconsElem = node.SelectSingleNode ("icon-factory") as XmlElement;
				if (iconsElem != null)
					iconFactory.Read (this, iconsElem);
				
				foreach (XmlElement toplevel in node.SelectNodes ("widget")) {
					topLevels.Add (new WidgetData (toplevel.GetAttribute ("id"), toplevel, null));
				}
			} finally {
				loading = false;
			}
		}
예제 #39
0
        void Read(XmlDocument doc)
        {
            loading = true;
            string basePath = fileName != null?Path.GetDirectoryName(fileName) : null;

            try {
                string fn = fileName;
                Close();
                fileName = fn;

                XmlNode node = doc.SelectSingleNode("/stetic-interface");
                if (node == null)
                {
                    throw new ApplicationException(Catalog.GetString("Not a Stetic file according to node name."));
                }

                // Load configuration options
                foreach (XmlNode configNode in node.SelectNodes("configuration/*"))
                {
                    XmlElement config = configNode as XmlElement;
                    if (config == null)
                    {
                        continue;
                    }

                    if (config.LocalName == "images-root-path")
                    {
                        imagesRootPath = config.InnerText;
                    }
                    else if (config.LocalName == "target-gtk-version")
                    {
                        targetGtkVersion = config.InnerText;
                    }
                }

                // Load the assembly directories
                resolver = new AssemblyResolver(app);
                foreach (XmlElement libElem in node.SelectNodes("import/assembly-directory"))
                {
                    string dir = libElem.GetAttribute("path");
                    if (dir.Length > 0)
                    {
                        if (basePath != null && !Path.IsPathRooted(dir))
                        {
                            dir = FromOSAgnosticRelPath(Path.Combine(basePath, dir));
                            if (Directory.Exists(dir))
                            {
                                dir = Path.GetFullPath(dir);
                            }
                        }
                        resolver.Directories.Add(dir);
                    }
                }

                // Import the referenced libraries
                foreach (XmlElement libElem in node.SelectNodes("import/widget-library"))
                {
                    string libname = libElem.GetAttribute("name");
                    if (libname.EndsWith(".dll") || libname.EndsWith(".exe"))
                    {
                        if (basePath != null && !Path.IsPathRooted(libname))
                        {
                            libname = FromOSAgnosticRelPath(Path.Combine(basePath, libname));
                            if (File.Exists(libname))
                            {
                                libname = Path.GetFullPath(libname);
                            }
                        }
                    }
                    widgetLibraries.Add(libname);
                    if (libElem.GetAttribute("internal") == "true")
                    {
                        internalLibs.Add(libname);
                    }
                }

                app.LoadLibraries(resolver, widgetLibraries);

                ObjectReader reader = new ObjectReader(this, FileFormat.Native);

                if (ownedGlobalActionGroups)
                {
                    foreach (XmlElement groupElem in node.SelectNodes("action-group"))
                    {
                        Wrapper.ActionGroup actionGroup = new Wrapper.ActionGroup();
                        actionGroup.Read(reader, groupElem);
                        actionGroups.Add(actionGroup);
                    }
                }

                XmlElement iconsElem = node.SelectSingleNode("icon-factory") as XmlElement;
                if (iconsElem != null)
                {
                    iconFactory.Read(this, iconsElem);
                }

                foreach (XmlElement toplevel in node.SelectNodes("widget"))
                {
                    topLevels.Add(new WidgetData(toplevel.GetAttribute("id"), toplevel, null));
                }
            } finally {
                loading = false;
            }
        }