]> Some of my projects - anidbudpclient.git/commitdiff
Do not stall when hashing a 0 length file.
authorAPTX <marek321@gmail.com>
Mon, 27 Feb 2012 17:58:53 +0000 (18:58 +0100)
committerAPTX <marek321@gmail.com>
Mon, 27 Feb 2012 17:58:53 +0000 (18:58 +0100)
hash.cpp
hashproducer.cpp

index f8c46e3059cce5f05f5b69a9657543f07822d95a..c540ce66b1da05daead61da81609f00ba9f7a9dc 100644 (file)
--- a/hash.cpp
+++ b/hash.cpp
@@ -108,11 +108,11 @@ void Hash::reportProgress(qint64 read, qint64 total)
        if (!fileQueue.first())
                return;
 
-       int filePercent = (read * 100) / total;
+       int filePercent = total ? (read * 100) / total : 100;
        emit fileProgress(filePercent);
        emit fileQueue.first()->progress(filePercent);
 
-       int totalPercent = ((hashedFileSize + read) * 100) / totalFileSize;
+       int totalPercent = totalFileSize ? ((hashedFileSize + read) * 100) / totalFileSize : 100;
        emit progress(totalPercent);
 }
 
index c81869c08075fb244e25a054b6a1ba4e8a80998d..473900fddd3a7d36136c4385e79f2bc8d5c07a37 100644 (file)
@@ -60,13 +60,13 @@ qDebug() << "File exists, opening";
 #endif
                        if (file.open(QIODevice::ReadOnly))
                        {
-                               while (!file.atEnd())
+                               do
                                {
                                        if (abort)
                                                return;
                                        QByteArray data = file.read(ED2K_PART_SIZE);
                                        while (!(buffer->put(data, file.atEnd()) || abort));
-                               }
+                               } while (!file.atEnd());
                        }
                }