| 0: | // Module.cs | |
| 1: | // Copyright (c) 2001 Mike Krueger | |
| 2: | // | |
| 3: | // This program is free software; you can redistribute it and/or modify | |
| 4: | // it under the terms of the GNU General Public License as published by | |
| 5: | // the Free Software Foundation; either version 2 of the License, or | |
| 6: | // (at your option) any later version. | |
| 7: | // | |
| 8: | // This program is distributed in the hope that it will be useful, | |
| 9: | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 10: | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 11: | // GNU General Public License for more details. | |
| 12: | // | |
| 13: | // You should have received a copy of the GNU General Public License | |
| 14: | // along with this program; if not, write to the Free Software | |
| 15: | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 16: | ||
| 17: | using System; | |
| 18: | using System.Collections; | |
| 19: | using System.Drawing; | |
| 20: | using System.Resources; | |
| 21: | using System.Reflection; | |
| 22: | using System.IO; | |
| 23: | using System.Xml; | |
| 24: | using SharpDevelop.Internal.Project; | |
| 25: | ||
| 26: | namespace SharpDevelop.Internal.Modules { | |
| 27: | ||
| 28: | public class Module | |
| 29: | { | |
| 30: | string name = null; | |
| 31: | string version = null; | |
| 32: | string author = null; | |
| 33: | string copyright = null; | |
| 34: | string url = null; | |
| 35: | string description = null; | |
| 36: | string language = null; | |
| 37: | string filefilter = null; | |
| 38: | ||
| 39: | string[] extensions = null; | |
| 40: | ||
| 41: | IDisplayModule displaymodule = null; | |
| 42: | ILanguageModule languagemodule = null; | |
| 43: | ||
| 44: | Bitmap projecticon = null; | |
| 45: | Hashtable fileicons = new Hashtable(); | |
| 46: | Hashtable icons = new Hashtable(); | |
| 47: | ||
| 48: | public string Name { | |
| 49: | get { | |
| 50: | return name; | |
| 51: | } | |
| 52: | } | |
| 53: | ||
| 54: | /// <summary> | |
| 55: | /// Returns the filefilter for File->Open and File->Save commands. | |
| 56: | /// </summary> | |
| 57: | public string FileFilter { | |
| 58: | get { | |
| 59: | return filefilter; | |
| 60: | } | |
| 61: | } | |
| 62: | ||
| 63: | public string Version { | |
| 64: | get { | |
| 65: | return version; | |
| 66: | } | |
| 67: | } | |
| 68: | public string Author { | |
| 69: | get { | |
| 70: | return author; | |
| 71: | } | |
| 72: | } | |
| 73: | public string Copyright { | |
| 74: | get { | |
| 75: | return copyright; | |
| 76: | } | |
| 77: | } | |
| 78: | public string Url { | |
| 79: | get { | |
| 80: | return url; | |
| 81: | } | |
| 82: | } | |
| 83: | public string Description { | |
| 84: | get { | |
| 85: | return description; | |
| 86: | } | |
| 87: | } | |
| 88: | public string Language { | |
| 89: | get { | |
| 90: | return language; | |
| 91: | } | |
| 92: | } | |
| 93: | public string[] Extensions { | |
| 94: | get { | |
| 95: | return extensions; | |
| 96: | } | |
| 97: | } | |
| 98: | public IDisplayModule DisplayModule { | |
| 99: | get { | |
| 100: | return displaymodule; | |
| 101: | } | |
| 102: | } | |
| 103: | public ILanguageModule LanguageModule { | |
| 104: | get { | |
| 105: | return languagemodule; | |
| 106: | } | |
| 107: | } | |
| 108: | ||
| 109: | public Hashtable Icons { | |
| 110: | get { | |
| 111: | return icons; | |
| 112: | } | |
| 113: | } | |
| 114: | public Hashtable FileIcons { | |
| 115: | get { | |
| 116: | return fileicons; | |
| 117: | } | |
| 118: | } | |
| 119: | public Bitmap ProjectIcon { | |
| 120: | get { | |
| 121: | return projecticon; | |
| 122: | } | |
| 123: | } | |
| 124: | ||
| 125: | Bitmap LoadIcon(string path, string locationname) | |
| 126: | { | |
| 127: | if (File.Exists(path + locationname)) { | |
| 128: | return new Bitmap(path + locationname); | |
| 129: | } else { | |
| 130: | string[] location = locationname.Split(new char[] {':'}); | |
| 131: | Assembly assembly = Assembly.LoadFrom(path + location[0]); | |
| 132: | ResourceManager resources = new ResourceManager(location[1], assembly); | |
| 133: | return (Bitmap)resources.GetObject(location[2]); | |
| 134: | } | |
| 135: | } | |
| 136: | ||
| 137: | public Module(string filename) | |
| 138: | { | |
| 139: | string path = Path.GetDirectoryName(filename) + Path.DirectorySeparatorChar; | |
| 140: | XmlDocument doc = new XmlDocument(); | |
| 141: | doc.Load(filename); | |
| 142: | ||
| 143: | XmlElement moduledescription = doc.DocumentElement["Module"]; | |
| 144: | ||
| 145: | name = moduledescription.Attributes["Name"].InnerText; | |
| 146: | version = moduledescription.Attributes["Version"].InnerText; | |
| 147: | ||
| 148: | extensions = moduledescription["Extensions"].InnerText.Split(new char[] {'|'}); | |
| 149: | for (int i = 0; i < extensions.Length; ++i) | |
| 150: | extensions[i] = extensions[i].ToUpper(); | |
| 151: | ||
| 152: | language = moduledescription["Language"].InnerText; | |
| 153: | author = moduledescription["Author"].InnerText; | |
| 154: | copyright = moduledescription["Copyright"].InnerText; | |
| 155: | url = moduledescription["Url"].InnerText; | |
| 156: | description = moduledescription["Description"].InnerText; | |
| 157: | ||
| 158: | if (moduledescription["FileFilter"] != null) { | |
| 159: | filefilter = moduledescription["FileFilter"].InnerText; | |
| 160: | } | |
| 161: | ||
| 162: | if (doc.DocumentElement["LanguageModule"] != null) { | |
| 163: | Assembly assembly = Assembly.LoadFrom(path + doc.DocumentElement["LanguageModule"].Attributes["Assembly"].InnerText); | |
| 164: | languagemodule = (ILanguageModule)assembly.CreateInstance(doc.DocumentElement["LanguageModule"].Attributes["Class"].InnerText); | |
| 165: | if (languagemodule == null) { | |
| 166: | throw new Exception("Can't create instance of LanguageModule for " + language + " (" + filename + ")"); | |
| 167: | } | |
| 168: | } | |
| 169: | ||
| 170: | if (doc.DocumentElement["DisplayModule"] != null) { | |
| 171: | Assembly assembly = Assembly.LoadFrom(path + doc.DocumentElement["DisplayModule"].Attributes["Assembly"].InnerText); | |
| 172: | displaymodule = (IDisplayModule)assembly.CreateInstance(doc.DocumentElement["DisplayModule"].Attributes["Class"].InnerText); | |
| 173: | if (displaymodule == null) { | |
| 174: | throw new Exception("Can't create instance of DisplayModule for " + language + " (" + filename + ")"); | |
| 175: | } | |
| 176: | } | |
| 177: | ||
| 178: | if (doc.DocumentElement["Icons"] != null) { | |
| 179: | XmlNodeList nodes = doc.DocumentElement["Icons"].ChildNodes; | |
| 180: | foreach (XmlElement iconnode in nodes) { | |
| 181: | switch (iconnode.Name) { | |
| 182: | case "ProjectIcon": | |
| 183: | projecticon = LoadIcon(path, iconnode.Attributes["Location"].InnerText); | |
| 184: | fileicons["ProjectIcon:" + language] = projecticon; | |
| 185: | break; | |
| 186: | case "FileIcon": | |
| 187: | fileicons[iconnode.Attributes["Extension"].InnerText] = LoadIcon(path, iconnode.Attributes["Location"].InnerText); | |
| 188: | break; | |
| 189: | case "Icon": | |
| 190: | icons[iconnode.Attributes["Name"].InnerText] = LoadIcon(path, iconnode.Attributes["Location"].InnerText); | |
| 191: | break; | |
| 192: | } | |
| 193: | } | |
| 194: | } | |
| 195: | } | |
| 196: | } | |
| 197: | } |
This page was automatically generated by SharpDevelop.