Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvng <viktor.govako@gmail.com>2012-03-02 03:58:49 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:36:10 +0300
commita58e260738ea973061d5108de17b35b3718f47f9 (patch)
tree03d9fa3982be52fdd7e3322fdd1afd79db83d8ca /coding/zip_reader.cpp
parent0fe9a881949fdc6fc3cff14ecad3873b9b0b8618 (diff)
Minor changes with better exception handling.
Diffstat (limited to 'coding/zip_reader.cpp')
-rw-r--r--coding/zip_reader.cpp51
1 files changed, 20 insertions, 31 deletions
diff --git a/coding/zip_reader.cpp b/coding/zip_reader.cpp
index 84d69f24ca..806e4d4b37 100644
--- a/coding/zip_reader.cpp
+++ b/coding/zip_reader.cpp
@@ -93,38 +93,27 @@ void ZipFileReader::UnzipFile(string const & zipContainer, string const & fileIn
MY_SCOPE_GUARD(currentFileGuard, bind(&unzCloseCurrentFile, zip));
static size_t const BUF_SIZE = 1024 * 50;
- char * buf = new char[BUF_SIZE];
- try
- {
- FileWriter outFile(outFilePath);
-
- int pos = 0;
- int readBytes;
-
- while (true)
- {
- readBytes = unzReadCurrentFile(zip, buf, BUF_SIZE);
- if (readBytes > 0)
- outFile.Write(buf, static_cast<size_t>(readBytes));
- else if (readBytes < 0)
- MYTHROW(InvalidZipException, ("Error", readBytes, "while unzipping", fileInZip, "from", zipContainer));
- else
- break;
-
- pos += readBytes;
-
- if (progressFn)
- progressFn(fileInfo.uncompressed_size, pos);
- }
- }
- catch (Exception const & e)
+ vector<char> buf(BUF_SIZE);
+
+ FileWriter outFile(outFilePath);
+ MY_SCOPE_GUARD(outFileGuard, bind(&FileWriter::DeleteFileX, cref(outFilePath)));
+
+ int pos = 0;
+ while (true)
{
- delete[] buf;
- // Delete unfinished output file
- FileWriter::DeleteFileX(outFilePath);
- // Rethrow exception - we've failed
- throw;
+ int const readBytes = unzReadCurrentFile(zip, &buf[0], BUF_SIZE);
+ if (readBytes > 0)
+ outFile.Write(&buf[0], static_cast<size_t>(readBytes));
+ else if (readBytes < 0)
+ MYTHROW(InvalidZipException, ("Error", readBytes, "while unzipping", fileInZip, "from", zipContainer));
+ else
+ break;
+
+ pos += readBytes;
+
+ if (progressFn)
+ progressFn(fileInfo.uncompressed_size, pos);
}
- delete[] buf;
+ outFileGuard.release();
}