2727RESTYPE = 'PYC '
2828RESNAME = '__main__'
2929
30+ # A resource with this name sets the "owner" (creator) of the destination
31+ OWNERNAME = "owner resource"
32+
3033# OpenResFile mode parameters
3134READ = 1
3235WRITE = 2
@@ -107,7 +110,6 @@ def process(template, filename):
107110 ctor , type = MacOS .GetCreatorAndType (destname )
108111 if type in undefs : type = 'APPL'
109112 if ctor in undefs : ctor = tctor
110- MacOS .SetCreatorAndType (destname , ctor , type )
111113
112114 # Open the output resource fork
113115
@@ -121,8 +123,9 @@ def process(template, filename):
121123 # Copy the resources from the template
122124
123125 input = FSpOpenResFile (template , READ )
124- copyres (input , output )
126+ newctor = copyres (input , output )
125127 CloseResFile (input )
128+ if newctor : ctor = newctor
126129
127130 # Copy the resources from the target specific resource template, if any
128131
@@ -131,8 +134,13 @@ def process(template, filename):
131134 except MacOS .Error :
132135 pass
133136 else :
134- copyres (input , output )
137+ newctor = copyres (input , output )
135138 CloseResFile (input )
139+ if newctor : ctor = newctor
140+
141+ # Now set the creator and type of the destination
142+
143+ MacOS .SetCreatorAndType (destname , ctor , type )
136144
137145 # Make sure we're manipulating the output resource file now
138146
@@ -171,10 +179,13 @@ def process(template, filename):
171179 message ("Applet %s created." % `destname` )
172180
173181
174- # Copy resources between two resource file descriptors
175- # Exception: don't copy a __main__ resource
182+ # Copy resources between two resource file descriptors.
183+ # Exception: don't copy a __main__ resource.
184+ # If a resource's name is "owner resource", its type is returned
185+ # (so the caller can use it to set the destination's creator)
176186
177187def copyres (input , output ):
188+ ctor = None
178189 UseResFile (input )
179190 ntypes = Count1Types ()
180191 for itype in range (1 , 1 + ntypes ):
@@ -183,8 +194,10 @@ def copyres(input, output):
183194 for ires in range (1 , 1 + nresources ):
184195 res = Get1IndResource (type , ires )
185196 id , type , name = res .GetResInfo ()
186- if (type , name ) == (RESTYPE , RESNAME ):
197+ lcname = string .lower (name )
198+ if (type , lcname ) == (RESTYPE , RESNAME ):
187199 continue # Don't copy __main__ from template
200+ if lcname == OWNERNAME : ctor = type
188201 size = res .SizeResource ()
189202 attrs = res .GetResAttrs ()
190203 print id , type , name , size , hex (attrs )
@@ -199,9 +212,12 @@ def copyres(input, output):
199212 print "Overwriting..."
200213 res2 .RmveResource ()
201214 res .AddResource (type , id , name )
202- #res.SetResAttrs(attrs)
203215 res .WriteResource ()
216+ attrs = attrs | res .GetResAttrs ()
217+ print "New attrs =" , hex (attrs )
218+ res .SetResAttrs (attrs )
204219 UseResFile (input )
220+ return ctor
205221
206222
207223# Show a message and exit
@@ -230,3 +246,4 @@ def message(str, id = 256):
230246
231247if __name__ == '__main__' :
232248 main ()
249+
0 commit comments