Squash bugs found testing compression

This commit is contained in:
Elliot Nunn 2018-12-13 16:05:39 +08:00
parent fbdb8eb61a
commit e9f9154dff

View File

@ -265,14 +265,10 @@ def parse_rez_code(from_rezcode):
from_rezcode = from_rezcode.replace(b'\r\n', b'\n').replace(b'\r', b'\n') from_rezcode = from_rezcode.replace(b'\r\n', b'\n').replace(b'\r', b'\n')
for line in from_rezcode.split(b'\n'): line_iter = iter(from_rezcode.split(b'\n'))
for line in line_iter:
line = line.lstrip() line = line.lstrip()
if line.startswith(b'data '): if line.startswith(b'data '):
try:
yield cur_resource
except NameError:
pass
_, _, line = line.partition(b' ') _, _, line = line.partition(b' ')
rsrctype, line = _rez_unescape(line) rsrctype, line = _rez_unescape(line)
_, _, line = line.partition(b'(') _, _, line = line.partition(b'(')
@ -292,10 +288,8 @@ def parse_rez_code(from_rezcode):
args.append(('nonstring', arg)) args.append(('nonstring', arg))
compression_format = None compression_format = None
line = line[1:].lstrip() # clip off the closing paren a, b, c = line.partition(b'Compress:')
if line.startswith(b'/* Compress: '): if b: compression_format = c.split()[0].decode('ascii')
line = line[13:]
compression_format = line.split()[0].decode('ascii')
rsrcname = None rsrcname = None
rsrcattrs = ResourceAttrs(0) rsrcattrs = ResourceAttrs(0)
@ -316,18 +310,17 @@ def parse_rez_code(from_rezcode):
newattr = getattr(ResourceAttrs, arg.decode('ascii')) newattr = getattr(ResourceAttrs, arg.decode('ascii'))
rsrcattrs |= newattr rsrcattrs |= newattr
cur_resource = Resource(type=rsrctype, id=rsrcid, name=rsrcname, attribs=rsrcattrs) data = bytearray()
cur_resource.compression_format = compression_format for line in line_iter:
line = line.lstrip()
if not line.startswith(b'$"'): break
hexdat = line[2:].partition(b'"')[0]
bindat = bytes.fromhex(hexdat.decode('ascii'))
data.extend(bindat)
elif line.startswith(b'$"'): cur_resource = Resource(type=rsrctype, id=rsrcid, name=rsrcname, attribs=rsrcattrs, data=data)
hexdat = line[2:].partition(b'"')[0] if compression_format: cur_resource.compression_format = compression_format
bindat = bytes.fromhex(hexdat.decode('ascii')) yield cur_resource
cur_resource.data.extend(bindat)
try:
yield cur_resource
except NameError:
pass
def make_file(from_iter, align=1): def make_file(from_iter, align=1):
@ -391,7 +384,7 @@ def make_file(from_iter, align=1):
else: else:
this_name_offset = res.name_offset - namelist_offset this_name_offset = res.name_offset - namelist_offset
this_data_offset = res.data_offset - data_offset this_data_offset = res.data_offset - data_offset
mixedfield = (int(attribs) << 24) | this_data_offset mixedfield = (int(res.attribs) << 24) | this_data_offset
struct.pack_into('>hHL', accum, counter, res.obj.id, this_name_offset, mixedfield) struct.pack_into('>hHL', accum, counter, res.obj.id, this_name_offset, mixedfield)
counter += 12 counter += 12