Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.3 kB
5
Indexable
Never
import os
import hashlib
import json

# Configuration
SERVER_DIR = "C:/Games/TestDirectory"  # Directory to scan
EXEMPT_DIR = os.path.join(SERVER_DIR, "TCO Updater")
MANIFEST_PATH = os.path.join(EXEMPT_DIR, "manifest.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, exempt_dir):
    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).replace("\\", "/")
            if file_path.startswith(exempt_dir) or relative_path == "TCO Updater/manifest.json":
                continue
            manifest["files"][relative_path] = get_file_checksum(file_path)
    return manifest

if __name__ == "__main__":
    manifest = generate_manifest(SERVER_DIR, EXEMPT_DIR)
    os.makedirs(EXEMPT_DIR, exist_ok=True)
    with open(MANIFEST_PATH, 'w') as f:
        json.dump(manifest, f, indent=4)
    print(f"Manifest generated at: {MANIFEST_PATH}")
Leave a Comment