Beispiel #1
0
void IFFWriter::begin(const fourcc& name)
{
	this->chunk.push_back(this->iff.tellp());
	this->iff
		<< nullPadded(name, 4)
		<< nullPadded("", 4)
	;
	return;
}
void Archive_Resource_TIM_FAT::updateFileName(const FATEntry *pid, const std::string& strNewName)
{
	// TESTED BY: fmt_resource_tim_fat_rename
	assert(strNewName.length() <= TIM_MAX_FILENAME_LEN);

	this->content->seekp(pid->iOffset + TIM_EFAT_FILENAME_OFFSET, stream::start);
	*this->content << nullPadded(strNewName, TIM_MAX_FILENAME_LEN);

	return;
}
void Archive_DAT_Bash::postInsertFile(FATEntry *pNewEntry)
{
	this->content->seekp(pNewEntry->iOffset, stream::start);

	int typeNum;

	int newLen = pNewEntry->strName.length();
	std::string ext = pNewEntry->strName.substr(newLen - 4);
	if (camoto::icasecmp(ext, ".mif")) typeNum = 0;
	else if (camoto::icasecmp(ext, ".mbg")) typeNum = 1;
	else if (camoto::icasecmp(ext, ".mfg")) typeNum = 2;
	else if (camoto::icasecmp(ext, ".tbg")) typeNum = 3;
	else if (camoto::icasecmp(ext, ".tfg")) typeNum = 4;
	else if (camoto::icasecmp(ext, ".tbn")) typeNum = 5;
	else if (camoto::icasecmp(ext, ".sgl")) typeNum = 6;
	else if (camoto::icasecmp(ext, ".msp")) typeNum = 7;
	else if (camoto::icasecmp(ext, ".snd")) typeNum = 8;
	else if (camoto::icasecmp(ext, ".pbg")) typeNum = 12;
	else if (camoto::icasecmp(ext, ".pfg")) typeNum = 13;
	else if (camoto::icasecmp(ext, ".pal")) typeNum = 14;
	else if (camoto::icasecmp(ext, ".pbn")) typeNum = 16;
	else if (camoto::icasecmp(ext, ".spr")) typeNum = 64;
	else typeNum = 32;

	if ((typeNum != 32) && (typeNum != 8)) {
		// Custom file, chop off extension
		pNewEntry->strName = pNewEntry->strName.substr(0, newLen - 4);
	}

	uint16_t expandedSize;
	if (pNewEntry->fAttr & File::Attribute::Compressed) {
		expandedSize = pNewEntry->realSize;
	} else {
		expandedSize = 0;
	}

	// Write out the entry
	*this->content
		<< u16le(typeNum)
		<< u16le(pNewEntry->storedSize)
		<< nullPadded(pNewEntry->strName, DAT_FILENAME_FIELD_LEN)
		<< u16le(expandedSize)
	;
	return;
}
void Archive_DAT_Bash::updateFileName(const FATEntry *pid, const std::string& strNewName)
{
	int typeNum;
	int newLen = strNewName.length();
	std::string ext = strNewName.substr(newLen - 4);
	if (camoto::icasecmp(ext, ".mif")) typeNum = 0;
	else if (camoto::icasecmp(ext, ".mbg")) typeNum = 1;
	else if (camoto::icasecmp(ext, ".mfg")) typeNum = 2;
	else if (camoto::icasecmp(ext, ".tbg")) typeNum = 3;
	else if (camoto::icasecmp(ext, ".tfg")) typeNum = 4;
	else if (camoto::icasecmp(ext, ".tbn")) typeNum = 5;
	else if (camoto::icasecmp(ext, ".sgl")) typeNum = 6;
	else if (camoto::icasecmp(ext, ".msp")) typeNum = 7;
	else if (camoto::icasecmp(ext, ".snd")) typeNum = 8;
	else if (camoto::icasecmp(ext, ".pbg")) typeNum = 12;
	else if (camoto::icasecmp(ext, ".pfg")) typeNum = 13;
	else if (camoto::icasecmp(ext, ".pal")) typeNum = 14;
	else if (camoto::icasecmp(ext, ".pbn")) typeNum = 16;
	else if (camoto::icasecmp(ext, ".spr")) typeNum = 64;
	else typeNum = 32;

	std::string strNativeName; // name to write to .dat file
	if ((typeNum != 32) && (typeNum != 8)) {
		// Custom file, chop off extension
		strNativeName = strNewName.substr(0, newLen - 4);
		newLen -= 4;
	} else {
		strNativeName = strNewName;
	}

	// TESTED BY: fmt_dat_bash_rename
	assert(newLen <= DAT_MAX_FILENAME_LEN);

	this->content->seekp(DAT_FILETYPE_OFFSET(pid), stream::start);
	*this->content << u16le(typeNum);

	this->content->seekp(DAT_FILENAME_OFFSET(pid), stream::start);
	*this->content << nullPadded(strNativeName, DAT_FILENAME_FIELD_LEN);
	return;
}
void Archive_Resource_TIM_FAT::preInsertFile(const FATEntry *idBeforeThis, FATEntry *pNewEntry)
{
	// TESTED BY: fmt_resource_tim_fat_insert*
	int len = pNewEntry->strName.length();
	assert(len <= TIM_MAX_FILENAME_LEN);

	if (pNewEntry->storedSize % TIM_CONTENT_ITEM_LEN) {
		throw stream::error("Files in this archive must be a multiple of "
			TOSTRING(TIM_CONTENT_ITEM_LEN) " bytes.");
	}

	// Set the format-specific variables
	pNewEntry->lenHeader = TIM_EFAT_ENTRY_LEN;

	boost::to_upper(pNewEntry->strName);

	// Write out the new embedded FAT entry
	this->content->seekp(pNewEntry->iOffset, stream::start);
	this->content->insert(TIM_EFAT_ENTRY_LEN);

	uint16_t actualSize = pNewEntry->storedSize / TIM_CONTENT_ITEM_LEN;

	// Write the header
	*this->content
		<< nullPadded(pNewEntry->strName, TIM_FILENAME_FIELD_LEN)
		<< u16le(actualSize)
	;

	// Since we've inserted some data for the embedded header, we need to update
	// the other file offsets accordingly.  This call updates the offset of the
	// files, then calls updateFileOffset() on them, using the *new* offset, so
	// we need to do this after the insert() call above to make sure the extra
	// data has been inserted.  Then when updateFileOffset() writes data out it
	// will go into the correct spot.
	this->shiftFiles(NULL, pNewEntry->iOffset, pNewEntry->lenHeader, 0);

	this->updateFileCount(this->vcFAT.size() + 1);
	return;
}