Add to-BinHex command "Rhqx"

This commit is contained in:
Elliot Nunn 2019-06-30 00:09:25 +08:00
parent 23a2e9c843
commit 495004c0db
2 changed files with 45 additions and 1 deletions

44
bin/Rhqx Normal file
View File

@ -0,0 +1,44 @@
from os import path
import argparse
import binhex
import macresources
parser = argparse.ArgumentParser(description='''
Convert a "rdump" file (provide base name) to hqx
''')
parser.add_argument('srcfile', help='base name (.rdump/.idump should be alongside)')
args = parser.parse_args()
finfo = binhex.FInfo()
finfo.Flags = 0
try:
info = open(args.srcfile + '.idump', 'rb').read(8)
assert len(info) == 8
finfo.Type = info[:4]
finfo.Creator = info[4:]
except:
pass
try:
data = open(args.srcfile, 'rb').read()
if finfo.Type in [b'TEXT', b'ttro']:
data = data.decode('utf-8').encode('mac_roman')
except:
data = b''
try:
rsrc = open(args.srcfile + '.rdump', 'rb').read()
rsrc = macresources.make_file(macresources.parse_rez_code(rsrc))
except:
rsrc = b''
bh = binhex.BinHex((path.basename(args.srcfile), finfo, len(data), len(rsrc)), args.srcfile + '.hqx')
bh.write(data)
bh.write_rsrc(rsrc)
bh.close()

View File

@ -18,5 +18,5 @@ setup(
'Development Status :: 3 - Alpha',
],
packages=['macresources'],
scripts=['bin/SimpleRez', 'bin/SimpleDeRez', 'bin/Rget'],
scripts=['bin/SimpleRez', 'bin/SimpleDeRez', 'bin/Rget', 'bin/Rhqx'],
)