source: branches/eraser6/pluginsRewrite/Eraser.Plugins/PluginInstance.cs @ 2292

Revision 2292, 3.7 KB checked in by lowjoel, 4 years ago (diff)

Fixed compilation.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1/*
2 * $Id$
3 * Copyright 2008-2010 The Eraser Project
4 * Original Author: Joel Low <lowjoel@users.sourceforge.net>
5 * Modified By:
6 *
7 * This file is part of Eraser.
8 *
9 * Eraser is free software: you can redistribute it and/or modify it under the
10 * terms of the GNU General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option) any later
12 * version.
13 *
14 * Eraser is distributed in the hope that it will be useful, but WITHOUT ANY
15 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 *
18 * A copy of the GNU General Public License can be found at
19 * <http://www.gnu.org/licenses/>.
20 */
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26
27using System.Reflection;
28using System.Runtime.InteropServices;
29using System.Security.Cryptography;
30using System.Security.Cryptography.X509Certificates;
31
32using Eraser.Util;
33using Eraser.Util.ExtensionMethods;
34
35namespace Eraser.Plugins
36{
37    /// <summary>
38    /// Structure holding the instance values of the plugin like handle and path.
39    /// </summary>
40    public class PluginInstance
41    {
42        /// <summary>
43        /// Constructor
44        /// </summary>
45        /// <param name="assembly">The assembly representing this plugin.</param>
46        /// <param name="path">The path to the ass</param>
47        /// <param name="plugin"></param>
48        internal PluginInstance(Assembly assembly, IPlugin plugin)
49        {
50            Assembly = assembly;
51            Plugin = plugin;
52
53            //Verify the certificate in the assembly.
54            if (Security.VerifyAuthenticode(assembly.Location))
55            {
56                X509Certificate2 cert = new X509Certificate2(
57                    X509Certificate.CreateFromSignedFile(assembly.Location));
58                AssemblyAuthenticode = cert;
59            }
60        }
61
62        /// <summary>
63        /// Gets the Assembly this plugin instance came from.
64        /// </summary>
65        public Assembly Assembly
66        {
67            get
68            {
69                return assembly;
70            }
71            internal set
72            {
73                assembly = value;
74
75                AssemblyInfo info = new AssemblyInfo();
76                info.Version = assembly.GetFileVersion();
77                IList<CustomAttributeData> attributes = CustomAttributeData.GetCustomAttributes(assembly);
78                foreach (CustomAttributeData attr in attributes)
79                    if (attr.Constructor.DeclaringType == typeof(GuidAttribute))
80                        info.Guid = new Guid((string)attr.ConstructorArguments[0].Value);
81                    else if (attr.Constructor.DeclaringType == typeof(AssemblyCompanyAttribute))
82                        info.Author = (string)attr.ConstructorArguments[0].Value;
83                    else if (attr.Constructor.DeclaringType == typeof(LoadingPolicyAttribute))
84                    {
85                        LoadingPolicy = (LoadingPolicy)attr.ConstructorArguments[0].Value;
86                        if (LoadingPolicy == LoadingPolicy.Core)
87                            LoadingPolicy = LoadingPolicy.None;
88                    }
89
90                this.AssemblyInfo = info;
91            }
92        }
93
94        /// <summary>
95        /// Gets the attributes of the assembly, loading from reflection-only sources.
96        /// </summary>
97        public AssemblyInfo AssemblyInfo { get; private set; }
98
99        /// <summary>
100        /// The Authenticode signature used for signing the assembly.
101        /// </summary>
102        public X509Certificate2 AssemblyAuthenticode { get; private set; }
103
104        /// <summary>
105        /// Gets whether the plugin is required for the functioning of Eraser (and
106        /// therefore cannot be disabled.)
107        /// </summary>
108        public LoadingPolicy LoadingPolicy { get; internal set; }
109
110        /// <summary>
111        /// Gets the IPlugin interface which the plugin exposed. This may be null
112        /// if the plugin was not loaded.
113        /// </summary>
114        public IPlugin Plugin { get; internal set; }
115
116        /// <summary>
117        /// Gets whether this particular plugin is currently loaded in memory.
118        /// </summary>
119        public bool Loaded
120        {
121            get { return Plugin != null; }
122        }
123
124        private Assembly assembly;
125    }
126}
Note: See TracBrowser for help on using the repository browser.