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.
93 lines
2.7 KiB
93 lines
2.7 KiB
#!/usr/bin/env python3 |
|
""" |
|
Example: Extract all files from an MPQ archive |
|
""" |
|
|
|
from pystorm import MPQArchive |
|
from pathlib import Path |
|
import sys |
|
|
|
|
|
def extract_all_files(archive_path, output_dir): |
|
""" |
|
Extract all files from an MPQ archive to a directory |
|
|
|
Args: |
|
archive_path: Path to the MPQ archive |
|
output_dir: Directory to extract files to |
|
""" |
|
archive_path = Path(archive_path) |
|
output_dir = Path(output_dir) |
|
|
|
if not archive_path.exists(): |
|
print(f"Error: Archive not found: {archive_path}") |
|
return False |
|
|
|
# Create output directory |
|
output_dir.mkdir(parents=True, exist_ok=True) |
|
|
|
print(f"Extracting files from: {archive_path}") |
|
print(f"Output directory: {output_dir}\n") |
|
|
|
try: |
|
with MPQArchive(str(archive_path)) as archive: |
|
# Find all files |
|
files = archive.find_files("*") |
|
total_files = len(files) |
|
|
|
if total_files == 0: |
|
print("No files found in archive") |
|
return True |
|
|
|
print(f"Found {total_files} file(s) to extract\n") |
|
|
|
# Extract each file |
|
extracted = 0 |
|
failed = 0 |
|
|
|
for i, file_info in enumerate(files, 1): |
|
filename = file_info['name'] |
|
|
|
# Create output path |
|
output_path = output_dir / filename |
|
output_path.parent.mkdir(parents=True, exist_ok=True) |
|
|
|
# Extract file |
|
try: |
|
archive.extract_file(filename, str(output_path)) |
|
extracted += 1 |
|
print(f"[{i}/{total_files}] ✓ {filename}") |
|
except Exception as e: |
|
failed += 1 |
|
print(f"[{i}/{total_files}] ✗ {filename} - Error: {e}") |
|
|
|
print(f"\n{'='*60}") |
|
print(f"Extraction complete!") |
|
print(f" Successful: {extracted}") |
|
print(f" Failed: {failed}") |
|
print(f"{'='*60}") |
|
|
|
return failed == 0 |
|
|
|
except Exception as e: |
|
print(f"Error opening archive: {e}") |
|
return False |
|
|
|
|
|
def main(): |
|
"""Main entry point""" |
|
if len(sys.argv) < 2: |
|
print("Usage: python extract_all.py <archive.mpq> [output_dir]") |
|
print("\nExample:") |
|
print(" python extract_all.py game.mpq extracted_files") |
|
sys.exit(1) |
|
|
|
archive_path = sys.argv[1] |
|
output_dir = sys.argv[2] if len(sys.argv) > 2 else "extracted_files" |
|
|
|
success = extract_all_files(archive_path, output_dir) |
|
sys.exit(0 if success else 1) |
|
|
|
|
|
if __name__ == "__main__": |
|
main()
|
|
|