import os import hashlib import json import argparse excluded_paths = [ 'manifest.json', 'Updater.exe' ] def is_excluded(path): for excluded in excluded_paths: if path.startswith(excluded): return True return False def file_hash(path): h = hashlib.sha1() with open(path, 'rb') as f: while chunk := f.read(8192): h.update(chunk) return h.hexdigest() def generate_manifest(directory): manifest = {} for root, dirs, 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 is_excluded(relative_path): continue hash_value = file_hash(file_path) manifest[relative_path] = hash_value return manifest def save_manifest(manifest, output_path): with open(output_path, 'w') as f: json.dump(manifest, f, indent=4) print(f"Manifest saved to {output_path}") def main(): parser = argparse.ArgumentParser(description="Generate manifest.json with SHA1 hashes.") parser.add_argument('directory', type=str, help="Folder to scan") parser.add_argument('--output', type=str, help="Optional output path for manifest.json") args = parser.parse_args() directory = args.directory if not os.path.isdir(directory): print(f"Directory '{directory}' does not exist.") return output_path = args.output if args.output else os.path.join(directory, 'manifest.json') print(f"Scanning directory: {directory}...") manifest = generate_manifest(directory) save_manifest(manifest, output_path) if __name__ == "__main__": main()