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.
122 lines
3.4 KiB
122 lines
3.4 KiB
#!/usr/bin/env python3 |
|
""" |
|
Create a sample MPQ archive for testing the MPQ Inspector |
|
This creates a small archive with a few text files |
|
""" |
|
|
|
from pathlib import Path |
|
import sys |
|
|
|
try: |
|
from pystorm import MPQArchive, MPQ_CREATE_ARCHIVE_V2, MPQ_FILE_COMPRESS, StormLibError |
|
except ImportError: |
|
print("Error: PyStorm not installed. Please run: pip install -e .") |
|
sys.exit(1) |
|
|
|
|
|
def create_sample_mpq(): |
|
"""Create a sample MPQ archive with test files""" |
|
|
|
# Create temporary directory with sample files |
|
temp_dir = Path("temp_sample_files") |
|
temp_dir.mkdir(exist_ok=True) |
|
|
|
# Create some sample text files |
|
files_to_add = { |
|
"readme.txt": """MPQ Archive Sample |
|
================== |
|
|
|
This is a sample MPQ archive created by PyStorm. |
|
|
|
MPQ (MoPaQ) is an archive format used by Blizzard Entertainment |
|
games including Diablo, StarCraft, Warcraft III, and World of Warcraft. |
|
|
|
This archive contains several sample files for demonstration purposes. |
|
""", |
|
"data/config.txt": """# Sample Configuration File |
|
setting1=value1 |
|
setting2=value2 |
|
enabled=true |
|
compression=zlib |
|
""", |
|
"data/items.txt": """ItemID,Name,Type,Value |
|
1,Sword,Weapon,100 |
|
2,Shield,Armor,75 |
|
3,Potion,Consumable,25 |
|
4,Ring,Accessory,150 |
|
""", |
|
"scripts/init.lua": """-- Sample Lua Script |
|
print("Loading MPQ archive...") |
|
|
|
function initialize() |
|
print("Initialization complete!") |
|
end |
|
|
|
initialize() |
|
""", |
|
"maps/level1.txt": """MAP: Level 1 |
|
Size: 100x100 |
|
Tiles: 10000 |
|
Objects: 250 |
|
Enemies: 15 |
|
""", |
|
} |
|
|
|
# Create the files |
|
created_files = [] |
|
for filename, content in files_to_add.items(): |
|
filepath = temp_dir / filename |
|
filepath.parent.mkdir(parents=True, exist_ok=True) |
|
filepath.write_text(content) |
|
created_files.append(filepath) |
|
print(f"Created: {filename}") |
|
|
|
# Create the MPQ archive |
|
archive_path = "sample_archive.mpq" |
|
|
|
try: |
|
print(f"\nCreating MPQ archive: {archive_path}") |
|
with MPQArchive(archive_path, flags=MPQ_CREATE_ARCHIVE_V2) as archive: |
|
for filepath in created_files: |
|
# Get archived name (relative path with forward slashes) |
|
archived_name = str(filepath.relative_to(temp_dir)) |
|
archived_name = archived_name.replace("\\", "/") |
|
|
|
# Add with compression |
|
archive.add_file(str(filepath), archived_name, flags=MPQ_FILE_COMPRESS) |
|
print(f"Added to archive: {archived_name}") |
|
|
|
# Flush changes |
|
archive.flush() |
|
|
|
print(f"\n✓ Sample archive created: {archive_path}") |
|
print(f" Size: {Path(archive_path).stat().st_size} bytes") |
|
print("\nYou can now open this file with mpq_inspector.py!") |
|
|
|
except StormLibError as e: |
|
print(f"\n✗ Error creating archive: {e}") |
|
return False |
|
finally: |
|
# Clean up temporary files |
|
for filepath in created_files: |
|
filepath.unlink() |
|
|
|
# Remove empty directories |
|
for dirpath in sorted(temp_dir.rglob("*"), reverse=True): |
|
if dirpath.is_dir(): |
|
try: |
|
dirpath.rmdir() |
|
except OSError: |
|
pass |
|
temp_dir.rmdir() |
|
|
|
return True |
|
|
|
|
|
if __name__ == "__main__": |
|
print("PyStorm Sample MPQ Creator") |
|
print("=" * 50) |
|
print() |
|
|
|
success = create_sample_mpq() |
|
sys.exit(0 if success else 1)
|
|
|