/* MemChunk::MemChunk * MemChunk class constructor taking initial data *******************************************************************/ MemChunk::MemChunk(const uint8_t* data, uint32_t size) { // Init variables this->cur_ptr = 0; this->data = NULL; this->size = size; // Load given data importMem(data, size); }
/* ArchiveEntry::importMemChunk * Imports data from a MemChunk object into the entry, resizing it * and clearing any currently existing data. * Returns false if the MemChunk has no data, or true otherwise. *******************************************************************/ bool ArchiveEntry::importMemChunk(MemChunk& mc) { // Check that the given MemChunk has data if (mc.hasData()) { // Copy the data from the MemChunk into the entry return importMem(mc.getData(), mc.getSize()); } else return false; }
/* ArchiveEntry::importEntry * Imports data from another entry into this entry, resizing it * and clearing any currently existing data. * Returns false if the entry is null, true otherwise *******************************************************************/ bool ArchiveEntry::importEntry(ArchiveEntry* entry) { // Check if locked if (locked) { Global::error = "Entry is locked"; return false; } // Check parameters if (!entry) return false; // Copy entry data importMem(entry->getData(), entry->getSize()); return true; }
/* ArchiveEntry::importFile * Loads a portion of a file into the entry, overwriting any existing * data currently in the entry. A size of 0 means load from the * offset to the end of the file. * Returns false if the file does not exist or the given offset/size * are out of bounds, otherwise returns true. *******************************************************************/ bool ArchiveEntry::importFile(string filename, uint32_t offset, uint32_t size) { // Check if locked if (locked) { Global::error = "Entry is locked"; return false; } // Open the file wxFile file(filename); // Check that it opened ok if (!file.IsOpened()) { Global::error = "Unable to open file for reading"; return false; } // Get the size to read, if zero if (size == 0) size = file.Length() - offset; // Check offset/size bounds if (offset + size > file.Length()) return false; // Create temporary buffer and load file contents uint8_t* temp_buf = new uint8_t[size]; file.Seek(offset, wxFromStart); file.Read(temp_buf, size); // Import data into entry importMem(temp_buf, size); // Delete temp buffer delete[] temp_buf; return true; }