/// <summary> /// Refreshes the list of plug-ins of the specified type. /// </summary> /// <param name="type">The type of plug-in list to refresh.</param> protected void RefreshPlugInList(PlugInTypes type) { string dir = null; switch (type) { case PlugInTypes.Vertices: dir = Path.GetDirectoryName(Application.ExecutablePath) + "\\Plug-Ins\\Vertices\\"; _vertexPlugins.Clear(); break; case PlugInTypes.Textures: dir = Path.GetDirectoryName(Application.ExecutablePath) + "\\Plug-Ins\\Textures\\"; _texturePlugins.Clear(); break; case PlugInTypes.Importing: dir = Path.GetDirectoryName(Application.ExecutablePath) + "\\Plug-Ins\\Importing\\"; _importPlugins.Clear(); break; case PlugInTypes.Exporting: dir = Path.GetDirectoryName(Application.ExecutablePath) + "\\Plug-Ins\\Exporting\\"; _exportPlugins.Clear(); break; default: break; } if (dir != null) { LoadPlugInsWithinDirectory(dir, type); } }
/// <summary> /// Loads the plug-ins from the specified directory, including sub-directories. /// </summary> /// <param name="dir">Directory to load plug-ins from.</param> /// <param name="type">Type of plug-in to load.</param> private void LoadPlugInDirectory(string dir, PlugInTypes type) { try { // Load the plug-ins withing the current directory LoadPlugInsWithinDirectory(dir, type); // Load the plug-ins nested inside sub-directories string[] directories = Directory.GetDirectories(dir); foreach (string d in directories) { LoadPlugInDirectory(d, type); } } catch (Exception e) { Debug.Assert(true, e.Source + ": " + e.Message, e.StackTrace); } }
/// <summary> /// Load the plug-ins from within the specified directory. /// </summary> /// <param name="dir">Directory to load plug-ins from.</param> /// <param name="type">Type of plug-in to load.</param> private void LoadPlugInsWithinDirectory( string dir, PlugInTypes type ) { string[] files = Directory.GetFiles( dir, "*.dll" ); Assembly asm; ArrayList plugs; if ( files != null ) { // Load each file found into the appropriate plug-in type collection switch ( type ) { case PlugInTypes.Vertices: try { foreach ( string f in files ) { asm = Assembly.LoadFile( f ); plugs = LoadPlugIns( asm ); foreach ( PlugIn p in plugs ) { _vertexPlugins.Add( p ); } } } catch ( Exception e ) { Debug.Assert( true, e.Source + ": " + e.Message, e.StackTrace ); } break; case PlugInTypes.Textures: try { foreach ( string f in files ) { asm = Assembly.LoadFile( f ); plugs = LoadPlugIns( asm ); foreach ( PlugIn p in plugs ) { _texturePlugins.Add( p ); } } } catch ( Exception e ) { Debug.Assert( true, e.Source + ": " + e.Message, e.StackTrace ); } break; case PlugInTypes.Importing: try { foreach ( string f in files ) { asm = Assembly.LoadFile( f ); plugs = LoadPlugIns( asm ); foreach ( PlugIn p in plugs ) { _importPlugins.Add( p ); } } } catch ( Exception e ) { Debug.Assert( true, e.Source + ": " + e.Message, e.StackTrace ); } break; case PlugInTypes.Exporting: try { foreach ( string f in files ) { asm = Assembly.LoadFile( f ); plugs = LoadPlugIns( asm ); foreach ( PlugIn p in plugs ) { _exportPlugins.Add( p ); } } } catch ( Exception e ) { Debug.Assert( true, e.Source + ": " + e.Message, e.StackTrace ); } break; default: // Do nothing break; } } }
/// <summary> /// Loads the plug-ins from the specified directory, including sub-directories. /// </summary> /// <param name="dir">Directory to load plug-ins from.</param> /// <param name="type">Type of plug-in to load.</param> private void LoadPlugInDirectory( string dir, PlugInTypes type ) { try { // Load the plug-ins withing the current directory LoadPlugInsWithinDirectory( dir, type ); // Load the plug-ins nested inside sub-directories string[] directories = Directory.GetDirectories( dir ); foreach ( string d in directories ) { LoadPlugInDirectory( d, type ); } } catch ( Exception e ) { Debug.Assert( true, e.Source + ": " + e.Message, e.StackTrace ); } }
/// <summary> /// Refreshes the list of plug-ins of the specified type. /// </summary> /// <param name="type">The type of plug-in list to refresh.</param> protected void RefreshPlugInList( PlugInTypes type ) { string dir = null; switch ( type ) { case PlugInTypes.Vertices: dir = Path.GetDirectoryName( Application.ExecutablePath ) + "\\Plug-Ins\\Vertices\\"; _vertexPlugins.Clear(); break; case PlugInTypes.Textures: dir = Path.GetDirectoryName( Application.ExecutablePath ) + "\\Plug-Ins\\Textures\\"; _texturePlugins.Clear(); break; case PlugInTypes.Importing: dir = Path.GetDirectoryName( Application.ExecutablePath ) + "\\Plug-Ins\\Importing\\"; _importPlugins.Clear(); break; case PlugInTypes.Exporting: dir = Path.GetDirectoryName( Application.ExecutablePath ) + "\\Plug-Ins\\Exporting\\"; _exportPlugins.Clear(); break; default: break; } if ( dir != null ) LoadPlugInsWithinDirectory( dir, type ); }
/// <summary> /// Loads a plug-in of the specified type. /// </summary> /// <param name="type">The type of plug-in to load.</param> public void LoadPlugIn( PlugInTypes type ) { try { OpenFileDialog dlgOpen = new OpenFileDialog(); DialogResult result = DialogResult.OK; bool valid = false; string filename = null; string destFile = null; string plugType = null; dlgOpen.Filter = "DLL Files (*.dll)|*.dll|All files (*.*)|*.*" ; dlgOpen.InitialDirectory = Path.GetDirectoryName( Application.ExecutablePath ); switch ( type ) { case PlugInTypes.Vertices: plugType = "Vertices\\"; break; case PlugInTypes.Textures: plugType = "Textures\\"; break; case PlugInTypes.Importing: plugType = "Importing\\"; break; case PlugInTypes.Exporting: plugType = "Exporting\\"; break; default: break; } while ( !valid && plugType != null ) { result = dlgOpen.ShowDialog(); if ( result == DialogResult.OK && dlgOpen.FileName != null ) { filename = Path.GetFileName( dlgOpen.FileName ); destFile = Path.GetDirectoryName( Application.ExecutablePath ) + "\\Plug-Ins\\" + plugType + filename; if ( !File.Exists( destFile ) ) valid = true; else MessageBox.Show( "Plug-in already exists!", "Cannot Load Plug-In", MessageBoxButtons.OK, MessageBoxIcon.Exclamation ); } else valid = true; } if ( result == DialogResult.OK && dlgOpen.FileName != null && plugType != null ) { File.Copy( dlgOpen.FileName, destFile, false ); RefreshPlugInList( type ); } } catch { MessageBox.Show( "The plug-in could not be loaded.", "Cannot Load Plug-In", MessageBoxButtons.OK, MessageBoxIcon.Error ); } finally { } }
/// <summary> /// Loads a plug-in of the specified type. /// </summary> /// <param name="type">The type of plug-in to load.</param> public void LoadPlugIn(PlugInTypes type) { try { OpenFileDialog dlgOpen = new OpenFileDialog(); DialogResult result = DialogResult.OK; bool valid = false; string filename = null; string destFile = null; string plugType = null; dlgOpen.Filter = "DLL Files (*.dll)|*.dll|All files (*.*)|*.*"; dlgOpen.InitialDirectory = Path.GetDirectoryName(Application.ExecutablePath); switch (type) { case PlugInTypes.Vertices: plugType = "Vertices\\"; break; case PlugInTypes.Textures: plugType = "Textures\\"; break; case PlugInTypes.Importing: plugType = "Importing\\"; break; case PlugInTypes.Exporting: plugType = "Exporting\\"; break; default: break; } while (!valid && plugType != null) { result = dlgOpen.ShowDialog(); if (result == DialogResult.OK && dlgOpen.FileName != null) { filename = Path.GetFileName(dlgOpen.FileName); destFile = Path.GetDirectoryName(Application.ExecutablePath) + "\\Plug-Ins\\" + plugType + filename; if (!File.Exists(destFile)) { valid = true; } else { MessageBox.Show("Plug-in already exists!", "Cannot Load Plug-In", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else { valid = true; } } if (result == DialogResult.OK && dlgOpen.FileName != null && plugType != null) { File.Copy(dlgOpen.FileName, destFile, false); RefreshPlugInList(type); } } catch { MessageBox.Show("The plug-in could not be loaded.", "Cannot Load Plug-In", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { } }
/// <summary> /// Load the plug-ins from within the specified directory. /// </summary> /// <param name="dir">Directory to load plug-ins from.</param> /// <param name="type">Type of plug-in to load.</param> private void LoadPlugInsWithinDirectory(string dir, PlugInTypes type) { string[] files = Directory.GetFiles(dir, "*.dll"); Assembly asm; ArrayList plugs; if (files != null) { // Load each file found into the appropriate plug-in type collection switch (type) { case PlugInTypes.Vertices: try { foreach (string f in files) { asm = Assembly.LoadFile(f); plugs = LoadPlugIns(asm); foreach (PlugIn p in plugs) { _vertexPlugins.Add(p); } } } catch (Exception e) { Debug.Assert(true, e.Source + ": " + e.Message, e.StackTrace); } break; case PlugInTypes.Textures: try { foreach (string f in files) { asm = Assembly.LoadFile(f); plugs = LoadPlugIns(asm); foreach (PlugIn p in plugs) { _texturePlugins.Add(p); } } } catch (Exception e) { Debug.Assert(true, e.Source + ": " + e.Message, e.StackTrace); } break; case PlugInTypes.Importing: try { foreach (string f in files) { asm = Assembly.LoadFile(f); plugs = LoadPlugIns(asm); foreach (PlugIn p in plugs) { _importPlugins.Add(p); } } } catch (Exception e) { Debug.Assert(true, e.Source + ": " + e.Message, e.StackTrace); } break; case PlugInTypes.Exporting: try { foreach (string f in files) { asm = Assembly.LoadFile(f); plugs = LoadPlugIns(asm); foreach (PlugIn p in plugs) { _exportPlugins.Add(p); } } } catch (Exception e) { Debug.Assert(true, e.Source + ": " + e.Message, e.StackTrace); } break; default: // Do nothing break; } } }