Untitled

 avatar
unknown
plain_text
a year ago
1.0 kB
6
Indexable
import os
import hashlib
import json

def get_file_checksum(file_path):
    """Calculate the MD5 checksum of a file."""
    md5 = hashlib.md5()
    with open(file_path, 'rb') as f:
        for chunk in iter(lambda: f.read(4096), b""):
            md5.update(chunk)
    return md5.hexdigest()

def generate_manifest(directory):
    manifest = {"files": {}}
    for root, _, files in os.walk(directory):
        for file in files:
            file_path = os.path.join(root, file)
            relative_path = os.path.relpath(file_path, directory)
            manifest["files"][relative_path.replace("\\", "/")] = get_file_checksum(file_path)
    return manifest

if __name__ == "__main__":
    directory = "C:/Games/TestDirectory"  # Change this to your server test directory
    manifest = generate_manifest(directory)
    manifest_path = os.path.join(directory, "manifest.json")
    with open(manifest_path, 'w') as f:
        json.dump(manifest, f, indent=4)
    print(f"Manifest generated at: {manifest_path}")
Editor is loading...
Leave a Comment