Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #I should reorganize this with functions, but meh, can't be stuffed
- import macfs
- import os
- from Res import *
- #FSpOpenResFile constants
- READ = 1
- WRITE = 2
- def main():
- filespec, ok = macfs.StandardGetFile()
- if not ok:
- exit(0)
- print filespec.as_pathname()
- print filespec.GetCreatorType()
- filename = filespec.as_tuple()[2]
- base_folder = '%s Dumped Resources' % filename
- #TODO Should handle this already existing
- os.mkdir(base_folder)
- #TODO Need to do some error handling here for files with no resource fork
- res_file = FSpOpenResFile(filespec, READ)
- type_count = Count1Types()
- print 'There are %d types here' % type_count
- #Get1IndType etc is 1-indexed
- for type_index in range(1, type_count + 1):
- res_type = Get1IndType(type_index)
- print ' Type %d: %s' % (type_index, res_type)
- #TODO Can a resource type have a : in the filename? Because this will break then
- type_folder = os.path.join(base_folder, res_type)
- #TODO Should handle this already existing
- os.mkdir(type_folder)
- res_count = Count1Resources(res_type)
- print ' There are %d resources of this type' % res_count
- for res_index in range(1, res_count + 1):
- res = Get1IndResource(res_type, res_index)
- res.LoadResource()
- #2nd item in tuple is resource type which we already have
- res_id, _junk, res_name = res.GetResInfo()
- print ' Resource %d: id = %d, name = %s' % (res_index, res_id, res_name)
- print ' size = %d' % res.size
- print ' Size on disk: %d' % res.GetResourceSizeOnDisk()
- #print ' data: %s' % res.data
- if len(res_name) > 0:
- res_filename = '%d - %s' % (res_id, res_name.replace(':', '_'))
- else:
- res_filename = str(res_id)
- #I guess filenames can only be 31 chars? *shrug*
- res_filename = res_filename[:31]
- try:
- output = open(os.path.join(type_folder, res_filename), 'wb')
- output.write(res.data)
- output.close()
- except:
- print 'WTF WHY I HATE YOU %s' % res_filename
- res.DetachResource()
- CloseResFile(res_file)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement