Edit
| 247 | |
| 248 | // Edit |
| 249 | void GobArchive::addFile(const char* fileName, const char* filePath) |
| 250 | { |
| 251 | FileStream file; |
| 252 | if (!file.open(filePath, Stream::MODE_READ)) |
| 253 | { |
| 254 | return; |
| 255 | } |
| 256 | const size_t len = file.getSize(); |
| 257 | const u32 newId = m_fileList.MASTERN; |
| 258 | m_fileList.MASTERN++; |
| 259 | GOB_Entry_t* newEntries = new GOB_Entry_t[m_fileList.MASTERN]; |
| 260 | memcpy(newEntries, m_fileList.entries, sizeof(GOB_Entry_t) * newId); |
| 261 | m_fileList.entries = newEntries; |
| 262 | |
| 263 | GOB_Entry_t* newFile = &m_fileList.entries[newId]; |
| 264 | memset(newFile, 0, sizeof(GOB_Entry_t)); |
| 265 | newFile->IX = newId > 0 ? m_fileList.entries[newId - 1].IX + m_fileList.entries[newId - 1].LEN : sizeof(GOB_Header_t); |
| 266 | newFile->LEN = u32(len); |
| 267 | strcpy(newFile->NAME, fileName); |
| 268 | m_header.MASTERX += newFile->LEN; |
| 269 | |
| 270 | // Read all of the file data. |
| 271 | std::vector<std::vector<u8>> fileData(m_fileList.MASTERN); |
| 272 | if (m_file.open(m_archivePath, Stream::MODE_READ) && m_fileList.MASTERN >= 1) |
| 273 | { |
| 274 | for (u32 f = 0; f < m_fileList.MASTERN - 1; f++) |
| 275 | { |
| 276 | fileData[f].resize(m_fileList.entries[f].LEN); |
| 277 | m_file.seek(m_fileList.entries[f].IX); |
| 278 | m_file.readBuffer(fileData[f].data(), m_fileList.entries[f].LEN); |
| 279 | } |
| 280 | m_file.close(); |
| 281 | |
| 282 | fileData[newId].resize(len); |
| 283 | file.readBuffer(fileData[newId].data(), (u32)len); |
| 284 | file.close(); |
| 285 | } |
| 286 | |
| 287 | // Now write the new file. |
| 288 | if (m_file.open(m_archivePath, Stream::MODE_WRITE)) |
| 289 | { |
| 290 | m_file.writeBuffer(&m_header, sizeof(GOB_Header_t)); |
| 291 | for (u32 f = 0; f < m_fileList.MASTERN; f++) |
| 292 | { |
| 293 | m_file.writeBuffer(fileData[f].data(), m_fileList.entries[f].LEN); |
| 294 | } |
| 295 | assert(m_file.getLoc() == m_header.MASTERX); |
| 296 | m_file.writeBuffer(&m_fileList.MASTERN, sizeof(u32)); |
| 297 | m_file.writeBuffer(m_fileList.entries, sizeof(GOB_Entry_t), m_fileList.MASTERN); |
| 298 | m_file.close(); |
| 299 | } |
| 300 | } |
nothing calls this directly
no test coverage detected