//-----------------------------------------------------------------------------
void* TextResource::load(Allocator& allocator, Bundle& bundle, ResourceId id)
{
	DiskFile* stream = bundle.open(id);

	CE_ASSERT(stream != NULL, "Resource does not exist: %.8X%.8X", id.name, id.type);

	TextResource* resource = (TextResource*)allocator.allocate(sizeof(TextResource));

	stream->read(&resource->length, sizeof(uint32_t));
	
	resource->data = (char*)allocator.allocate(sizeof(char) * (resource->length + 1));

	stream->read(resource->data, (size_t)resource->length);
	
	resource->data[resource->length] = '\0';

	bundle.close(stream);

	return resource;
}
//-----------------------------------------------------------------------------
DiskFile* FileBundle::open(ResourceId name)
{
	// Convert name/type into strings
	char resource_name[512];
	snprintf(resource_name, 512, "%.8X%.8X", name.name, name.type);

	// Search the resource in the filesystem
	bool exists = m_filesystem.exists(resource_name);
	CE_ASSERT(exists == true, "Resource does not exist: %s", resource_name);

	// Open the resource and check magic number/version
	DiskFile* file = (DiskFile*)m_filesystem.open(resource_name, FOM_READ);

	ResourceHeader header;
	file->read(&header, sizeof(ResourceHeader));

	CE_ASSERT(header.magic == RESOURCE_MAGIC_NUMBER, "Resource is not valid: %s", resource_name);
	CE_ASSERT(header.version == RESOURCE_VERSION, "Resource version mismatch: %s", resource_name);

	return file;
}