⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pgpfilespecmac.c

📁 vc环境下的pgp源码
💻 C
📖 第 1 页 / 共 2 页
字号:
	
	return( err );
}


	static PGPError
sGetNameProc(
	PFLConstFileSpecRef	ref,
	char				name[ 256 ] )
{
	const MyData *	myData	= GetMyData( ref );
	const FSSpec *	spec;
	
	PGPValidatePtr( myData );
	spec	= &myData->spec;
	PGPValidateParam( StrLength( spec->name ) <= 31 );
	
	pgpCopyMemory( &spec->name[ 1 ], name, StrLength( spec->name ) );
	name[ StrLength( spec->name ) ]	= '\0';
	
	return( kPGPError_NoErr );
}


	static PGPError
sSetNameProc(
	PFLFileSpecRef		ref,
	char const *		name )
{
	PGPError	err		= kPGPError_NoErr;
	MyData *	myData	= GetMyData( ref );
	PGPUInt32	nameLength;
	
	PGPValidatePtr( myData );
	nameLength	= strlen( name );
	PGPValidateParam( nameLength <= sizeof( myData->spec.name ) - 1 );
	
	if ( nameLength > sizeof( myData->spec.name ) - 1 )
	{
		err = kPGPError_BufferTooSmall;
	}
	else
	{
		pgpCopyMemory( name, &myData->spec.name[ 1 ], nameLength );
		myData->spec.name[ 0 ]	= nameLength;
	}
	
	return( err );

}


	static PGPError
sGetMaxNameLengthProc(
	PFLConstFileSpecRef	ref,
	PGPSize *		maxNameLength )
{
	const MyData *	myData	= GetMyData( ref );
	
	PGPValidatePtr( myData );
	
	/* at some point, this will need to be done programmatically by
	examining the file system in use which the file is  on */
	*maxNameLength	= kMaxHFSFileNameLength;
	
	return( kPGPError_NoErr );
}



	static PGPError
sSetMetaInfoProc(
	PFLFileSpecRef	ref,
	void const *	infoIn )
{
	PGPError	err	= kPGPError_NoErr;
	MyData *	myData	= GetMyData( ref );
	PFLFileSpecMacMetaInfo const *	info;
	
	info	= (PFLFileSpecMacMetaInfo const *)infoIn;
	pgpAssert( info->fInfo.reserved == 0 );
	
	myData->metaInfo	= *info;
	
	return( err );
}


	static PGPError
sExistsProc(
	PFLFileSpecRef	ref,
	PGPBoolean *	exists)
{
	PGPError	err	= kPGPError_NoErr;
	MyData *	myData	= GetMyData( ref );
	FInfo		fInfo;
	
	if ( myData->specIsValid )
	{
		err		= FSpGetFInfo( &myData->spec, &fInfo );
		*exists	= ( err == noErr );
	}
	else
	{
		*exists	= FALSE;
	}
	
	return( kPGPError_NoErr );
}

	static PGPError
sCreateProc( PFLFileSpecRef ref )
{
	PGPError		err	= kPGPError_NoErr;
	OSStatus		macErr	= noErr;
	MyData *		myData	= GetMyData( ref );
	OSType			fileCreator;
	OSType			fileType;

	fileCreator	= myData->metaInfo.fInfo.fileCreator;
	fileType	= myData->metaInfo.fInfo.fileType;
	
	if( myData->specIsValid )
	{
		macErr = FSpCreate( &myData->spec, fileCreator, fileType, smSystemScript );
		if ( macErr != noErr )
		{
			err	= kPGPError_FileOpFailed;
		}
	}
	else
	{
		err	= kPGPError_FileOpFailed;
	}
	
	return( err );
}


	static PGPError
sDeleteProc( PFLConstFileSpecRef ref )
{
	PGPError		err	= kPGPError_NoErr;
	MyData *		myData	= GetMyData( ref );
	
	if ( myData->specIsValid )
	{
		err	= FSpDelete( &myData->spec );
		if ( err == fnfErr )
			err	= kPGPError_FileNotFound;
		else if ( IsPGPError( err ) )
			err	= kPGPError_FileOpFailed;
	}
	else
	{
		err	= kPGPError_FileNotFound;
	}
	
	return( err );
}


	static PGPError
sRenameProc(
	PFLFileSpecRef	ref,
	const char *	newName)
{
	PGPError		err	= kPGPError_NoErr;
	MyData *		myData	= GetMyData( ref );
	PGPUInt32		nameLength;
	Str255			pascalName;
	
	if ( myData->specIsValid )
	{
		nameLength	= strlen( newName );
		PGPValidateParam( nameLength <= 31 );
		
		pgpCopyMemory( newName, &pascalName[ 1 ], nameLength );
		pascalName[ 0 ]	= nameLength;
		
		err	= FSpRename( &myData->spec, pascalName );
		if ( IsntPGPError( err ) )
		{
			err	= sSetNameProc( ref, newName );
		}
		else if ( err == fnfErr )
			err	= kPGPError_FileNotFound;
		else
			err	= kPGPError_FileOpFailed;
	}
	else
	{
		err	= kPGPError_FileNotFound;
	}
	
	return( err );
}

	static PGPError
sParentDirProc(
	PFLConstFileSpecRef	ref,
	PFLFileSpecRef *	outParent )
{
	PGPError		err		= kPGPError_NoErr;
	MyData *		myData;
	FSSpec			spec;
	HFileInfo		pb;

	PGPValidateParam( ref->type == kPFLFileSpecMacType );

	myData	= GetMyData( ref );
	spec	= myData->spec;
	
	if( myData->specIsValid )
	{
		pb.ioNamePtr = spec.name;
		pb.ioVRefNum = spec.vRefNum;
		pb.ioDirID = spec.parID;
		pb.ioFDirIndex = -1;
		
		if ( PBGetCatInfoSync( (CInfoPBPtr)&pb ) != noErr )
		{
			if ( pb.ioResult == fnfErr )
				err	= kPGPError_FileNotFound;
			else
				err	= kPGPError_FileOpFailed;
		}
		else
		{
			spec.vRefNum = pb.ioVRefNum;
			spec.parID = pb.ioFlParID;
			err = PFLNewFileSpecFromFSSpec( ref->memoryMgr, &spec, outParent );
		}
	}
	else
	{
		err = kPGPError_FileNotFound;
	}
	
	return( err );
}

	static PGPError
sComposeProc(
	PFLConstFileSpecRef	parent,
	const char *		fileName,
	PFLFileSpecRef *	outRef )
{
	PGPError	err		= kPGPError_NoErr;
	FSSpec		spec;
	PGPSize		nameLength;
	CInfoPBRec	cpb;
	
	PGPValidateParam( parent->type == kPFLFileSpecMacType );

	err = GetSpec( parent, &spec, &cpb );
	if( IsntPGPError( err ) )
	{
		nameLength = strlen( fileName );
		if ( nameLength > sizeof( spec.name ) - 1 )
		{
			err = kPGPError_BufferTooSmall;
		}
		else
		{
			pgpCopyMemory( fileName, spec.name + 1, nameLength );
			spec.name[0] 	= nameLength;
			spec.vRefNum 	= cpb.dirInfo.ioVRefNum;
			spec.parID 		= cpb.dirInfo.ioDrDirID;
			
			err = PFLNewFileSpecFromFSSpec( parent->memoryMgr, &spec,
											outRef );
		}
	}
	
	return( err );
}


	PGPError 
PFLNewFileSpecFromFSSpec(
	PGPMemoryMgrRef		memoryMgr,
	FSSpec const *		spec,
	PFLFileSpecRef *	outRef )
{
	PFLFileSpecRef	newFileRef	= NULL;
	PGPError		err	= kPGPError_NoErr;
	
	PGPValidatePtr( outRef );
	*outRef	= NULL;
	PGPValidateMemoryMgr( memoryMgr );
	PGPValidatePtr( spec );
	PGPValidateParam( spec->vRefNum < 0 && spec->parID != 0 &&
		spec->name[ 0 ] != 0 && spec->name[ 0 ] <= 31 );
	
	err	= pgpNewFileSpec( memoryMgr, kPFLFileSpecMacType,
		sizeof( MyData ), &newFileRef );
	if ( IsntPGPError( err ) )
	{
		MyData *	myData	= GetMyData( newFileRef );
		
		pgpClearMemory( myData, sizeof( *myData ) );
		myData->spec			= *spec;
		
		/* volume info not used if vRefNumIsValid */
		myData->specIsValid	= TRUE;

		if( FSpGetFInfo( spec, (FInfo *) &myData->metaInfo.fInfo ) != noErr )
		{
			myData->metaInfo.fInfo.fileType 		= 'BINA';
			myData->metaInfo.fInfo.fileCreator 		= '????';
			myData->metaInfo.fInfo.finderFlags 		= 0;
			myData->metaInfo.fInfo.location.h 		= -1;
			myData->metaInfo.fInfo.location.v 		= -1;
			myData->metaInfo.fInfo.reserved			= 0;
		}
	}
	
	*outRef	= newFileRef;
	return err;
}

	PGPError
PFLGetFSSpecFromFileSpec(
	PFLConstFileSpecRef		ref,
	FSSpec *				spec)
{
	PGPError	err	= kPGPError_NoErr;
		
	PGPValidatePtr( spec );
	pgpClearMemory( spec, sizeof( *spec ) );
	PFLValidateFileSpec( ref );

	err = GetSpec( ref, spec, NULL );
	
	return err;
}


	PGPError
pgpPlatformGetTempFileSpec(
	PGPMemoryMgrRef			memoryMgr,
	PFLConstFileSpecRef		optionalRef,
	PFLFileSpecRef *		outRef )
{
	PGPError				err	= kPGPError_NoErr;
	OSStatus				macErr	= noErr;
	FSSpec					tempSpec;
	const unsigned char	*	kTempFileBase	= "\pPGPTemp";
	
	if ( IsntNull( optionalRef ) )
	{
		err	= PFLGetFSSpecFromFileSpec( optionalRef, &tempSpec );
	}
	else
	{
		macErr	= FindFolder( kOnSystemDisk, kTemporaryFolderType,
					kCreateFolder, &tempSpec.vRefNum, &tempSpec.parID);
		if ( macErr != noErr )
			err	= kPGPError_FileOpFailed;
	}
	
	if ( IsntPGPError( err ) )
	{
		CopyPString( kTempFileBase, tempSpec.name );
		macErr	= FSpGetUniqueSpec( &tempSpec, &tempSpec );
		if ( macErr == noErr )
			err	= PFLNewFileSpecFromFSSpec( memoryMgr, &tempSpec, outRef );
		else
			err	= kPGPError_FileOpFailed;
	}
	
	return( err );
}



	PGPError
pgpPlatformOpenFileSpecAsFILE(
	PFLFileSpecRef	spec,
	const char *	openMode,
	FILE **			fileOut )
{
	PGPError		err	= kPGPError_NoErr;
	FILE *			stdioFILE	= NULL;
	FSSpec			fsSpec;
	
	PGPValidatePtr( fileOut );
	*fileOut	= NULL;
	PFLValidateFileSpec( spec );
	PGPValidatePtr( openMode );
	PGPValidateParam( spec->type == kPFLFileSpecMacType );
	
	err	= PFLGetFSSpecFromFileSpec( spec, &fsSpec );
	if ( IsntPGPError( err ) )
	{
		stdioFILE	= FSp_fopen( &fsSpec, openMode );
		if ( IsNull( stdioFILE ) )
			err	= kPGPError_FileNotFound;
	}
		
	*fileOut = stdioFILE;
	
	return( err );
}


#endif	/* ] PGP_MACINTOSH */


/*
 * Local Variables:
 * tab-width: 4
 * End:
 * vi: ts=4 sw=4
 * vim: si
 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -