2008-01-02 21:49:43 +00:00
|
|
|
|
|
|
|
#region ================== Copyright (c) 2007 Pascal vd Heiden
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
|
|
|
* This program is released under GNU General Public License
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Globalization;
|
|
|
|
using System.Text;
|
|
|
|
using System.IO;
|
|
|
|
using CodeImp.DoomBuilder.Editing;
|
2008-04-27 12:07:26 +00:00
|
|
|
using System.Reflection;
|
2008-10-15 11:46:43 +00:00
|
|
|
using CodeImp.DoomBuilder.Map;
|
|
|
|
using CodeImp.DoomBuilder.Rendering;
|
2009-02-01 22:33:01 +00:00
|
|
|
using CodeImp.DoomBuilder.Windows;
|
2008-01-02 21:49:43 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Plugins
|
|
|
|
{
|
|
|
|
internal class PluginManager
|
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
// Plugins
|
|
|
|
private List<Plugin> plugins;
|
|
|
|
|
|
|
|
// Disposing
|
|
|
|
private bool isdisposed = false;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
2008-11-27 10:33:09 +00:00
|
|
|
|
|
|
|
internal List<Plugin> Plugins { get { return plugins; } }
|
2008-01-02 21:49:43 +00:00
|
|
|
public bool IsDisposed { get { return isdisposed; } }
|
2008-11-27 10:33:09 +00:00
|
|
|
|
2008-01-02 21:49:43 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
public PluginManager()
|
2008-05-16 20:00:49 +00:00
|
|
|
{
|
|
|
|
// Make lists
|
|
|
|
this.plugins = new List<Plugin>();
|
|
|
|
|
|
|
|
// We have no destructor
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disposer
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
// Not already disposed?
|
|
|
|
if(!isdisposed)
|
|
|
|
{
|
|
|
|
// Clean up
|
|
|
|
foreach(Plugin p in plugins) p.Dispose();
|
|
|
|
|
|
|
|
// Done
|
|
|
|
isdisposed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
2008-11-13 16:21:11 +00:00
|
|
|
|
|
|
|
// This creates a list of assemblies
|
|
|
|
public List<Assembly> GetPluginAssemblies()
|
|
|
|
{
|
|
|
|
List<Assembly> asms = new List<Assembly>(plugins.Count);
|
|
|
|
foreach(Plugin p in plugins)
|
|
|
|
asms.Add(p.Assembly);
|
|
|
|
return asms;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-16 20:00:49 +00:00
|
|
|
// This loads all plugins
|
|
|
|
public void LoadAllPlugins()
|
2008-01-02 21:49:43 +00:00
|
|
|
{
|
|
|
|
string[] filenames;
|
|
|
|
Type[] editclasses;
|
|
|
|
EditModeAttribute[] emattrs;
|
|
|
|
EditModeInfo editmodeinfo;
|
|
|
|
Plugin p;
|
2008-05-16 20:00:49 +00:00
|
|
|
|
2008-01-02 21:49:43 +00:00
|
|
|
// Find all .dll files
|
|
|
|
filenames = Directory.GetFiles(General.PluginsPath, "*.dll", SearchOption.TopDirectoryOnly);
|
|
|
|
foreach(string fn in filenames)
|
|
|
|
{
|
|
|
|
// Load plugin from this file
|
2008-05-13 22:28:30 +00:00
|
|
|
try
|
2008-01-02 21:49:43 +00:00
|
|
|
{
|
2008-05-13 22:28:30 +00:00
|
|
|
p = new Plugin(fn);
|
|
|
|
}
|
2008-05-14 21:48:36 +00:00
|
|
|
catch(InvalidProgramException)
|
2008-05-13 22:28:30 +00:00
|
|
|
{
|
|
|
|
p = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Continue if no errors
|
|
|
|
if((p != null) && (!p.IsDisposed))
|
|
|
|
{
|
|
|
|
// Add to plugins
|
|
|
|
this.plugins.Add(p);
|
|
|
|
|
2008-05-16 20:00:49 +00:00
|
|
|
// Load actions
|
|
|
|
General.Actions.LoadActions(p.Assembly);
|
|
|
|
|
|
|
|
// Plugin is now initialized
|
|
|
|
p.Plug.OnInitialize();
|
2008-01-02 21:49:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-27 12:07:26 +00:00
|
|
|
// This returns a plugin by assembly, or null when plugin cannot be found
|
|
|
|
public Plugin FindPluginByAssembly(Assembly assembly)
|
|
|
|
{
|
|
|
|
// Go for all plugins the find the one with matching assembly
|
|
|
|
foreach(Plugin p in plugins)
|
|
|
|
{
|
|
|
|
if(p.Assembly == assembly) return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Nothing found
|
|
|
|
return null;
|
|
|
|
}
|
2008-05-14 21:48:36 +00:00
|
|
|
|
2008-05-15 09:43:19 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Events
|
|
|
|
|
2008-09-22 20:57:50 +00:00
|
|
|
|
2008-05-14 21:48:36 +00:00
|
|
|
public void ReloadResources()
|
|
|
|
{
|
2008-09-22 20:57:50 +00:00
|
|
|
foreach(Plugin p in plugins) p.Plug.OnReloadResources();
|
2008-05-14 21:48:36 +00:00
|
|
|
}
|
|
|
|
|
2008-09-22 20:57:50 +00:00
|
|
|
|
2008-10-08 15:14:02 +00:00
|
|
|
public bool ModeChanges(EditMode oldmode, EditMode newmode)
|
2008-05-14 21:48:36 +00:00
|
|
|
{
|
2008-10-08 15:14:02 +00:00
|
|
|
bool result = true;
|
|
|
|
foreach(Plugin p in plugins) result &= p.Plug.OnModeChange(oldmode, newmode);
|
|
|
|
return result;
|
2008-05-14 21:48:36 +00:00
|
|
|
}
|
2008-05-15 09:43:19 +00:00
|
|
|
|
2008-09-22 20:57:50 +00:00
|
|
|
|
2008-05-15 09:43:19 +00:00
|
|
|
public void ProgramReconfigure()
|
|
|
|
{
|
2008-09-22 20:57:50 +00:00
|
|
|
foreach(Plugin p in plugins) p.Plug.OnProgramReconfigure();
|
2008-05-15 09:43:19 +00:00
|
|
|
}
|
|
|
|
|
2008-09-22 20:57:50 +00:00
|
|
|
|
2008-05-15 09:43:19 +00:00
|
|
|
public void MapReconfigure()
|
|
|
|
{
|
2008-09-22 20:57:50 +00:00
|
|
|
foreach(Plugin p in plugins) p.Plug.OnMapReconfigure();
|
2008-05-15 09:43:19 +00:00
|
|
|
}
|
2008-09-22 20:57:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
public bool OnCopyBegin()
|
|
|
|
{
|
|
|
|
bool result = true;
|
|
|
|
foreach(Plugin p in plugins) result &= p.Plug.OnCopyBegin(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnCopyEnd()
|
|
|
|
{
|
|
|
|
foreach(Plugin p in plugins) p.Plug.OnCopyEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool OnPasteBegin()
|
|
|
|
{
|
|
|
|
bool result = true;
|
|
|
|
foreach(Plugin p in plugins) result &= p.Plug.OnPasteBegin(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnPasteEnd()
|
|
|
|
{
|
|
|
|
foreach(Plugin p in plugins) p.Plug.OnPasteEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool OnUndoBegin()
|
|
|
|
{
|
|
|
|
bool result = true;
|
|
|
|
foreach(Plugin p in plugins) result &= p.Plug.OnUndoBegin(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnUndoEnd()
|
|
|
|
{
|
|
|
|
foreach(Plugin p in plugins) p.Plug.OnUndoEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool OnRedoBegin()
|
|
|
|
{
|
|
|
|
bool result = true;
|
|
|
|
foreach(Plugin p in plugins) result &= p.Plug.OnRedoBegin(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnRedoEnd()
|
|
|
|
{
|
|
|
|
foreach(Plugin p in plugins) p.Plug.OnRedoEnd();
|
|
|
|
}
|
|
|
|
|
2008-10-13 17:47:08 +00:00
|
|
|
|
|
|
|
public void OnMapOpenBegin()
|
|
|
|
{
|
|
|
|
foreach(Plugin p in plugins) p.Plug.OnMapOpenBegin();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnMapOpenEnd()
|
|
|
|
{
|
|
|
|
foreach(Plugin p in plugins) p.Plug.OnMapOpenEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnMapNewBegin()
|
|
|
|
{
|
|
|
|
foreach(Plugin p in plugins) p.Plug.OnMapNewBegin();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnMapNewEnd()
|
|
|
|
{
|
|
|
|
foreach(Plugin p in plugins) p.Plug.OnMapNewEnd();
|
|
|
|
}
|
2008-12-24 18:27:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
public void OnMapSetChangeBegin()
|
|
|
|
{
|
|
|
|
foreach(Plugin p in plugins) p.Plug.OnMapSetChangeBegin();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnMapSetChangeEnd()
|
|
|
|
{
|
|
|
|
foreach(Plugin p in plugins) p.Plug.OnMapSetChangeEnd();
|
|
|
|
}
|
2008-10-13 17:47:08 +00:00
|
|
|
|
2008-10-15 11:46:43 +00:00
|
|
|
|
|
|
|
public void OnSectorCeilingSurfaceUpdate(Sector s, ref FlatVertex[] vertices)
|
|
|
|
{
|
|
|
|
foreach(Plugin p in plugins) p.Plug.OnSectorCeilingSurfaceUpdate(s, ref vertices);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnSectorFloorSurfaceUpdate(Sector s, ref FlatVertex[] vertices)
|
|
|
|
{
|
|
|
|
foreach(Plugin p in plugins) p.Plug.OnSectorFloorSurfaceUpdate(s, ref vertices);
|
|
|
|
}
|
|
|
|
|
2008-04-27 12:07:26 +00:00
|
|
|
|
2009-02-01 22:33:01 +00:00
|
|
|
public void OnShowPreferences(PreferencesController controller)
|
|
|
|
{
|
|
|
|
foreach(Plugin p in plugins) p.Plug.OnShowPreferences(controller);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnClosePreferences(PreferencesController controller)
|
|
|
|
{
|
|
|
|
foreach(Plugin p in plugins) p.Plug.OnClosePreferences(controller);
|
|
|
|
}
|
|
|
|
|
2008-01-02 21:49:43 +00:00
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|