|
1 # List all resources |
|
2 |
|
3 from Carbon import Res |
|
4 from Carbon.Resources import * |
|
5 |
|
6 def list1resources(): |
|
7 ntypes = Res.Count1Types() |
|
8 for itype in range(1, 1+ntypes): |
|
9 type = Res.Get1IndType(itype) |
|
10 print "Type:", repr(type) |
|
11 nresources = Res.Count1Resources(type) |
|
12 for i in range(1, 1 + nresources): |
|
13 Res.SetResLoad(0) |
|
14 res = Res.Get1IndResource(type, i) |
|
15 Res.SetResLoad(1) |
|
16 info(res) |
|
17 |
|
18 def listresources(): |
|
19 ntypes = Res.CountTypes() |
|
20 for itype in range(1, 1+ntypes): |
|
21 type = Res.GetIndType(itype) |
|
22 print "Type:", repr(type) |
|
23 nresources = Res.CountResources(type) |
|
24 for i in range(1, 1 + nresources): |
|
25 Res.SetResLoad(0) |
|
26 res = Res.GetIndResource(type, i) |
|
27 Res.SetResLoad(1) |
|
28 info(res) |
|
29 |
|
30 def info(res): |
|
31 print res.GetResInfo(), res.SizeResource(), decodeattrs(res.GetResAttrs()) |
|
32 |
|
33 attrnames = { |
|
34 resChanged: 'Changed', |
|
35 resPreload: 'Preload', |
|
36 resProtected: 'Protected', |
|
37 resLocked: 'Locked', |
|
38 resPurgeable: 'Purgeable', |
|
39 resSysHeap: 'SysHeap', |
|
40 } |
|
41 |
|
42 def decodeattrs(attrs): |
|
43 names = [] |
|
44 for bit in range(16): |
|
45 mask = 1<<bit |
|
46 if attrs & mask: |
|
47 if attrnames.has_key(mask): |
|
48 names.append(attrnames[mask]) |
|
49 else: |
|
50 names.append(hex(mask)) |
|
51 return names |
|
52 |
|
53 def test(): |
|
54 print "=== Local resourcess ===" |
|
55 list1resources() |
|
56 print "=== All resources ===" |
|
57 listresources() |
|
58 |
|
59 if __name__ == '__main__': |
|
60 test() |