diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2016-12-05 23:51:09 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2016-12-05 23:51:09 -0500 |
commit | 315943614573f0e1973bafc761c27207b8ea2b45 (patch) | |
tree | 80678aded464bc3b6b6414d688b180986886aa83 /src/StardewModdingAPI/Framework/AssemblyRewriting/CacheEntry.cs | |
parent | 31301988e97a9460ea2cb4898eb263a4e6c297d2 (diff) | |
download | SMAPI-315943614573f0e1973bafc761c27207b8ea2b45.tar.gz SMAPI-315943614573f0e1973bafc761c27207b8ea2b45.tar.bz2 SMAPI-315943614573f0e1973bafc761c27207b8ea2b45.zip |
reimplement assembly caching (#187)
This commit ensures DLLs are copied to the cache directory only if they changed, to avoid breaking debugging support unless necessary. To support this change, the assembly hash file has been replaced with a more detailed JSON structure, which is used to determine whether the cache is up-to-date and whether to use the cached or original assembly. Some mods contain multiple DLLs, which must be kept together to prevent assembly resolution issues; to simplify that (and avoid orphaned cache entries), each mod now has its own separate cache.
Diffstat (limited to 'src/StardewModdingAPI/Framework/AssemblyRewriting/CacheEntry.cs')
-rw-r--r-- | src/StardewModdingAPI/Framework/AssemblyRewriting/CacheEntry.cs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/StardewModdingAPI/Framework/AssemblyRewriting/CacheEntry.cs b/src/StardewModdingAPI/Framework/AssemblyRewriting/CacheEntry.cs new file mode 100644 index 00000000..3dfbc78c --- /dev/null +++ b/src/StardewModdingAPI/Framework/AssemblyRewriting/CacheEntry.cs @@ -0,0 +1,46 @@ +using System.IO; + +namespace StardewModdingAPI.Framework.AssemblyRewriting +{ + /// <summary>Represents cached metadata for a rewritten assembly.</summary> + internal class CacheEntry + { + /********* + ** Accessors + *********/ + /// <summary>The MD5 hash for the original assembly.</summary> + public readonly string Hash; + + /// <summary>The SMAPI version used to rewrite the assembly.</summary> + public readonly string ApiVersion; + + /// <summary>Whether to use the cached assembly instead of the original assembly.</summary> + public readonly bool UseCachedAssembly; + + + /********* + ** Public methods + *********/ + /// <summary>Construct an instance.</summary> + /// <param name="hash">The MD5 hash for the original assembly.</param> + /// <param name="apiVersion">The SMAPI version used to rewrite the assembly.</param> + /// <param name="useCachedAssembly">Whether to use the cached assembly instead of the original assembly.</param> + public CacheEntry(string hash, string apiVersion, bool useCachedAssembly) + { + this.Hash = hash; + this.ApiVersion = apiVersion; + this.UseCachedAssembly = useCachedAssembly; + } + + /// <summary>Get whether the cache entry is up-to-date for the given assembly hash.</summary> + /// <param name="paths">The paths for the cached assembly.</param> + /// <param name="hash">The MD5 hash of the original assembly.</param> + /// <param name="currentVersion">The current SMAPI version.</param> + public bool IsUpToDate(CachePaths paths, string hash, Version currentVersion) + { + return hash == this.Hash + && this.ApiVersion == currentVersion.ToString() + && (!this.UseCachedAssembly || File.Exists(paths.Assembly)); + } + } +}
\ No newline at end of file |