diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2021-11-30 17:12:49 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2021-11-30 17:12:49 -0500 |
commit | 919bbe94aa027c8a4ff8db4bdb50e8e2a28c48d9 (patch) | |
tree | 5c03ee1bd3cd658586755694940ac329491d6493 /src/SMAPI.Toolkit/Utilities/FileUtilities.cs | |
parent | 3ca6fb562417748c87567d6bb6915d56b2c1b57c (diff) | |
parent | d1d09ae1df63826dd453aa0347d668f420754ed7 (diff) | |
download | SMAPI-919bbe94aa027c8a4ff8db4bdb50e8e2a28c48d9.tar.gz SMAPI-919bbe94aa027c8a4ff8db4bdb50e8e2a28c48d9.tar.bz2 SMAPI-919bbe94aa027c8a4ff8db4bdb50e8e2a28c48d9.zip |
Merge branch 'beta' into develop
Diffstat (limited to 'src/SMAPI.Toolkit/Utilities/FileUtilities.cs')
-rw-r--r-- | src/SMAPI.Toolkit/Utilities/FileUtilities.cs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/SMAPI.Toolkit/Utilities/FileUtilities.cs b/src/SMAPI.Toolkit/Utilities/FileUtilities.cs index 7856fdb1..a6bf5929 100644 --- a/src/SMAPI.Toolkit/Utilities/FileUtilities.cs +++ b/src/SMAPI.Toolkit/Utilities/FileUtilities.cs @@ -1,4 +1,6 @@ +using System; using System.IO; +using System.Security.Cryptography; using System.Threading; namespace StardewModdingAPI.Toolkit.Utilities @@ -42,5 +44,16 @@ namespace StardewModdingAPI.Toolkit.Utilities if (entry.Exists) throw new IOException($"Timed out trying to delete {entry.FullName}"); } + + /// <summary>Get the MD5 hash for a file.</summary> + /// <param name="absolutePath">The absolute file path.</param> + public static string GetFileHash(string absolutePath) + { + using FileStream stream = File.OpenRead(absolutePath); + using MD5 md5 = MD5.Create(); + + byte[] hash = md5.ComputeHash(stream); + return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); + } } } |