| 112 | |
| 113 | namespace inst::zip { |
| 114 | bool extractFile(const std::string filename, const std::string destination) { |
| 115 | unzFile unz = unzOpen(filename.c_str()); |
| 116 | |
| 117 | int i = 0; |
| 118 | for (;;) { |
| 119 | int code; |
| 120 | if (i == 0) { |
| 121 | code = unzGoToFirstFile(unz); |
| 122 | } else { |
| 123 | code = unzGoToNextFile(unz); |
| 124 | } |
| 125 | i++; |
| 126 | |
| 127 | if (code == UNZ_END_OF_LIST_OF_FILE) { |
| 128 | break; |
| 129 | } else { |
| 130 | unz_file_pos pos; |
| 131 | unzGetFilePos(unz, &pos); |
| 132 | } |
| 133 | |
| 134 | unz_file_info_s * fileInfo = _getFileInfo(unz); |
| 135 | |
| 136 | std::string fileName = destination; |
| 137 | fileName += _getFullFileName(unz, fileInfo); |
| 138 | |
| 139 | if (fileName.back() != '/') { |
| 140 | int result = _extractFile(fileName.c_str(), unz, fileInfo); |
| 141 | if (result < 0) { |
| 142 | free(fileInfo); |
| 143 | unzClose(unz); |
| 144 | return false; |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | free(fileInfo); |
| 149 | } |
| 150 | |
| 151 | if (i <= 0) { |
| 152 | unzClose(unz); |
| 153 | return false; |
| 154 | } |
| 155 | |
| 156 | unzClose(unz); |
| 157 | return true; |
| 158 | } |
| 159 | } |
no test coverage detected