summaryrefslogtreecommitdiff
path: root/src/SMAPI.Toolkit/Utilities/FileUtilities.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-11-30 17:12:49 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-11-30 17:12:49 -0500
commit919bbe94aa027c8a4ff8db4bdb50e8e2a28c48d9 (patch)
tree5c03ee1bd3cd658586755694940ac329491d6493 /src/SMAPI.Toolkit/Utilities/FileUtilities.cs
parent3ca6fb562417748c87567d6bb6915d56b2c1b57c (diff)
parentd1d09ae1df63826dd453aa0347d668f420754ed7 (diff)
downloadSMAPI-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.cs13
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();
+ }
}
}