diff --git a/coding/coding_tests/zip_creator_test.cpp b/coding/coding_tests/zip_creator_test.cpp index 9b96acafee..9f03d1d57e 100644 --- a/coding/coding_tests/zip_creator_test.cpp +++ b/coding/coding_tests/zip_creator_test.cpp @@ -17,10 +17,12 @@ void CreateAndTestZip(string const & filePath, string const & zipPath) { TEST(CreateZipFromPathDeflatedAndDefaultCompression(filePath, zipPath), ()); - vector files; + ZipFileReader::FileListT files; ZipFileReader::FilesList(zipPath, files); + TEST_EQUAL(files[0].second, FileReader(filePath).Size(), ()); + string const unzippedFile = "unzipped.tmp"; - ZipFileReader::UnzipFile(zipPath, files[0], unzippedFile); + ZipFileReader::UnzipFile(zipPath, files[0].first, unzippedFile); TEST(my::IsEqualFiles(filePath, unzippedFile), ()); TEST(my::DeleteFileX(filePath), ()); diff --git a/coding/coding_tests/zip_reader_test.cpp b/coding/coding_tests/zip_reader_test.cpp index ca30cd6cc4..b07a1d0c52 100644 --- a/coding/coding_tests/zip_reader_test.cpp +++ b/coding/coding_tests/zip_reader_test.cpp @@ -104,13 +104,16 @@ UNIT_TEST(ZipFilesList) try { - vector files; + ZipFileReader::FileListT files; ZipFileReader::FilesList(ZIPFILE, files); TEST_EQUAL(files.size(), 3, ()); - TEST_EQUAL(files[0], "1.txt", ()); - TEST_EQUAL(files[1], "2.txt", ()); - TEST_EQUAL(files[2], "3.ttt", ()); + TEST_EQUAL(files[0].first, "1.txt", ()); + TEST_EQUAL(files[0].second, 2, ()); + TEST_EQUAL(files[1].first, "2.txt", ()); + TEST_EQUAL(files[1].second, 2, ()); + TEST_EQUAL(files[2].first, "3.ttt", ()); + TEST_EQUAL(files[2].second, 2, ()); } catch (std::exception const & e) { @@ -119,7 +122,7 @@ UNIT_TEST(ZipFilesList) try { - vector files; + ZipFileReader::FileListT files; ZipFileReader::FilesList(ZIPFILE_INVALID, files); TEST(false, ("This test shouldn't be reached - exception should be thrown")); } @@ -164,19 +167,19 @@ UNIT_TEST(ZipExtract) } TEST(ZipFileReader::IsZip(ZIPFILE), ("Not a zip file")); - vector files; + ZipFileReader::FileListT files; ZipFileReader::FilesList(ZIPFILE, files); TEST_EQUAL(files.size(), 2, ()); string const OUTFILE = "out.tmp"; string s; - ZipFileReader::UnzipFile(ZIPFILE, files[0], OUTFILE); + ZipFileReader::UnzipFile(ZIPFILE, files[0].first, OUTFILE); { FileReader(OUTFILE).ReadAsString(s); } TEST_EQUAL(s, "aaaaaaaaaa\x0A", ()); // OUTFILE should be rewritten correctly in the next lines - ZipFileReader::UnzipFile(ZIPFILE, files[1], OUTFILE); + ZipFileReader::UnzipFile(ZIPFILE, files[1].first, OUTFILE); { FileReader(OUTFILE).ReadAsString(s); } @@ -195,18 +198,18 @@ UNIT_TEST(ZipFileSizes) } TEST(ZipFileReader::IsZip(ZIPFILE), ("Not a zip file")); - vector files; + ZipFileReader::FileListT files; ZipFileReader::FilesList(ZIPFILE, files); TEST_EQUAL(files.size(), 2, ()); { - ZipFileReader file(ZIPFILE, files[0]); + ZipFileReader file(ZIPFILE, files[0].first); TEST_EQUAL(file.Size(), 6, ()); TEST_EQUAL(file.UncompressedSize(), 11, ()); } { - ZipFileReader file(ZIPFILE, files[1]); + ZipFileReader file(ZIPFILE, files[1].first); TEST_EQUAL(file.Size(), 8, ()); TEST_EQUAL(file.UncompressedSize(), 9, ()); } diff --git a/coding/zip_reader.cpp b/coding/zip_reader.cpp index 843d9ef8b5..7bafa65595 100644 --- a/coding/zip_reader.cpp +++ b/coding/zip_reader.cpp @@ -53,10 +53,11 @@ void ZipFileReader::FilesList(string const & zipContainer, FileListT & filesList do { char fileName[256]; - if (UNZ_OK != unzGetCurrentFileInfo64(zip, NULL, fileName, ARRAY_SIZE(fileName), NULL, 0, NULL, 0)) + unz_file_info64 fileInfo; + if (UNZ_OK != unzGetCurrentFileInfo64(zip, &fileInfo, fileName, ARRAY_SIZE(fileName), NULL, 0, NULL, 0)) MYTHROW(LocateZipException, ("Can't get file name inside zip", zipContainer)); - filesList.push_back(fileName); + filesList.push_back(make_pair(fileName, fileInfo.uncompressed_size)); } while (UNZ_OK == unzGoToNextFile(zip)); } diff --git a/coding/zip_reader.hpp b/coding/zip_reader.hpp index 088ee2651a..a9070cee39 100644 --- a/coding/zip_reader.hpp +++ b/coding/zip_reader.hpp @@ -14,7 +14,8 @@ private: public: typedef function ProgressFn; - typedef vector FileListT; + /// Contains file name inside zip and it's uncompressed size + typedef vector > FileListT; DECLARE_EXCEPTION(OpenZipException, OpenException); DECLARE_EXCEPTION(LocateZipException, OpenException); diff --git a/map/framework.cpp b/map/framework.cpp index e5d1255830..0bb715380f 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -545,14 +545,14 @@ bool Framework::AddBookmarksFile(string const & filePath) { try { - vector files; + ZipFileReader::FileListT files; ZipFileReader::FilesList(filePath, files); string kmlFileName; - for (size_t i = 0; i < files.size();++i) + for (size_t i = 0; i < files.size(); ++i) { - if (GetFileExt(files[i]) == BOOKMARKS_FILE_EXTENSION) + if (GetFileExt(files[i].first) == BOOKMARKS_FILE_EXTENSION) { - kmlFileName = files[i]; + kmlFileName = files[i].first; break; } } diff --git a/map/map_tests/kmz_unarchive_test.cpp b/map/map_tests/kmz_unarchive_test.cpp index 8d197a04b5..0446053d08 100644 --- a/map/map_tests/kmz_unarchive_test.cpp +++ b/map/map_tests/kmz_unarchive_test.cpp @@ -12,14 +12,14 @@ UNIT_TEST(Open_KMZ_Test) { string const KMZFILE = GetPlatform().WritablePathForFile("test.kmz"); - vector files; + ZipFileReader::FileListT files; ZipFileReader::FilesList(KMZFILE, files); bool isKMLinZip = false; for (int i = 0; i < files.size();++i) { - if (files[i] == "doc.kml") + if (files[i].first == "doc.kml") { isKMLinZip = true; break;