home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / OpenDoc 1.2b2c1 / Implementation / OpenDocSetup / ProcessStuff.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-13  |  3.7 KB  |  171 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        ProcessStuff.cpp
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Owned by:    Nick Pilch
  7.  
  8.     Copyright:    © 1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <4>     6/28/96    TJ        Fixed Non-Debug Build.
  13.          <3>     6/24/96    NP        10002: Launch time speedups
  14.          <2>     6/23/96    NP        10002: Add some routines.
  15.          <1>     6/23/96    NP        first checked in
  16.  
  17.     To Do:
  18. */
  19.  
  20. #ifndef __TEXTUTILS__
  21. #include <TextUtils.h>
  22. #endif
  23.  
  24. #ifndef __FILES__
  25. #include <Files.h>
  26. #endif
  27.  
  28. #ifndef _PROCESSSTUFF_
  29. #include "ProcessStuff.h"
  30. #endif
  31.  
  32. #ifndef _ODPRCS_
  33. #include "ODPrcs.h"
  34. #endif
  35.  
  36. #ifndef _SHELLDEF_
  37. #include "ShellDef.h"
  38. #endif
  39.  
  40. inline StringHandle GETSTRING(short resID)
  41. {
  42. #if ODDebug
  43.     StringHandle h = GetString(resID);
  44.     if (!h)
  45.         DebugStr("\pGetString failed. I suggest 'es' now.");
  46.     return h;
  47. #else
  48.     return GetString(resID);
  49. #endif
  50. }
  51.  
  52. inline void GETINDSTRING(StringPtr string, short resID, short index)
  53. {
  54.  
  55.     GetIndString(string, resID, index);
  56. #if ODDebug
  57.     if (!string[0])
  58.         DebugStr("\pGetIndString returned a NULL string. Is this right?");
  59. #endif
  60. }
  61.  
  62. //------------------------------------------------------------------------------
  63. // SystemProcessFileSpecFromName
  64. //------------------------------------------------------------------------------
  65.  
  66. OSErr SystemProcessFileSpecFromName(FSSpec* fileSpec)
  67. {
  68.     OSErr    error;
  69.  
  70.     error = GetOpenDocLibsFolderInfo(&fileSpec->parID, &fileSpec->vRefNum);
  71.     if (!error)
  72.     {
  73.         CopyPascalString(fileSpec->name, *GETSTRING(kSHLSystemProcessNameResID));
  74.     }
  75.     
  76.     return error;
  77. }
  78.  
  79. //------------------------------------------------------------------------------
  80. // SystemProcessFileSpecFromSecretResource
  81. //------------------------------------------------------------------------------
  82.  
  83. OSErr SystemProcessFileSpecFromSecretResource(FSSpec* fileSpec)
  84. {
  85.     OSErr        error;
  86.     CInfoPBRec    catInfo;
  87.     long        dirID;
  88.     short        vRefNum;
  89.     Str255        fileName;
  90.  
  91.     error = GetOpenDocLibsFolderInfo(&dirID, &vRefNum);
  92.  
  93.     if (!error)
  94.     {
  95.         // LOOP THROUGH ALL THE FILES IN THE FOLDER
  96.         memset (&catInfo, 0, sizeof(catInfo));
  97.         catInfo.dirInfo.ioNamePtr = fileName;
  98.         catInfo.dirInfo.ioFDirIndex = 1;
  99.         catInfo.dirInfo.ioVRefNum = vRefNum;
  100.         catInfo.dirInfo.ioDrDirID = dirID;
  101.     
  102.         for(error = PBGetCatInfoSync(&catInfo); 
  103.                         error == noErr; 
  104.                        error = PBGetCatInfoSync(&catInfo))
  105.         {
  106.             // if this is a folder
  107.             if ((catInfo.dirInfo.ioFlAttrib & (1<<4))) 
  108.             {
  109.                 // IGNORE IT
  110.             }
  111.             else
  112.             {
  113.                 // if this is an alias
  114.                 if ((catInfo.hFileInfo.ioFlFndrInfo.fdFlags & 0x8000) /* kIsAlias */)
  115.                 {
  116.                     // IGNORE IT
  117.                 }
  118.                 else
  119.                 {
  120.                     FInfo    fileInfo;
  121.  
  122.                     CopyPascalString(fileSpec->name, fileName);
  123.                     fileSpec->parID = dirID;
  124.                     fileSpec->vRefNum = vRefNum;
  125.                     
  126.                     error = FSpGetFInfo(fileSpec, &fileInfo);
  127.                     if (!error)
  128.                     {
  129.                         // IF THE CREATOR IS RIGHT, WE ARE GOLDEN
  130.                         if (fileInfo.fdCreator == kODSystemProcessSignature)
  131.                         {
  132.                                 error = noErr;
  133.                                 break;
  134.                         }
  135.                         // WELL THE CREATOR MIGHT BE kShellSignature IF THIS IS
  136.                         //    7.5.3 OR LATER, IN WHICH CASE WE CHECK FOR A SPECIAL
  137.                         //    RESOURCE
  138.                         else if (fileInfo.fdType == 'APPL')
  139.                         {
  140.                             short refNum = FSpOpenResFile(fileSpec, fsRdPerm);
  141.                             if (refNum != -1)
  142.                             {
  143.                                 Handle    h;
  144.                                 short    saveResFile = CurResFile();
  145.                                 UseResFile(refNum);
  146.                                 h = Get1Resource(kODSystemProcessSignature, 0);
  147.                                 if (h)
  148.                                 {
  149.                                     error = noErr;
  150.                                     CloseResFile(refNum);
  151.                                     break;
  152.                                 }
  153.                                 UseResFile(saveResFile);
  154.                             }
  155.                             CloseResFile(refNum);
  156.                         }
  157.                     }
  158.                 }
  159.             }
  160.     
  161.             catInfo.hFileInfo.ioFDirIndex++;
  162.             //need to do this each time since PBGetCatInfo call returns val here
  163.             catInfo.hFileInfo.ioNamePtr = fileName;
  164.             catInfo.hFileInfo.ioVRefNum = vRefNum;
  165.             catInfo.hFileInfo.ioDirID = dirID;  
  166.         }
  167.     }
  168.     return error;
  169. }
  170.  
  171.