diff --git a/source/Cosmos.sln b/source/Cosmos.sln index 75e156fc8..30d2cc4fa 100644 --- a/source/Cosmos.sln +++ b/source/Cosmos.sln @@ -566,7 +566,6 @@ Global {5C293BB9-FB42-495E-AAD9-D15888631CA4}.Release|Any CPU.ActiveCfg = Release|Any CPU {5C293BB9-FB42-495E-AAD9-D15888631CA4}.Release|Any CPU.Build.0 = Release|Any CPU {5C293BB9-FB42-495E-AAD9-D15888631CA4}.Release|Mixed Platforms.ActiveCfg = Release|x86 - {5C293BB9-FB42-495E-AAD9-D15888631CA4}.Release|Mixed Platforms.Build.0 = Release|x86 {5C293BB9-FB42-495E-AAD9-D15888631CA4}.Release|x86.ActiveCfg = Release|x86 {5C293BB9-FB42-495E-AAD9-D15888631CA4}.Release|x86.Build.0 = Release|x86 {819DB8FC-5DA1-461F-83C9-2F5C88088C94}.Debug|Any CPU.ActiveCfg = Debug|Any CPU @@ -576,7 +575,6 @@ Global {819DB8FC-5DA1-461F-83C9-2F5C88088C94}.Release|Any CPU.ActiveCfg = Release|Any CPU {819DB8FC-5DA1-461F-83C9-2F5C88088C94}.Release|Any CPU.Build.0 = Release|Any CPU {819DB8FC-5DA1-461F-83C9-2F5C88088C94}.Release|Mixed Platforms.ActiveCfg = Release|x86 - {819DB8FC-5DA1-461F-83C9-2F5C88088C94}.Release|Mixed Platforms.Build.0 = Release|x86 {819DB8FC-5DA1-461F-83C9-2F5C88088C94}.Release|x86.ActiveCfg = Release|x86 {819DB8FC-5DA1-461F-83C9-2F5C88088C94}.Release|x86.Build.0 = Release|x86 {6110AD07-EB07-4A99-BB73-7A69AF5732F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU @@ -586,7 +584,6 @@ Global {6110AD07-EB07-4A99-BB73-7A69AF5732F1}.Release|Any CPU.ActiveCfg = Release|Any CPU {6110AD07-EB07-4A99-BB73-7A69AF5732F1}.Release|Any CPU.Build.0 = Release|Any CPU {6110AD07-EB07-4A99-BB73-7A69AF5732F1}.Release|Mixed Platforms.ActiveCfg = Release|x86 - {6110AD07-EB07-4A99-BB73-7A69AF5732F1}.Release|Mixed Platforms.Build.0 = Release|x86 {6110AD07-EB07-4A99-BB73-7A69AF5732F1}.Release|x86.ActiveCfg = Release|x86 {6110AD07-EB07-4A99-BB73-7A69AF5732F1}.Release|x86.Build.0 = Release|x86 {0462E82B-8C29-41A9-8265-9C89038ADB29}.Debug|Any CPU.ActiveCfg = Debug|Any CPU @@ -668,7 +665,6 @@ Global {B2F76E27-EAE1-4ECF-8A33-77B2CFBB9367}.Release|Any CPU.ActiveCfg = Release|Any CPU {B2F76E27-EAE1-4ECF-8A33-77B2CFBB9367}.Release|Any CPU.Build.0 = Release|Any CPU {B2F76E27-EAE1-4ECF-8A33-77B2CFBB9367}.Release|Mixed Platforms.ActiveCfg = Release|x86 - {B2F76E27-EAE1-4ECF-8A33-77B2CFBB9367}.Release|Mixed Platforms.Build.0 = Release|x86 {B2F76E27-EAE1-4ECF-8A33-77B2CFBB9367}.Release|x86.ActiveCfg = Release|x86 {B2F76E27-EAE1-4ECF-8A33-77B2CFBB9367}.Release|x86.Build.0 = Release|x86 {6658FCE0-7032-4B7B-BD95-F2765C393442}.Debug|Any CPU.ActiveCfg = Debug|Any CPU @@ -855,7 +851,6 @@ Global {73CF15C1-0AB6-4B3A-8142-D326ADA72970}.Release|Any CPU.ActiveCfg = Release|Any CPU {73CF15C1-0AB6-4B3A-8142-D326ADA72970}.Release|Any CPU.Build.0 = Release|Any CPU {73CF15C1-0AB6-4B3A-8142-D326ADA72970}.Release|Mixed Platforms.ActiveCfg = Release|x86 - {73CF15C1-0AB6-4B3A-8142-D326ADA72970}.Release|Mixed Platforms.Build.0 = Release|x86 {73CF15C1-0AB6-4B3A-8142-D326ADA72970}.Release|x86.ActiveCfg = Release|x86 {73CF15C1-0AB6-4B3A-8142-D326ADA72970}.Release|x86.Build.0 = Release|x86 {5B2C0369-7A84-4113-892C-F71B50E1DA12}.Debug|Any CPU.ActiveCfg = Debug|x86 @@ -960,7 +955,6 @@ Global {6C14B7D1-CACB-4049-A0BD-9CAC5CFCF2C2}.Release|Any CPU.ActiveCfg = Release|Any CPU {6C14B7D1-CACB-4049-A0BD-9CAC5CFCF2C2}.Release|Any CPU.Build.0 = Release|Any CPU {6C14B7D1-CACB-4049-A0BD-9CAC5CFCF2C2}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {6C14B7D1-CACB-4049-A0BD-9CAC5CFCF2C2}.Release|Mixed Platforms.Build.0 = Release|Any CPU {6C14B7D1-CACB-4049-A0BD-9CAC5CFCF2C2}.Release|x86.ActiveCfg = Release|Any CPU {86F88A09-6801-4474-BFC8-EF09F3A9B89D}.Debug|Any CPU.ActiveCfg = Debug|x86 {86F88A09-6801-4474-BFC8-EF09F3A9B89D}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 @@ -1117,7 +1111,6 @@ Global {8E71FA9E-BB28-4B34-AB11-729E33B8C8E6}.Release|Any CPU.ActiveCfg = Release|Any CPU {8E71FA9E-BB28-4B34-AB11-729E33B8C8E6}.Release|Any CPU.Build.0 = Release|Any CPU {8E71FA9E-BB28-4B34-AB11-729E33B8C8E6}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {8E71FA9E-BB28-4B34-AB11-729E33B8C8E6}.Release|Mixed Platforms.Build.0 = Release|Any CPU {8E71FA9E-BB28-4B34-AB11-729E33B8C8E6}.Release|x86.ActiveCfg = Release|Any CPU {91CBD640-C07D-4556-B4CB-6F8CD88C67C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {91CBD640-C07D-4556-B4CB-6F8CD88C67C9}.Debug|Any CPU.Build.0 = Debug|Any CPU @@ -1127,7 +1120,6 @@ Global {91CBD640-C07D-4556-B4CB-6F8CD88C67C9}.Release|Any CPU.ActiveCfg = Debug|Any CPU {91CBD640-C07D-4556-B4CB-6F8CD88C67C9}.Release|Any CPU.Build.0 = Debug|Any CPU {91CBD640-C07D-4556-B4CB-6F8CD88C67C9}.Release|Mixed Platforms.ActiveCfg = Debug|Any CPU - {91CBD640-C07D-4556-B4CB-6F8CD88C67C9}.Release|Mixed Platforms.Build.0 = Debug|Any CPU {91CBD640-C07D-4556-B4CB-6F8CD88C67C9}.Release|x86.ActiveCfg = Debug|Any CPU {5DE37AE3-3F59-4D15-851B-945C23DBB633}.Debug|Any CPU.ActiveCfg = Debug|x86 {5DE37AE3-3F59-4D15-851B-945C23DBB633}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 @@ -1147,7 +1139,6 @@ Global {DA4198CA-59DF-41B3-9884-867647900D76}.Release|Any CPU.ActiveCfg = Release|Any CPU {DA4198CA-59DF-41B3-9884-867647900D76}.Release|Any CPU.Build.0 = Release|Any CPU {DA4198CA-59DF-41B3-9884-867647900D76}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {DA4198CA-59DF-41B3-9884-867647900D76}.Release|Mixed Platforms.Build.0 = Release|Any CPU {DA4198CA-59DF-41B3-9884-867647900D76}.Release|x86.ActiveCfg = Release|Any CPU {0A7DF241-1000-405D-A09B-9E2C51A5CB95}.Debug|Any CPU.ActiveCfg = Debug|x86 {0A7DF241-1000-405D-A09B-9E2C51A5CB95}.Debug|Any CPU.Build.0 = Debug|x86 @@ -1199,7 +1190,6 @@ Global {05FC6729-A0E3-48A4-AC5C-A0126F1972F4}.Release|Any CPU.ActiveCfg = Release|Any CPU {05FC6729-A0E3-48A4-AC5C-A0126F1972F4}.Release|Any CPU.Build.0 = Release|Any CPU {05FC6729-A0E3-48A4-AC5C-A0126F1972F4}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {05FC6729-A0E3-48A4-AC5C-A0126F1972F4}.Release|Mixed Platforms.Build.0 = Release|Any CPU {05FC6729-A0E3-48A4-AC5C-A0126F1972F4}.Release|x86.ActiveCfg = Release|Any CPU {6C741857-F812-4D37-85CA-A0487B95A8D7}.Debug|Any CPU.ActiveCfg = Debug|x86 {6C741857-F812-4D37-85CA-A0487B95A8D7}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 diff --git a/source2/IL2CPU/Cosmos.IL2CPU/ILScanner.cs b/source2/IL2CPU/Cosmos.IL2CPU/ILScanner.cs index 83e574028..884898f03 100644 --- a/source2/IL2CPU/Cosmos.IL2CPU/ILScanner.cs +++ b/source2/IL2CPU/Cosmos.IL2CPU/ILScanner.cs @@ -14,6 +14,8 @@ using _MemberInfo = System.Runtime.InteropServices._MemberInfo; namespace Cosmos.IL2CPU { + public delegate void LogExceptionDelegate(Exception e); + // This is necessary because HashSet and Dictionary // have troubles when different types of objects are stored // in them. I dont remember the exact problem, but something @@ -58,7 +60,6 @@ namespace Cosmos.IL2CPU public class ILScanner : IDisposable { - public delegate void LogExceptionDelegate(Exception e); public LogExceptionDelegate LogException = null; protected ILReader mReader; @@ -100,7 +101,7 @@ namespace Cosmos.IL2CPU mAsmblr = aAsmblr; mReader = new ILReader(); - mPlugManager = new PlugManager(this.ScanMethod, this.Queue); + mPlugManager = new PlugManager(this.LogException, this.ScanMethod, this.Queue); } public void EnableLogging(string aPathname) diff --git a/source2/IL2CPU/Cosmos.IL2CPU/PlugManager.cs b/source2/IL2CPU/Cosmos.IL2CPU/PlugManager.cs index baf969f1c..9eddf5d82 100644 --- a/source2/IL2CPU/Cosmos.IL2CPU/PlugManager.cs +++ b/source2/IL2CPU/Cosmos.IL2CPU/PlugManager.cs @@ -16,7 +16,8 @@ namespace Cosmos.IL2CPU { public class PlugManager { - public delegate void LogExceptionDelegate(Exception e); + public bool ThrowExceptions = true; + public LogExceptionDelegate LogException = null; public delegate void ScanMethodDelegate(MethodBase aMethod, bool aIsPlug, object sourceItem); @@ -63,11 +64,13 @@ namespace Cosmos.IL2CPU } - public PlugManager() + public PlugManager(LogExceptionDelegate aLogException) { + LogException = aLogException; } - public PlugManager(ScanMethodDelegate aScanMethod, QueueDelegate aQueueMethod) + public PlugManager(LogExceptionDelegate aLogException, ScanMethodDelegate aScanMethod, QueueDelegate aQueueMethod) { + LogException = aLogException; ScanMethod = aScanMethod; Queue = aQueueMethod; } @@ -319,7 +322,15 @@ namespace Cosmos.IL2CPU { if (xAttrib.IsWildcard && xAttrib.Assembler == null) { - throw new Exception("Wildcard PlugMethods need to use an assembler for now."); + Exception anEx = new Exception("Wildcard PlugMethods need to use an assembler for now."); + if (ThrowExceptions) + { + throw anEx; + } + else + { + LogException(anEx); + } } if (xAttrib.Enabled && !xAttrib.IsMonoOnly) { @@ -342,7 +353,15 @@ namespace Cosmos.IL2CPU } if (xFields.ContainsKey(xField.FieldId)) { - throw new Exception("Duplicate PlugField found for field '" + xField.FieldId + "'!"); + Exception anEx = new Exception("Duplicate PlugField found for field '" + xField.FieldId + "'!"); + if (ThrowExceptions) + { + throw anEx; + } + else + { + LogException(anEx); + } } xFields.Add(xField.FieldId, xField); } @@ -718,5 +737,13 @@ namespace Cosmos.IL2CPU } } + public void Clean() + { + mPlugImpls = new Dictionary>(); + mPlugImplsInhrt = new Dictionary>(); + mPlugFields = new Dictionary>(); + + ResolvedPlugs = new Orvid.Collections.SkipList(); + } } } diff --git a/source2/Tools/PlugsInspector/AssembliesPreloader.cs b/source2/Tools/PlugsInspector/AssembliesPreloader.cs new file mode 100644 index 000000000..920072ad7 --- /dev/null +++ b/source2/Tools/PlugsInspector/AssembliesPreloader.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.IO; +using System.Reflection; +using System.Windows.Forms; + +namespace PlugsInspector +{ + public class AssembliesPreloader + { + public static void LoadAllAssemblies() + { + AllFilesInApplicationFolder().ForEach(fi => Assembly.LoadFrom(fi.FullName)); + } + + public static List AllDllFilesIn(string path, bool recursively = false) + { + return new DirectoryInfo(path) + .EnumerateFiles("*.dll", recursively ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly).ToList(); + } + public static List AllFilesInApplicationFolder() + { + return AllDllFilesIn(Path.GetDirectoryName(Application.ExecutablePath), true); + } + } +} diff --git a/source2/Tools/PlugsInspector/Form1.Designer.cs b/source2/Tools/PlugsInspector/Form1.Designer.cs index 839f221e2..42b300adf 100644 --- a/source2/Tools/PlugsInspector/Form1.Designer.cs +++ b/source2/Tools/PlugsInspector/Form1.Designer.cs @@ -28,36 +28,60 @@ /// private void InitializeComponent() { - this.label1 = new System.Windows.Forms.Label(); + this.LoadPlugsButton = new System.Windows.Forms.Button(); + this.PlugsListBox = new System.Windows.Forms.ListBox(); + this.ExceptionsListBox = new System.Windows.Forms.ListBox(); this.SuspendLayout(); // - // label1 + // LoadPlugsButton // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(12, 9); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(85, 13); - this.label1.TabIndex = 0; - this.label1.Text = "Plugs assembly :"; + this.LoadPlugsButton.Location = new System.Drawing.Point(13, 13); + this.LoadPlugsButton.Name = "LoadPlugsButton"; + this.LoadPlugsButton.Size = new System.Drawing.Size(75, 23); + this.LoadPlugsButton.TabIndex = 0; + this.LoadPlugsButton.Text = "Load Plugs"; + this.LoadPlugsButton.UseVisualStyleBackColor = true; + this.LoadPlugsButton.Click += new System.EventHandler(this.LoadPlugsButton_Click); + // + // PlugsListBox + // + this.PlugsListBox.FormattingEnabled = true; + this.PlugsListBox.Location = new System.Drawing.Point(13, 42); + this.PlugsListBox.Name = "PlugsListBox"; + this.PlugsListBox.Size = new System.Drawing.Size(642, 511); + this.PlugsListBox.Sorted = true; + this.PlugsListBox.TabIndex = 1; + // + // ExceptionsListBox + // + this.ExceptionsListBox.FormattingEnabled = true; + this.ExceptionsListBox.Location = new System.Drawing.Point(661, 42); + this.ExceptionsListBox.Name = "ExceptionsListBox"; + this.ExceptionsListBox.Size = new System.Drawing.Size(505, 511); + this.ExceptionsListBox.TabIndex = 2; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1178, 568); - this.Controls.Add(this.label1); + this.Controls.Add(this.ExceptionsListBox); + this.Controls.Add(this.PlugsListBox); + this.Controls.Add(this.LoadPlugsButton); this.Name = "Form1"; this.ShowIcon = false; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Plugs Inspector"; this.ResumeLayout(false); - this.PerformLayout(); } #endregion - private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button LoadPlugsButton; + private System.Windows.Forms.ListBox PlugsListBox; + private System.Windows.Forms.ListBox ExceptionsListBox; + } } diff --git a/source2/Tools/PlugsInspector/Form1.cs b/source2/Tools/PlugsInspector/Form1.cs index da1931fa2..539fd981e 100644 --- a/source2/Tools/PlugsInspector/Form1.cs +++ b/source2/Tools/PlugsInspector/Form1.cs @@ -8,13 +8,128 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using Cosmos.IL2CPU; +using System.Reflection; + namespace PlugsInspector { public partial class Form1 : Form { + PlugManager plugManager; + bool LoadingPlugs = false; + public Form1() { InitializeComponent(); + + //Force it to load/include all plugs assemblies so all types are correctly found + //Otherwise the CLR's delay loading techniques block us... + AssembliesPreloader.LoadAllAssemblies(); + + + plugManager = new PlugManager((Exception ex) => { + AddExceptionEntry(ex.Message); + }, this.ScanMethod, null); + plugManager.ThrowExceptions = false; + } + + private void LoadPlugsButton_Click(object sender, EventArgs e) + { + if (!LoadingPlugs) + { + PlugsListBox.Items.Clear(); + ExceptionsListBox.Items.Clear(); + + new Task(LoadPlugs).Start(); + } + } + private void LoadPlugs() + { + if (LoadingPlugs) + return; + + try + { + LoadingPlugs = true; + + plugManager.Clean(); + + plugManager.FindPlugImpls(); + plugManager.ScanFoundPlugs(); + foreach (Type pluggedMethodType in plugManager.PlugImpls.Keys) + { + string name = ""; + if (pluggedMethodType.DeclaringType != null) + { + name += pluggedMethodType.DeclaringType.Name + "."; + } + name += pluggedMethodType.Name; + AddPlugEntry(name); + } + foreach (Type pluggedMethodType in plugManager.PlugImplsInhrt.Keys) + { + string name = ""; + if (pluggedMethodType.DeclaringType != null) + { + name += pluggedMethodType.DeclaringType.Name + "."; + } + name += pluggedMethodType.Name; + AddPlugEntry(name); + } + foreach (Type pluggedFieldType in plugManager.PlugFields.Keys) + { + string name = ""; + if (pluggedFieldType.DeclaringType != null) + { + name += pluggedFieldType.DeclaringType.Name + "."; + } + name += pluggedFieldType.Name; + AddPlugEntry(name); + } + } + catch(Exception ex) + { + AddPlugEntry("Error loading plugs: " + ex.Message); + } + finally + { + LoadingPlugs = false; + } + } + private void ScanMethod(MethodBase aMethod, bool aIsPlug, object sourceItem) + { + string name = ""; + if (aMethod.DeclaringType != null) + { + name += aMethod.DeclaringType.Name + "."; + } + name += aMethod.Name; + AddPlugEntry(name); + } + + private delegate void AddPlugEntryCallback(string text); + private void AddPlugEntry(string text) + { + if (this.InvokeRequired) + { + this.Invoke(new AddPlugEntryCallback(this.AddPlugEntry), new object[] { text }); + } + else + { + this.PlugsListBox.Items.Add(text); + } + } + private delegate void AddExceptionEntryCallback(string text); + private void AddExceptionEntry(string text) + { + if (this.InvokeRequired) + { + this.Invoke(new AddExceptionEntryCallback(this.AddExceptionEntry), new object[] { text }); + } + else + { + this.ExceptionsListBox.Items.Add(text); + } } } } diff --git a/source2/Tools/PlugsInspector/PlugsInspector.csproj b/source2/Tools/PlugsInspector/PlugsInspector.csproj index 8fced3106..ff6075132 100644 --- a/source2/Tools/PlugsInspector/PlugsInspector.csproj +++ b/source2/Tools/PlugsInspector/PlugsInspector.csproj @@ -48,6 +48,7 @@ + Form @@ -81,6 +82,28 @@ + + + {c801f19c-a9d3-42d5-9a57-9ffdf9b4d05e} + Cosmos.IL2CPU.Plugs + + + {239e33a7-f0c3-4801-85ca-4d8f89a31dc0} + Cosmos.IL2CPU + + + {b97a2956-c363-47f2-a6aa-b4fccff4d315} + Cosmos.Debug.Kernel.Plugs + + + {61607f1e-58f9-41cf-972f-128384f3e115} + Cosmos.Debug.Kernel + + + {7c64b97f-516d-4a6d-b9e1-3fe48f561409} + Cosmos.System.Plugs.System + +