| 44 | } |
| 45 | |
| 46 | bool ZipArchive::open(const char *archivePath) |
| 47 | { |
| 48 | m_curFile = INVALID_FILE; |
| 49 | m_entryCount = 0; |
| 50 | m_fileOffset = 0; |
| 51 | m_tempBuffer = nullptr; |
| 52 | m_tempBufferSize = 0; |
| 53 | |
| 54 | struct zip_t* zip = zip_open(archivePath, 0, 'r'); |
| 55 | if (!zip) |
| 56 | { |
| 57 | TFE_System::logWrite(LOG_ERROR, "zipArchive", "Cannot open Zip Archive '%s'", archivePath); |
| 58 | return false; |
| 59 | } |
| 60 | |
| 61 | // Read the directory. |
| 62 | m_entryCount = zip_total_entries(zip); |
| 63 | if (m_entryCount <= 0) |
| 64 | { |
| 65 | TFE_System::logWrite(LOG_ERROR, "zipArchive", "Zip Archive '%s' is empty.", archivePath); |
| 66 | zip_close(zip); |
| 67 | return false; |
| 68 | } |
| 69 | m_entries = new ZipEntry[m_entryCount]; |
| 70 | |
| 71 | for (s32 i = 0; i < m_entryCount; i++) |
| 72 | { |
| 73 | if (zip_entry_openbyindex(zip, i) != 0) |
| 74 | { |
| 75 | TFE_System::logWrite(LOG_ERROR, "zipArchive", "Cannot read entry '%d' from archive '%s'", i, archivePath); |
| 76 | zip_close(zip); |
| 77 | return false; |
| 78 | } |
| 79 | |
| 80 | m_entries[i].isDir = (zip_entry_isdir(zip) == 1); |
| 81 | m_entries[i].name = zip_entry_name(zip); |
| 82 | m_entries[i].length = (size_t)zip_entry_size(zip); |
| 83 | zip_entry_close(zip); |
| 84 | } |
| 85 | zip_close(zip); |
| 86 | |
| 87 | strcpy(m_archivePath, archivePath); |
| 88 | m_fileHandle = nullptr; |
| 89 | |
| 90 | return true; |
| 91 | } |
| 92 | |
| 93 | void ZipArchive::close() |
| 94 | { |
no test coverage detected