home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 15 / BBS in a box XV-1.iso / Files / System 7 / Frontier / Frontier SDK 2.1.sit / Frontier SDK 2.1 / Toolkits / Applet Toolkit / appletresource.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-11  |  3.1 KB  |  2 lines  |  [TEXT/KAHL]

  1. appletresource.cTEXTKAHL
  2. GQ¶˛#(¶˛#(ÅÅ3Ü
  3. /*© Copyright 1988-1992 UserLand Software, Inc.  All Rights Reserved.*/
  4.  
  5.  
  6. #include "appletmemory.h"
  7. #include "appletresource.h"
  8.  
  9.  
  10.  
  11. boolean openresourcefile (bigstring fname, short vnum, short *rnum) {
  12.     
  13.     short resourcerefnum = -1;
  14.     short oldvnum;
  15.     
  16.     if (GetVol (nil, &oldvnum) != noErr)
  17.         return (false);
  18.     
  19.     if (SetVol (nil, vnum) != noErr)
  20.         goto error;
  21.     
  22.     resourcerefnum = OpenResFile (fname);
  23.     
  24.     if (ResError () == -39) { /*eof error, file has no resource fork, create one*/
  25.         
  26.         CreateResFile (fname);
  27.         
  28.         if (ResError () != noErr) /*failed to create resource fork*/
  29.             goto error;
  30.             
  31.         resourcerefnum = OpenResFile (fname);
  32.         }
  33.     
  34.     if (resourcerefnum != -1) /*it's open*/ {
  35.         
  36.         UseResFile (resourcerefnum); /*in case it was already open*/
  37.         
  38.         *rnum = resourcerefnum;
  39.         
  40.         SetVol (nil, oldvnum);
  41.         
  42.         return (true);
  43.         }
  44.     
  45.     error:
  46.     
  47.     SetVol (nil, oldvnum);
  48.     
  49.     closeresourcefile (resourcerefnum); /*checks for -1*/
  50.     
  51.     *rnum = -1;
  52.     
  53.     return (false);
  54.     } /*openresourcefile*/
  55.  
  56.  
  57. boolean closeresourcefile (short rnum) {
  58.     
  59.     if (rnum != -1) { /*resource file was successfully opened*/
  60.         
  61.         if (rnum > 2) /*not System or ROM*/
  62.             CloseResFile (rnum);
  63.         else
  64.             UpdateResFile (rnum); /*make sure map is consistent*/
  65.         
  66.         if (ResError () != noErr)
  67.             return (false);
  68.         }
  69.     
  70.     return (true);
  71.     } /*closeresourcefile*/
  72.     
  73.     
  74. boolean getresource (short rnum, OSType type, short id, long ct, void *p) {
  75.     
  76.     Handle h;
  77.     
  78.     h = Get1Resource (type, id);
  79.     
  80.     if (h == nil)
  81.         return (false);
  82.  
  83.     moveleft (*h, p, ct);
  84.         
  85.     return (true);
  86.     } /*getresource*/
  87.     
  88.     
  89. boolean putresource (short rnum, OSType type, short id, long ct, void *p) {
  90.  
  91.     Handle h;
  92.     
  93.     h = Get1Resource (type, id);
  94.     
  95.     if (h != nil) { /*resource already exists*/
  96.         
  97.         if (!sethandlecontents (p, ct, h)) /*couldn't increase size of handle*/
  98.             return (false);
  99.         
  100.         ChangedResource (h);
  101.         }
  102.     else {
  103.         
  104.         if (!newfilledhandle (p, ct, &h))
  105.             return (false);
  106.         
  107.         AddResource (h, type, id, "\p");
  108.         }
  109.     
  110.     return (ResError () == noErr);
  111.     } /*putresource*/
  112.     
  113.     
  114. boolean getresourcehandle (short rnum, OSType type, short id, Handle *hreturned) {
  115.     
  116.     Handle h;
  117.     
  118.     *hreturned = nil;
  119.     
  120.     h = Get1Resource (type, id);
  121.     
  122.     if (h == nil)
  123.         return (false);
  124.         
  125.     return (copyhandle (h, hreturned));
  126.     } /*getresource*/
  127.     
  128.     
  129. boolean putresourcehandle (short rnum, OSType type, short id, Handle h) {
  130.     
  131.     boolean fl;
  132.     
  133.     lockhandle (h);
  134.     
  135.     fl = putresource (rnum, type, id, GetHandleSize (h), *h);
  136.     
  137.     unlockhandle (h);
  138.     
  139.     return (fl);
  140.     } /*putresourcehandle*/
  141.     
  142.     
  143. boolean getresourcestring (short index, bigstring bs) {
  144.     
  145.     GetIndString (bs, 131, index);
  146.     
  147.     return (ResError () == noErr);
  148.     } /*getresourcestring*/
  149.     
  150.     
  151.     33•appletresource.cpPartSITxPartSITx©ÅDŒQform    %™¥%™%™/Ä2.0rc1!2.0rc1; © 1992, UserLand Software33ÌÀ
  152. òˇˇ