Update gcmtest.py

This commit is contained in:
tmpz23 2022-01-18 17:23:08 +01:00 committed by GitHub
parent 37f28f0175
commit ae15654732
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,7 +5,7 @@ import os
import shutil import shutil
__version__ = "0.0.3" __version__ = "0.0.4"
__author__ = "rigodron, algoflash, GGLinnk" __author__ = "rigodron, algoflash, GGLinnk"
__license__ = "MIT" __license__ = "MIT"
__status__ = "developpement" __status__ = "developpement"
@ -13,11 +13,13 @@ __status__ = "developpement"
################################################## ##################################################
# Set roms_path with your ROMs (at the root of the ROM folder) # Set roms_path with your ROMs (at the root of the ROM folder)
# Extract all files from file system using dolphin emu - put it in gcm_dolphin/root/ # Extract all files from file system using dolphin emu - put it in f"{dolphin_unpack_path}/root/"
# Extract boot.dol and apploader.img using dolphin emu - put it in gcm_dolphin/sys/ # Extract boot.dol and apploader.img using dolphin emu - put it in f"{dolphin_unpack_path}/sys/"
################################################## ##################################################
roms_path = Path("../ROM") roms_path = Path("../ROM")
dolphin_unpack_path = Path("dolphin_unpack") dolphin_unpack_path = Path("dolphin_unpack")
# Created tmp paths
unpack_path = Path("unpack") unpack_path = Path("unpack")
unpack2_path = Path("unpack2") unpack2_path = Path("unpack2")
repack_path = Path("repack") repack_path = Path("repack")
@ -48,7 +50,11 @@ def compare_sha256(file1_path:Path, file2_path:Path):
# compare two GCM # compare two GCM
# -> raise an exception if there is a difference # -> raise an exception if there is a difference
def verify_GCM_sha256(folder1: Path, folder2: Path): def verify_GCM_sha256(folder1: Path, folder2: Path):
print(f"compare \"{folder1}\" - \"{folder2}\"") folder1_file_count = len(list(folder1.glob("**/*")))
print(f"compare \"{folder1}\" - \"{folder2}\" ({folder1_file_count} files)")
if folder1_file_count == 0:
raise Exception(f"ERROR - EMPTY FOLDER: {folder1}")
len1 = len(folder1.parts) len1 = len(folder1.parts)
len2 = len(folder2.parts) len2 = len(folder2.parts)
# 1. Compare names of filesystems # 1. Compare names of filesystems
@ -75,10 +81,11 @@ print("# Checking tests folder")
print("###############################################################################") print("###############################################################################")
# Check if tests folders exist # Check if tests folders exist
if unpack_path.is_dir() or unpack2_path.is_dir() or repack_path.is_dir(): if unpack_path.is_dir() or unpack2_path.is_dir() or repack_path.is_dir():
raise Exception(f"Error - Please remove:\n-{unpack_path}\n-{unpack2_path}\n{repack_path}") raise Exception(f"Error - Please remove:\n-{unpack_path}\n-{unpack2_path}\n-{repack_path}")
print("###############################################################################") print("###############################################################################")
print("# Comparing unpacked ROMs with dolphin extracts") print("# TEST 1/3")
print("# Comparing roms_path->unpack->[unpack_path] ROMs with [dolphin_unpack_path]")
print("###############################################################################") print("###############################################################################")
# unpack ROM in unpack_path # unpack ROM in unpack_path
unpack_path.mkdir(parents=True) unpack_path.mkdir(parents=True)
@ -92,7 +99,8 @@ for folder_path in unpack_path.glob("*"):
verify_GCM_sha256(folder_path, dolphin_unpack_path / folder_path.name) verify_GCM_sha256(folder_path, dolphin_unpack_path / folder_path.name)
print("###############################################################################") print("###############################################################################")
print("# Comparing iso->[1:unpacked]->repacked->[2:unpacked]") print("# TEST 2/3")
print("# Comparing [unpack_path]->pack->unpack->[unpack2_path]")
print("###############################################################################") print("###############################################################################")
# repack unpack_path repack_path # repack unpack_path repack_path
repack_path.mkdir() repack_path.mkdir()
@ -117,7 +125,8 @@ for folder_path in unpack_path.glob("*"):
shutil.rmtree(unpack2_path) shutil.rmtree(unpack2_path)
print("###############################################################################") print("###############################################################################")
print("# Comparing iso->[1:unpacked]->rebuild_fst->repack->[2:unpacked]") print("# TEST 3/3")
print("# Comparing [unpack_path]->rebuild_fst->repack->unpack->[unpack2_path]")
print("###############################################################################") print("###############################################################################")
# rebuild unpack_path FSTs # rebuild unpack_path FSTs
for folder_path in unpack_path.glob("*"): for folder_path in unpack_path.glob("*"):
@ -143,7 +152,7 @@ shutil.rmtree(repack_path)
for folder_path in unpack_path.glob("*"): for folder_path in unpack_path.glob("*"):
verify_GCM_sha256(folder_path, unpack2_path / folder_path.name) verify_GCM_sha256(folder_path, unpack2_path / folder_path.name)
# remove unpack_path unpack2_path # Remove tests folders
print("###############################################################################") print("###############################################################################")
print(f"# Cleaning test folders.") print(f"# Cleaning test folders.")
print("###############################################################################") print("###############################################################################")