You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
150 lines
4.3 KiB
150 lines
4.3 KiB
#!/usr/bin/env python3 |
|
""" |
|
Debug script to test PyStorm with Starcraft.mpq |
|
""" |
|
|
|
import sys |
|
from pathlib import Path |
|
|
|
print("="*60) |
|
print("PyStorm Debug Script - Testing with Starcraft.mpq") |
|
print("="*60) |
|
|
|
# Test 1: Import PyStorm |
|
print("\n[1/5] Importing PyStorm...") |
|
try: |
|
from pystorm import MPQArchive, StormLibError |
|
print("✓ PyStorm imported successfully") |
|
except ImportError as e: |
|
print(f"✗ Failed to import PyStorm: {e}") |
|
sys.exit(1) |
|
|
|
# Test 2: Check file exists |
|
print("\n[2/5] Checking if Starcraft.mpq exists...") |
|
mpq_path = Path("Starcraft.mpq") |
|
if not mpq_path.exists(): |
|
print(f"✗ File not found: {mpq_path.absolute()}") |
|
sys.exit(1) |
|
|
|
file_size = mpq_path.stat().st_size |
|
print(f"✓ File found: {mpq_path}") |
|
print(f" Size: {file_size:,} bytes ({file_size / 1024 / 1024:.2f} MB)") |
|
|
|
# Test 3: Open the archive |
|
print("\n[3/5] Opening archive...") |
|
try: |
|
archive = MPQArchive(str(mpq_path)) |
|
print("✓ Archive opened successfully") |
|
except StormLibError as e: |
|
print(f"✗ Failed to open archive: {e}") |
|
sys.exit(1) |
|
except Exception as e: |
|
print(f"✗ Unexpected error: {e}") |
|
import traceback |
|
traceback.print_exc() |
|
sys.exit(1) |
|
|
|
# Test 4: List files |
|
print("\n[4/5] Listing files in archive...") |
|
try: |
|
files = archive.find_files("*") |
|
print(f"✓ Found {len(files)} files in archive") |
|
|
|
# Show first 10 files |
|
print("\nFirst 10 files:") |
|
for i, file_info in enumerate(files[:10], 1): |
|
name = file_info['name'] |
|
size = file_info['size'] |
|
compressed = file_info['compressed_size'] |
|
print(f" {i:2d}. {name:40s} {size:>10,} bytes") |
|
|
|
if len(files) > 10: |
|
print(f" ... and {len(files) - 10} more files") |
|
|
|
# Statistics |
|
total_size = sum(f['size'] for f in files) |
|
total_compressed = sum(f['compressed_size'] for f in files) |
|
ratio = (1 - total_compressed / total_size) * 100 if total_size > 0 else 0 |
|
|
|
print(f"\nArchive Statistics:") |
|
print(f" Total files: {len(files)}") |
|
print(f" Uncompressed size: {total_size:,} bytes ({total_size / 1024 / 1024:.2f} MB)") |
|
print(f" Compressed size: {total_compressed:,} bytes ({total_compressed / 1024 / 1024:.2f} MB)") |
|
print(f" Compression ratio: {ratio:.1f}%") |
|
|
|
except StormLibError as e: |
|
print(f"✗ Failed to list files: {e}") |
|
archive.close() |
|
sys.exit(1) |
|
except Exception as e: |
|
print(f"✗ Unexpected error: {e}") |
|
import traceback |
|
traceback.print_exc() |
|
archive.close() |
|
sys.exit(1) |
|
|
|
# Test 5: Extract a small file |
|
print("\n[5/5] Testing file extraction...") |
|
try: |
|
# Find the smallest file to extract |
|
if files: |
|
smallest = min(files, key=lambda f: f['size']) |
|
test_file = smallest['name'] |
|
test_size = smallest['size'] |
|
|
|
print(f" Extracting: {test_file} ({test_size} bytes)") |
|
|
|
# Extract to temporary file then read |
|
import tempfile |
|
with tempfile.NamedTemporaryFile(delete=False) as tmp: |
|
tmp_path = tmp.name |
|
|
|
archive.extract_file(test_file, tmp_path) |
|
with open(tmp_path, 'rb') as f: |
|
data = f.read() |
|
|
|
import os |
|
os.unlink(tmp_path) |
|
|
|
print(f"✓ Successfully extracted {len(data)} bytes") |
|
|
|
# Show first 100 bytes if it's text-like |
|
if test_size < 1000: |
|
try: |
|
text = data.decode('utf-8', errors='ignore')[:200] |
|
if text.isprintable() or '\n' in text: |
|
print(f"\n Preview (first 200 chars):") |
|
print(" " + "-"*50) |
|
for line in text.split('\n')[:5]: |
|
print(f" {line}") |
|
print(" " + "-"*50) |
|
except: |
|
pass |
|
else: |
|
print(" No files to extract") |
|
|
|
except StormLibError as e: |
|
print(f"✗ Failed to extract file: {e}") |
|
archive.close() |
|
sys.exit(1) |
|
except Exception as e: |
|
print(f"✗ Unexpected error: {e}") |
|
import traceback |
|
traceback.print_exc() |
|
archive.close() |
|
sys.exit(1) |
|
|
|
# Cleanup |
|
print("\n[6/6] Closing archive...") |
|
try: |
|
archive.close() |
|
print("✓ Archive closed") |
|
except Exception as e: |
|
print(f"✗ Failed to close archive: {e}") |
|
finally: |
|
# Prevent __del__ from trying to close again |
|
archive._closed = True |
|
|
|
print("\n" + "="*60) |
|
print("ALL TESTS PASSED! PyStorm is working correctly.") |
|
print("="*60)
|
|
|