Example #1
0
DataContainer PackageHandle::ReadAsset(const std::string& _assetName)
{
	std::ifstream fs;
	std::vector<std::string> path = SplitPathName(_assetName);

	Asset* a = root->ReadAsset(path, 0);

	if (a == nullptr)
		return DataContainer(PackageResult::FILE_NOT_FOUND);

	fs.open(packageName.c_str(), std::ifstream::binary);
	char* result = (char*)allocator->FlatAllocate(a->GetSize());

	if (result == nullptr)
		return DataContainer(PackageResult::OUT_OF_MEMORY);

	fs.seekg(a->GetStart());
	fs.read(result, a->GetSize());
	fs.close();

	return DataContainer(result, a->GetSize());
}
Example #2
0
ImageFormat_TGA::ImageFormat_TGA(const Asset& asset):
	image_(0)
	{
	int size=asset.GetSize();
	char* buffer=new char[size];
	asset.Open();
	asset.Read(buffer,size);
    asset.Close();

	image_=new tga_image;
	tga_read_from_Buffer(static_cast<tga_image*>(image_),buffer);

	delete[] buffer;
    }
Example #3
0
bool ImageFormat_TGA::TestAsset(const Asset& asset)
	{
	// Check if the footer says that this is a TGA file
	if (asset.Open())
		{
		asset.Seek(-18,Asset::SEEK_FROM_END);
		char buffer[16];
		asset.Read(buffer,16);
		asset.Close();
		if (StrNCmp(buffer,"TRUEVISION-XFILE",16)==0)
			{
			return true;
			}
		}

	// If the footer doesn't match, this might still be a tga file (version < 2)
	// so try and load it as a tga and see if it works...
	int size=asset.GetSize();
	char* buffer=new char[size];
	asset.Open();
	asset.Read(buffer,size);
    asset.Close();

	tga_image image;
	tga_read_from_Buffer(&image,buffer);

	delete[] buffer;

	// Check to see if the header data makes sense...
	if (image.width<32767 && image.height<32767 && image.image_data && (image.pixel_depth==8 || image.pixel_depth==24 || image.pixel_depth==16 || image.pixel_depth==32))
		{
		// Yeah, sure, this looks like proper data, so give thumbs up and hope for the best
		return true;
		}

	tga_free_buffers(&image);

	// Nope, not likely to be a TGA
	return false;
	}
Example #4
0
AudioFormat_YM::AudioFormat_YM(const Asset& asset):
	ymFile_(0),
	chunkStart_(0),
	chunkEnd_(0)
	{
	if (asset.Open())
		{
		int size=asset.GetSize();
		unsigned char* buffer=static_cast<unsigned char*>(Malloc(size));
		asset.Read(buffer,size);
		asset.Close();

		ymFile_=new CYmMusic();
		ymFile_->loadMemory(buffer,size);
		ymFile_->setLoopMode(true);
		ymFile_->play();
		Free(buffer);
		}
	// Report missing file
	#ifdef _DEBUG
	else
		{
		const char* filename=asset.GetFilename().GetString();
		if (filename)
			{
			char errorMessage[1024];
			SNPrintF(errorMessage,1024,"File not found: %s",filename);
			Assert(false,errorMessage);
			}
		else
			{
			Assert(false,"An asset could not be accessed.");
			}
		}
	#endif
	}