Skip to content

Commit

Permalink
Fix mod presets being deleted when changed
Browse files Browse the repository at this point in the history
  • Loading branch information
pizzaboxer committed Aug 23, 2022
1 parent 1ab1977 commit 4c0e7f5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Bloxstrap/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ private void ApplyModifications()
private static void CheckModPreset(bool condition, string location, string base64Contents)
{
string modFolderLocation = Path.Combine(Directories.Modifications, location);
byte[] binaryData = Convert.FromBase64String(base64Contents);

if (condition)
{
Expand All @@ -575,10 +576,10 @@ private static void CheckModPreset(bool condition, string location, string base6

Directory.CreateDirectory(directory);

File.WriteAllBytes(modFolderLocation, Convert.FromBase64String(base64Contents));
File.WriteAllBytes(modFolderLocation, binaryData);
}
}
else if (File.Exists(modFolderLocation))
else if (File.Exists(modFolderLocation) && Utilities.MD5File(modFolderLocation) == Utilities.MD5Data(binaryData))
{
File.Delete(modFolderLocation);
}
Expand Down
9 changes: 9 additions & 0 deletions Bloxstrap/Helpers/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ public static string MD5File(string filename)
}
}

public static string MD5Data(byte[] data)
{
using (MD5 md5 = MD5.Create())
{
byte[] hash = md5.ComputeHash(data);
return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
}
}

// quick and hacky way of getting a value from any key/value pair formatted list
// (command line args, uri params, etc)
public static string? GetKeyValue(string subject, string key, char delimiter)
Expand Down

0 comments on commit 4c0e7f5

Please sign in to comment.