comparison Core/Compression/ZipWriter.cpp @ 1582:bd1889029cbb

encoding of exceptions
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 25 Aug 2015 17:39:38 +0200
parents 6e7e5ed91c2d
children b1291df2f780
comparison
equal deleted inserted replaced
1581:357c4bb15701 1582:bd1889029cbb
42 #include <boost/filesystem.hpp> 42 #include <boost/filesystem.hpp>
43 #include <boost/date_time/posix_time/posix_time.hpp> 43 #include <boost/date_time/posix_time/posix_time.hpp>
44 44
45 #include "../../Resources/ThirdParty/minizip/zip.h" 45 #include "../../Resources/ThirdParty/minizip/zip.h"
46 #include "../OrthancException.h" 46 #include "../OrthancException.h"
47 #include "../Logging.h"
47 48
48 49
49 static void PrepareFileInfo(zip_fileinfo& zfi) 50 static void PrepareFileInfo(zip_fileinfo& zfi)
50 { 51 {
51 memset(&zfi, 0, sizeof(zfi)); 52 memset(&zfi, 0, sizeof(zfi));
120 return; 121 return;
121 } 122 }
122 123
123 if (path_.size() == 0) 124 if (path_.size() == 0)
124 { 125 {
125 throw OrthancException("Please call SetOutputPath() before creating the file"); 126 LOG(ERROR) << "Please call SetOutputPath() before creating the file";
127 throw OrthancException(ErrorCode_BadSequenceOfCalls);
126 } 128 }
127 129
128 hasFileInZip_ = false; 130 hasFileInZip_ = false;
129 131
130 int mode = APPEND_STATUS_CREATE; 132 int mode = APPEND_STATUS_CREATE;
163 165
164 void ZipWriter::SetCompressionLevel(uint8_t level) 166 void ZipWriter::SetCompressionLevel(uint8_t level)
165 { 167 {
166 if (level >= 10) 168 if (level >= 10)
167 { 169 {
168 throw OrthancException("ZIP compression level must be between 0 (no compression) and 9 (highest compression"); 170 LOG(ERROR) << "ZIP compression level must be between 0 (no compression) and 9 (highest compression)";
171 throw OrthancException(ErrorCode_ParameterOutOfRange);
169 } 172 }
170 173
171 Close(); 174 Close();
172 compressionLevel_ = level; 175 compressionLevel_ = level;
173 } 176 }
222 225
223 void ZipWriter::Write(const char* data, size_t length) 226 void ZipWriter::Write(const char* data, size_t length)
224 { 227 {
225 if (!hasFileInZip_) 228 if (!hasFileInZip_)
226 { 229 {
227 throw OrthancException("Call first OpenFile()"); 230 LOG(ERROR) << "Call first OpenFile()";
231 throw OrthancException(ErrorCode_BadSequenceOfCalls);
228 } 232 }
229 233
230 const size_t maxBytesInAStep = std::numeric_limits<int32_t>::max(); 234 const size_t maxBytesInAStep = std::numeric_limits<int32_t>::max();
231 235
232 while (length > 0) 236 while (length > 0)