Commit 70f4ee2a authored by Ronan Abhamon's avatar Ronan Abhamon

fix(FileExtractor): many fixes

parent 386f1130
...@@ -31,40 +31,6 @@ ...@@ -31,40 +31,6 @@
using namespace std; using namespace std;
static const char *minizipErrorToString (int error) {
switch (error) {
case MZ_OK:
return "ok";
case MZ_STREAM_ERROR:
return "stream error";
case MZ_DATA_ERROR:
return "data error";
case MZ_MEM_ERROR:
return "memory error";
case MZ_END_OF_LIST:
return "end of list";
case MZ_END_OF_STREAM:
return "end of stream";
case MZ_PARAM_ERROR:
return "param error";
case MZ_FORMAT_ERROR:
return "format error";
case MZ_INTERNAL_ERROR:
return "internal error";
case MZ_CRC_ERROR:
return "crc error";
case MZ_CRYPT_ERROR:
return "crypt error";
case MZ_EXIST_ERROR:
return "exist error";
case MZ_PASSWORD_ERROR:
return "password error";
}
Q_ASSERT(false);
return "";
}
static int openMinizipStream (void **stream, const char *filePath) { static int openMinizipStream (void **stream, const char *filePath) {
*stream = nullptr; *stream = nullptr;
if (!mz_stream_bzip_create(stream)) if (!mz_stream_bzip_create(stream))
...@@ -185,8 +151,8 @@ void FileExtractor::clean () { ...@@ -185,8 +151,8 @@ void FileExtractor::clean () {
} }
void FileExtractor::emitExtractFailed (int error) { void FileExtractor::emitExtractFailed (int error) {
qWarning() << QStringLiteral("Unable to open extract file: `%1` (%2).") qWarning() << QStringLiteral("Unable to extract file: `%1` (code: %2).")
.arg(mFile).arg(minizipErrorToString(error)); .arg(mFile).arg(error);
mDestinationFile.remove(); mDestinationFile.remove();
clean(); clean();
emit extractFailed(); emit extractFailed();
...@@ -208,18 +174,13 @@ void FileExtractor::emitOutputError () { ...@@ -208,18 +174,13 @@ void FileExtractor::emitOutputError () {
void FileExtractor::handleExtraction () { void FileExtractor::handleExtraction () {
char buffer[4096]; char buffer[4096];
int32_t readBytes = mz_stream_bzip_read(mStream, buffer, sizeof buffer); int32_t readBytes = mz_stream_bzip_read(mStream, buffer, sizeof buffer);
switch (readBytes) { if (readBytes == 0)
case MZ_OK: emitExtractFinished();
break; else if (readBytes < 0)
case MZ_END_OF_STREAM: emitExtractFailed(readBytes);
emitExtractFinished(); else {
return; setReadBytes(mReadBytes + readBytes);
default: if (mDestinationFile.write(buffer, sizeof buffer) == -1)
emitExtractFailed(readBytes); emitOutputError();
return;
} }
setReadBytes(readBytes);
if (mDestinationFile.write(buffer, sizeof buffer) == -1)
emitOutputError();
} }
...@@ -48,7 +48,7 @@ signals: ...@@ -48,7 +48,7 @@ signals:
void totalBytesChanged (qint64 totalBytes); void totalBytesChanged (qint64 totalBytes);
void extractingChanged (bool extracting); void extractingChanged (bool extracting);
void extractFinished (); void extractFinished ();
void extractFailed(); void extractFailed ();
private: private:
QString getFile () const; QString getFile () const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment