2001-08-25 09:15:04 -03:00
|
|
|
|
from Carbon.Res import *
|
|
|
|
|
from Carbon.Resources import *
|
1995-01-30 07:53:55 -04:00
|
|
|
|
import MacOS
|
|
|
|
|
|
|
|
|
|
READ = 1
|
|
|
|
|
WRITE = 2
|
|
|
|
|
smAllScripts = -3
|
|
|
|
|
|
2006-03-17 02:49:51 -04:00
|
|
|
|
def raw_input(prompt):
|
|
|
|
|
import sys
|
|
|
|
|
sys.stdout.write(prompt)
|
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
return sys.stdin.readline()
|
|
|
|
|
|
1995-01-30 07:53:55 -04:00
|
|
|
|
def copyres(src, dst):
|
2004-07-18 03:16:08 -03:00
|
|
|
|
"""Copy resource from src file to dst file."""
|
|
|
|
|
|
|
|
|
|
cur = CurResFile()
|
|
|
|
|
ctor, type = MacOS.GetCreatorAndType(src)
|
|
|
|
|
input = FSpOpenResFile(src, READ)
|
|
|
|
|
try:
|
|
|
|
|
FSpCreateResFile(dst, ctor, type, smAllScripts)
|
|
|
|
|
except:
|
|
|
|
|
raw_input("%s already exists... CR to write anyway! " % dst)
|
|
|
|
|
output = FSpOpenResFile(dst, WRITE)
|
|
|
|
|
UseResFile(input)
|
|
|
|
|
ntypes = Count1Types()
|
|
|
|
|
for itype in range(1, 1+ntypes):
|
|
|
|
|
type = Get1IndType(itype)
|
|
|
|
|
nresources = Count1Resources(type)
|
|
|
|
|
for ires in range(1, 1+nresources):
|
|
|
|
|
res = Get1IndResource(type, ires)
|
|
|
|
|
res.LoadResource()
|
|
|
|
|
id, type, name = res.GetResInfo()
|
|
|
|
|
size = res.SizeResource()
|
|
|
|
|
attrs = res.GetResAttrs()
|
2007-08-30 15:39:28 -03:00
|
|
|
|
print(id, type, name, size, hex(attrs))
|
2004-07-18 03:16:08 -03:00
|
|
|
|
res.DetachResource()
|
|
|
|
|
UseResFile(output)
|
|
|
|
|
try:
|
|
|
|
|
res2 = Get1Resource(type, id)
|
2007-01-10 12:19:56 -04:00
|
|
|
|
except (RuntimeError, Res.Error) as msg:
|
2004-07-18 03:16:08 -03:00
|
|
|
|
res2 = None
|
|
|
|
|
if res2:
|
2007-08-30 15:39:28 -03:00
|
|
|
|
print("Duplicate type+id, not copied")
|
2004-07-18 03:16:08 -03:00
|
|
|
|
print (res2.size, res2.data)
|
2007-08-30 15:39:28 -03:00
|
|
|
|
print(res2.GetResInfo())
|
2004-07-18 03:16:08 -03:00
|
|
|
|
if res2.HomeResFile() == output:
|
|
|
|
|
'OK'
|
|
|
|
|
elif res2.HomeResFile() == input:
|
|
|
|
|
'BAD!'
|
|
|
|
|
else:
|
2007-08-30 15:39:28 -03:00
|
|
|
|
print('Home:', res2.HomeResFile())
|
2004-07-18 03:16:08 -03:00
|
|
|
|
else:
|
|
|
|
|
res.AddResource(type, id, name)
|
|
|
|
|
#res.SetResAttrs(attrs)
|
|
|
|
|
res.WriteResource()
|
|
|
|
|
UseResFile(input)
|
|
|
|
|
UseResFile(cur)
|
|
|
|
|
CloseResFile(output)
|
|
|
|
|
CloseResFile(input)
|
1995-01-30 07:53:55 -04:00
|
|
|
|
|
|
|
|
|
copyres('::python.<2E>.rsrc', '::foo.rsrc')
|