From e55c2ee7d78f316e8ad5b16652708829b4217d60 Mon Sep 17 00:00:00 2001 From: Elliot Nunn Date: Tue, 23 Oct 2018 20:10:38 +0800 Subject: [PATCH] Roundtrip fix: Rez is very cautious about */ --- macresources/main.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/macresources/main.py b/macresources/main.py index 9cd1488..79e26d9 100644 --- a/macresources/main.py +++ b/macresources/main.py @@ -333,14 +333,28 @@ def make_rez_code(from_iter, ascii_clean=False): lines.append(b'data %s (%s) {' % (fourcc, args)) step = 16 + + star, slash, dot, space = b'*/. ' + whole_preview = bytearray(resource.data) + for i in range(len(whole_preview)): + if not i % step: mode = False + thisone = whole_preview[i] + if mode and thisone == slash: + thisone = dot + mode = False + elif thisone == star: + mode = True + elif thisone >= space: + mode = False + whole_preview[i] = themap[thisone] + for ofs in range(0, len(resource.data), step): linedat = resource.data[ofs:ofs+step] line = ' '.join(linedat[i:i+2].hex() for i in range(0, len(linedat), 2)).encode('ascii') line = line.upper() line = b'\t$"%s"' % line - prevstr = bytes(themap[ch] for ch in linedat).replace(b'*/', b'*.') line = line.ljust(55) - line += b'/* %s */' % prevstr + line += b'/* %s */' % whole_preview[ofs:ofs+step] lines.append(line) lines.append(b'};')