| 0: | // ModuleManager.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.Xml; | |
| 19: | using System.IO; | |
| 20: | using System.Collections; | |
| 21: | using System.Reflection; | |
| 22: | using System.CodeDom.Compiler; | |
| 23: | using System.Windows.Forms; | |
| 24: | using SharpDevelop.Tool.Function; | |
| 25: | using SharpDevelop.Internal.Text; | |
| 26: | using SharpDevelop.Internal.Project; | |
| 27: | ||
| 28: | ||
| 29: | namespace SharpDevelop.Internal.Modules { | |
| 30: | ||
| 31: | public class ModuleManager | |
| 32: | { | |
| 33: | static ArrayList modules = new ArrayList(); | |
| 34: | ||
| 35: | public static ArrayList Modules { | |
| 36: | get { | |
| 37: | return modules; | |
| 38: | } | |
| 39: | } | |
| 40: | ||
| 41: | public static Module GetModulePerLanguageName(string languagename) | |
| 42: | { | |
| 43: | foreach (Module module in modules) { | |
| 44: | if (module.Language == languagename) | |
| 45: | return module; | |
| 46: | } | |
| 47: | return null; | |
| 48: | } | |
| 49: | ||
| 50: | public static Module GetModulePerFileName(string filename) | |
| 51: | { | |
| 52: | string extension = Path.GetExtension(filename).ToUpper(); | |
| 53: | foreach (Module module in modules) { | |
| 54: | foreach (string ext in module.Extensions) { | |
| 55: | if (extension == ext) { | |
| 56: | return module; | |
| 57: | } | |
| 58: | } | |
| 59: | } | |
| 60: | return null; | |
| 61: | } | |
| 62: | ||
| 63: | public static Module GetModulePerProjectFile(string filename) | |
| 64: | { | |
| 65: | XmlDocument doc = new XmlDocument(); | |
| 66: | doc.Load(filename); | |
| 67: | return GetModulePerLanguageName(doc.DocumentElement.Attributes["projecttype"].InnerText); | |
| 68: | } | |
| 69: | ||
| 70: | static void LoadModuleDefinition(string filename) | |
| 71: | { | |
| 72: | try { | |
| 73: | modules.Add(new Module(filename)); | |
| 74: | } catch (Exception e) { | |
| 75: | throw new ApplicationException("Error in module " + filename + "\n " + e.ToString()); | |
| 76: | } | |
| 77: | } | |
| 78: | ||
| 79: | public static void LoadModules() | |
| 80: | { | |
| 81: | FileUtility.SearchDirectory(Application.StartupPath + | |
| 82: | Path.DirectorySeparatorChar + ".." + | |
| 83: | Path.DirectorySeparatorChar + "add-ins" + | |
| 84: | Path.DirectorySeparatorChar + "modules", "*.xml", new FileSearchDelegate(LoadModuleDefinition)); | |
| 85: | } | |
| 86: | } | |
| 87: | } |
This page was automatically generated by SharpDevelop.