diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-06-01 19:59:00 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-06-01 19:59:00 -0400 |
commit | e10147e7bda94a8fbc58684246628a6520d2c6b8 (patch) | |
tree | 3135a4ef641192e42ee1f97b8c56fc9b76a52aee /src/SMAPI/Framework/ModLoading/Finders | |
parent | 0209e70695b6d12692d4de554ce1fc9d65ca4715 (diff) | |
parent | 1cded44f7a5626a0d4f5c3ce48a83aa544d517c3 (diff) | |
download | SMAPI-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.cs | 49 |
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 + }; + } + } +} |