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 (); }
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; }
public bool IsWidgetLibrary (string assemblyRef) { AssemblyResolver resolver = new AssemblyResolver (Backend); return InternalIsWidgetLibrary (resolver, assemblyRef); }
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); } }
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; }
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; } }
internal void LoadLibraries(AssemblyResolver resolver, Hashtable visited, IEnumerable libraries) { foreach (string s in libraries) AddLibrary (resolver, visited, s); }
internal void LoadLibraries (AssemblyResolver resolver, IEnumerable libraries) { try { Registry.BeginChangeSet (); Hashtable visited = new Hashtable (); LoadLibraries (resolver, visited, libraries); } finally { Registry.EndChangeSet (); } }
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; }
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; }
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; }
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); }
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); }
internal TypeDefinition FindTypeDefinition(AssemblyResolver resolver, AssemblyDefinition assembly, string basePath, string fullName) { TypeDefinition t = FindTypeDefinition(new Hashtable(), resolver, basePath, assembly, fullName); return(t); }
internal LibraryInfo Refresh(AssemblyResolver resolver, string assembly) { return(Refresh(resolver, assembly, null)); }
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); }
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); } }
internal LibraryInfo Refresh (AssemblyResolver resolver, string assembly) { return Refresh (resolver, assembly, null); }
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; }
internal TypeDefinition FindTypeDefinition (AssemblyResolver resolver, AssemblyDefinition assembly, string basePath, string fullName) { TypeDefinition t = FindTypeDefinition (new Hashtable (), resolver, basePath, assembly, fullName); return t; }
public bool IsWidgetLibrary(string assemblyRef) { AssemblyResolver resolver = new AssemblyResolver(Backend); return(InternalIsWidgetLibrary(resolver, assemblyRef)); }
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; } }
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); } }
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; }
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); } } }
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 (); }
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; }
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); } }
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; }
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); // } }
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); }
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); }
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); } }
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; }
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; }
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; } }
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; } }