home *** CD-ROM | disk | FTP | other *** search
- /*
- File: ProcessStuff.cpp
-
- Contains: xxx put contents here xxx
-
- Owned by: Nick Pilch
-
- Copyright: © 1996 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <4> 6/28/96 TJ Fixed Non-Debug Build.
- <3> 6/24/96 NP 10002: Launch time speedups
- <2> 6/23/96 NP 10002: Add some routines.
- <1> 6/23/96 NP first checked in
-
- To Do:
- */
-
- #ifndef __TEXTUTILS__
- #include <TextUtils.h>
- #endif
-
- #ifndef __FILES__
- #include <Files.h>
- #endif
-
- #ifndef _PROCESSSTUFF_
- #include "ProcessStuff.h"
- #endif
-
- #ifndef _ODPRCS_
- #include "ODPrcs.h"
- #endif
-
- #ifndef _SHELLDEF_
- #include "ShellDef.h"
- #endif
-
- inline StringHandle GETSTRING(short resID)
- {
- #if ODDebug
- StringHandle h = GetString(resID);
- if (!h)
- DebugStr("\pGetString failed. I suggest 'es' now.");
- return h;
- #else
- return GetString(resID);
- #endif
- }
-
- inline void GETINDSTRING(StringPtr string, short resID, short index)
- {
-
- GetIndString(string, resID, index);
- #if ODDebug
- if (!string[0])
- DebugStr("\pGetIndString returned a NULL string. Is this right?");
- #endif
- }
-
- //------------------------------------------------------------------------------
- // SystemProcessFileSpecFromName
- //------------------------------------------------------------------------------
-
- OSErr SystemProcessFileSpecFromName(FSSpec* fileSpec)
- {
- OSErr error;
-
- error = GetOpenDocLibsFolderInfo(&fileSpec->parID, &fileSpec->vRefNum);
- if (!error)
- {
- CopyPascalString(fileSpec->name, *GETSTRING(kSHLSystemProcessNameResID));
- }
-
- return error;
- }
-
- //------------------------------------------------------------------------------
- // SystemProcessFileSpecFromSecretResource
- //------------------------------------------------------------------------------
-
- OSErr SystemProcessFileSpecFromSecretResource(FSSpec* fileSpec)
- {
- OSErr error;
- CInfoPBRec catInfo;
- long dirID;
- short vRefNum;
- Str255 fileName;
-
- error = GetOpenDocLibsFolderInfo(&dirID, &vRefNum);
-
- if (!error)
- {
- // LOOP THROUGH ALL THE FILES IN THE FOLDER
- memset (&catInfo, 0, sizeof(catInfo));
- catInfo.dirInfo.ioNamePtr = fileName;
- catInfo.dirInfo.ioFDirIndex = 1;
- catInfo.dirInfo.ioVRefNum = vRefNum;
- catInfo.dirInfo.ioDrDirID = dirID;
-
- for(error = PBGetCatInfoSync(&catInfo);
- error == noErr;
- error = PBGetCatInfoSync(&catInfo))
- {
- // if this is a folder
- if ((catInfo.dirInfo.ioFlAttrib & (1<<4)))
- {
- // IGNORE IT
- }
- else
- {
- // if this is an alias
- if ((catInfo.hFileInfo.ioFlFndrInfo.fdFlags & 0x8000) /* kIsAlias */)
- {
- // IGNORE IT
- }
- else
- {
- FInfo fileInfo;
-
- CopyPascalString(fileSpec->name, fileName);
- fileSpec->parID = dirID;
- fileSpec->vRefNum = vRefNum;
-
- error = FSpGetFInfo(fileSpec, &fileInfo);
- if (!error)
- {
- // IF THE CREATOR IS RIGHT, WE ARE GOLDEN
- if (fileInfo.fdCreator == kODSystemProcessSignature)
- {
- error = noErr;
- break;
- }
- // WELL THE CREATOR MIGHT BE kShellSignature IF THIS IS
- // 7.5.3 OR LATER, IN WHICH CASE WE CHECK FOR A SPECIAL
- // RESOURCE
- else if (fileInfo.fdType == 'APPL')
- {
- short refNum = FSpOpenResFile(fileSpec, fsRdPerm);
- if (refNum != -1)
- {
- Handle h;
- short saveResFile = CurResFile();
- UseResFile(refNum);
- h = Get1Resource(kODSystemProcessSignature, 0);
- if (h)
- {
- error = noErr;
- CloseResFile(refNum);
- break;
- }
- UseResFile(saveResFile);
- }
- CloseResFile(refNum);
- }
- }
- }
- }
-
- catInfo.hFileInfo.ioFDirIndex++;
- //need to do this each time since PBGetCatInfo call returns val here
- catInfo.hFileInfo.ioNamePtr = fileName;
- catInfo.hFileInfo.ioVRefNum = vRefNum;
- catInfo.hFileInfo.ioDirID = dirID;
- }
- }
- return error;
- }
-
-