summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/ModLoading/Finders
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-06-01 19:59:00 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-06-01 19:59:00 -0400
commite10147e7bda94a8fbc58684246628a6520d2c6b8 (patch)
tree3135a4ef641192e42ee1f97b8c56fc9b76a52aee /src/SMAPI/Framework/ModLoading/Finders
parent0209e70695b6d12692d4de554ce1fc9d65ca4715 (diff)
parent1cded44f7a5626a0d4f5c3ce48a83aa544d517c3 (diff)
downloadSMAPI-e10147e7bda94a8fbc58684246628a6520d2c6b8.tar.gz
SMAPI-e10147e7bda94a8fbc58684246628a6520d2c6b8.tar.bz2
SMAPI-e10147e7bda94a8fbc58684246628a6520d2c6b8.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI/Framework/ModLoading/Finders')
-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
+ };
+ }
+ }
+}