#!/usr/bin/env python3 """Read CHM file directly using Windows API""" import subprocess import sys def read_chm_with_keyhh(chm_path): """Try to read CHM table of contents using keyhh.exe""" try: # Try using keyhh.exe to dump CHM info result = subprocess.run( ['keyhh.exe', '-#klink', 'contents', chm_path], capture_output=True, text=True, timeout=10 ) return result.stdout except Exception as e: return f"Error: {e}" def extract_with_expand(chm_path, output_dir): """Try using expand.exe""" try: result = subprocess.run( ['expand.exe', chm_path, '-F:*', output_dir], capture_output=True, text=True, timeout=30 ) return result.stdout + "\n" + result.stderr except Exception as e: return f"Error: {e}" if __name__ == "__main__": chm_file = r"C:\GEVISOFT\Documentation\GeViSoft .NET SDK API Documentation.chm" output_dir = r"C:\DEV\COPILOT\SOURCES\GeViSoft_NET_SDK_API" print(f"Attempting to extract: {chm_file}") print(f"Output directory: {output_dir}\n") print("=== Trying expand.exe ===") result = extract_with_expand(chm_file, output_dir) print(result) print("\n=== Trying keyhh.exe ===") result = read_chm_with_keyhh(chm_file) print(result) # Check if any files were created import os if os.path.exists(output_dir): file_count = sum([len(files) for r, d, files in os.walk(output_dir)]) print(f"\nFiles in output directory: {file_count}") else: print("\nOutput directory doesn't exist")