* Creates a CAT file stream. A CAT file starts with an index of the * offset and size of every file contained within. Each file consists * of a filename followed by its contents. * @param path Full path to CAT file. */
| 30 | * @param path Full path to CAT file. |
| 31 | */ |
| 32 | CatFile::CatFile(const char *path) : std::ifstream(path, std::ios::in | std::ios::binary), _amount(0), _offset(0), _size(0) |
| 33 | { |
| 34 | if (!this) |
| 35 | return; |
| 36 | |
| 37 | |
| 38 | // Get amount of files |
| 39 | read((char*)&_amount, sizeof(_amount)); |
| 40 | |
| 41 | _amount = (unsigned int)SDL_SwapLE32(_amount); |
| 42 | _amount /= 2 * sizeof(_amount); |
| 43 | |
| 44 | // Get object offsets |
| 45 | seekg(0, std::ios::beg); |
| 46 | |
| 47 | _offset = new unsigned int[_amount]; |
| 48 | _size = new unsigned int[_amount]; |
| 49 | |
| 50 | for (unsigned int i = 0; i < _amount; ++i) |
| 51 | { |
| 52 | read((char*)&_offset[i], sizeof(*_offset)); |
| 53 | _offset[i] = (unsigned int)SDL_SwapLE32(_offset[i]); |
| 54 | read((char*)&_size[i], sizeof(*_size)); |
| 55 | _size[i] = (unsigned int)SDL_SwapLE32(_size[i]); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Frees associated memory. |
nothing calls this directly
no outgoing calls
no test coverage detected