2012-08-11 14:27:38 +02:00
|
|
|
|
2012-01-21 21:57:41 +01:00
|
|
|
#include <ogcsys.h>
|
|
|
|
#include <locale.h>
|
|
|
|
#include <ogc/isfs.h>
|
2012-08-11 14:27:38 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
2012-01-21 21:57:41 +01:00
|
|
|
#include "fs.h"
|
2012-08-11 14:27:38 +02:00
|
|
|
#include "utils.h"
|
2012-12-08 17:17:35 +01:00
|
|
|
#include "gecko/gecko.hpp"
|
2012-08-11 14:27:38 +02:00
|
|
|
#include "memory/mem2.hpp"
|
|
|
|
|
|
|
|
static fstats stats ATTRIBUTE_ALIGN(32);
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-11-12 21:12:00 +01:00
|
|
|
u8 *ISFS_GetFile(const char *path, u32 *size, s32 length)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
|
|
|
*size = 0;
|
2012-11-12 21:12:00 +01:00
|
|
|
//gprintf("ISFS_GetFile %s", path);
|
|
|
|
s32 fd = ISFS_Open(path, ISFS_OPEN_READ);
|
2012-01-21 21:57:41 +01:00
|
|
|
u8 *buf = NULL;
|
2012-08-11 14:27:38 +02:00
|
|
|
|
2012-07-27 19:26:49 +02:00
|
|
|
if(fd >= 0)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-08-11 14:27:38 +02:00
|
|
|
memset(&stats, 0, sizeof(fstats));
|
2012-07-27 19:26:49 +02:00
|
|
|
if(ISFS_GetFileStats(fd, &stats) >= 0)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-07-27 19:26:49 +02:00
|
|
|
if(length <= 0)
|
|
|
|
length = stats.file_length;
|
|
|
|
if(length > 0)
|
2012-08-11 14:27:38 +02:00
|
|
|
buf = (u8 *)MEM2_memalign(32, ALIGN32(length));
|
2012-07-27 19:26:49 +02:00
|
|
|
if(buf)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
|
|
|
*size = stats.file_length;
|
2012-07-27 19:26:49 +02:00
|
|
|
if(ISFS_Read(fd, (char*)buf, length) != length)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
|
|
|
*size = 0;
|
2012-08-11 14:27:38 +02:00
|
|
|
MEM2_free(buf);
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ISFS_Close(fd);
|
|
|
|
}
|
2012-08-11 14:27:38 +02:00
|
|
|
if(*size > 0)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-11-12 21:12:00 +01:00
|
|
|
//gprintf(" succeed!\n");
|
2012-01-21 21:57:41 +01:00
|
|
|
DCFlushRange(buf, *size);
|
|
|
|
ICInvalidateRange(buf, *size);
|
|
|
|
}
|
2012-11-12 21:12:00 +01:00
|
|
|
//else
|
|
|
|
// gprintf(" failed!\n");
|
2012-01-21 21:57:41 +01:00
|
|
|
return buf;
|
2012-05-13 19:25:26 +02:00
|
|
|
}
|