Ejemplo n.º 1
0
int __PHYSFS_platformMkDir(const char *path)
{
    SInt32 val = 0;
    FSSpec spec;
    OSErr err = fnameToFSSpec(path, &spec);

    BAIL_IF_MACRO(err == noErr, ERR_FILE_EXISTS, 0);
    BAIL_IF_MACRO(err != fnfErr, NULL, 0);

    err = DirCreate(spec.vRefNum, spec.parID, spec.name, &val);
    BAIL_IF_MACRO(oserr(err) != noErr, NULL, 0);
    return(1);
} /* __PHYSFS_platformMkDir */
Ejemplo n.º 2
0
int TbnCacheLoad( const fileInfo_t *pFile, const char *pDir, GSTEXTURE **pTexture )
{
	FHANDLE		fHandle;
	TBN_HEADER	tbnHeader;
	char		strPath[256], strTmp[256];
	char		*pStr;
	u8			*pImgData;
	int			nSize;

	if( !SC_GetValueForKey_Int( "tbn_caching", NULL ) )
		return 0;

	if( HDD_Available() == HDD_NOT_AVAIL )
		return 0;

	// build path to TBN file
	if( !SC_GetValueForKey_Str( "tbn_cache_path", strPath ) )
		return 0;

	if( strPath[ strlen(strPath) - 1 ] != '/' )
		strcat( strPath, "/" );

	strcpy( strTmp, pDir );

	if( (pStr = strchr( strTmp, ':' )) == NULL )
		return 0;

	*pStr = 0;
	pStr++;

	strcat( strPath, strTmp );
	strcat( strPath, pStr );

	// make sure directory path exists
	DirCreate( strPath );

	StripFileExt( strTmp, pFile->name );
	strcat( strPath, strTmp );
	strcat( strPath, ".TBN" );

	fHandle = FileOpen( strPath, O_RDONLY | O_CREAT );

	if( fHandle.fh < 0 )
		return 0;

	// file was just created by FileOpen
	nSize = FileSeek( fHandle, 0, SEEK_END );
	if( nSize == 0 )
	{
		FileClose( fHandle );
		return 0;
	}

	FileSeek( fHandle, 0, SEEK_SET );
	FileRead( fHandle, &tbnHeader, sizeof(tbnHeader) );

	if( tbnHeader.magic[0] != 'T' || tbnHeader.magic[1] != 'C' )
	{
		FileClose(fHandle);
		return 0;
	}

	if( tbnHeader.size != pFile->size )
		return 0;

	// read the RGB data
	pImgData = (u8*) memalign( 128, tbnHeader.width * tbnHeader.height * 3 );
	
	if( pImgData == NULL )
	{
		FileClose(fHandle);
		return 0;
	}

	FileRead( fHandle, pImgData, tbnHeader.width * tbnHeader.height * 3 );
	FileClose( fHandle );

	if( pTexture )
		*pTexture = gsLib_texture_raw( tbnHeader.width, tbnHeader.height, GS_PSM_CT24,
									   pImgData, GS_CLUT_NONE, NULL );

	free(pImgData);

	if( pTexture && *pTexture == NULL )
		return 0;

	return 1;
}