本文整理汇总了C++中MemChunk::reSize方法的典型用法代码示例。如果您正苦于以下问题:C++ MemChunk::reSize方法的具体用法?C++ MemChunk::reSize怎么用?C++ MemChunk::reSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemChunk
的用法示例。
在下文中一共展示了MemChunk::reSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getIndexedData
/* SImage::getIndexedData
* Loads the image as index data into <mc>. Returns false if image is
* invalid, true otherwise
*******************************************************************/
bool SImage::getIndexedData(MemChunk& mc)
{
// Check the image is valid
if (!isValid())
return false;
// Init rgb data
mc.reSize(width * height, false);
// Cannot do this for trucolor graphics.
if (type == RGBA)
return false;
else if (type == PALMASK)
{
mc.write(data, width * height);
return true;
}
else if (type == ALPHAMAP)
{
mc.write(data, width * height);
return true;
}
return false; // Invalid image type
}
示例2: getRGBAData
/* SImage::getRGBAData
* Loads the image as RGBA data into <mc>. Returns false if image is
* invalid, true otherwise
*******************************************************************/
bool SImage::getRGBAData(MemChunk& mc, Palette8bit* pal)
{
// Check the image is valid
if (!isValid())
return false;
// Init rgba data
mc.reSize(width * height * 4, false);
// If data is already in RGBA format just return a copy
if (type == RGBA)
{
mc.importMem(data, width * height * 4);
return true;
}
// Convert paletted
else if (type == PALMASK)
{
// Get palette to use
if (has_palette || !pal)
pal = &palette;
uint8_t rgba[4];
for (int a = 0; a < width * height; a++)
{
// Get colour
rgba_t col = pal->colour(data[a]);
// Set alpha
if (mask)
col.a = mask[a];
else
col.a = 255;
col.write(rgba); // Write colour to array
mc.write(rgba, 4); // Write array to MemChunk
}
return true;
}
// Convert if alpha map
else if (type == ALPHAMAP)
{
uint8_t rgba[4];
rgba_t col;
for (int a = 0; a < width * height; a++)
{
// Get pixel as colour (greyscale)
col.set(data[a], data[a], data[a], data[a]);
col.write(rgba); // Write colour to array
mc.write(rgba, 4); // Write array to MemChunk
}
}
return false; // Invalid image type
}
示例3: entryAt
// -----------------------------------------------------------------------------
// Writes the wad archive to a MemChunk
// Returns true if successful, false otherwise
// -----------------------------------------------------------------------------
bool Wad2Archive::write(MemChunk& mc, bool update)
{
// Determine directory offset & individual lump offsets
uint32_t dir_offset = 12;
ArchiveEntry* entry = nullptr;
for (uint32_t l = 0; l < numEntries(); l++)
{
entry = entryAt(l);
entry->exProp("Offset") = (int)dir_offset;
dir_offset += entry->size();
}
// Clear/init MemChunk
mc.clear();
mc.seek(0, SEEK_SET);
mc.reSize(dir_offset + numEntries() * 32);
// Setup wad type
char wad_type[4] = { 'W', 'A', 'D', '2' };
if (wad3_)
wad_type[3] = '3';
// Write the header
uint32_t num_lumps = numEntries();
mc.write(wad_type, 4);
mc.write(&num_lumps, 4);
mc.write(&dir_offset, 4);
// Write the lumps
for (uint32_t l = 0; l < num_lumps; l++)
{
entry = entryAt(l);
mc.write(entry->rawData(), entry->size());
}
// Write the directory
for (uint32_t l = 0; l < num_lumps; l++)
{
entry = entryAt(l);
// Setup directory entry
Wad2Entry info;
memset(info.name, 0, 16);
memcpy(info.name, CHR(entry->name()), entry->name().Len());
info.cmprs = (bool)entry->exProp("W2Comp");
info.dsize = entry->size();
info.size = entry->size();
info.offset = (int)entry->exProp("Offset");
info.type = (int)entry->exProp("W2Type");
// Write it
mc.write(&info, 32);
if (update)
entry->setState(ArchiveEntry::State::Unmodified);
}
return true;
}
示例4: write
/* GobArchive::write
* Writes the gob archive to a MemChunk
* Returns true if successful, false otherwise
*******************************************************************/
bool GobArchive::write(MemChunk& mc, bool update)
{
// Determine directory offset & individual lump offsets
uint32_t dir_offset = 8;
ArchiveEntry* entry = NULL;
for (uint32_t l = 0; l < numEntries(); l++)
{
entry = getEntry(l);
setEntryOffset(entry, dir_offset);
dir_offset += entry->getSize();
}
// Clear/init MemChunk
mc.clear();
mc.seek(0, SEEK_SET);
mc.reSize(dir_offset + 4 + numEntries() * 21);
// Write the header
uint32_t num_lumps = wxINT32_SWAP_ON_BE(numEntries());
dir_offset = wxINT32_SWAP_ON_BE(dir_offset);
char header[4] = { 'G', 'O', 'B', 0xA };
mc.write(header, 4);
mc.write(&dir_offset, 4);
// Write the lumps
for (uint32_t l = 0; l < numEntries(); l++)
{
entry = getEntry(l);
mc.write(entry->getData(), entry->getSize());
}
// Write the directory
mc.write(&num_lumps, 4);
for (uint32_t l = 0; l < numEntries(); l++)
{
entry = getEntry(l);
char name[13] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
long offset = wxINT32_SWAP_ON_BE(getEntryOffset(entry));
long size = wxINT32_SWAP_ON_BE(entry->getSize());
for (size_t c = 0; c < entry->getName().length() && c < 13; c++)
name[c] = entry->getName()[c];
mc.write(&offset, 4);
mc.write(&size, 4);
mc.write(name, 13);
if (update)
{
entry->setState(0);
entry->exProp("Offset") = (int)offset;
}
}
return true;
}
示例5: getRGBData
/* SImage::getRGBData
* Loads the image as RGB data into <mc>. Returns false if image is
* invalid, true otherwise
*******************************************************************/
bool SImage::getRGBData(MemChunk& mc, Palette8bit* pal)
{
// Check the image is valid
if (!isValid())
return false;
// Init rgb data
mc.reSize(width * height * 3, false);
if (type == RGBA)
{
// RGBA format, remove alpha information
for (int a = 0; a < width * height * 4; a += 4)
mc.write(&data[a], 3);
return true;
}
else if (type == PALMASK)
{
// Paletted, convert to RGB
// Get palette to use
if (has_palette || !pal)
pal = &palette;
// Build RGB data
uint8_t rgba[4];
for (int a = 0; a < width * height; a ++)
{
pal->colour(data[a]).write(rgba);
mc.write(rgba, 3);
}
return true;
}
else if (type == ALPHAMAP)
{
// Alpha map, convert to RGB
uint8_t rgba[4];
rgba_t col;
for (int a = 0; a < width * height; a++)
{
// Get pixel as colour (greyscale)
col.set(data[a], data[a], data[a], data[a]);
col.write(rgba); // Write colour to array
mc.write(rgba, 3); // Write array to MemChunk
}
}
return false; // Invalid image type
}
示例6: write
/* HogArchive::write
* Writes the hog archive to a MemChunk
* Returns true if successful, false otherwise
*******************************************************************/
bool HogArchive::write(MemChunk& mc, bool update)
{
// Determine individual lump offsets
uint32_t offset = 3;
ArchiveEntry* entry = NULL;
for (uint32_t l = 0; l < numEntries(); l++)
{
offset += 17;
entry = getEntry(l);
setEntryOffset(entry, offset);
if (update)
{
entry->setState(0);
entry->exProp("Offset") = (int)offset;
}
offset += entry->getSize();
}
// Clear/init MemChunk
mc.clear();
mc.seek(0, SEEK_SET);
mc.reSize(offset);
// Write the header
char header[3] = { 'D', 'H', 'F' };
mc.write(header, 3);
// Write the lumps
for (uint32_t l = 0; l < numEntries(); l++)
{
entry = getEntry(l);
mc.write(entry->getData(), entry->getSize());
}
// Write the directory
for (uint32_t l = 0; l < numEntries(); l++)
{
entry = getEntry(l);
char name[13] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
long size = wxINT32_SWAP_ON_BE(entry->getSize());
for (size_t c = 0; c < entry->getName().length() && c < 13; c++)
name[c] = entry->getName()[c];
mc.write(name, 13);
mc.write(&size, 4);
mc.write(entry->getData(), entry->getSize());
}
return true;
}
示例7: exportMemChunk
/* MemChunk::exportMemChunk
* Writes the MemChunk data to another MemChunk, starting from
* [start] to [start+size]. If [size] is 0, writes from [start] to
* the end of the data
*******************************************************************/
bool MemChunk::exportMemChunk(MemChunk& mc, uint32_t start, uint32_t size)
{
// Check data exists
if (!hasData())
return false;
// Check parameters
if (start >= this->size || start + size > this->size)
return false;
// Check size
if (size == 0)
size = this->size - start;
// Write data to MemChunk
mc.reSize(size, false);
return mc.importMem(data+start, size);
}
示例8: write
// -----------------------------------------------------------------------------
// Writes the grp archive to a MemChunk
// Returns true if successful, false otherwise
// -----------------------------------------------------------------------------
bool GrpArchive::write(MemChunk& mc, bool update)
{
// Clear/init MemChunk
mc.clear();
mc.seek(0, SEEK_SET);
mc.reSize((1 + numEntries()) * 16);
ArchiveEntry* entry;
// Write the header
uint32_t num_lumps = numEntries();
mc.write("KenSilverman", 12);
mc.write(&num_lumps, 4);
// Write the directory
for (uint32_t l = 0; l < num_lumps; l++)
{
entry = entryAt(l);
char name[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
long size = entry->size();
for (size_t c = 0; c < entry->name().length() && c < 12; c++)
name[c] = entry->name()[c];
mc.write(name, 12);
mc.write(&size, 4);
if (update)
{
long offset = getEntryOffset(entry);
entry->setState(ArchiveEntry::State::Unmodified);
entry->exProp("Offset") = (int)offset;
}
}
// Write the lumps
for (uint32_t l = 0; l < num_lumps; l++)
{
entry = entryAt(l);
mc.write(entry->rawData(), entry->size());
}
return true;
}
示例9: write
/* DatArchive::write
* Writes the dat archive to a MemChunk
* Returns true if successful, false otherwise
*******************************************************************/
bool DatArchive::write(MemChunk& mc, bool update)
{
// Only two bytes are used for storing entry amount,
// so abort for excessively large files:
if (numEntries() > 65535)
return false;
// Determine directory offset, name offsets & individual lump offsets
uint32_t dir_offset = 10;
uint16_t name_offset = numEntries() * 12;
uint32_t name_size = 0;
string previousname = "";
uint16_t* nameoffsets = new uint16_t[numEntries()];
ArchiveEntry* entry = NULL;
for (uint16_t l = 0; l < numEntries(); l++)
{
entry = getEntry(l);
setEntryOffset(entry, dir_offset);
dir_offset += entry->getSize();
// Does the entry has a name?
string name = entry->getName();
if (l > 0 && previousname.length() > 0 && name.length() > previousname.length() &&
!previousname.compare(0, previousname.length(), name, 0, previousname.length()) &&
name.at(previousname.length()) == '+')
{
// This is a fake name
name = "";
nameoffsets[l] = 0;
}
else
{
// This is a true name
previousname = name;
nameoffsets[l] = uint16_t(name_offset + name_size);
name_size += name.length() + 1;
}
}
// Clear/init MemChunk
mc.clear();
mc.seek(0, SEEK_SET);
mc.reSize(dir_offset + name_size + numEntries() * 12);
// Write the header
uint16_t num_lumps = wxINT16_SWAP_ON_BE(numEntries());
dir_offset = wxINT32_SWAP_ON_BE(dir_offset);
uint32_t unknown = 0;
mc.write(&num_lumps, 2);
mc.write(&dir_offset, 4);
mc.write(&unknown, 4);
// Write the lumps
for (uint16_t l = 0; l < numEntries(); l++)
{
entry = getEntry(l);
mc.write(entry->getData(), entry->getSize());
}
// Write the directory
for (uint16_t l = 0; l < num_lumps; l++)
{
entry = getEntry(l);
uint32_t offset = wxINT32_SWAP_ON_BE(getEntryOffset(entry));
uint32_t size = wxINT32_SWAP_ON_BE(entry->getSize());
uint16_t nameofs = wxINT16_SWAP_ON_BE(nameoffsets[l]);
uint16_t flags = wxINT16_SWAP_ON_BE((entry->isEncrypted() == ENC_SCRLE0) ? 1 : 0);
mc.write(&offset, 4); // Offset
mc.write(&size, 4); // Size
mc.write(&nameofs, 2); // Name offset
mc.write(&flags, 2); // Flags
if (update)
{
entry->setState(0);
entry->exProp("Offset") = (int)wxINT32_SWAP_ON_BE(offset);
}
}
// Write the names
for (uint16_t l = 0; l < num_lumps; l++)
{
uint8_t zero = 0;
entry = getEntry(l);
if (nameoffsets[l])
{
mc.write(CHR(entry->getName()), entry->getName().length());
mc.write(&zero, 1);
}
}
// Clean-up
delete[] nameoffsets;
//.........这里部分代码省略.........
示例10: write
// -----------------------------------------------------------------------------
// Writes Chasm bin archive to a MemChunk
// Returns true if successful, false otherwise
// -----------------------------------------------------------------------------
bool ChasmBinArchive::write(MemChunk& mc, bool update)
{
// Clear current data
mc.clear();
// Get archive tree as a list
vector<ArchiveEntry*> entries;
getEntryTreeAsList(entries);
// Check limit of entries count
const uint16_t num_entries = static_cast<uint16_t>(entries.size());
if (num_entries > MAX_ENTRY_COUNT)
{
LOG_MESSAGE(1, "ChasmBinArchive::write: Bin archive can contain no more than %u entries", MAX_ENTRY_COUNT);
Global::error = "Maximum number of entries exceeded for Chasm: The Rift bin archive";
return false;
}
// Init data size
static const uint32_t HEADER_TOC_SIZE = HEADER_SIZE + ENTRY_SIZE * MAX_ENTRY_COUNT;
mc.reSize(HEADER_TOC_SIZE, false);
mc.fillData(0);
// Write header
const char magic[4] = { 'C', 'S', 'i', 'd' };
mc.seek(0, SEEK_SET);
mc.write(magic, 4);
mc.write(&num_entries, sizeof num_entries);
// Write directory
uint32_t offset = HEADER_TOC_SIZE;
for (uint16_t i = 0; i < num_entries; ++i)
{
ArchiveEntry* const entry = entries[i];
// Update entry
if (update)
{
entry->setState(0);
entry->exProp("Offset") = static_cast<int>(offset);
}
// Check entry name
string name = entry->getName();
uint8_t name_length = static_cast<uint8_t>(name.Length());
if (name_length > NAME_SIZE - 1)
{
LOG_MESSAGE(1, "Warning: Entry %s name is too long, it will be truncated", name);
name.Truncate(NAME_SIZE - 1);
name_length = static_cast<uint8_t>(NAME_SIZE - 1);
}
// Write entry name
char name_data[NAME_SIZE] = {};
memcpy(name_data, &name_length, 1);
memcpy(name_data + 1, CHR(name), name_length);
mc.write(name_data, NAME_SIZE);
// Write entry size
const uint32_t size = entry->getSize();
mc.write(&size, sizeof size);
// Write entry offset
mc.write(&offset, sizeof offset);
// Increment/update offset
offset += size;
}
// Write entry data
mc.reSize(offset);
mc.seek(HEADER_TOC_SIZE, SEEK_SET);
for (uint16_t i = 0; i < num_entries; ++i)
{
ArchiveEntry* const entry = entries[i];
mc.write(entry->getData(), entry->getSize());
}
return true;
}
示例11: generateColormaps
bool PaletteEntryPanel::generateColormaps()
{
if (!entry || !entry->getParent() || ! palettes[0])
return false;
MemChunk mc;
SImage img;
MemChunk imc;
mc.reSize(34*256);
mc.seek(0, SEEK_SET);
imc.reSize(34*256*4);
imc.seek(0, SEEK_SET);
uint8_t rgba[4];
rgba[3] = 255;
rgba_t rgb;
float grey;
// Generate 34 maps: the first 32 for diminishing light levels,
// the 33th for the inverted grey map used by invulnerability.
// The 34th colormap remains empty and black.
for (size_t l = 0; l < 34; ++l)
{
for (size_t c = 0; c < 256; ++c)
{
rgb = palettes[0]->colour(c);
if (l < 32)
{
// Generate light maps
DIMINISH(rgb.r, l);
DIMINISH(rgb.g, l);
DIMINISH(rgb.b, l);
#if (0)
}
else if (l == GREENMAP)
{
// Point of mostly useless trivia: the green "light amp" colormap in the Press Release beta
// have colors that, on average, correspond to a bit less than (R*75/256, G*225/256, B*115/256)
#endif
}
else if (l == GRAYMAP)
{
// Generate inverse map
grey = ((float)rgb.r/256.0 * col_greyscale_r) + ((float)rgb.g/256.0 * col_greyscale_g) + ((float)rgb.b/256.0 * col_greyscale_b);
grey = 1.0 - grey;
// Clamp value: with Id Software's values, the sum is greater than 1.0 (0.299+0.587+0.144=1.030)
// This means the negation above can give a negative value (for example, with RGB values of 247 or more),
// which will not be converted correctly to unsigned 8-bit int in the rgba_t struct.
if (grey < 0.0) grey = 0;
rgb.r = rgb.g = rgb.b = grey*255;
}
else
{
// Fill with 0
rgb = palettes[0]->colour(0);
}
rgba[0] = rgb.r; rgba[1] = rgb.g; rgba[2] = rgb.b;
imc.write(&rgba, 4);
mc[(256*l)+c] = palettes[0]->nearestColour(rgb);
}
}
#if 0
// Create truecolor image
uint8_t* imd = new uint8_t[256*34*4];
memcpy(imd, imc.getData(), 256*34*4);
img.setImageData(imd, 256, 34, RGBA);
// imd will be freed by img's destructor
ArchiveEntry* tcolormap;
string name = entry->getName(true) + "-tcm.png";
tcolormap = new ArchiveEntry(name);
if (tcolormap)
{
entry->getParent()->addEntry(tcolormap);
SIFormat::getFormat("png")->saveImage(img, tcolormap->getMCData());
EntryType::detectEntryType(tcolormap);
}
#endif
// Now override or create new entry
ArchiveEntry* colormap;
colormap = entry->getParent()->getEntry("COLORMAP", true);
bool preexisting = colormap != NULL;
if (!colormap)
{
// We need to create this entry
colormap = new ArchiveEntry("COLORMAP.lmp", 34*256);
}
if (!colormap)
return false;
colormap->importMemChunk(mc);
if (!preexisting)
{
entry->getParent()->addEntry(colormap);
}
return true;
}
示例12: write
// -----------------------------------------------------------------------------
// Writes the disk archive to a MemChunk.
// Returns true if successful, false otherwise
// -----------------------------------------------------------------------------
bool DiskArchive::write(MemChunk& mc, bool update)
{
// Clear current data
mc.clear();
// Get archive tree as a list
vector<ArchiveEntry*> entries;
getEntryTreeAsList(entries);
// Process entry list
uint32_t num_entries = 0;
uint32_t size_entries = 0;
for (unsigned a = 0; a < entries.size(); a++)
{
// Ignore folder entries
if (entries[a]->getType() == EntryType::folderType())
continue;
// Increment directory offset and size
size_entries += entries[a]->getSize();
++num_entries;
}
// Init data size
uint32_t start_offset = 8 + (num_entries * 72);
uint32_t offset = start_offset;
mc.reSize(size_entries + start_offset, false);
// Write header
num_entries = wxUINT32_SWAP_ON_LE(num_entries);
mc.seek(0, SEEK_SET);
mc.write(&num_entries, 4);
// Write directory
for (unsigned a = 0; a < entries.size(); a++)
{
// Skip folders
if (entries[a]->getType() == EntryType::folderType())
continue;
// Update entry
if (update)
{
entries[a]->setState(0);
entries[a]->exProp("Offset") = (int)offset;
}
// Check entry name
string name = entries[a]->getPath(true);
name.Replace("/", "\\");
// The leading "GAME:\" part of the name means there is only 58 usable characters for path
if (name.Len() > 58)
{
LOG_MESSAGE(
1, "Warning: Entry %s path is too long (> 58 characters), putting it in the root directory", name);
wxFileName fn(name);
name = fn.GetFullName();
if (name.Len() > 57)
name.Truncate(57);
// Add leading "\"
name = "\\" + name;
}
name = "GAME:" + name;
DiskEntry dent;
// Write entry name
// The names field are padded with FD for doom.disk, FE for doom2.disk. No idea whether
// a non-null padding is actually required, though. It probably should work with anything.
memset(dent.name, 0xFE, 64);
memcpy(dent.name, CHR(name), name.Length());
dent.name[name.Length()] = 0;
// Write entry offset
dent.offset = wxUINT32_SWAP_ON_LE(offset - start_offset);
// Write entry size
dent.length = wxUINT32_SWAP_ON_LE(entries[a]->getSize());
// Actually write stuff
mc.write(&dent, 72);
// Increment/update offset
offset += wxUINT32_SWAP_ON_LE(dent.length);
}
// Finish writing header
size_entries = wxUINT32_SWAP_ON_LE(size_entries);
mc.write(&size_entries, 4);
// Write entry data
for (unsigned a = 0; a < entries.size(); a++)
{
// Skip folders
if (entries[a]->getType() == EntryType::folderType())
continue;
//.........这里部分代码省略.........
示例13: write
// -----------------------------------------------------------------------------
// Writes the pod archive to a MemChunk
// Returns true if successful, false otherwise
// -----------------------------------------------------------------------------
bool PodArchive::write(MemChunk& mc, bool update)
{
// Get all entries
vector<ArchiveEntry*> entries;
putEntryTreeAsList(entries);
// Process entries
int ndirs = 0;
uint32_t data_size = 0;
for (auto& entry : entries)
{
if (entry->type() == EntryType::folderType())
ndirs++;
else
data_size += entry->size();
}
// Init MemChunk
mc.clear();
mc.reSize(4 + 80 + (entries.size() * 40) + data_size, false);
LOG_MESSAGE(5, "MC size %d", mc.size());
// Write no. entries
uint32_t n_entries = entries.size() - ndirs;
LOG_MESSAGE(5, "n_entries %d", n_entries);
mc.write(&n_entries, 4);
// Write id
LOG_MESSAGE(5, "id %s", id_);
mc.write(id_, 80);
// Write directory
FileEntry fe;
fe.offset = 4 + 80 + (n_entries * 40);
for (auto& entry : entries)
{
if (entry->type() == EntryType::folderType())
continue;
// Name
memset(fe.name, 0, 32);
string path = entry->path(true);
path.Replace("/", "\\");
path = path.AfterFirst('\\');
// LOG_MESSAGE(2, path);
memcpy(fe.name, CHR(path), path.Len());
// Size
fe.size = entry->size();
// Write directory entry
mc.write(fe.name, 32);
mc.write(&fe.size, 4);
mc.write(&fe.offset, 4);
LOG_MESSAGE(
5,
"entry %s: old=%d new=%d size=%d",
fe.name,
entry->exProp("Offset").intValue(),
fe.offset,
entry->size());
// Next offset
fe.offset += fe.size;
}
// Write entry data
for (auto& entry : entries)
if (entry->type() != EntryType::folderType())
mc.write(entry->rawData(), entry->size());
return true;
}
示例14: write
/* PakArchive::write
* Writes the pak archive to a MemChunk
* Returns true if successful, false otherwise
*******************************************************************/
bool PakArchive::write(MemChunk& mc, bool update)
{
// Clear current data
mc.clear();
// Get archive tree as a list
vector<ArchiveEntry*> entries;
getEntryTreeAsList(entries);
// Process entry list
long dir_offset = 12;
long dir_size = 0;
for (unsigned a = 0; a < entries.size(); a++)
{
// Ignore folder entries
if (entries[a]->getType() == EntryType::folderType())
continue;
// Increment directory offset and size
dir_offset += entries[a]->getSize();
dir_size += 64;
}
// Init data size
mc.reSize(dir_offset + dir_size, false);
// Write header
char pack[4] = { 'P', 'A', 'C', 'K' };
mc.seek(0, SEEK_SET);
mc.write(pack, 4);
mc.write(&dir_offset, 4);
mc.write(&dir_size, 4);
// Write directory
mc.seek(dir_offset, SEEK_SET);
long offset = 12;
for (unsigned a = 0; a < entries.size(); a++)
{
// Skip folders
if (entries[a]->getType() == EntryType::folderType())
continue;
// Update entry
if (update)
{
entries[a]->setState(0);
entries[a]->exProp("Offset") = (int)offset;
}
// Check entry name
string name = entries[a]->getPath(true);
name.Remove(0, 1); // Remove leading /
if (name.Len() > 56)
{
wxLogMessage("Warning: Entry %s path is too long (> 56 characters), putting it in the root directory", name);
wxFileName fn(name);
name = fn.GetFullName();
if (name.Len() > 56)
name.Truncate(56);
}
// Write entry name
char name_data[56];
memset(name_data, 0, 56);
memcpy(name_data, CHR(name), name.Length());
mc.write(name_data, 56);
// Write entry offset
mc.write(&offset, 4);
// Write entry size
long size = entries[a]->getSize();
mc.write(&size, 4);
// Increment/update offset
offset += size;
}
// Write entry data
mc.seek(12, SEEK_SET);
for (unsigned a = 0; a < entries.size(); a++)
{
// Skip folders
if (entries[a]->getType() == EntryType::folderType())
continue;
// Write data
mc.write(entries[a]->getData(), entries[a]->getSize());
}
return true;
}
示例15: write
/* LfdArchive::write
* Writes the lfd archive to a MemChunk
* Returns true if successful, false otherwise
*******************************************************************/
bool LfdArchive::write(MemChunk& mc, bool update)
{
// Determine total size
uint32_t dir_size = (numEntries() + 1)<<4;
uint32_t total_size = dir_size;
ArchiveEntry* entry = NULL;
for (uint32_t l = 0; l < numEntries(); l++)
{
entry = getEntry(l);
total_size += 16;
setEntryOffset(entry, total_size);
if (update)
{
entry->setState(0);
entry->exProp("Offset") = (int)total_size;
}
total_size += entry->getSize();
}
// Clear/init MemChunk
mc.clear();
mc.seek(0, SEEK_SET);
mc.reSize(total_size);
// Variables
char type[5] = "RMAP";
char name[9] = "resource";
size_t size = wxINT32_SWAP_ON_BE(numEntries()<<4);
// Write the resource map first
mc.write(type, 4);
mc.write(name, 8);
mc.write(&size,4);
for (uint32_t l = 0; l < numEntries(); l++)
{
entry = getEntry(l);
for (int t = 0; t < 5; ++t) type[t] = 0;
for (int n = 0; n < 9; ++n) name[n] = 0;
size = wxINT32_SWAP_ON_BE(entry->getSize());
wxFileName fn(entry->getName());
for (size_t c = 0; c < fn.GetName().length() && c < 9; c++)
name[c] = fn.GetName()[c];
for (size_t c = 0; c < fn.GetExt().length() && c < 5; c++)
type[c] = fn.GetExt()[c];
mc.write(type, 4);
mc.write(name, 8);
mc.write(&size,4);
}
// Write the lumps
for (uint32_t l = 0; l < numEntries(); l++)
{
entry = getEntry(l);
for (int t = 0; t < 5; ++t) type[t] = 0;
for (int n = 0; n < 9; ++n) name[n] = 0;
size = wxINT32_SWAP_ON_BE(entry->getSize());
wxFileName fn(entry->getName());
for (size_t c = 0; c < fn.GetName().length() && c < 9; c++)
name[c] = fn.GetName()[c];
for (size_t c = 0; c < fn.GetExt().length() && c < 5; c++)
type[c] = fn.GetExt()[c];
mc.write(type, 4);
mc.write(name, 8);
mc.write(&size,4);
mc.write(entry->getData(), entry->getSize());
}
return true;
}