From e3b38a70f8d710af07732b325a6013ed18aa0fb0 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 25 Aug 2021 19:17:29 -0400 Subject: reorganize new classes --- src/SMAPI/Framework/ModLoading/AssemblyLoader.cs | 1 + src/SMAPI/Framework/ModLoading/MySymbolReader.cs | 55 ---------------------- .../Framework/ModLoading/SymbolReaderProvider.cs | 37 --------------- .../Framework/ModLoading/SymbolWriterProvider.cs | 25 ---------- .../Framework/ModLoading/Symbols/SymbolReader.cs | 51 ++++++++++++++++++++ .../ModLoading/Symbols/SymbolReaderProvider.cs | 35 ++++++++++++++ .../ModLoading/Symbols/SymbolWriterProvider.cs | 22 +++++++++ 7 files changed, 109 insertions(+), 117 deletions(-) delete mode 100644 src/SMAPI/Framework/ModLoading/MySymbolReader.cs delete mode 100644 src/SMAPI/Framework/ModLoading/SymbolReaderProvider.cs delete mode 100644 src/SMAPI/Framework/ModLoading/SymbolWriterProvider.cs create mode 100644 src/SMAPI/Framework/ModLoading/Symbols/SymbolReader.cs create mode 100644 src/SMAPI/Framework/ModLoading/Symbols/SymbolReaderProvider.cs create mode 100644 src/SMAPI/Framework/ModLoading/Symbols/SymbolWriterProvider.cs (limited to 'src/SMAPI/Framework/ModLoading') diff --git a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs index 98154b53..72cfd119 100644 --- a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs +++ b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs @@ -7,6 +7,7 @@ using Mono.Cecil; using Mono.Cecil.Cil; using StardewModdingAPI.Framework.Exceptions; using StardewModdingAPI.Framework.ModLoading.Framework; +using StardewModdingAPI.Framework.ModLoading.Symbols; using StardewModdingAPI.Metadata; using StardewModdingAPI.Toolkit.Framework.ModData; using StardewModdingAPI.Toolkit.Utilities; diff --git a/src/SMAPI/Framework/ModLoading/MySymbolReader.cs b/src/SMAPI/Framework/ModLoading/MySymbolReader.cs deleted file mode 100644 index 215631c6..00000000 --- a/src/SMAPI/Framework/ModLoading/MySymbolReader.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Mono.Cecil; -using Mono.Cecil.Cil; -using Mono.Cecil.Pdb; - -namespace StardewModdingAPI.Framework.ModLoading -{ - internal class MySymbolReader : ISymbolReader - { - private ModuleDefinition Module; - private Stream Stream; - private ISymbolReader Using; - - public MySymbolReader( ModuleDefinition module, Stream stream ) - { - this.Module = module; - this.Stream = stream; - this.Using = new NativePdbReaderProvider().GetSymbolReader( module, stream ); - } - - public void Dispose() - { - this.Using.Dispose(); - } - - public ISymbolWriterProvider GetWriterProvider() - { - return new PortablePdbWriterProvider(); - } - - public bool ProcessDebugHeader( ImageDebugHeader header ) - { - try - { - return this.Using.ProcessDebugHeader( header ); - } - catch (Exception e) - { - this.Using.Dispose(); - this.Using = new PortablePdbReaderProvider().GetSymbolReader( this.Module, this.Stream ); - return this.Using.ProcessDebugHeader( header ); - } - } - - public MethodDebugInformation Read( MethodDefinition method ) - { - return Using.Read( method ); - } - } -} diff --git a/src/SMAPI/Framework/ModLoading/SymbolReaderProvider.cs b/src/SMAPI/Framework/ModLoading/SymbolReaderProvider.cs deleted file mode 100644 index c92e1e4d..00000000 --- a/src/SMAPI/Framework/ModLoading/SymbolReaderProvider.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using Mono.Cecil; -using Mono.Cecil.Cil; -using Mono.Cecil.Pdb; - -namespace StardewModdingAPI.Framework.ModLoading -{ - internal class SymbolReaderProvider : ISymbolReaderProvider - { - private readonly ISymbolReaderProvider BaseProvider = new DefaultSymbolReaderProvider(); - - private readonly Dictionary SymbolMapping = new Dictionary(); - - public void AddSymbolMapping( string dllName, Stream symbolStream ) - { - this.SymbolMapping.Add( dllName, symbolStream ); - } - - public ISymbolReader GetSymbolReader( ModuleDefinition module, string fileName ) - { - if ( this.SymbolMapping.ContainsKey( module.Name ) ) - return new MySymbolReader( module, this.SymbolMapping[ module.Name ] ); - - return this.BaseProvider.GetSymbolReader( module, fileName ); - } - - public ISymbolReader GetSymbolReader( ModuleDefinition module, Stream symbolStream ) - { - if ( this.SymbolMapping.ContainsKey( module.Name ) ) - return new MySymbolReader( module, this.SymbolMapping[ module.Name ] ); - - return this.BaseProvider.GetSymbolReader( module, symbolStream ); - } - } -} diff --git a/src/SMAPI/Framework/ModLoading/SymbolWriterProvider.cs b/src/SMAPI/Framework/ModLoading/SymbolWriterProvider.cs deleted file mode 100644 index 116e341a..00000000 --- a/src/SMAPI/Framework/ModLoading/SymbolWriterProvider.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using Mono.Cecil; -using Mono.Cecil.Cil; -using Mono.Cecil.Pdb; - -namespace StardewModdingAPI.Framework.ModLoading -{ - internal class SymbolWriterProvider : ISymbolWriterProvider - { - private readonly ISymbolWriterProvider BaseProvider = new DefaultSymbolWriterProvider(); - - public ISymbolWriter GetSymbolWriter( ModuleDefinition module, string fileName ) - { - return this.BaseProvider.GetSymbolWriter( module, fileName ); - } - - public ISymbolWriter GetSymbolWriter( ModuleDefinition module, Stream symbolStream ) - { - // Not implemented in default native pdb writer, so fallback to portable - return new PortablePdbWriterProvider().GetSymbolWriter( module, symbolStream ); - } - } -} diff --git a/src/SMAPI/Framework/ModLoading/Symbols/SymbolReader.cs b/src/SMAPI/Framework/ModLoading/Symbols/SymbolReader.cs new file mode 100644 index 00000000..f1ae86a2 --- /dev/null +++ b/src/SMAPI/Framework/ModLoading/Symbols/SymbolReader.cs @@ -0,0 +1,51 @@ +using System; +using System.IO; +using Mono.Cecil; +using Mono.Cecil.Cil; +using Mono.Cecil.Pdb; + +namespace StardewModdingAPI.Framework.ModLoading.Symbols +{ + internal class SymbolReader : ISymbolReader + { + private ModuleDefinition Module; + private Stream Stream; + private ISymbolReader Using; + + public SymbolReader( ModuleDefinition module, Stream stream ) + { + this.Module = module; + this.Stream = stream; + this.Using = new NativePdbReaderProvider().GetSymbolReader( module, stream ); + } + + public void Dispose() + { + this.Using.Dispose(); + } + + public ISymbolWriterProvider GetWriterProvider() + { + return new PortablePdbWriterProvider(); + } + + public bool ProcessDebugHeader( ImageDebugHeader header ) + { + try + { + return this.Using.ProcessDebugHeader( header ); + } + catch (Exception e) + { + this.Using.Dispose(); + this.Using = new PortablePdbReaderProvider().GetSymbolReader( this.Module, this.Stream ); + return this.Using.ProcessDebugHeader( header ); + } + } + + public MethodDebugInformation Read( MethodDefinition method ) + { + return this.Using.Read( method ); + } + } +} diff --git a/src/SMAPI/Framework/ModLoading/Symbols/SymbolReaderProvider.cs b/src/SMAPI/Framework/ModLoading/Symbols/SymbolReaderProvider.cs new file mode 100644 index 00000000..e2a6d21e --- /dev/null +++ b/src/SMAPI/Framework/ModLoading/Symbols/SymbolReaderProvider.cs @@ -0,0 +1,35 @@ +using System.Collections.Generic; +using System.IO; +using Mono.Cecil; +using Mono.Cecil.Cil; + +namespace StardewModdingAPI.Framework.ModLoading.Symbols +{ + internal class SymbolReaderProvider : ISymbolReaderProvider + { + private readonly ISymbolReaderProvider BaseProvider = new DefaultSymbolReaderProvider(); + + private readonly Dictionary SymbolMapping = new Dictionary(); + + public void AddSymbolMapping( string dllName, Stream symbolStream ) + { + this.SymbolMapping.Add( dllName, symbolStream ); + } + + public ISymbolReader GetSymbolReader( ModuleDefinition module, string fileName ) + { + if ( this.SymbolMapping.ContainsKey( module.Name ) ) + return new SymbolReader( module, this.SymbolMapping[ module.Name ] ); + + return this.BaseProvider.GetSymbolReader( module, fileName ); + } + + public ISymbolReader GetSymbolReader( ModuleDefinition module, Stream symbolStream ) + { + if ( this.SymbolMapping.ContainsKey( module.Name ) ) + return new SymbolReader( module, this.SymbolMapping[ module.Name ] ); + + return this.BaseProvider.GetSymbolReader( module, symbolStream ); + } + } +} diff --git a/src/SMAPI/Framework/ModLoading/Symbols/SymbolWriterProvider.cs b/src/SMAPI/Framework/ModLoading/Symbols/SymbolWriterProvider.cs new file mode 100644 index 00000000..33e91db0 --- /dev/null +++ b/src/SMAPI/Framework/ModLoading/Symbols/SymbolWriterProvider.cs @@ -0,0 +1,22 @@ +using System.IO; +using Mono.Cecil; +using Mono.Cecil.Cil; + +namespace StardewModdingAPI.Framework.ModLoading.Symbols +{ + internal class SymbolWriterProvider : ISymbolWriterProvider + { + private readonly ISymbolWriterProvider BaseProvider = new DefaultSymbolWriterProvider(); + + public ISymbolWriter GetSymbolWriter( ModuleDefinition module, string fileName ) + { + return this.BaseProvider.GetSymbolWriter( module, fileName ); + } + + public ISymbolWriter GetSymbolWriter( ModuleDefinition module, Stream symbolStream ) + { + // Not implemented in default native pdb writer, so fallback to portable + return new PortablePdbWriterProvider().GetSymbolWriter( module, symbolStream ); + } + } +} -- cgit