Number output files and folders instead of overwriting

Pack now writes <Name>.cache, or <Name>.cache.1, .2, ... if that file
already exists (replaces the fixed .cache.new name). Unpack writes each
target folder under ARCANE_DUMP the same way, e.g. COBJECTS.1. The
output folder is created only after the cache loads, so a missing cache
does not leave an empty numbered folder.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
MagicBotandClaude Opus 5.5 committed 2026-10-16 13:43:40 -04:00
1 parent 7bcbed08a8
commit 9005de76d9
3 files changed
+60 -45

No files matched your search

@@ -6,6 +6,7 @@
# Magicbane Emulator Project © 2013 - 2022
# www.magicbane.com
import os
import struct
import zlib
@@ -81,7 +82,21 @@ def write_bytes(cache_file, value):
cache_file.write(value)
def next_available_path(path):
# Returns path if unused, otherwise the first free path.1, path.2, ...
if not os.path.exists(path):
return path
index = 1
while os.path.exists(f'{path}.{index}'):
index += 1
return f'{path}.{index}'
def save_cache_file(filename, resources, compress=True):
filename = next_available_path(filename)
print('Packing to ' + filename)
cache_file = open(filename, 'wb')
num_resources = len(resources)