Correct issue with updating host address. (#68)
This commit is contained in:
parent
a36d887122
commit
e60f20ef44
19
Patch.py
19
Patch.py
|
@ -33,13 +33,17 @@ def get_base_rom_bytes(file_name: str = "") -> bytes:
|
||||||
return base_rom_bytes
|
return base_rom_bytes
|
||||||
|
|
||||||
|
|
||||||
|
def generate_yaml(patch: bytes, metadata: Optional[dict] = None) -> bytes:
|
||||||
|
patch = yaml.dump({"meta": metadata,
|
||||||
|
"patch": patch})
|
||||||
|
return patch.encode(encoding="utf-8-sig")
|
||||||
|
|
||||||
|
|
||||||
def generate_patch(rom: bytes, metadata: Optional[dict] = None) -> bytes:
|
def generate_patch(rom: bytes, metadata: Optional[dict] = None) -> bytes:
|
||||||
if metadata is None:
|
if metadata is None:
|
||||||
metadata = {}
|
metadata = {}
|
||||||
patch = bsdiff4.diff(get_base_rom_bytes(), rom)
|
patch = bsdiff4.diff(get_base_rom_bytes(), rom)
|
||||||
patch = yaml.dump({"meta": metadata,
|
return generate_yaml(patch, metadata)
|
||||||
"patch": patch})
|
|
||||||
return patch.encode(encoding="utf-8-sig")
|
|
||||||
|
|
||||||
|
|
||||||
def create_patch_file(rom_file_to_patch: str, server: str = "") -> str:
|
def create_patch_file(rom_file_to_patch: str, server: str = "") -> str:
|
||||||
|
@ -63,7 +67,7 @@ def create_rom_file(patch_file: str) -> Tuple[dict, str]:
|
||||||
def update_patch_data(patch_data: bytes, server: str = "") -> bytes:
|
def update_patch_data(patch_data: bytes, server: str = "") -> bytes:
|
||||||
data = Utils.parse_yaml(lzma.decompress(patch_data).decode("utf-8-sig"))
|
data = Utils.parse_yaml(lzma.decompress(patch_data).decode("utf-8-sig"))
|
||||||
data["meta"]["server"] = server
|
data["meta"]["server"] = server
|
||||||
bytes = generate_patch(data["patch"], data["meta"])
|
bytes = generate_yaml(data["patch"], data["meta"])
|
||||||
return lzma.compress(bytes)
|
return lzma.compress(bytes)
|
||||||
|
|
||||||
|
|
||||||
|
@ -76,6 +80,7 @@ def write_lzma(data: bytes, path: str):
|
||||||
with lzma.LZMAFile(path, 'wb') as f:
|
with lzma.LZMAFile(path, 'wb') as f:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
host = Utils.get_public_ipv4()
|
host = Utils.get_public_ipv4()
|
||||||
options = Utils.get_options()['server_options']
|
options = Utils.get_options()['server_options']
|
||||||
|
@ -86,7 +91,6 @@ if __name__ == "__main__":
|
||||||
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}")
|
||||||
|
|
||||||
Processed = False
|
|
||||||
for rom in sys.argv:
|
for rom in sys.argv:
|
||||||
try:
|
try:
|
||||||
if rom.endswith(".sfc"):
|
if rom.endswith(".sfc"):
|
||||||
|
@ -101,6 +105,7 @@ if __name__ == "__main__":
|
||||||
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):
|
def _handle_zip_file_entry(zfinfo : zipfile.ZipInfo, server: str):
|
||||||
data = zfr.read(zfinfo)
|
data = zfr.read(zfinfo)
|
||||||
if zfinfo.filename.endswith(".bmbp"):
|
if zfinfo.filename.endswith(".bmbp"):
|
||||||
|
@ -122,6 +127,4 @@ if __name__ == "__main__":
|
||||||
except:
|
except:
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
input("Press enter to close.")
|
||||||
if Processed:
|
|
||||||
input("Press enter to close.")
|
|
||||||
|
|
Loading…
Reference in New Issue