appletresource.c

Go to the documentation of this file.
00001 
00002 /*  $Id: appletresource.c 355 2005-01-11 22:48:55Z andreradke $    */
00003 
00004 /* copyright 1991-96 UserLand Software, Inc. All Rights Reserved.*/
00005 
00006 
00007 #include "appletmemory.h"
00008 #include "appletresource.h"
00009 
00010 
00011 
00012 boolean openresourcefile (ptrfilespec pfs, short *rnum) {
00013     
00014     short resourcerefnum = -1;
00015     OSErr ec;
00016     
00017     resourcerefnum = HOpenResFile ((*pfs).vRefNum, (*pfs).parID, (*pfs).name, fsCurPerm);
00018 
00019     ec = ResError ();
00020     
00021     if (ec == -39) { /*eof error, file has no resource fork, create one*/
00022         
00023         HCreateResFile ((*pfs).vRefNum, (*pfs).parID, (*pfs).name);
00024         
00025         if (ResError () != noErr) /*failed to create resource fork*/
00026             goto error;
00027             
00028         resourcerefnum = OpenResFile ((*pfs).name);
00029         }
00030     
00031     if (resourcerefnum != -1) /*it's open*/ {
00032         
00033         UseResFile (resourcerefnum); /*in case it was already open*/
00034         
00035         *rnum = resourcerefnum;
00036         
00037         return (true);
00038         }
00039     
00040     error:
00041     
00042     closeresourcefile (resourcerefnum); /*checks for -1*/
00043     
00044     *rnum = -1;
00045     
00046     return (false);
00047     } /*openresourcefile*/
00048 
00049 
00050 boolean closeresourcefile (short rnum) {
00051     
00052     if (rnum != -1) { /*resource file was successfully opened*/
00053         
00054         if (rnum > 2) /*not System or ROM*/
00055             CloseResFile (rnum);
00056         else
00057             UpdateResFile (rnum); /*make sure map is consistent*/
00058         
00059         if (ResError () != noErr)
00060             return (false);
00061         }
00062     
00063     return (true);
00064     } /*closeresourcefile*/
00065     
00066     
00067 boolean getresource (short rnum, OSType type, short id, long ct, void *p) {
00068     
00069     Handle h;
00070     
00071     h = Get1Resource (type, id);
00072     
00073     if (h == nil)
00074         return (false);
00075 
00076     moveleft (*h, p, ct);
00077         
00078     return (true);
00079     } /*getresource*/
00080     
00081     
00082 boolean putresource (short rnum, OSType type, short id, long ct, void *p) {
00083 
00084     Handle h;
00085     
00086     h = Get1Resource (type, id);
00087     
00088     if (h != nil) { /*resource already exists*/
00089         
00090         if (!sethandlecontents (p, ct, h)) /*couldn't increase size of handle*/
00091             return (false);
00092         
00093         ChangedResource (h);
00094         }
00095     else {
00096         
00097         if (!newfilledhandle (p, ct, &h))
00098             return (false);
00099         
00100         AddResource (h, type, id, "\p");
00101         }
00102     
00103     return (ResError () == noErr);
00104     } /*putresource*/
00105     
00106     
00107 boolean getresourcehandle (short rnum, OSType type, short id, Handle *hreturned) {
00108     
00109     Handle h;
00110     
00111     *hreturned = nil;
00112     
00113     h = Get1Resource (type, id);
00114     
00115     if (h == nil)
00116         return (false);
00117         
00118     return (copyhandle (h, hreturned));
00119     } /*getresource*/
00120     
00121     
00122 boolean putresourcehandle (short rnum, OSType type, short id, Handle h) {
00123     
00124     boolean fl;
00125     
00126     lockhandle (h);
00127     
00128     fl = putresource (rnum, type, id, GetHandleSize (h), *h);
00129     
00130     unlockhandle (h);
00131     
00132     return (fl);
00133     } /*putresourcehandle*/
00134     
00135     
00136 boolean getresourcestring (short index, bigstring bs) {
00137     
00138     GetIndString (bs, 131, index);
00139     
00140     return (ResError () == noErr);
00141     } /*getresourcestring*/
00142     
00143     
00144 boolean getstringlistitem (short resnum, short index, bigstring bs) {
00145 
00146     GetIndString (bs, resnum, index);
00147     
00148     return (ResError () == noErr);
00149     } /*getstringlistitem*/
00150     
00151     
00152 boolean deleteresource (short rnum, OSType type, short id) {
00153     
00154     boolean fl = true;
00155     Handle h;
00156     
00157     SetResLoad (false);
00158     
00159     h = Get1Resource (type, id);
00160     
00161     SetResLoad (true);
00162     
00163     if (h != nil) { /*got the indicated resource*/
00164         
00165         RmveResource (h);
00166         
00167         fl = !ResError ();
00168         
00169         disposehandle (h);
00170         }
00171     
00172     return (fl);
00173     } /*deleteresource*/
00174 
00175 
00176 
00177     
00178     
00179     

Generated on Wed May 31 18:19:44 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6