summaryrefslogtreecommitdiff
path: root/src/SMAPI.Toolkit
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI.Toolkit')
-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();
+ }
}
}