#!/usr/bin/env python # -*- coding: utf-8 -*- import os import sys from pathlib import Path RUST_CODE = '''#[cfg(target_os = "windows")] #[no_mangle] pub extern "C" fn NoHotPatch() {} ''' def should_add_code(content): return "NoHotPatch" not in content def process_file(file_path): try: with open(file_path, 'r', encoding='utf-8') as f: content = f.read() if should_add_code(content): print(f"Adding NoHotPatch to {file_path}") with open(file_path, 'w', encoding='utf-8') as f: f.write(RUST_CODE + content) else: print(f"NoHotPatch already exists in {file_path}") except Exception as e: print(f"Error processing {file_path}: {e}") def main(): # Get target directory from command line arg or use current directory target_dir = sys.argv[1] if len(sys.argv) > 1 else "." # Convert to absolute path target_dir = os.path.abspath(target_dir) print(f"Scanning directory: {target_dir}") # Walk through all directories for root, _, files in os.walk(target_dir): for file in files: if file in ["main.rs", "lib.rs"]: file_path = os.path.join(root, file) process_file(file_path) if __name__ == "__main__": main()