home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 October: Mac OS SDK / Dev.CD Oct 00 SDK1.toast / Development Kits / Mac OS / Apple Guide / Engineering / Context Check Modules / Express Modem CC / ExpressModemVer.c next >
Encoding:
C/C++ Source or Header  |  1994-03-25  |  3.2 KB  |  147 lines  |  [TEXT/KAHL]

  1. /****************************************/
  2.     
  3. /*    ExpressModemVer.c                    */
  4. /*    Author:             Shemin Gau, IP    */
  5. /*    Revision History:    03/20/94        */
  6.  
  7. /****************************************/
  8.  
  9.  
  10. #include <Files.h>
  11. #include <string.h>
  12. #include <Resources.h>
  13. #include <Memory.h>
  14. #include <ToolUtils.h>
  15. #include <Errors.h>
  16. #include <Packages.h>
  17. #include <Types.h>
  18. #include <OSUtils.h>
  19.  
  20.  
  21.  
  22. //pascal OSErr main(char *msg, Size inSize, void* outMessage, Size* outSize, Handle ignoreMe)
  23. pascal OSErr main(Str255 msg, Size inSize, void* outMessage, Size* outSize, Handle ignoreMe)
  24. {    
  25.     SysEnvRec        theWorld;
  26.     CInfoPBRec        pBlck;
  27.     short            volID;
  28.     char            pathName[256] ;
  29.     char            cDummy[128] ;
  30.     Str255            pasDummy;    
  31.     
  32.     Handle            my_hndl;
  33.     char            *str_holder = '\0';
  34.     short            myResRefNum;
  35.     char            *retstr = '\0';
  36.     char            *cp;
  37.     char            *version = "1.5";
  38.     
  39.     char            *ctemp1;
  40.     char            *ctemp2 = "SheminCI:System 7 pro:";
  41.     char            *ctemp3 = "Control Panels:PowerBook Setup";
  42.     char            *ctemp4 = "SheminCI:System 7 pro:Control Panels:PowerBook Setup";
  43.     char            *ctemp5 = "System 7 pro";
  44.     char            *ctemp7;
  45.     Str255            ptemp3 = "SheminCI:System 7 pro:";
  46.     StringPtr        ptemp4;
  47.     Str255            ptemp5 = "System 7 pro";
  48.     
  49.     StringPtr        ptemp1;    
  50.     short            k = 1;
  51.     
  52.     
  53.     pathName[0] = '\0';
  54.     cDummy[0] = '\0';
  55.     pasDummy[0] = '\0';
  56.     
  57.     if (SysEnvirons(2, &theWorld)) {
  58.         return(1);
  59.     } else {
  60.         volID = theWorld.sysVRefNum;
  61.     }
  62.  
  63.     /* set up pBlck stuff */
  64.     pBlck.dirInfo.ioNamePtr = pasDummy;
  65.     pBlck.dirInfo.ioVRefNum = volID;
  66.     pBlck.dirInfo.ioFDirIndex = 1;
  67.     pBlck.dirInfo.ioDrDirID = 0;
  68.     
  69.     /* get the first directory ID (if we can't, then errorback. */
  70.     if ( PBGetCatInfo(&pBlck, false) != noErr ) {
  71.         return(1);
  72.     }
  73.  
  74.     /* now, keep going up the tree things we reach the top */
  75.     while (pBlck.dirInfo.ioDrDirID != 2) {
  76.         /* swap id's from the parent ID to the current ID and reset the index. */
  77.         pBlck.dirInfo.ioDrDirID = pBlck.dirInfo.ioDrParID;
  78.         pBlck.dirInfo.ioFDirIndex = -1;
  79.         /* get load the NamePtr (which is equal to pasDummy) and build the C string. */
  80.         if (!PBGetCatInfo(&pBlck, false)) {
  81. #if 0
  82.             /* debugging codes    */
  83.             if (pasDummy[1] == 'S')
  84.                 return (0);
  85.  
  86.             if (strcmp(p2cstr(pasDummy), ctemp5) == 0)
  87.                 return (0);
  88. #endif
  89.             ctemp1 = p2cstr(pasDummy);
  90.             strcpy(cDummy, ctemp1);
  91.             strcat(cDummy, ":");
  92.             strcat(cDummy, pathName);
  93.             strcpy(pathName, cDummy);
  94.         } else {
  95.             /* this is just in case the PB call fails.  */
  96.             return(1);
  97.         }
  98.     }    
  99.  
  100. #if 0
  101.     /* debugging codes    */
  102.     if (strcmp(pathName, ctemp2) == 0)
  103.         return(0);
  104. #endif
  105.     
  106.     ctemp7 = p2cstr(msg);
  107.     
  108. #if 0
  109.     /* debugging codes    */
  110.     if (strcmp(ctemp7, ctemp3) == 0)
  111.         return(0);    
  112. #endif
  113.             
  114.     strcat(pathName, ctemp7);
  115.     //strcat(pathName, '\0');
  116.     
  117.         
  118.     //now, convert the whole pathname into pascal string
  119.     ptemp1 = c2pstr(pathName);
  120.         
  121.     myResRefNum = OpenResFile(ptemp1);
  122.     UseResFile(myResRefNum);
  123.     
  124.     if (ResError() == noErr) {
  125.         if (my_hndl = (Handle)Get1Resource('vers', 2)) {
  126.             HLock(my_hndl);
  127.             cp = *my_hndl;
  128.             HUnlock(my_hndl);
  129.         }
  130.         ReleaseResource((Handle)my_hndl);
  131.     
  132.         //use derez to decode the memory address of the version number
  133.         strncpy(retstr, cp + 7, (size_t)(3));        
  134.         if (strcmp(retstr, version) >= 0) {
  135.             CloseResFile(myResRefNum);
  136.             return(0);
  137.         } else {
  138.             CloseResFile(myResRefNum);
  139.             return(1);
  140.         }
  141.     } else {
  142.         CloseResFile(myResRefNum);
  143.         return(1);
  144.     }
  145.         
  146. }
  147.