From da3142812bea5e38e88254a3691d2997c2849cbf Mon Sep 17 00:00:00 2001
From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com>
Date: Sat, 29 Jul 2023 23:34:19 +0200
Subject: [PATCH] Create script for creating manifest files

---
 r5dev/resource/script/bld_man.py | 51 ++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
 create mode 100644 r5dev/resource/script/bld_man.py

diff --git a/r5dev/resource/script/bld_man.py b/r5dev/resource/script/bld_man.py
new file mode 100644
index 00000000..0001c283
--- /dev/null
+++ b/r5dev/resource/script/bld_man.py
@@ -0,0 +1,51 @@
+#------------------------------------------------------------------------------
+import os
+import json
+import hashlib
+
+#------------------------------------------------------------------------------
+# Compute the SHA-256 checksum of a file
+#------------------------------------------------------------------------------
+def ComputeChecksum(filePath, blockSize=65536):
+    checksum = hashlib.sha256()
+    with open(filePath, "rb") as file:
+        for block in iter(lambda: file.read(blockSize), b""):
+            checksum.update(block)
+    return checksum.hexdigest()
+
+#------------------------------------------------------------------------------
+# Compute checksums for all files in a directory
+#------------------------------------------------------------------------------
+def RecursiveComputeChecksum(directoryPath):
+    checksums = {}
+    scriptPath = os.path.abspath(__file__)
+
+    for root, _, files in os.walk(directoryPath):
+        for fileName in files:
+            filePath = os.path.join(root, fileName)
+            relativePath = os.path.relpath(filePath, directoryPath)
+            normalizedPath = relativePath.replace("\\", "/")
+
+            # Exclude the script itself from the manifest
+            if os.path.abspath(filePath) == scriptPath:
+                continue
+
+            checksum = ComputeChecksum(filePath)
+            checksums[normalizedPath] = checksum
+
+    return checksums
+
+#------------------------------------------------------------------------------
+# Save the checksums to a manifest file
+#------------------------------------------------------------------------------
+def CreateManifest(checksums, outManifestFile):
+    with open(outManifestFile, "w") as jsonFile:
+        json.dump(checksums, jsonFile, indent=4)
+
+#------------------------------------------------------------------------------
+if __name__ == "__main__":
+    workingDirectory = os.getcwd()
+    outManifestFile = "manifest.json"
+
+    checksums = RecursiveComputeChecksum(workingDirectory)
+    CreateManifest(checksums, outManifestFile)