| 23 | } |
| 24 | |
| 25 | bool ZipDataProvider::openArchive(const UString &path, bool write) |
| 26 | { |
| 27 | this->zipPath = path; |
| 28 | writing = write; |
| 29 | if (write) |
| 30 | { |
| 31 | auto outPath = fs::path(path); |
| 32 | auto outDir = outPath.parent_path(); |
| 33 | if (!outDir.empty()) |
| 34 | { |
| 35 | fs::create_directories(outDir); |
| 36 | } |
| 37 | if (!mz_zip_writer_init_file(&archive, path.c_str(), 0)) |
| 38 | { |
| 39 | LogWarning("Failed to init zip file \"%s\" for writing", path); |
| 40 | return false; |
| 41 | } |
| 42 | } |
| 43 | else |
| 44 | { |
| 45 | if (!mz_zip_reader_init_file(&archive, path.c_str(), 0)) |
| 46 | { |
| 47 | LogWarning("Failed to init zip file \"%s\" for reading", path); |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | unsigned fileCount = mz_zip_reader_get_num_files(&archive); |
| 52 | for (unsigned idx = 0; idx < fileCount; idx++) |
| 53 | { |
| 54 | unsigned filenameLength = mz_zip_reader_get_filename(&archive, idx, nullptr, 0); |
| 55 | up<char[]> data(new char[(unsigned int)filenameLength]); |
| 56 | mz_zip_reader_get_filename(&archive, idx, data.get(), filenameLength); |
| 57 | std::string filename(data.get()); |
| 58 | fileLookup[filename] = idx; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | return true; |
| 63 | } |
| 64 | bool ZipDataProvider::readDocument(const UString &filename, UString &result) |
| 65 | { |
| 66 |
no test coverage detected