home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / 68k Make thng / Make thng.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-16  |  2.7 KB  |  132 lines  |  [TEXT/KAHL]

  1. /*
  2.     Make thng.c
  3.     
  4.     C code to turn a resource file into a 'thng', or a system extension containing a
  5.     component.
  6.     
  7.     This is not really needed for older versions of Sym/Think C/C++; however, for version
  8.     8.x, code resources are built and added to the projects resource file.  The project
  9.     resource file must then have it's type and creator changed into whatever it should
  10.     be, i.e. an INIT or a 'thng'.
  11.     
  12.     This tiny little drop application will do that automagically. ;-)
  13.     
  14. */
  15.  
  16. #include <Files.h>
  17. #include <SegLoad.h>
  18.  
  19. #define kThingType 'thng'
  20.  
  21. typedef OSType** OSTypeHdl;
  22.  
  23. void InitToolbox(void);
  24. OSErr TickleParent(FSSpecPtr spec);
  25.  
  26. void InitToolbox(void){
  27.     InitGraf((Ptr) &qd.thePort);
  28.     InitFonts();
  29.     InitWindows();
  30.     InitMenus();
  31.     FlushEvents(everyEvent,0);
  32.     TEInit();
  33.     InitDialogs(0L);
  34.     InitCursor();
  35. }
  36.  
  37. void main(void){
  38.     short message,count;
  39.     register short loop;
  40.     AppFile theFile;
  41.     FSSpec spec;
  42.     short rnum;
  43.     short vref;
  44.     long dirid,junk;
  45.     OSTypeHdl bndl;
  46.     Handle h;
  47.     OSErr err;
  48.     OSType sig;
  49.     FInfo info;
  50.     
  51.     InitToolbox();
  52.     
  53.     CountAppFiles(&message,&count);
  54.     
  55.     if (count==0) // no files to process, return
  56.         return;
  57.     
  58.     if (message==appOpen){
  59.         // got the open file message, ignore the print message
  60.         for (loop=1;loop<=count;loop++){
  61.             // for each file given to us...
  62.             GetAppFiles(loop,&theFile);
  63.             
  64.             // make an FSSpec from the file
  65.             err=GetWDInfo(theFile.vRefNum,&vref,&dirid,&junk);
  66.             if (err!=noErr)
  67.                 continue; // can't do this file, try another
  68.             
  69.             FSMakeFSSpec(vref,dirid,theFile.fName,&spec);
  70.             
  71.             // have the file, open the resource fork
  72.             rnum=FSpOpenResFile(&spec,fsRdPerm);
  73.             if (rnum==0)
  74.                 continue; // can't do this file, try another
  75.                 
  76.             // after open, get the handle for the 'BNDL' resource
  77.             h=Get1IndResource('BNDL',1);
  78.             if (h==(Handle)0){
  79.                 CloseResFile(rnum);
  80.                 continue;
  81.             }
  82.             
  83.             // detach and close the res file
  84.             DetachResource(h);
  85.             CloseResFile(rnum);
  86.             
  87.             // extract the signature from the 'BNDL' resource
  88.             bndl=(OSTypeHdl)h;
  89.             sig=**bndl;
  90.             DisposeHandle(h);
  91.             
  92.             // set the new type and creator
  93.             err=FSpGetFInfo(&spec,&info);
  94.             if (err!=noErr)
  95.                 continue;
  96.             
  97.             info.fdType=kThingType;
  98.             info.fdCreator=sig;
  99.             
  100.             FSpSetFInfo(&spec,&info);
  101.             
  102.             TickleParent(&spec);
  103.         }
  104.     }
  105. }
  106.  
  107. OSErr TickleParent(FSSpecPtr spec){
  108.     CInfoPBRec pb;
  109.     OSErr err;
  110.     
  111.     // Fill in the parm block
  112.     pb.dirInfo.ioCompletion = 0;
  113.     pb.dirInfo.ioNamePtr = 0;
  114.     pb.dirInfo.ioVRefNum = spec->vRefNum;
  115.     pb.dirInfo.ioFDirIndex = -1;            // get info based on the DirID
  116.     pb.dirInfo.ioDrDirID = spec->parID;
  117.     
  118.     // get the dir info
  119.     err=PBGetCatInfoSync(&pb);
  120.     
  121.     if (err!=noErr)
  122.         return err;
  123.     
  124.     // get the new modification date
  125.     GetDateTime( &pb.dirInfo.ioDrMdDat );
  126.     
  127.     // set dir is modified
  128.     err=PBSetCatInfoSync( &pb );
  129.     
  130.     return err;
  131. }
  132.