home *** CD-ROM | disk | FTP | other *** search
- #ifndef __Files__
- #include <Files.h>
- #endif
-
- #ifndef __GestaltEqu__
- #include <GestaltEqu.h>
- #endif
-
- #ifndef __Memory__
- #include <Memory.h>
- #endif
-
- #ifndef __OSUtils__
- #include <OSUtils.h>
- #endif
-
- #ifndef __Packages__
- #include <Packages.h>
- #endif
-
-
- #ifndef __CallbackDispatcherHeader__
- #include "CallbackDispatcherHeader.h"
- #endif
-
- #ifndef __ActionHandlerHeader__
- #include "ActionHandlerHeader.h"
- #endif
-
- #ifndef __InstallerMemoryFuncsHeader__
- #include "InstallerMemoryFuncsHeader.h"
- #endif
-
- #ifndef __SearchProcedureHeader__
- #include "SearchProcedureHeader.h"
- #endif
-
- void DisplaySearchInfo( SearchProcedurePBPtr pSearchProcedurePBPtr, SearchResult pResultCode );
- FoundFileArrayHdl MakeFoundFilesArrayHdl();
- OSErr AddFSSpecToFoundFilesArrayHdl( FoundFileArrayHdl pFoundFileArrayHdl,
- FSSpec pFSSpec );
-
- SearchResult FindTargetFile( SearchProcedurePBPtr pSearchProcedurePBPtr )
- {
- #define kMaxNumOfMatches 40
- #define kOptBufferSize 0x100
-
- SearchResult result;
- FoundFileArrayHdl myFoundFileArrayHdl;
-
- long theSysVersionNum;
-
- OSErr theErr;
- CInfoPBRec theFirstSearchCriteria;
- CInfoPBRec theSecondSearchCriteria;
- CSParam theCatParamBlock;
- FSSpec theMatchedFSSpecArray[kMaxNumOfMatches];
- char theOptionalBuffer[kOptBufferSize];
- short theByteCtr;
- short theFoundFSSpecCtr;
- FSSpec theTempFSSpec;
-
- myFoundFileArrayHdl = MakeFoundFilesArrayHdl( pSearchProcedurePBPtr->fCallBackProcPtr );
-
- if( myFoundFileArrayHdl != NULL ) {
-
- Gestalt( 'sysv', &theSysVersionNum );
- if( theSysVersionNum >= 0x00000700 ) {
-
- theCatParamBlock.ioCompletion = NULL;
- theCatParamBlock.ioNamePtr = NULL;
- theCatParamBlock.ioVRefNum = pSearchProcedurePBPtr->fTargetVRefNum;
-
- theCatParamBlock.ioMatchPtr = (FSSpecArrayPtr)theMatchedFSSpecArray; /* match array */
- theCatParamBlock.ioReqMatchCount = kMaxNumOfMatches; /* maximum allowable matches */
- theCatParamBlock.ioSearchBits = fsSBFlFndrInfo + fsSBFlAttrib; /* search criteria selector */
- theCatParamBlock.ioSearchInfo1 = &theFirstSearchCriteria; /* search values and range lower bounds */
- theCatParamBlock.ioSearchInfo2 = &theSecondSearchCriteria; /* search values and range upper bounds */
- theCatParamBlock.ioSearchTime = 0; /* length of time to run search */
- theCatParamBlock.ioCatPosition.initialize = 0; /* current position in the catalog */
- theCatParamBlock.ioOptBuffer = theOptionalBuffer; /* optional performance enhancement buffer */
- theCatParamBlock.ioOptBufSize = kOptBufferSize; /* size of buffer pointed to by ioOptBuffer */
-
- theFirstSearchCriteria.hFileInfo.ioFlFndrInfo.fdType = pSearchProcedurePBPtr->fFileSpecType; /* An application */
- theFirstSearchCriteria.hFileInfo.ioFlFndrInfo.fdCreator = pSearchProcedurePBPtr->fFileSpecCreator; /* TeachText creator */
- theFirstSearchCriteria.hFileInfo.ioFlAttrib = 0x00; /* A File */
-
- theSecondSearchCriteria.hFileInfo.ioFlFndrInfo.fdType = 0xFFFFFFFF; /*the type of the file*/
- theSecondSearchCriteria.hFileInfo.ioFlFndrInfo.fdCreator = 0xFFFFFFFF; /*file's creator*/
- theSecondSearchCriteria.hFileInfo.ioFlFndrInfo.fdFlags = 0x0000; /*flags ex. hasbundle,invisible,locked, etc.*/
- theSecondSearchCriteria.hFileInfo.ioFlFndrInfo.fdLocation.h = 0x0000; /*file's location in folder*/
- theSecondSearchCriteria.hFileInfo.ioFlFndrInfo.fdLocation.v = 0x0000; /*file's location in folder*/
- theSecondSearchCriteria.hFileInfo.ioFlFndrInfo.fdFldr = 0x0000; /*folder containing file*/
- theSecondSearchCriteria.hFileInfo.ioFlAttrib = 0x10; /* Check file/directory bit */
-
- theErr = PBCatSearchSync( &theCatParamBlock );
-
- // Add each found
- for( theFoundFSSpecCtr = 0; theFoundFSSpecCtr < theCatParamBlock.ioActMatchCount; theFoundFSSpecCtr++ ) {
- theTempFSSpec.vRefNum = theMatchedFSSpecArray[theFoundFSSpecCtr].vRefNum;
- theTempFSSpec.parID = theMatchedFSSpecArray[theFoundFSSpecCtr].parID;
-
- for( theByteCtr = 0; theByteCtr <= theMatchedFSSpecArray[theFoundFSSpecCtr].name[0]; theByteCtr++ )
- theTempFSSpec.name[theByteCtr] = theMatchedFSSpecArray[theFoundFSSpecCtr].name[theByteCtr];
-
- AddFSSpecToFoundFilesArrayHdl( myFoundFileArrayHdl,theTempFSSpec );
- }
-
- }
- else {
-
- // Implement the pre-7.0 search code here
-
- }
-
-
- pSearchProcedurePBPtr->fFoundFilesArray = myFoundFileArrayHdl;
- result = kSearchSuccessful;
-
- DisplaySearchInfo( pSearchProcedurePBPtr, result );
-
- }
- else
- result = kFatalSearchError;
-
- return result;
- }
-
-
-
- // ***********************************************************************************************
- // ******************************** FoundFileArrayHdl routines ***********************************
- // ***********************************************************************************************
-
- FoundFileArrayHdl MakeFoundFilesArrayHdl( ProcPtr pCallBackProcPtr)
- {
- return (FoundFileArrayHdl)INewHandle( pCallBackProcPtr, 0 );
- }
-
- OSErr AddFSSpecToFoundFilesArrayHdl( FoundFileArrayHdl pFoundFileArrayHdl,
- FSSpec pFSSpec )
- {
- FSSpecPtr newFSSpecPtr;
- OSErr theErr = noErr;
- Size orgSize = GetHandleSize( (Handle)pFoundFileArrayHdl );
-
- if( pFoundFileArrayHdl != NULL ) {
- SetHandleSize( (Handle)pFoundFileArrayHdl, orgSize + sizeof( FoundFileRec ) );
- theErr = MemError();
-
- if( theErr == noErr ) {
- newFSSpecPtr = (FSSpecPtr)(StripAddress(*pFoundFileArrayHdl) + orgSize);
- *newFSSpecPtr = pFSSpec;
- }
- }
-
- return theErr;
- }
-
-
-
- // -------------------------------------------------------------------------------------------------------------------------------------
- // The routines below are for displaying the contents of the parameter block passed to the Setup Function.
- // Call DisplayPreferenceInfo to write this information to the Installer Debugger.
-
- void MakeFilePath( FSSpec* pFileFSSpec, Str255 pFilePath )
- {
-
- CInfoPBRec cPBRec;
- Str255 directoryName = "";
- short i;
- OSErr theErr;
-
- // Get the file name
- for( i=0;i<=pFileFSSpec->name[0];i++)
- pFilePath[i] = pFileFSSpec->name[i];
-
- cPBRec.hFileInfo.ioCompletion = NULL;
- cPBRec.hFileInfo.ioNamePtr = directoryName;
- cPBRec.hFileInfo.ioFDirIndex = -1;
- cPBRec.hFileInfo.ioDirID = pFileFSSpec->parID;
- cPBRec.hFileInfo.ioVRefNum = pFileFSSpec->vRefNum;
- theErr = PBGetCatInfo( &cPBRec, 0 );
-
- // Preappend directoryName
- BlockMove( pFilePath + 1, pFilePath + directoryName[0] + 2, pFilePath[0] );
- for( i=1;i<=directoryName[0];i++)
- pFilePath[i] = directoryName[i];
- pFilePath[i] = ':';
- pFilePath[0] += directoryName[0] + 1;
-
- while ( theErr == noErr && cPBRec.dirInfo.ioDrParID != 1 && pFilePath[0] + directoryName[0] + 1 < 255 ) {
-
- // Preappend directoryName
- cPBRec.hFileInfo.ioDirID = cPBRec.dirInfo.ioDrParID;
- cPBRec.hFileInfo.ioFDirIndex = -1;
- theErr = PBGetCatInfo( &cPBRec, 0 );
-
- if( theErr == noErr ) {
- // Preappend directoryName
- BlockMove( pFilePath + 1, pFilePath + directoryName[0] + 2, pFilePath[0] );
- for( i=1;i<=directoryName[0];i++)
- pFilePath[i] = directoryName[i];
- pFilePath[i] = ':';
- pFilePath[0] += directoryName[0] + 1;
- }
- }
-
- }
-
- void PrintLine( ProcPtr pCallBackProcPtr, Str255 pParam0, Str255 pParam1, Str255 pParam2, Str255 pParam3 )
- {
- long theResult;
- RegisterScriptAction( pCallBackProcPtr, kDebuggingAction, kGenericDebugActID, pParam0, pParam1, pParam2, pParam3, &theResult );
- }
-
- void DisplaySearchInfo( SearchProcedurePBPtr pSearchProcedurePBPtr, SearchResult pResultCode )
- {
-
- StringPtr kBeginCallPart1 = "\p=>========================== Begin File Search Function Call ====";
- StringPtr kBeginCallPart3 = "\p==================================================";
-
- StringPtr kEndCallPart1 = "\p-<-------------------------- End File Search Function Call ------ ";
- StringPtr kEndCallPart3 = "\p ----------------------------\n";
-
- StringPtr kResultText = "\p Result Code: ";
- StringPtr kRefConText = "\p RefCon: ";
- StringPtr kFileTypeText = "\p Type: ";
- StringPtr kFileCreatorText = "\p Creator: ";
- StringPtr kFileFileSpecPathText = "\p File Spec Path: ";
-
- StringPtr kFilesFoundTitleText = "\pFound Files...";
- StringPtr kNoFilesFoundTitleText = "\pNo Files Found!";
- StringPtr kFoundFilePathText = "\p Found File: ";
-
- StringPtr kTargetFolderPathText = "\p Target Folder Path: ";
- StringPtr kSystemDiskText = "\p System Disk Name: ";
-
- Str255 tempNumStr;
- Str255 tempStr255;
-
- short numOfFoundFiles;
- short foundFileCtr;
- FoundFileRec theFoundFileRec;
-
- // -- Beginning line
- PrintLine( pSearchProcedurePBPtr->fCallBackProcPtr, kBeginCallPart1, kBeginCallPart3, "\p", "\p" );
-
- // —— Print File Path from File Spec
- PrintLine( pSearchProcedurePBPtr->fCallBackProcPtr, kFileFileSpecPathText, pSearchProcedurePBPtr->fFileSpecPath, "\p", "\p" );
-
- // —— Print Type from File Spec
- BlockMove( &(pSearchProcedurePBPtr->fFileSpecType), &(tempNumStr[2]), 4 );
- tempNumStr[1] = '\'';
- tempNumStr[6] = '\'';
- tempNumStr[0] = 6;
- PrintLine( pSearchProcedurePBPtr->fCallBackProcPtr, kFileTypeText, tempNumStr, "\p", "\p" );
-
- // —— Print Creator from File Spec
- BlockMove( &(pSearchProcedurePBPtr->fFileSpecCreator), &(tempNumStr[2]), 4 );
- tempNumStr[1] = '\'';
- tempNumStr[6] = '\'';
- tempNumStr[0] = 6;
- PrintLine( pSearchProcedurePBPtr->fCallBackProcPtr, kFileCreatorText, tempNumStr, "\p", "\p" );
-
- // —— Print RefCon
- NumToString( pSearchProcedurePBPtr->fRefCon, tempNumStr );
- PrintLine( pSearchProcedurePBPtr->fCallBackProcPtr, kRefConText, tempNumStr, "\p", "\p" );
-
- if( pSearchProcedurePBPtr->fFoundFilesArray != NULL ) {
- numOfFoundFiles = GetHandleSize( (Handle)pSearchProcedurePBPtr->fFoundFilesArray ) / sizeof( FoundFileRec);
-
- if( numOfFoundFiles > 0 )
- PrintLine( pSearchProcedurePBPtr->fCallBackProcPtr, kFilesFoundTitleText, "\p", "\p", "\p" );
- else
- PrintLine( pSearchProcedurePBPtr->fCallBackProcPtr, kNoFilesFoundTitleText, "\p", "\p", "\p" );
-
- // Print found file paths
- for( foundFileCtr = 0; foundFileCtr < numOfFoundFiles; foundFileCtr++ ) {
- theFoundFileRec = (*(pSearchProcedurePBPtr->fFoundFilesArray))[foundFileCtr];
- MakeFilePath( (FSSpec*)&theFoundFileRec, tempStr255 );
- PrintLine( pSearchProcedurePBPtr->fCallBackProcPtr, kFoundFilePathText, tempStr255, "\p", "\p" );
- }
- }
-
- // -- Ending line
- NumToString( pResultCode, tempNumStr );
- PrintLine( pSearchProcedurePBPtr->fCallBackProcPtr, kEndCallPart1, kResultText, tempNumStr, kEndCallPart3 );
- }
-
- #include "ActionHandlerCBGlue.c"
- #include "InstallerMemoryCBGlue.c"
-