Skip to content

Commit

Permalink
Made raw export not try to load any files besides file being export. …
Browse files Browse the repository at this point in the history
…Rebuilding SARCs is done by making symlinks
  • Loading branch information
kk49 committed May 21, 2019
1 parent 8a83827 commit 065784d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
28 changes: 16 additions & 12 deletions deca/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ def build_node(self, dst_path: str, vnode: VfsNode, vfs: VfsBase, src_map):
entry_new: EntrySarc = sarc_new.entries[i]
vpath = entry_old.vpath

make_symlink = False
if entry_old.vpath in src_map:
src_files[i] = src_map[vpath]
sz = os.stat(src_files[i]).st_size
make_symlink = True
else:
sz = entry_old.length

if entry_old.offset == 0:
if entry_old.offset == 0 or make_symlink:
entry_new.offset = 0
entry_new.length = sz
else:
Expand Down Expand Up @@ -71,20 +73,22 @@ def build_node(self, dst_path: str, vnode: VfsNode, vfs: VfsBase, src_map):
fso.seek(entry_new.META_entry_size_ptr)
fso.write_u32(entry_new.length)

if entry_new.offset != 0:
if src_files[i] is None:
print(' COPYING {} from old file to new file'.format(entry_old.vpath))
fsi.seek(entry_old.offset)
buf = fsi.read(entry_old.length)
else:
print(' INSERTING {} src file to new file'.format(entry_old.vpath))
with open(src_files[i], 'rb') as f:
buf = f.read(entry_new.length)
buf = None

if entry_new.offset == 0:
print(' SYMLINK {}'.format(entry_old.vpath))
elif src_files[i] is not None:
print(' INSERTING {} src file to new file'.format(entry_old.vpath))
with open(src_files[i], 'rb') as f:
buf = f.read(entry_new.length)
else:
print(' COPYING {} from old file to new file'.format(entry_old.vpath))
fsi.seek(entry_old.offset)
buf = fsi.read(entry_old.length)

if buf is not None:
fso.seek(entry_new.offset)
fso.write(buf)
else:
print(' SYMLINK {}'.format(entry_old.vpath))

return fn_dst
else:
Expand Down
27 changes: 16 additions & 11 deletions deca/vfs_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,18 +724,23 @@ def extract_node(self, node: VfsNode, extract_dir: str, export_raw, export_proce
os.makedirs(ofiledir, exist_ok=True)

do_export_raw = export_raw
try:
if node.ftype in {FTYPE_ADF, FTYPE_ADF_BARE}:
if node.ftype == FTYPE_ADF_BARE:

if node.ftype == FTYPE_ADF_BARE:
do_export_raw = False
self.logger.log(
'WARNING: Extracting raw ADFB file {} not supported, extract gdc/global.gdcc instead.'.format(
ofile))

if export_processed:
try:
if node.ftype in {FTYPE_ADF, FTYPE_ADF_BARE}:
if export_processed:
adf_export(self, node, ofile, allow_overwrite=allow_overwrite)
elif node.ftype in {FTYPE_BMP, FTYPE_DDS, FTYPE_AVTX, FTYPE_ATX, FTYPE_HMDDSC}:
do_export_raw = False
self.logger.log('WARNING: Extracting raw ADFB file {} not supported, extract gdc/global.gdcc instead.'.format(ofile))
if export_processed:
adf_export(self, node, ofile, allow_overwrite=allow_overwrite)
elif node.ftype in {FTYPE_BMP, FTYPE_DDS, FTYPE_AVTX, FTYPE_ATX, FTYPE_HMDDSC}:
do_export_raw = False
image_export(self, node, extract_dir, export_raw, export_processed, allow_overwrite=allow_overwrite)
except EDecaFileExists as e:
self.logger.log('WARNING: Extraction failed overwrite disabled and {} exists, skipping'.format(e.args[0]))
image_export(self, node, extract_dir, export_raw, export_processed, allow_overwrite=allow_overwrite)
except EDecaFileExists as e:
self.logger.log('WARNING: Extraction failed overwrite disabled and {} exists, skipping'.format(e.args[0]))

if do_export_raw:
if not allow_overwrite and os.path.isfile(ofile):
Expand Down

0 comments on commit 065784d

Please sign in to comment.