summaryrefslogtreecommitdiffstats
path: root/Mac/Demo/resources/listres.py
blob: 7575db803e1a4b8a3389c0604d5f8389b4bb0980 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# List all resources

from Carbon import Res
from Carbon.Resources import *

def list1resources():
	ntypes = Res.Count1Types()
	for itype in range(1, 1+ntypes):
		type = Res.Get1IndType(itype)
		print "Type:", `type`
		nresources = Res.Count1Resources(type)
		for i in range(1, 1 + nresources):
			Res.SetResLoad(0)
			res = Res.Get1IndResource(type, i)
			Res.SetResLoad(1)
			info(res)

def listresources():
	ntypes = Res.CountTypes()
	for itype in range(1, 1+ntypes):
		type = Res.GetIndType(itype)
		print "Type:", `type`
		nresources = Res.CountResources(type)
		for i in range(1, 1 + nresources):
			Res.SetResLoad(0)
			res = Res.GetIndResource(type, i)
			Res.SetResLoad(1)
			info(res)

def info(res):
	print res.GetResInfo(), res.SizeResource(), decodeattrs(res.GetResAttrs())

attrnames = {
	resChanged:	'Changed',
	resPreload:	'Preload',
	resProtected:	'Protected',
	resLocked:	'Locked',
	resPurgeable:	'Purgeable',
	resSysHeap:	'SysHeap',
}

def decodeattrs(attrs):
	names = []
	for bit in range(16):
		mask = 1<<bit
		if attrs & mask:
			if attrnames.has_key(mask):
				names.append(attrnames[mask])
			else:
				names.append(hex(mask))
	return names

def test():
	print "=== Local resourcess ==="
	list1resources()
	print "=== All resources ==="
	listresources()

if __name__ == '__main__':
	test()