summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/ModLoading/Finders/LegacyAssemblyFinder.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI/Framework/ModLoading/Finders/LegacyAssemblyFinder.cs')
-rw-r--r--src/SMAPI/Framework/ModLoading/Finders/LegacyAssemblyFinder.cs49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/SMAPI/Framework/ModLoading/Finders/LegacyAssemblyFinder.cs b/src/SMAPI/Framework/ModLoading/Finders/LegacyAssemblyFinder.cs
new file mode 100644
index 00000000..d3437b05
--- /dev/null
+++ b/src/SMAPI/Framework/ModLoading/Finders/LegacyAssemblyFinder.cs
@@ -0,0 +1,49 @@
+using Mono.Cecil;
+using StardewModdingAPI.Framework.ModLoading.Framework;
+
+namespace StardewModdingAPI.Framework.ModLoading.Finders
+{
+ /// <summary>Detects assembly references which will break in SMAPI 4.0.0.</summary>
+ internal class LegacyAssemblyFinder : BaseInstructionHandler
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public LegacyAssemblyFinder()
+ : base(defaultPhrase: "legacy assembly references") { }
+
+
+ /// <inheritdoc />
+ public override bool Handle(ModuleDefinition module)
+ {
+ foreach (AssemblyNameReference assembly in module.AssemblyReferences)
+ {
+ InstructionHandleResult flag = this.GetFlag(assembly);
+ if (flag is InstructionHandleResult.None)
+ continue;
+
+ this.MarkFlag(flag);
+ }
+
+ return false;
+ }
+
+
+ /*********
+ ** Private methods
+ *********/
+ /// <summary>Get the instruction handle flag for the given assembly reference, if any.</summary>
+ /// <param name="assemblyRef">The assembly reference.</param>
+ private InstructionHandleResult GetFlag(AssemblyNameReference assemblyRef)
+ {
+ return assemblyRef.Name switch
+ {
+ "System.Configuration.ConfigurationManager" => InstructionHandleResult.DetectedLegacyConfigurationDll,
+ "System.Runtime.Caching" => InstructionHandleResult.DetectedLegacyCachingDll,
+ "System.Security.Permission" => InstructionHandleResult.DetectedLegacyPermissionsDll,
+ _ => InstructionHandleResult.None
+ };
+ }
+ }
+}