parent
dd0a4e84e9
commit
815ec85da9
55
Patch.py
55
Patch.py
|
@ -93,31 +93,34 @@ if __name__ == "__main__":
|
||||||
address = f"{host}:{options['port']}"
|
address = f"{host}:{options['port']}"
|
||||||
ziplock = threading.Lock()
|
ziplock = threading.Lock()
|
||||||
print(f"Host for patches to be created is {address}")
|
print(f"Host for patches to be created is {address}")
|
||||||
|
with concurrent.futures.ThreadPoolExecutor() as pool:
|
||||||
|
for rom in sys.argv:
|
||||||
|
try:
|
||||||
|
|
||||||
for rom in sys.argv:
|
if rom.endswith(".sfc"):
|
||||||
try:
|
print(f"Creating patch for {rom}")
|
||||||
if rom.endswith(".sfc"):
|
result = pool.submit(create_patch_file, rom, address)
|
||||||
print(f"Creating patch for {rom}")
|
result.add_done_callback(lambda task: print(f"Created patch {task.result()}"))
|
||||||
result = create_patch_file(rom, address)
|
|
||||||
print(f"Created patch {result}")
|
elif rom.endswith(".bmbp"):
|
||||||
elif rom.endswith(".bmbp"):
|
print(f"Applying patch {rom}")
|
||||||
print(f"Applying patch {rom}")
|
data, target = create_rom_file(rom)
|
||||||
data, target = create_rom_file(rom)
|
print(f"Created rom {target}.")
|
||||||
print(f"Created rom {target}.")
|
if 'server' in data:
|
||||||
if 'server' in data:
|
print(f"Host is {data['server']}")
|
||||||
print(f"Host is {data['server']}")
|
|
||||||
elif rom.endswith(".zip"):
|
elif rom.endswith(".zip"):
|
||||||
print(f"Updating host in patch files contained in {rom}")
|
print(f"Updating host in patch files contained in {rom}")
|
||||||
|
|
||||||
|
def _handle_zip_file_entry(zfinfo : zipfile.ZipInfo, server: str):
|
||||||
|
data = zfr.read(zfinfo)
|
||||||
|
if zfinfo.filename.endswith(".bmbp"):
|
||||||
|
data = update_patch_data(data, server)
|
||||||
|
with ziplock:
|
||||||
|
zfw.writestr(zfinfo, data)
|
||||||
|
return zfinfo.filename
|
||||||
|
|
||||||
def _handle_zip_file_entry(zfinfo : zipfile.ZipInfo, server: str):
|
|
||||||
data = zfr.read(zfinfo)
|
|
||||||
if zfinfo.filename.endswith(".bmbp"):
|
|
||||||
data = update_patch_data(data, server)
|
|
||||||
with ziplock:
|
|
||||||
zfw.writestr(zfinfo, data)
|
|
||||||
return zfinfo.filename
|
|
||||||
|
|
||||||
with concurrent.futures.ThreadPoolExecutor() as pool:
|
|
||||||
futures = []
|
futures = []
|
||||||
with zipfile.ZipFile(rom, "r") as zfr:
|
with zipfile.ZipFile(rom, "r") as zfr:
|
||||||
updated_zip = os.path.splitext(rom)[0] + "_updated.zip"
|
updated_zip = os.path.splitext(rom)[0] + "_updated.zip"
|
||||||
|
@ -127,7 +130,7 @@ if __name__ == "__main__":
|
||||||
for future in futures:
|
for future in futures:
|
||||||
print(f"File {future.result()} added to {os.path.split(updated_zip)[1]}")
|
print(f"File {future.result()} added to {os.path.split(updated_zip)[1]}")
|
||||||
|
|
||||||
except:
|
except:
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
input("Press enter to close.")
|
input("Press enter to close.")
|
||||||
|
|
Loading…
Reference in New Issue