#!/usr/bin/env python3 """Test PS3 update/DLC application on Borderlands 2. Creates a test copy and applies updates to show the difference. """ import sys import shutil from pathlib import Path # Add project to path sys.path.insert(0, '/data/emu/rom-groomer-python/src') from romgroomer.stages.apply_ps3_updates import ApplyPS3UpdatesStage from romgroomer.stages.base import StageContext def main(): """Test update application.""" # Paths source_game = Path("/data/emu/ps3netsrv/GAMES/Street Fighter IV (USA, Korea) (En,Ja,Fr,De,Es,It,Ko).ps3") test_game = Path("/tmp/Street Fighter IV (USA) (Test - No Updates).ps3") nps_database = "/data/emu/source/nopaystation/PS3_DLCS.tsv" pkg_archive = "/data/emu/source/nopaystation/downloads-ps3-dlc" pkg2zip_path = "/data/emu/rom-groomer-python/tools/bin/pkg2zip" print("=" * 70) print("Street Fighter IV Update/DLC Test") print("=" * 70) print() # Check source if not source_game.exists(): print(f"Error: Source game not found: {source_game}") return 1 # Remove old test if exists if test_game.exists(): print(f"Removing old test copy...") shutil.rmtree(test_game) # Copy game print(f"Creating test copy...") print(f" Source: {source_game.name}") print(f" Test: {test_game.name}") shutil.copytree(source_game, test_game) print(f" ✓ Copied") print() # Remove PS3_UPDATE if it exists update_dir = test_game / "PS3_UPDATE" if update_dir.exists(): print(f"Removing existing PS3_UPDATE folder...") shutil.rmtree(update_dir) print(f" ✓ Removed (simulating base game)") print() # Show before state print("=" * 70) print("BEFORE: Test Game State") print("=" * 70) for item in sorted(test_game.iterdir()): if item.is_dir(): file_count = len(list(item.rglob("*"))) print(f" {item.name}/ ({file_count} items)") else: print(f" {item.name}") print() # Create and run stage print("=" * 70) print("Running ApplyPS3UpdatesStage...") print("=" * 70) stage = ApplyPS3UpdatesStage( nps_database=nps_database, pkg_archive=pkg_archive, pkg2zip_path=pkg2zip_path, apply_updates=True, apply_dlc=False, # Start with updates only ) context = StageContext( platform_name="ps3", platform_config=None, target_name="test", source_dir=test_game.parent, work_dir=test_game.parent, output_dir=test_game.parent, ) result = stage.execute(context) print() # Show after state print("=" * 70) print("AFTER: Test Game State") print("=" * 70) for item in sorted(test_game.iterdir()): if item.is_dir(): file_count = len(list(item.rglob("*"))) size = sum(f.stat().st_size for f in item.rglob("*") if f.is_file()) print(f" {item.name}/ ({file_count} items, {size:,} bytes)") else: size = item.stat().st_size print(f" {item.name} ({size:,} bytes)") print() # Show what was added to PS3_UPDATE if update_dir.exists(): print("=" * 70) print("PS3_UPDATE Contents:") print("=" * 70) for item in sorted(update_dir.rglob("*"))[:20]: # Show first 20 rel_path = item.relative_to(test_game) if item.is_file(): size = item.stat().st_size print(f" {rel_path} ({size:,} bytes)") else: print(f" {rel_path}/") total_update_files = len(list(update_dir.rglob("*"))) if total_update_files > 20: print(f" ... and {total_update_files - 20} more items") else: print("⚠ No PS3_UPDATE folder created") print() print("=" * 70) print("Test Complete!") print("=" * 70) print() print("You can now see both versions in WebMAN:") print(f" Original: {source_game.name}") print(f" Test: {test_game.name}") print() print("The test version should now have updates applied.") return 0 if __name__ == '__main__': sys.exit(main())