close files properly after patching
parent
1f2cba725d
commit
ad6cf68969
|
@ -2616,20 +2616,22 @@ def patch_game():
|
||||||
os.system('.\\armips\\armips.exe "Metroid Fusion Open Randomizer.asm" -root ".\\data\\asm" -sym ".\\temp.sym"')
|
os.system('.\\armips\\armips.exe "Metroid Fusion Open Randomizer.asm" -root ".\\data\\asm" -sym ".\\temp.sym"')
|
||||||
os.replace('.\\data\\MFOR.gba', '.\\seeds\\{}.gba'.format(FileName))
|
os.replace('.\\data\\MFOR.gba', '.\\seeds\\{}.gba'.format(FileName))
|
||||||
else:
|
else:
|
||||||
source = open(BaseGame, 'rb')
|
error = False
|
||||||
target = open(os.path.join('.', 'seeds', '{}.gba'.format(FileName)), 'wb')
|
with open(BaseGame, 'rb') as source:
|
||||||
patch = open(os.path.join('.', 'data', 'MFOR.bps'), 'rb')
|
with open(os.path.join('.', 'seeds', '{}.gba'.format(FileName)), 'wb') as target:
|
||||||
|
with open(os.path.join('.', 'data', 'MFOR.bps'), 'rb') as patch:
|
||||||
try:
|
try:
|
||||||
apply_to_files(patch, source, target)
|
apply_to_files(patch, source, target)
|
||||||
except:
|
except Exception:
|
||||||
target.close()
|
error = True
|
||||||
os.unlink(os.path.join('.', 'seeds', '{}.gba'.format(FileName)))
|
if error:
|
||||||
|
os.remove(os.path.join('.', 'seeds', '{}.gba'.format(FileName)))
|
||||||
print('Error: failed to patch game with base patch!')
|
print('Error: failed to patch game with base patch!')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
checksum = fileHash(os.path.join('.', 'seeds', '{}.gba'.format(FileName)))
|
checksum = fileHash(os.path.join('.', 'seeds', '{}.gba'.format(FileName)))
|
||||||
if checksum != 2455114263:
|
if checksum != 2455114263:
|
||||||
os.unlink(os.path.join('.', 'seeds', '{}.gba'.format(FileName)))
|
os.remove(os.path.join('.', 'seeds', '{}.gba'.format(FileName)))
|
||||||
print('Error: Base patch file has been modified. Please go to https://metroidconstruction.com/ and re-download MFOR.')
|
print('Error: Base patch file has been modified. Please go to https://metroidconstruction.com/ and re-download MFOR.')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -2865,13 +2867,13 @@ def patch_game():
|
||||||
with open(os.path.join('.', 'seeds', '{}.gba'.format(FileName)), 'rb') as target:
|
with open(os.path.join('.', 'seeds', '{}.gba'.format(FileName)), 'rb') as target:
|
||||||
targetdata = target.read()
|
targetdata = target.read()
|
||||||
|
|
||||||
patch = open(os.path.join('.', 'seeds', '{}.bps'.format(FileName)), 'wb')
|
|
||||||
|
|
||||||
blocksize = (len(sourcedata) + len(targetdata)) // 1000000 + 1
|
blocksize = (len(sourcedata) + len(targetdata)) // 1000000 + 1
|
||||||
print("Using blocks of {0} bytes".format(blocksize))
|
print("Using blocks of {0} bytes".format(blocksize))
|
||||||
|
|
||||||
iterable = diff_bytearrays(blocksize, sourcedata, targetdata)
|
iterable = diff_bytearrays(blocksize, sourcedata, targetdata)
|
||||||
|
with open(os.path.join('.', 'seeds', '{}.bps'.format(FileName)), 'wb') as patch:
|
||||||
write_bps(bps_progress(iterable), patch)
|
write_bps(bps_progress(iterable), patch)
|
||||||
|
|
||||||
print('')
|
print('')
|
||||||
|
|
||||||
ItemNames = [
|
ItemNames = [
|
||||||
|
|
Loading…
Reference in New Issue