//**************************************** /// <summary> /// Initialise the GuiService, automatically selecting the GUI Toolkit /// </summary> public static void Init() { //**************************************** GuiToolkit NewToolkit; string RootPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Toolkits"); string ToolkitPath = null; Assembly MyAssembly; object[] Attribs; //**************************************** foreach (string Argument in Environment.GetCommandLineArgs()) { // Was the toolkit specified on the command line? if (Argument.StartsWith("-Toolkit:")) { ToolkitPath = Path.Combine(RootPath, string.Format("Proximity.Gui.{0}.dll", Argument.Substring(9))); break; } } //**************************************** if (ToolkitPath == null) { // No toolkit specified, pick an appropriate one automatically switch (Environment.OSVersion.Platform) { case PlatformID.Win32NT: case PlatformID.Win32S: case PlatformID.Win32Windows: case PlatformID.WinCE: try { // Check if WPF is installed MyAssembly = Assembly.Load("PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); // Success, use the WPF toolkit ToolkitPath = Path.Combine(RootPath, "Proximity.Gui.Wpf.dll"); } catch (FileNotFoundException) { // Exception, use WinForms instead ToolkitPath = Path.Combine(RootPath, "Proximity.Gui.WinForms.dll"); } break; case PlatformID.MacOSX: case PlatformID.Unix: case (PlatformID)128: ToolkitPath = Path.Combine(RootPath, "Proximity.Gui.GtkSharp.dll"); break; default: throw new PlatformNotSupportedException("Platform is unsupported"); } } //**************************************** // Load the Toolkit Assembly MyAssembly = Assembly.LoadFrom(ToolkitPath); // Find the Attribute that tells us the Toolkit Class Attribs = MyAssembly.GetCustomAttributes(typeof(GuiToolkitAttribute), false); if (Attribs.Length == 0) { throw new GuiException("Missing Toolkit Attribute"); } // Create the Toolkit NewToolkit = (GuiToolkit)Activator.CreateInstance(((GuiToolkitAttribute)Attribs[0]).ToolkitType); //**************************************** Init(NewToolkit); }