import os
import hashlib
import concurrent.futures

def get_sha1(file_path):
    hasher = hashlib.sha1()
    with open(file_path, 'rb') as afile:
        buf = afile.read()
        hasher.update(buf)
    return hasher.hexdigest()

def worker(file_path, root_length):
    relative_path = ".\\\\" + file_path[root_length:].strip(os.sep).replace(os.sep, "\\")
    relative_path = relative_path.replace("\\app", "", 1)
    sha1_hash = get_sha1(file_path)
    return f"{relative_path}={sha1_hash}\n"

def generate_checksums(root_folder, output_file):
    root_folder_app = os.path.join(root_folder, "app")
    output_file_path = os.path.join(root_folder_app, output_file)

    with open(output_file_path, 'w') as f:
        root_length = len(root_folder)

        with concurrent.futures.ThreadPoolExecutor() as executor:
            future_to_file = {executor.submit(worker, os.path.join(folder, filename), root_length): filename
                              for folder, subfolders, files in os.walk(root_folder_app)
                              for filename in files if filename != output_file}
            for future in concurrent.futures.as_completed(future_to_file):
                result = future.result()
                f.write(result)

generate_checksums(r"C:\xampp\htdocs\upl", "checksum.ch")
