Changeset 2288


Ignore:
Timestamp:
1/4/2011 5:23:07 AM (4 years ago)
Author:
lowjoel
Message:

First compilable version.

  • Whether plugins are allowed to be loaded is now a callback function which must be set by the initialising class, otherwise all plugins found are loaded
  • Split the PluginLoadedEventArgs? class to its own file
Location:
branches/eraser6/pluginsRewrite
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • branches/eraser6/pluginsRewrite/Eraser.Manager/ManagerLibrary.cs

    r2286 r2288  
    2424using System.Text; 
    2525using System.Runtime.Serialization; 
     26 
     27using Eraser.Plugins; 
     28using Eraser.Util; 
    2629 
    2730namespace Eraser.Manager 
     
    6265            { 
    6366                EntropySourceRegistrar.Poller.Abort(); 
    64                 Host.Dispose(); 
     67                Host.Instance.Dispose(); 
    6568                SettingsManager.Save(); 
    6669            } 
     
    7477            Dispose(true); 
    7578            GC.SuppressFinalize(this); 
     79        } 
     80 
     81        private void OnPluginLoad(object sender, PluginLoadEventArgs e) 
     82        { 
     83            //If the plugin does not have an approval or denial, check for the presence of 
     84            //a valid signature. 
     85            IDictionary<Guid, bool> approvals = ManagerLibrary.Settings.PluginApprovals; 
     86            if (!approvals.ContainsKey(e.Plugin.AssemblyInfo.Guid) && 
     87                (e.Plugin.Assembly.GetName().GetPublicKey().Length == 0 || 
     88                !Security.VerifyStrongName(e.Plugin.Assembly.Location) || 
     89                e.Plugin.AssemblyAuthenticode == null)) 
     90            { 
     91                e.Load = false; 
     92            } 
     93 
     94            //Is there an approval or denial? 
     95            else if (approvals.ContainsKey(e.Plugin.AssemblyInfo.Guid)) 
     96                e.Load = approvals[e.Plugin.AssemblyInfo.Guid]; 
     97 
     98            //There's no approval or denial, what is the specified loading policy? 
     99            else 
     100                e.Load = e.Plugin.LoadingPolicy != LoadingPolicy.DefaultOff; 
    76101        } 
    77102 
     
    129154        /// </summary> 
    130155        private static ManagerSettings settingsInstance; 
    131  
    132         /// <summary> 
    133         /// The global instance of the Plugin host. 
    134         /// </summary> 
    135         internal Plugin.DefaultHost Host; 
    136156    } 
    137157} 
  • branches/eraser6/pluginsRewrite/Eraser.Manager/Settings.cs

    r2013 r2288  
    2525using System.Reflection; 
    2626using System.Runtime.InteropServices; 
     27using System.Globalization; 
     28 
    2729using Eraser.Util; 
    28 using System.Globalization; 
     30using Eraser.Plugins; 
    2931 
    3032namespace Eraser.Manager 
     
    374376 
    375377            //We have not computed the value. Compute the default. 
    376             Plugin.Host pluginHost = ManagerLibrary.Instance.Host; 
    377             IList<Plugin.PluginInstance> plugins = pluginHost.Plugins; 
     378            Host pluginHost = Host.Instance; 
     379            IList<PluginInstance> plugins = pluginHost.Plugins; 
    378380            SortedList<int, Guid> priorities = new SortedList<int, Guid>(); 
    379381 
    380             foreach (Plugin.PluginInstance plugin in plugins) 
     382            foreach (PluginInstance plugin in plugins) 
    381383            { 
    382384                //Check whether the plugin is signed by us. 
  • branches/eraser6/pluginsRewrite/Eraser.Plugins/Eraser.Plugins.csproj

    r2286 r2288  
    1313    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> 
    1414    <FileAlignment>512</FileAlignment> 
     15    <SignAssembly>true</SignAssembly> 
     16    <AssemblyOriginatorKeyFile>..\Strong Name.snk</AssemblyOriginatorKeyFile> 
    1517  </PropertyGroup> 
    1618  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> 
     
    4951    <Compile Include="IConfigurer.cs" /> 
    5052    <Compile Include="IRegistrar.cs" /> 
     53    <Compile Include="PluginLoadedEventArgs.cs" /> 
     54    <Compile Include="PluginLoadEventArgs.cs" /> 
    5155    <Compile Include="Plugins.cs" /> 
    5256    <Compile Include="Properties\AssemblyInfo.cs" /> 
  • branches/eraser6/pluginsRewrite/Eraser.Plugins/Plugins.cs

    r2286 r2288  
    3232 
    3333using Eraser.Util; 
    34  
    35 namespace Eraser.Manager.Plugin 
     34using Eraser.Util.ExtensionMethods; 
     35using Path = System.IO.Path; 
     36 
     37namespace Eraser.Plugins 
    3638{ 
    3739    /// <summary> 
     
    9496 
    9597        /// <summary> 
     98        /// The plugin load event, allowing clients to decide whether to load 
     99        /// the given plugin. 
     100        /// </summary> 
     101        public EventHandler<PluginLoadEventArgs> PluginLoad { get; set; } 
     102 
     103        /// <summary> 
    96104        /// The plugin loaded event. 
    97105        /// </summary> 
     
    116124        /// and return True.</remarks> 
    117125        public abstract bool LoadPlugin(string filePath); 
    118     } 
    119  
    120     /// <summary> 
    121     /// Event argument for the plugin loaded event. 
    122     /// </summary> 
    123     public class PluginLoadedEventArgs : EventArgs 
    124     { 
    125         /// <summary> 
    126         /// Constructor. 
    127         /// </summary> 
    128         /// <param name="instance">The plugin instance of the recently loaded plugin.</param> 
    129         public PluginLoadedEventArgs(PluginInstance instance) 
    130         { 
    131             Instance = instance; 
    132         } 
    133  
    134         /// <summary> 
    135         /// The <see cref="PluginInstance"/> object representing the newly loaded plugin. 
    136         /// </summary> 
    137         public PluginInstance Instance { get; private set; } 
    138126    } 
    139127 
     
    308296                plugins.Add(instance); 
    309297 
    310             //If the plugin does not have an approval or denial, check for the presence of 
    311             //a valid signature. 
    312             IDictionary<Guid, bool> approvals = ManagerLibrary.Settings.PluginApprovals; 
    313             if (!approvals.ContainsKey(instance.AssemblyInfo.Guid) && 
    314                 (reflectAssembly.GetName().GetPublicKey().Length == 0 || 
    315                 !Security.VerifyStrongName(filePath) || 
    316                 instance.AssemblyAuthenticode == null)) 
    317             { 
    318                 return false; 
    319             } 
    320  
    321             //Preliminary checks to verify whether the plugin can be loaded (safely) passes, 
    322             //Load the assembly fully, and then initialise it. 
    323             instance.Assembly = Assembly.Load(reflectAssembly.GetName()); 
    324              
    325             //The plugin either is explicitly allowed or disallowed to load, or 
    326             //it has an Authenticode Signature as well as a Strong Name. Get the 
    327             //loading policy of the plugin. 
    328             { 
    329                  
    330             } 
    331  
    332             bool initialisePlugin = false; 
    333  
    334             //Is there an approval or denial? 
    335             if (approvals.ContainsKey(instance.AssemblyInfo.Guid)) 
    336                 initialisePlugin = approvals[instance.AssemblyInfo.Guid]; 
    337  
    338             //There's no approval or denial, what is the specified loading policy? 
    339             else 
    340                 initialisePlugin = instance.LoadingPolicy != LoadingPolicy.DefaultOff; 
    341  
    342             if (initialisePlugin) 
     298            PluginLoadEventArgs e = new PluginLoadEventArgs(instance); 
     299            PluginLoad(this, e); 
     300            if (PluginLoad == null || e.Load) 
    343301            { 
    344302                InitialisePlugin(instance); 
     
    353311        /// </summary> 
    354312        /// <param name="instance">The <see cref="PluginInstance"/> structure to fill.</param> 
     313        /// <exception cref="System.IO.FileLoadException" /> 
    355314        private void InitialisePlugin(PluginInstance instance) 
    356315        { 
     
    373332            catch (System.Security.SecurityException e) 
    374333            { 
    375                 MessageBox.Show(S._("Could not load the plugin {0}.\n\nThe error returned was: {1}", 
    376                     instance.Assembly.Location, e.Message), S._("Eraser"), MessageBoxButtons.OK, 
    377                     MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 
    378                     Localisation.IsRightToLeft(null) ? 
    379                         MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign : 0); 
     334                throw new FileLoadException(S._("Could not load the plugin."), 
     335                    instance.Assembly.Location, e); 
    380336            } 
    381337        } 
  • branches/eraser6/pluginsRewrite/Eraser.Plugins/Properties/AssemblyInfo.cs

    r2286 r2288  
    2222// The following GUID is for the ID of the typelib if this project is exposed to COM 
    2323[assembly: Guid("1c4e0bd3-4272-4cc8-9fb6-d0e0703b2013")] 
    24  
    25 // Version information for an assembly consists of the following four values: 
    26 // 
    27 //      Major Version 
    28 //      Minor Version  
    29 //      Build Number 
    30 //      Revision 
    31 // 
    32 // You can specify all the values or you can default the Build and Revision Numbers  
    33 // by using the '*' as shown below: 
    34 // [assembly: AssemblyVersion("1.0.*")] 
    35 [assembly: AssemblyVersion("1.0.0.0")] 
    36 [assembly: AssemblyFileVersion("1.0.0.0")] 
Note: See TracChangeset for help on using the changeset viewer.